Skip to content

Commit aee3c7a

Browse files
committed
Fix Data Races on DDS-Pipe (#145)
* Refs #21670: Protect on_data_available_lambda_ Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21670: Set listener in RederCreation Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21670: Separate DDS/RTPS Listeners from Base Classes Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21670: Uncrustify Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21670: Apply Review Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21670: Apply Review 2 Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21670: Apply review 3 Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21670: Avoid using capital letters in DDS Listener Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21670: Fix leak Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> --------- Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> (cherry picked from commit ee0e639)
1 parent 8abd633 commit aee3c7a

9 files changed

Lines changed: 470 additions & 28 deletions

File tree

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

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace dds {
5454
* @warning This Participant class does not support RPC so far.
5555
* @todo TODO
5656
*/
57-
class CommonParticipant : public core::IParticipant, public fastdds::dds::DomainParticipantListener
57+
class CommonParticipant : public core::IParticipant
5858
{
5959
public:
6060

@@ -106,6 +106,7 @@ class CommonParticipant : public core::IParticipant, public fastdds::dds::Domain
106106
// LISTENER METHODS
107107
/////////////////////////
108108

109+
<<<<<<< HEAD
109110
virtual void on_participant_discovery(
110111
fastdds::dds::DomainParticipant* participant,
111112
fastrtps::rtps::ParticipantDiscoveryInfo&& info) override;
@@ -117,6 +118,64 @@ class CommonParticipant : public core::IParticipant, public fastdds::dds::Domain
117118
virtual void on_publisher_discovery(
118119
fastdds::dds::DomainParticipant* participant,
119120
fastrtps::rtps::WriterDiscoveryInfo&& info) override;
121+
=======
122+
class DdsListener : public fastdds::dds::DomainParticipantListener
123+
{
124+
public:
125+
126+
DDSPIPE_PARTICIPANTS_DllAPI
127+
explicit DdsListener(
128+
std::shared_ptr<SimpleParticipantConfiguration> conf,
129+
std::shared_ptr<core::DiscoveryDatabase> ddb);
130+
131+
/**
132+
* @brief Override method from \c DomainParticipantListener
133+
*
134+
* This method is only used for debugging purposes.
135+
*/
136+
DDSPIPE_PARTICIPANTS_DllAPI
137+
void on_participant_discovery(
138+
fastdds::dds::DomainParticipant* participant,
139+
fastdds::rtps::ParticipantDiscoveryStatus reason,
140+
const fastdds::rtps::ParticipantBuiltinTopicData& info,
141+
bool& /*should_be_ignored*/) override;
142+
143+
/**
144+
* @brief Override method from \c DomainParticipantListener .
145+
*
146+
* This method adds to the database the discovered or modified endpoint.
147+
*/
148+
DDSPIPE_PARTICIPANTS_DllAPI
149+
void on_data_reader_discovery(
150+
fastdds::dds::DomainParticipant* participant,
151+
fastdds::rtps::ReaderDiscoveryStatus reason,
152+
const fastdds::dds::SubscriptionBuiltinTopicData& info,
153+
bool& /*should_be_ignored*/) override;
154+
155+
/**
156+
* @brief Override method from \c DomainParticipantListener .
157+
*
158+
* This method adds to the database the discovered or modified endpoint.
159+
*/
160+
DDSPIPE_PARTICIPANTS_DllAPI
161+
void on_data_writer_discovery(
162+
fastdds::dds::DomainParticipant* participant,
163+
fastdds::rtps::WriterDiscoveryStatus reason,
164+
const fastdds::dds::PublicationBuiltinTopicData& info,
165+
bool& /*should_be_ignored*/) override;
166+
167+
protected:
168+
169+
//! Shared pointer to the configuration of the participant
170+
const std::shared_ptr<SimpleParticipantConfiguration> configuration_;
171+
//! Shared pointer to the discovery database
172+
const std::shared_ptr<core::DiscoveryDatabase> discovery_database_;
173+
174+
};
175+
176+
//! Unique pointer to the internal DDS Participant Listener
177+
std::unique_ptr<fastdds::dds::DomainParticipantListener> dds_participant_listener_;
178+
>>>>>>> ee0e639 (Fix Data Races on DDS-Pipe (#145))
120179

121180
protected:
122181

@@ -130,14 +189,36 @@ class CommonParticipant : public core::IParticipant, public fastdds::dds::Domain
130189
const std::shared_ptr<core::PayloadPool>& payload_pool,
131190
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database);
132191

192+
/////////////////////////
193+
// VIRTUAL METHODS
194+
/////////////////////////
195+
196+
/**
197+
* @brief Virtual method that creates a listener for the internal DDS Participant.
198+
* It should be overridden if a different listener is needed.
199+
*/
200+
DDSPIPE_PARTICIPANTS_DllAPI
201+
virtual std::unique_ptr<fastdds::dds::DomainParticipantListener> create_listener_();
202+
133203
/////////////////////////
134204
// INTERNAL VIRTUAL METHODS
135205
/////////////////////////
136206

207+
DDSPIPE_PARTICIPANTS_DllAPI
208+
virtual
209+
fastdds::dds::DomainParticipantQos
210+
<<<<<<< HEAD
211+
=======
212+
add_qos_properties_(
213+
fastdds::dds::DomainParticipantQos& qos) const;
214+
215+
DDSPIPE_PARTICIPANTS_DllAPI
137216
virtual
138217
fastdds::dds::DomainParticipantQos
218+
>>>>>>> ee0e639 (Fix Data Races on DDS-Pipe (#145))
139219
reckon_participant_qos_() const;
140220

221+
DDSPIPE_PARTICIPANTS_DllAPI
141222
virtual
142223
fastdds::dds::DomainParticipant*
143224
create_dds_participant_();

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

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

74+
<<<<<<< HEAD
7475
DDSPIPE_PARTICIPANTS_DllAPI
7576
void on_type_discovery(
7677
eprosima::fastdds::dds::DomainParticipant* participant,
@@ -98,6 +99,59 @@ class DynTypesParticipant : public rtps::SimpleParticipant, public eprosima::fas
9899

99100
//! Type Object Internal Reader
100101
std::shared_ptr<InternalReader> type_object_reader_;
102+
=======
103+
class DynTypesRtpsListener : public rtps::CommonParticipant::RtpsListener
104+
{
105+
public:
106+
107+
DDSPIPE_PARTICIPANTS_DllAPI
108+
explicit DynTypesRtpsListener(
109+
std::shared_ptr<ParticipantConfiguration> conf,
110+
std::shared_ptr<core::DiscoveryDatabase> ddb,
111+
std::shared_ptr<InternalReader> internal_reader);
112+
113+
DDSPIPE_PARTICIPANTS_DllAPI
114+
void on_reader_discovery(
115+
fastdds::rtps::RTPSParticipant* participant,
116+
fastdds::rtps::ReaderDiscoveryStatus reason,
117+
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
118+
bool& should_be_ignored) override;
119+
120+
DDSPIPE_PARTICIPANTS_DllAPI
121+
void on_writer_discovery(
122+
fastdds::rtps::RTPSParticipant* participant,
123+
fastdds::rtps::WriterDiscoveryStatus reason,
124+
const fastdds::rtps::PublicationBuiltinTopicData& info,
125+
bool& should_be_ignored) override;
126+
127+
//! Type Object Reader getter
128+
inline std::shared_ptr<InternalReader> type_object_reader() const
129+
{
130+
return type_object_reader_;
131+
}
132+
133+
protected:
134+
135+
//! Copy of Type Object Internal Reader
136+
std::shared_ptr<InternalReader> type_object_reader_;
137+
//! Received types set
138+
std::set<std::string> received_types_;
139+
140+
void notify_type_discovered_(
141+
const fastdds::dds::xtypes::TypeInformation& type_info,
142+
const std::string& type_name);
143+
144+
};
145+
146+
protected:
147+
148+
//! Override method from \c CommonParticipant to create the internal RTPS participant listener
149+
std::unique_ptr<fastdds::rtps::RTPSParticipantListener> create_listener_() override;
150+
151+
//! Type Object Internal Reader
152+
std::shared_ptr<InternalReader> type_object_reader_;
153+
154+
>>>>>>> ee0e639 (Fix Data Races on DDS-Pipe (#145))
101155
};
102156

103157
} /* namespace participants */

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ namespace rtps {
5050
*/
5151
class CommonParticipant
5252
: public core::IParticipant
53+
<<<<<<< HEAD
5354
, public fastrtps::rtps::RTPSParticipantListener
55+
=======
56+
>>>>>>> ee0e639 (Fix Data Races on DDS-Pipe (#145))
5457
{
5558
public:
5659

@@ -121,6 +124,7 @@ class CommonParticipant
121124
// RTPS LISTENER METHODS
122125
/////////////////////////
123126

127+
<<<<<<< HEAD
124128
/**
125129
* @brief Override method from \c RTPSParticipantListener .
126130
*
@@ -150,6 +154,64 @@ class CommonParticipant
150154
virtual void onWriterDiscovery(
151155
fastrtps::rtps::RTPSParticipant* participant,
152156
fastrtps::rtps::WriterDiscoveryInfo&& info) override;
157+
=======
158+
class RtpsListener : public fastdds::rtps::RTPSParticipantListener
159+
{
160+
public:
161+
162+
DDSPIPE_PARTICIPANTS_DllAPI
163+
explicit RtpsListener(
164+
std::shared_ptr<ParticipantConfiguration> conf,
165+
std::shared_ptr<core::DiscoveryDatabase> ddb);
166+
167+
/**
168+
* @brief Override method from \c RTPSParticipantListener .
169+
*
170+
* This method is only used for debugging purposes.
171+
*/
172+
DDSPIPE_PARTICIPANTS_DllAPI
173+
virtual void on_participant_discovery(
174+
fastdds::rtps::RTPSParticipant* participant,
175+
fastdds::rtps::ParticipantDiscoveryStatus reason,
176+
const fastdds::rtps::ParticipantBuiltinTopicData& info,
177+
bool& /*should_be_ignored*/) override;
178+
179+
/**
180+
* @brief Override method from \c RTPSParticipantListener .
181+
*
182+
* This method adds to database the endpoint discovered or modified.
183+
*/
184+
DDSPIPE_PARTICIPANTS_DllAPI
185+
virtual void on_reader_discovery(
186+
fastdds::rtps::RTPSParticipant* participant,
187+
fastdds::rtps::ReaderDiscoveryStatus reason,
188+
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
189+
bool& /*should_be_ignored*/) override;
190+
191+
/**
192+
* @brief Override method from \c RTPSParticipantListener .
193+
*
194+
* This method adds to database the endpoint discovered or modified.
195+
*/
196+
DDSPIPE_PARTICIPANTS_DllAPI
197+
virtual void on_writer_discovery(
198+
fastdds::rtps::RTPSParticipant* participant,
199+
fastdds::rtps::WriterDiscoveryStatus reason,
200+
const fastdds::rtps::PublicationBuiltinTopicData& info,
201+
bool& /*should_be_ignored*/) override;
202+
203+
protected:
204+
205+
//! Shared pointer to the configuration of the participant
206+
const std::shared_ptr<ParticipantConfiguration> configuration_;
207+
//! Shared pointer to the discovery database
208+
const std::shared_ptr<core::DiscoveryDatabase> discovery_database_;
209+
210+
};
211+
212+
//! Unique pointer to the internal RTPS Participant Listener
213+
std::unique_ptr<fastdds::rtps::RTPSParticipantListener> rtps_participant_listener_;
214+
>>>>>>> ee0e639 (Fix Data Races on DDS-Pipe (#145))
153215

154216
//////////////////
155217
// STATIC METHODS
@@ -207,6 +269,15 @@ class CommonParticipant
207269
static fastrtps::rtps::RTPSParticipantAttributes reckon_participant_attributes_(
208270
const ParticipantConfiguration* participant_configuration);
209271

272+
/**
273+
* @brief Virtual method that creates a listener for the internal RTPS Participant.
274+
* It should be overridden if a different listener is needed.
275+
* This method must be called after the RTPS Participant is created, otherwise no listener will be set.
276+
* @return A unique pointer to an RTPS Participant Listener.
277+
*/
278+
DDSPIPE_PARTICIPANTS_DllAPI
279+
virtual std::unique_ptr<fastdds::rtps::RTPSParticipantListener> create_listener_();
280+
210281
/////
211282
// VARIABLES
212283

0 commit comments

Comments
 (0)