From 8914782aa82648d2979e55364d03ed31a9cf372e Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Wed, 16 Jul 2025 17:08:08 +0200 Subject: [PATCH 1/2] Split Listeners in DynTypesParticipant Signed-off-by: cferreiragonz --- .../dynamic_types/DynTypesParticipant.hpp | 37 +++++++++++++++++-- .../dynamic_types/DynTypesParticipant.cpp | 35 ++++++++++++------ 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp index 2fe5fbfba..18deef53e 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp @@ -71,16 +71,36 @@ class DynTypesParticipant : public rtps::SimpleParticipant std::shared_ptr create_reader( const core::ITopic& topic) override; - class DynTypesRtpsListener : public rtps::CommonParticipant::RtpsListener, - public eprosima::fastdds::dds::DomainParticipantListener + // DynTypesParticipant makes use of both RTPS and DDS listeners + + /** + * @brief This class is the RTPS Listener for DynTypesParticipant. It inherits from + * \c rtps::CommonParticipant::RtpsListener . + */ + class DynTypesRtpsListener : public rtps::CommonParticipant::RtpsListener { public: DDSPIPE_PARTICIPANTS_DllAPI explicit DynTypesRtpsListener( std::shared_ptr conf, - std::shared_ptr ddb, - std::shared_ptr internal_reader); + std::shared_ptr ddb); + + }; + + /** + * @brief This class is the DDS Listener for DynTypesParticipant. It inherits directly from + * \c fastdds::dds::DomainParticipantListener and implements the methods needed to process type objects and + * type lookup services. + */ + class DynTypesDdsListener : public eprosima::fastdds::dds::DomainParticipantListener + { + public: + + DDSPIPE_PARTICIPANTS_DllAPI + explicit DynTypesDdsListener( + std::shared_ptr type_object_reader, + core::types::ParticipantId participant_id); DDSPIPE_PARTICIPANTS_DllAPI void on_type_discovery( @@ -106,6 +126,9 @@ class DynTypesParticipant : public rtps::SimpleParticipant //! Copy of Type Object Internal Reader std::shared_ptr type_object_reader_; + //! Participant ID for informative purposes. It is stored in the CommonParticipant (RTPS) + core::types::ParticipantId participant_id_; + }; protected: @@ -114,6 +137,8 @@ class DynTypesParticipant : public rtps::SimpleParticipant eprosima::fastdds::dds::DomainParticipant* dds_participant_; + std::unique_ptr dds_participant_listener_; + //! Type Object Internal Reader std::shared_ptr type_object_reader_; @@ -121,6 +146,10 @@ class DynTypesParticipant : public rtps::SimpleParticipant DDSPIPE_PARTICIPANTS_DllAPI std::unique_ptr create_listener_() override; + //! Method to create the internal DDS participant listener + DDSPIPE_PARTICIPANTS_DllAPI + virtual std::unique_ptr create_dds_listener_(); + }; } /* namespace participants */ diff --git a/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp b/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp index cda950714..12b39b060 100644 --- a/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp @@ -96,16 +96,22 @@ std::shared_ptr DynTypesParticipant::create_reader( DynTypesParticipant::DynTypesRtpsListener::DynTypesRtpsListener( std::shared_ptr conf, - std::shared_ptr ddb, - std::shared_ptr internal_reader) + std::shared_ptr ddb) : rtps::CommonParticipant::RtpsListener( conf, ddb) - , type_object_reader_(internal_reader) { } -void DynTypesParticipant::DynTypesRtpsListener::on_type_discovery( +DynTypesParticipant::DynTypesDdsListener::DynTypesDdsListener( + std::shared_ptr type_object_reader, + core::types::ParticipantId participant_id) + : type_object_reader_(type_object_reader) + , participant_id_(participant_id) +{ +} + +void DynTypesParticipant::DynTypesDdsListener::on_type_discovery( eprosima::fastdds::dds::DomainParticipant* /* participant */, const fastrtps::rtps::SampleIdentity& /* request_sample_id */, const fastrtps::string_255& /* topic */, @@ -122,7 +128,7 @@ void DynTypesParticipant::DynTypesRtpsListener::on_type_discovery( } } -void DynTypesParticipant::DynTypesRtpsListener::on_type_information_received( +void DynTypesParticipant::DynTypesDdsListener::on_type_information_received( eprosima::fastdds::dds::DomainParticipant* participant, const fastrtps::string_255 /* topic_name */, const fastrtps::string_255 type_name, @@ -177,11 +183,11 @@ void DynTypesParticipant::DynTypesRtpsListener::on_type_information_received( } } -void DynTypesParticipant::DynTypesRtpsListener::internal_notify_type_object_( +void DynTypesParticipant::DynTypesDdsListener::internal_notify_type_object_( DynamicType_ptr dynamic_type) { logInfo(DDSPIPE_DYNTYPES_PARTICIPANT, - "Participant " << configuration_->id << " discovered type object " << dynamic_type->get_name()); + "Participant " << participant_id_ << " discovered type object " << dynamic_type->get_name()); monitor_type_discovered(dynamic_type->get_name()); @@ -295,9 +301,9 @@ void DynTypesParticipant::initialize_internal_dds_participant_() configuration->domain, pqos); - // Note that this listeners also inherits from DomainParticipantListener - dds_participant_->set_listener( - dynamic_cast(rtps_participant_listener_.get())); + // Create the DDS listener and set it in the participant + dds_participant_listener_ = create_dds_listener_(); + dds_participant_->set_listener(dds_participant_listener_.get()); dds_participant_->enable(); @@ -315,7 +321,14 @@ void DynTypesParticipant::initialize_internal_dds_participant_() std::unique_ptr DynTypesParticipant::create_listener_() { - return std::make_unique(configuration_, discovery_database_, type_object_reader_); + return std::make_unique(configuration_, discovery_database_); +} + +std::unique_ptr DynTypesParticipant::create_dds_listener_() +{ + // Note that when the DDS listener is created, the RTPS participant is already created and enabled. + // Therefore, we can access to the RTPS participant GUID prefix safely. + return std::make_unique(type_object_reader_, configuration_->id); } } /* namespace participants */ From 558bf481c3c7de6dfc40546779dd2a3a0cec918b Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Thu, 17 Jul 2025 07:56:22 +0200 Subject: [PATCH 2/2] Apply Review Signed-off-by: cferreiragonz --- .../dynamic_types/DynTypesParticipant.hpp | 21 ------------------- .../dynamic_types/DynTypesParticipant.cpp | 14 ------------- 2 files changed, 35 deletions(-) diff --git a/ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp index 18deef53e..be582b2db 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp @@ -71,23 +71,6 @@ class DynTypesParticipant : public rtps::SimpleParticipant std::shared_ptr create_reader( const core::ITopic& topic) override; - // DynTypesParticipant makes use of both RTPS and DDS listeners - - /** - * @brief This class is the RTPS Listener for DynTypesParticipant. It inherits from - * \c rtps::CommonParticipant::RtpsListener . - */ - class DynTypesRtpsListener : public rtps::CommonParticipant::RtpsListener - { - public: - - DDSPIPE_PARTICIPANTS_DllAPI - explicit DynTypesRtpsListener( - std::shared_ptr conf, - std::shared_ptr ddb); - - }; - /** * @brief This class is the DDS Listener for DynTypesParticipant. It inherits directly from * \c fastdds::dds::DomainParticipantListener and implements the methods needed to process type objects and @@ -142,10 +125,6 @@ class DynTypesParticipant : public rtps::SimpleParticipant //! Type Object Internal Reader std::shared_ptr type_object_reader_; - //! Override method from \c CommonParticipant to create the internal RTPS participant listener - DDSPIPE_PARTICIPANTS_DllAPI - std::unique_ptr create_listener_() override; - //! Method to create the internal DDS participant listener DDSPIPE_PARTICIPANTS_DllAPI virtual std::unique_ptr create_dds_listener_(); diff --git a/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp b/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp index 12b39b060..2789bd721 100644 --- a/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp @@ -94,15 +94,6 @@ std::shared_ptr DynTypesParticipant::create_reader( return rtps::SimpleParticipant::create_reader(topic); } -DynTypesParticipant::DynTypesRtpsListener::DynTypesRtpsListener( - std::shared_ptr conf, - std::shared_ptr ddb) - : rtps::CommonParticipant::RtpsListener( - conf, - ddb) -{ -} - DynTypesParticipant::DynTypesDdsListener::DynTypesDdsListener( std::shared_ptr type_object_reader, core::types::ParticipantId participant_id) @@ -319,11 +310,6 @@ void DynTypesParticipant::initialize_internal_dds_participant_() } } -std::unique_ptr DynTypesParticipant::create_listener_() -{ - return std::make_unique(configuration_, discovery_database_); -} - std::unique_ptr DynTypesParticipant::create_dds_listener_() { // Note that when the DDS listener is created, the RTPS participant is already created and enabled.