Skip to content

Commit 5829875

Browse files
Split RTPS and DDS Listeners in DynTypesParticipant (#157)
* Split Listeners in DynTypesParticipant Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Apply Review Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> --------- Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
1 parent 748f67a commit 5829875

2 files changed

Lines changed: 32 additions & 25 deletions

File tree

ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/DynTypesParticipant.hpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,19 @@ class DynTypesParticipant : public rtps::SimpleParticipant
7171
std::shared_ptr<core::IReader> create_reader(
7272
const core::ITopic& topic) override;
7373

74-
class DynTypesRtpsListener : public rtps::CommonParticipant::RtpsListener,
75-
public eprosima::fastdds::dds::DomainParticipantListener
74+
/**
75+
* @brief This class is the DDS Listener for DynTypesParticipant. It inherits directly from
76+
* \c fastdds::dds::DomainParticipantListener and implements the methods needed to process type objects and
77+
* type lookup services.
78+
*/
79+
class DynTypesDdsListener : public eprosima::fastdds::dds::DomainParticipantListener
7680
{
7781
public:
7882

7983
DDSPIPE_PARTICIPANTS_DllAPI
80-
explicit DynTypesRtpsListener(
81-
std::shared_ptr<ParticipantConfiguration> conf,
82-
std::shared_ptr<core::DiscoveryDatabase> ddb,
83-
std::shared_ptr<InternalReader> internal_reader);
84+
explicit DynTypesDdsListener(
85+
std::shared_ptr<InternalReader> type_object_reader,
86+
core::types::ParticipantId participant_id);
8487

8588
DDSPIPE_PARTICIPANTS_DllAPI
8689
void on_type_discovery(
@@ -106,6 +109,9 @@ class DynTypesParticipant : public rtps::SimpleParticipant
106109
//! Copy of Type Object Internal Reader
107110
std::shared_ptr<InternalReader> type_object_reader_;
108111

112+
//! Participant ID for informative purposes. It is stored in the CommonParticipant (RTPS)
113+
core::types::ParticipantId participant_id_;
114+
109115
};
110116

111117
protected:
@@ -114,12 +120,14 @@ class DynTypesParticipant : public rtps::SimpleParticipant
114120

115121
eprosima::fastdds::dds::DomainParticipant* dds_participant_;
116122

123+
std::unique_ptr<eprosima::fastdds::dds::DomainParticipantListener> dds_participant_listener_;
124+
117125
//! Type Object Internal Reader
118126
std::shared_ptr<InternalReader> type_object_reader_;
119127

120-
//! Override method from \c CommonParticipant to create the internal RTPS participant listener
128+
//! Method to create the internal DDS participant listener
121129
DDSPIPE_PARTICIPANTS_DllAPI
122-
std::unique_ptr<fastrtps::rtps::RTPSParticipantListener> create_listener_() override;
130+
virtual std::unique_ptr<fastdds::dds::DomainParticipantListener> create_dds_listener_();
123131

124132
};
125133

ddspipe_participants/src/cpp/participant/dynamic_types/DynTypesParticipant.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,15 @@ std::shared_ptr<IReader> DynTypesParticipant::create_reader(
9494
return rtps::SimpleParticipant::create_reader(topic);
9595
}
9696

97-
DynTypesParticipant::DynTypesRtpsListener::DynTypesRtpsListener(
98-
std::shared_ptr<ParticipantConfiguration> conf,
99-
std::shared_ptr<core::DiscoveryDatabase> ddb,
100-
std::shared_ptr<InternalReader> internal_reader)
101-
: rtps::CommonParticipant::RtpsListener(
102-
conf,
103-
ddb)
104-
, type_object_reader_(internal_reader)
97+
DynTypesParticipant::DynTypesDdsListener::DynTypesDdsListener(
98+
std::shared_ptr<InternalReader> type_object_reader,
99+
core::types::ParticipantId participant_id)
100+
: type_object_reader_(type_object_reader)
101+
, participant_id_(participant_id)
105102
{
106103
}
107104

108-
void DynTypesParticipant::DynTypesRtpsListener::on_type_discovery(
105+
void DynTypesParticipant::DynTypesDdsListener::on_type_discovery(
109106
eprosima::fastdds::dds::DomainParticipant* /* participant */,
110107
const fastrtps::rtps::SampleIdentity& /* request_sample_id */,
111108
const fastrtps::string_255& /* topic */,
@@ -122,7 +119,7 @@ void DynTypesParticipant::DynTypesRtpsListener::on_type_discovery(
122119
}
123120
}
124121

125-
void DynTypesParticipant::DynTypesRtpsListener::on_type_information_received(
122+
void DynTypesParticipant::DynTypesDdsListener::on_type_information_received(
126123
eprosima::fastdds::dds::DomainParticipant* participant,
127124
const fastrtps::string_255 /* topic_name */,
128125
const fastrtps::string_255 type_name,
@@ -177,11 +174,11 @@ void DynTypesParticipant::DynTypesRtpsListener::on_type_information_received(
177174
}
178175
}
179176

180-
void DynTypesParticipant::DynTypesRtpsListener::internal_notify_type_object_(
177+
void DynTypesParticipant::DynTypesDdsListener::internal_notify_type_object_(
181178
DynamicType_ptr dynamic_type)
182179
{
183180
logInfo(DDSPIPE_DYNTYPES_PARTICIPANT,
184-
"Participant " << configuration_->id << " discovered type object " << dynamic_type->get_name());
181+
"Participant " << participant_id_ << " discovered type object " << dynamic_type->get_name());
185182

186183
monitor_type_discovered(dynamic_type->get_name());
187184

@@ -295,9 +292,9 @@ void DynTypesParticipant::initialize_internal_dds_participant_()
295292
configuration->domain,
296293
pqos);
297294

298-
// Note that this listeners also inherits from DomainParticipantListener
299-
dds_participant_->set_listener(
300-
dynamic_cast<fastdds::dds::DomainParticipantListener*>(rtps_participant_listener_.get()));
295+
// Create the DDS listener and set it in the participant
296+
dds_participant_listener_ = create_dds_listener_();
297+
dds_participant_->set_listener(dds_participant_listener_.get());
301298

302299
dds_participant_->enable();
303300

@@ -313,9 +310,11 @@ void DynTypesParticipant::initialize_internal_dds_participant_()
313310
}
314311
}
315312

316-
std::unique_ptr<fastrtps::rtps::RTPSParticipantListener> DynTypesParticipant::create_listener_()
313+
std::unique_ptr<fastdds::dds::DomainParticipantListener> DynTypesParticipant::create_dds_listener_()
317314
{
318-
return std::make_unique<DynTypesRtpsListener>(configuration_, discovery_database_, type_object_reader_);
315+
// Note that when the DDS listener is created, the RTPS participant is already created and enabled.
316+
// Therefore, we can access to the RTPS participant GUID prefix safely.
317+
return std::make_unique<DynTypesDdsListener>(type_object_reader_, configuration_->id);
319318
}
320319

321320
} /* namespace participants */

0 commit comments

Comments
 (0)