Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Make STopicId available in subscriber callbacks #1719

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

KerstinKeller
Copy link
Contributor

  • Add new Callback Type which includes STopicId (ecal_callback.h)
  • Remove topic_name and topic_id from memfile_pool
  • Subgate applies Payload::Topic

TODO: take care of PID for TCP and UDP layer.

Description

We don't yet have the information in callbacks about who sent a message, we only receive the topic name. This PR fixes this in a way that callbacks receive an STopicID containing both topic name and additional information (unique sender id).

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

ecal/core/src/readwrite/shm/ecal_reader_shm.cpp Outdated Show resolved Hide resolved
@KerstinKeller KerstinKeller added the cherry-pick-to-NONE Don't cherry-pick these changes label Aug 26, 2024
@KerstinKeller
Copy link
Contributor Author

PID is currently not transferred correctly in UDP und TCP layer.
This information can be passed via CUDPReaderLayer, CTCTReaderLayer.

Otherwise things look good. Might consider some renaming for the future, but all to be discussed.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/callback_topicid_test.cpp Outdated Show resolved Hide resolved
ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp Outdated Show resolved Hide resolved
@rex-schilasky
Copy link
Contributor

PID is currently not transferred correctly in UDP und TCP layer. This information can be passed via CUDPReaderLayer, CTCTReaderLayer.

Otherwise things look good. Might consider some renaming for the future, but all to be discussed.

  • Callback function type renamed to ReceiveIDCallbackT
  • UDP and TCP layer transport host name and process id as well now

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

}
}
}

size_t CSHMReaderLayer::OnNewShmFileContent(const std::string& topic_name_, const std::string& topic_id_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_)
size_t CSHMReaderLayer::OnNewShmFileContent(const Payload::TopicInfo& topic_id_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'OnNewShmFileContent' can be made static [readability-convert-member-functions-to-static]

ecal/core/src/readwrite/shm/ecal_reader_shm.h:51:

-     size_t OnNewShmFileContent(const Payload::TopicInfo& topic_id_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_);
+     static size_t OnNewShmFileContent(const Payload::TopicInfo& topic_id_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_);

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

}
}
}

size_t CSHMReaderLayer::OnNewShmFileContent(const std::string& topic_name_, const std::string& topic_id_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_)
size_t CSHMReaderLayer::OnNewShmFileContent(const Payload::TopicInfo& topic_info_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'OnNewShmFileContent' can be made static [readability-convert-member-functions-to-static]

ecal/core/src/readwrite/shm/ecal_reader_shm.h:51:

-     size_t OnNewShmFileContent(const Payload::TopicInfo& topic_info_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_);
+     static size_t OnNewShmFileContent(const Payload::TopicInfo& topic_info_, const char* buf_, size_t len_, long long id_, long long clock_, long long time_, size_t hash_);


#include <atomic>
#include <thread>
#include <gtest/gtest.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include <gtest/gtest.h>
         ^

eCAL::Initialize(config, "callback_topic_id");
}

void TearDown() override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'TearDown' can be made static [readability-convert-member-functions-to-static]

Suggested change
void TearDown() override
static void TearDown() override

}
};

TEST_P(TestFixture, OnePubSub)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_P(TestFixture, OnePubSub)
TEST_P(TestFixture /*unused*/, OnePubSub /*unused*/)

EXPECT_EQ(callback_topic_id, pub_id);
}

TEST_P(TestFixture, MultiplePubSub)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_P(TestFixture, MultiplePubSub)
TEST_P(TestFixture /*unused*/, MultiplePubSub /*unused*/)

{
const int num_publishers = 4;

std::vector<eCAL::CPublisher> publishers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'publishers' is not initialized [cppcoreguidelines-init-variables]

Suggested change
std::vector<eCAL::CPublisher> publishers;
std::vector<eCAL::CPublisher> publishers = 0;


#ifndef NDEBUG
// log it
Logging::Log(log_level_debug2, std::string("CMemFileObserver started (" + topic_name_ + ", " + topic_id_ + ")"));
Logging::Log(log_level_debug2, std::string("CMemFileObserver started."));
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe log the memfile name (currently it's not, but we could make it a member variable)

Copy link
Contributor Author

@KerstinKeller KerstinKeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the adaptions.

I'm a bit undecided. The changes that you made will work, but it will introduce an incompatibility, if different eCAL versions now communicate. The callbackID will be "wrong" for anyone receiving messages send by an older eCAL version.
And what is even worse, if you will then want to look up the corresponding descriptors to this ID from the descgate, you will get missmatches, or no info.

I wonder if we can make adjustments based on what we know from registration only.
E.g. on registration layer we already receive the info... tid (our unique identifier) - relates to pid X, topic_name Y, host_name Z. ...
Thus the ecal_reader layers can keep track of the information, and based on the incoming tid fill the rest of the information. Then you do not have to send it over the layers together with the actual data.

proto_header_topic.tname = m_topic_name;
proto_header_topic.tid = m_topic_id;
proto_header_topic.pid = static_cast<int32_t>(Process::GetProcessID());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this "break compatibility" with older ecal versions? we're now filling the sample differently?

{
return std::make_tuple(false, false, true);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmhm I am not convinced. Let's pass Configs instead of tuples to the tests. We want to test based on different configs, not based on different tuples.
You can still create functions that return different Config objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this shows, that we might want to create some helper functions, like "DisableAllLayers", "EnableSHM", "EnableUDP", ... which take reference to a Config object.

- Add new Callback Type which includes STopicId (ecal_callback.h)
- Remove topic_name and topic_id from memfile_pool
- Subgate applies Payload::TopicInfo
- Provide new GetId function for publishers and subscribers (should add also for client / servers in different PR)
- Add testcases to check correct IDs are received in callbacks.
- Do not modify info being sent over the wire (for compatibility reasons). Instead modify == and < operators for STopicId.
Copy link
Contributor

@rex-schilasky rex-schilasky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

@KerstinKeller KerstinKeller merged commit 1f1a151 into master Sep 13, 2024
19 of 20 checks passed
@KerstinKeller KerstinKeller deleted the feature/topicinfo-in-callback branch September 26, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-to-NONE Don't cherry-pick these changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants