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] ported CMsgPublisher/Subscriber to v6 #1944

Merged
merged 17 commits into from
Jan 27, 2025
Merged

Conversation

rex-schilasky
Copy link
Contributor

Description

CMsgPub/Sub porting to v6.

@rex-schilasky rex-schilasky added the cherry-pick-to-NONE Don't cherry-pick these changes label Jan 24, 2025
@rex-schilasky rex-schilasky added this to the eCAL 6 milestone Jan 24, 2025
@rex-schilasky rex-schilasky marked this pull request as draft January 24, 2025 11:52
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

app/mon/mon_tui/src/main.cpp Show resolved Hide resolved
app/mon/mon_tui/src/main.cpp Show resolved Hide resolved
ecal/core/include/ecal/msg/subscriber.h Outdated Show resolved Hide resolved
ecal/core/src/pubsub/ecal_subscriber.cpp Outdated Show resolved Hide resolved
sub.AddEventCallback(eCAL::eSubscriberEvent::connected, evt_callback);
sub.AddEventCallback(eCAL::eSubscriberEvent::disconnected, evt_callback);
sub.AddEventCallback(eCAL::eSubscriberEvent::dropped, evt_callback);
eCAL::protobuf::CSubscriber<pb::People::Person> sub("person", OnEvent);
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 'sub' of type 'eCAL::protobuf::CSubscriberpb::People::Person' (aka 'CMessageSubscriber<pb::People::Person, internal::ProtobufDeserializer>') can be declared 'const' [misc-const-correctness]

Suggested change
eCAL::protobuf::CSubscriber<pb::People::Person> sub("person", OnEvent);
eCAL::protobuf::CSubscriber<pb::People::Person> const sub("person", OnEvent);

@rex-schilasky rex-schilasky marked this pull request as ready for review January 25, 2025 14:09
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

- no default constructor
- 2 constructor types with and without event callback
- no Create function
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

**/
CPublisher()
: eCAL::v5::CPublisher()
explicit CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = GetPublisherConfiguration()) : eCAL::CPublisher(topic_name_, GetDataTypeInformation(), config_)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: constructor does not initialize these fields: builder [cppcoreguidelines-pro-type-member-init]

serialization/capnproto/capnproto/include/ecal/msg/capnproto/publisher.h:172:

-       std::unique_ptr<capnp::MallocMessageBuilder>    builder;
+       std::unique_ptr<capnp::MallocMessageBuilder>    builder{};

**/
CPublisher(const std::string& topic_name_, const eCAL::Publisher::Configuration& config_ = {})
: eCAL::v5::CPublisher(topic_name_, GetDataTypeInformation(), config_)
explicit CPublisher(const std::string& topic_name_, const eCAL::PubEventCallbackT& event_callback_, const eCAL::Publisher::Configuration& config_ = GetPublisherConfiguration()) : eCAL::CPublisher(topic_name_, GetDataTypeInformation(), event_callback_, config_)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: constructor does not initialize these fields: builder [cppcoreguidelines-pro-type-member-init]

      explicit CPublisher(const std::string& topic_name_, const eCAL::PubEventCallbackT& event_callback_, const eCAL::Publisher::Configuration& config_ = GetPublisherConfiguration()) : eCAL::CPublisher(topic_name_, GetDataTypeInformation(), event_callback_, config_)
      ^

@@ -219,7 +215,8 @@ bool MeasurementContainer::PublishFrame(long long index)
{
timestamp_usecs = std::chrono::duration_cast<std::chrono::microseconds>(frame_table_[index].send_timestamp_.time_since_epoch()).count();
}
frame_table_[index].publisher_info_->publisher_.SetID(frame_table_[index].send_id_);
// this is not supported by the eCAL v6 API
//frame_table_[index].publisher_info_->publisher_.SetID(frame_table_[index].send_id_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this in any way be problematic?
So with eCAL 5, publishers will have the same ID they had when originally recording the measurement. In eCAL 6, they won't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its about the topic id for subscriber side filtering. This feature is rarely used and no way to support this in the future, it's removed on both sides (pub and sub). So in v5 I can filter out different "streams" of the the same topic on subscriber side in v6 the connection will just receive all messages and I need to implement an ID myself (for example as part of my protobuf description).

@@ -144,6 +144,9 @@ std::unique_ptr<eCAL::rec_cli::command::Record> record_command;
int main(int argc, char** argv)
{
#ifdef WIN32
(void)argc; // suppress unused warning
Copy link
Contributor

Choose a reason for hiding this comment

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

Why surpress it only for Windows? also maybe just comment in the function declaration int main(int /*argc*/, char** /*argv*/) (also this has nothing to do with this PR!!! 😏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For LINUX platform both arguments are used unfortunately and yes it's not really related but I tried to fix at least some warnings when I touched a file.

@@ -113,7 +113,7 @@ namespace eCAL
bool first_message_received; /**< Whether we received at least one Message (used for the status message)*/
eCAL::pb::SimTime::eState play_state; /**< Current state (used for the status message)*/

eCAL::protobuf::CSubscriber<eCAL::pb::SimTime> sim_time_subscriber; /**< Subscriber for getting simulation timestamps */
std::unique_ptr<eCAL::protobuf::CSubscriber<eCAL::pb::SimTime>> sim_time_subscriber; /**< Subscriber for getting simulation timestamps */
Copy link
Contributor

Choose a reason for hiding this comment

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

I kind of don't like that now we're "forcing" code to use pointers.
Do you now have to check the pointers in other locations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without a Create/Destroy interface and the removed empty default constructors I see no alternative here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to think about error handling for all communication entities (pub/sub/server/client) in case construction fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but the thing is, construction is unlikely to fail. Failure is more likely to occur during the runtime. E.g. The connections (memory files, sockets, ...) are usually not created during construction, but when we receive monitoring information about other entities in the system.
So we have to find a way to deal with this effectively.
Maybe error/event callbacks would be interesting in that case, too.

Copy link
Contributor

@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.

I just have the few minor remarks... but I guess it looks good!

**/
explicit CMsgPublisher(const std::string& topic_name_, const Publisher::Configuration& config_ = GetPublisherConfiguration()) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_)
CMsgPublisher(const std::string& topic_name_, const struct SDataTypeInformation& data_type_info_, const PubEventCallbackT& event_callback_, const Publisher::Configuration& config_ = GetPublisherConfiguration()) : CPublisher(topic_name_, data_type_info_, event_callback_, config_)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove the explicit keyword?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also why the struct keywords? They are not necessary and I would consider them bad practice in this case. (I know we have them in various places, but I already remove them when I do see them).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by next commit.

@@ -70,7 +70,7 @@ namespace eCAL
* @param config_ Optional configuration parameters.
**/
ECAL_API_EXPORTED_MEMBER
CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const PubEventCallbackT event_callback_, const Publisher::Configuration& config_ = GetPublisherConfiguration());
CPublisher(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const PubEventCallbackT& event_callback_, const Publisher::Configuration& config_ = GetPublisherConfiguration());
Copy link
Contributor

Choose a reason for hiding this comment

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

I came across this, too, and I do wonder if it was on purpose, to copy the callbacks... But wasn't sure.

struct SDataTypeInformation -> SDataTypeInformation
@rex-schilasky rex-schilasky merged commit fc0b30f into master Jan 27, 2025
21 checks passed
@rex-schilasky rex-schilasky deleted the core/v6-msg-pub-sub branch January 27, 2025 13:45
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