Skip to content

Commit 28075a9

Browse files
committed
Refs #21670: Separate DDS/RTPS Listeners from Base Classes
Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
1 parent 38122d3 commit 28075a9

6 files changed

Lines changed: 244 additions & 107 deletions

File tree

ddspipe_participants/include/ddspipe_participants/participant/dds/CommonParticipant.hpp

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace dds {
6060
* @warning This Participant class does not support RPC so far.
6161
* @todo TODO
6262
*/
63-
class CommonParticipant : public core::IParticipant, public fastdds::dds::DomainParticipantListener
63+
class CommonParticipant : public core::IParticipant
6464
{
6565
public:
6666

@@ -112,23 +112,70 @@ class CommonParticipant : public core::IParticipant, public fastdds::dds::Domain
112112
// LISTENER METHODS
113113
/////////////////////////
114114

115-
void on_participant_discovery(
116-
fastdds::dds::DomainParticipant* participant,
117-
fastdds::rtps::ParticipantDiscoveryStatus reason,
118-
const fastdds::rtps::ParticipantBuiltinTopicData& info,
119-
bool& /*should_be_ignored*/) override;
120-
121-
void on_data_reader_discovery(
122-
fastdds::dds::DomainParticipant* participant,
123-
fastdds::rtps::ReaderDiscoveryStatus reason,
124-
const fastdds::dds::SubscriptionBuiltinTopicData& info,
125-
bool& /*should_be_ignored*/) override;
126-
127-
void on_data_writer_discovery(
128-
fastdds::dds::DomainParticipant* participant,
129-
fastdds::rtps::WriterDiscoveryStatus reason,
130-
const fastdds::dds::PublicationBuiltinTopicData& info,
131-
bool& /*should_be_ignored*/) override;
115+
class DDSListener : public fastdds::dds::DomainParticipantListener
116+
{
117+
public:
118+
119+
explicit DDSListener(
120+
std::shared_ptr<SimpleParticipantConfiguration> conf,
121+
std::shared_ptr<core::DiscoveryDatabase> ddb)
122+
: configuration_(conf)
123+
, discovery_database_(ddb)
124+
{
125+
}
126+
127+
/**
128+
* @brief Override method from \c DomainParticipantListener
129+
*
130+
* This method is only used for debugging purposes.
131+
*/
132+
void on_participant_discovery(
133+
fastdds::dds::DomainParticipant* participant,
134+
fastdds::rtps::ParticipantDiscoveryStatus reason,
135+
const fastdds::rtps::ParticipantBuiltinTopicData& info,
136+
bool& /*should_be_ignored*/) override;
137+
138+
/**
139+
* @brief Override method from \c DomainParticipantListener .
140+
*
141+
* This method adds to the database the discovered or modified endpoint.
142+
*/
143+
void on_data_reader_discovery(
144+
fastdds::dds::DomainParticipant* participant,
145+
fastdds::rtps::ReaderDiscoveryStatus reason,
146+
const fastdds::dds::SubscriptionBuiltinTopicData& info,
147+
bool& /*should_be_ignored*/) override;
148+
149+
/**
150+
* @brief Override method from \c DomainParticipantListener .
151+
*
152+
* This method adds to the database the discovered or modified endpoint.
153+
*/
154+
void on_data_writer_discovery(
155+
fastdds::dds::DomainParticipant* participant,
156+
fastdds::rtps::WriterDiscoveryStatus reason,
157+
const fastdds::dds::PublicationBuiltinTopicData& info,
158+
bool& /*should_be_ignored*/) override;
159+
160+
//! Getter for GUID of the participant
161+
const fastdds::rtps::GUID_t& guid() const;
162+
163+
//! Setter for GUID of the participant
164+
void guid(
165+
const fastdds::rtps::GUID_t& guid);
166+
private:
167+
168+
//! GUID of the participant
169+
fastdds::rtps::GUID_t guid_;
170+
//! Shared pointer to the configuration of the participant
171+
const std::shared_ptr<SimpleParticipantConfiguration> configuration_;
172+
//! Shared pointer to the discovery database
173+
const std::shared_ptr<core::DiscoveryDatabase> discovery_database_;
174+
175+
};
176+
177+
//! Unique pointer to the internal DDS Participant Listener
178+
std::unique_ptr<fastdds::dds::DomainParticipantListener> dds_participant_listener_;
132179

133180
protected:
134181

@@ -159,6 +206,15 @@ class CommonParticipant : public core::IParticipant, public fastdds::dds::Domain
159206
fastdds::dds::DomainParticipant*
160207
create_dds_participant_();
161208

209+
/**
210+
* @brief Virtual method that creates a listener for the internal DDS Participant.
211+
* It should be overridden if a different listener is needed.
212+
*/
213+
virtual std::unique_ptr<fastdds::dds::DomainParticipantListener> create_listener()
214+
{
215+
return std::make_unique<DDSListener>(configuration_, discovery_database_);
216+
}
217+
162218
/////////////////////////
163219
// INTERNAL METHODS
164220
/////////////////////////

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

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,55 @@ class DynTypesParticipant : public rtps::SimpleParticipant
7474
std::shared_ptr<core::IReader> create_reader(
7575
const core::ITopic& topic) override;
7676

77-
DDSPIPE_PARTICIPANTS_DllAPI
78-
void on_reader_discovery(
79-
fastdds::rtps::RTPSParticipant* participant,
80-
fastdds::rtps::ReaderDiscoveryStatus reason,
81-
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
82-
bool& should_be_ignored) override;
83-
84-
DDSPIPE_PARTICIPANTS_DllAPI
85-
void on_writer_discovery(
86-
fastdds::rtps::RTPSParticipant* participant,
87-
fastdds::rtps::WriterDiscoveryStatus reason,
88-
const fastdds::rtps::PublicationBuiltinTopicData& info,
89-
bool& should_be_ignored) override;
77+
class DynRTPSListener : public rtps::CommonParticipant::RTPSListener
78+
{
79+
public:
80+
81+
explicit DynRTPSListener(
82+
std::shared_ptr<ParticipantConfiguration> conf,
83+
std::shared_ptr<core::DiscoveryDatabase> ddb,
84+
std::shared_ptr<InternalReader> type_object_reader_,
85+
std::set<std::string> received_types_)
86+
: rtps::CommonParticipant::RTPSListener(conf, ddb)
87+
, type_object_reader_(type_object_reader_)
88+
, received_types_(received_types_)
89+
{
90+
}
91+
92+
DDSPIPE_PARTICIPANTS_DllAPI
93+
void on_reader_discovery(
94+
fastdds::rtps::RTPSParticipant* participant,
95+
fastdds::rtps::ReaderDiscoveryStatus reason,
96+
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
97+
bool& should_be_ignored) override;
98+
99+
DDSPIPE_PARTICIPANTS_DllAPI
100+
void on_writer_discovery(
101+
fastdds::rtps::RTPSParticipant* participant,
102+
fastdds::rtps::WriterDiscoveryStatus reason,
103+
const fastdds::rtps::PublicationBuiltinTopicData& info,
104+
bool& should_be_ignored) override;
105+
106+
private:
107+
108+
//! Type Object Internal Reader
109+
std::shared_ptr<InternalReader> type_object_reader_;
110+
//! Received types set
111+
std::set<std::string> received_types_;
112+
113+
void notify_type_discovered_(
114+
const fastdds::dds::xtypes::TypeInformation& type_info,
115+
const std::string& type_name);
116+
117+
};
90118

91119
protected:
92120

93-
void notify_type_discovered_(
94-
const fastdds::dds::xtypes::TypeInformation& type_info,
95-
const std::string& type_name);
121+
//! Override method from \c CommonParticipant to create the internal RTPS participant listener
122+
std::unique_ptr<fastdds::rtps::RTPSParticipantListener> create_listener() override
123+
{
124+
return std::make_unique<DynRTPSListener>(configuration_, discovery_database_, type_object_reader_, received_types_);
125+
}
96126

97127
//! Type Object Internal Reader
98128
std::shared_ptr<InternalReader> type_object_reader_;

ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ namespace rtps {
5252
*/
5353
class CommonParticipant
5454
: public core::IParticipant
55-
, public fastdds::rtps::RTPSParticipantListener
5655
{
5756
public:
5857

@@ -123,41 +122,65 @@ class CommonParticipant
123122
// RTPS LISTENER METHODS
124123
/////////////////////////
125124

126-
/**
127-
* @brief Override method from \c RTPSParticipantListener .
128-
*
129-
* This method only is for debugging purposes.
130-
*/
131-
DDSPIPE_PARTICIPANTS_DllAPI
132-
virtual void on_participant_discovery(
133-
fastdds::rtps::RTPSParticipant* participant,
134-
fastdds::rtps::ParticipantDiscoveryStatus reason,
135-
const fastdds::rtps::ParticipantBuiltinTopicData& info,
136-
bool& /*should_be_ignored*/) override;
137-
138-
/**
139-
* @brief Override method from \c RTPSParticipantListener .
140-
*
141-
* This method adds to database the endpoint discovered or modified.
142-
*/
143-
DDSPIPE_PARTICIPANTS_DllAPI
144-
virtual void on_reader_discovery(
145-
fastdds::rtps::RTPSParticipant* participant,
146-
fastdds::rtps::ReaderDiscoveryStatus reason,
147-
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
148-
bool& /*should_be_ignored*/) override;
149-
150-
/**
151-
* @brief Override method from \c RTPSParticipantListener .
152-
*
153-
* This method adds to database the endpoint discovered or modified.
154-
*/
155-
DDSPIPE_PARTICIPANTS_DllAPI
156-
virtual void on_writer_discovery(
157-
fastdds::rtps::RTPSParticipant* participant,
158-
fastdds::rtps::WriterDiscoveryStatus reason,
159-
const fastdds::rtps::PublicationBuiltinTopicData& info,
160-
bool& /*should_be_ignored*/) override;
125+
class RTPSListener : public fastdds::rtps::RTPSParticipantListener
126+
{
127+
public:
128+
129+
explicit RTPSListener(
130+
std::shared_ptr<ParticipantConfiguration> conf,
131+
std::shared_ptr<core::DiscoveryDatabase> ddb)
132+
: configuration_(conf)
133+
, discovery_database_(ddb)
134+
{
135+
}
136+
137+
/**
138+
* @brief Override method from \c RTPSParticipantListener .
139+
*
140+
* This method is only used for debugging purposes.
141+
*/
142+
DDSPIPE_PARTICIPANTS_DllAPI
143+
virtual void on_participant_discovery(
144+
fastdds::rtps::RTPSParticipant* participant,
145+
fastdds::rtps::ParticipantDiscoveryStatus reason,
146+
const fastdds::rtps::ParticipantBuiltinTopicData& info,
147+
bool& /*should_be_ignored*/) override;
148+
149+
/**
150+
* @brief Override method from \c RTPSParticipantListener .
151+
*
152+
* This method adds to database the endpoint discovered or modified.
153+
*/
154+
DDSPIPE_PARTICIPANTS_DllAPI
155+
virtual void on_reader_discovery(
156+
fastdds::rtps::RTPSParticipant* participant,
157+
fastdds::rtps::ReaderDiscoveryStatus reason,
158+
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
159+
bool& /*should_be_ignored*/) override;
160+
161+
/**
162+
* @brief Override method from \c RTPSParticipantListener .
163+
*
164+
* This method adds to database the endpoint discovered or modified.
165+
*/
166+
DDSPIPE_PARTICIPANTS_DllAPI
167+
virtual void on_writer_discovery(
168+
fastdds::rtps::RTPSParticipant* participant,
169+
fastdds::rtps::WriterDiscoveryStatus reason,
170+
const fastdds::rtps::PublicationBuiltinTopicData& info,
171+
bool& /*should_be_ignored*/) override;
172+
173+
protected:
174+
175+
//! Shared pointer to the configuration of the participant
176+
const std::shared_ptr<ParticipantConfiguration> configuration_;
177+
//! Shared pointer to the discovery database
178+
const std::shared_ptr<core::DiscoveryDatabase> discovery_database_;
179+
180+
};
181+
182+
//! Unique pointer to the internal RTPS Participant Listener
183+
std::unique_ptr<fastdds::rtps::RTPSParticipantListener> rtps_participant_listener_;
161184

162185
//////////////////
163186
// STATIC METHODS
@@ -221,6 +244,17 @@ class CommonParticipant
221244
DDSPIPE_PARTICIPANTS_DllAPI
222245
virtual fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const;
223246

247+
/**
248+
* @brief Virtual method that creates a listener for the internal RTPS Participant.
249+
* It should be overridden if a different listener is needed.
250+
* This method must be called after the RTPS Participant is created, otherwise no listener will be set.
251+
* @return A unique pointer to an RTPS Participant Listener.
252+
*/
253+
virtual std::unique_ptr<fastdds::rtps::RTPSParticipantListener> create_listener()
254+
{
255+
return std::make_unique<RTPSListener>(configuration_, discovery_database_);
256+
}
257+
224258
/////
225259
// VARIABLES
226260

0 commit comments

Comments
 (0)