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..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,16 +71,19 @@ 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 + /** + * @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 DynTypesRtpsListener( - std::shared_ptr conf, - std::shared_ptr ddb, - std::shared_ptr internal_reader); + explicit DynTypesDdsListener( + std::shared_ptr type_object_reader, + core::types::ParticipantId participant_id); DDSPIPE_PARTICIPANTS_DllAPI void on_type_discovery( @@ -106,6 +109,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,12 +120,14 @@ 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_; - //! Override method from \c CommonParticipant to create the internal RTPS participant listener + //! Method to create the internal DDS participant listener DDSPIPE_PARTICIPANTS_DllAPI - std::unique_ptr create_listener_() override; + 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 cda950714..2789bd721 100644 --- a/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp @@ -94,18 +94,15 @@ std::shared_ptr DynTypesParticipant::create_reader( return rtps::SimpleParticipant::create_reader(topic); } -DynTypesParticipant::DynTypesRtpsListener::DynTypesRtpsListener( - std::shared_ptr conf, - std::shared_ptr ddb, - std::shared_ptr internal_reader) - : rtps::CommonParticipant::RtpsListener( - conf, - ddb) - , type_object_reader_(internal_reader) +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::DynTypesRtpsListener::on_type_discovery( +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 +119,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 +174,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 +292,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(); @@ -313,9 +310,11 @@ void DynTypesParticipant::initialize_internal_dds_participant_() } } -std::unique_ptr DynTypesParticipant::create_listener_() +std::unique_ptr DynTypesParticipant::create_dds_listener_() { - return std::make_unique(configuration_, discovery_database_, type_object_reader_); + // 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 */