Skip to content

Commit 505817d

Browse files
cferreiragonzmergify[bot]
authored andcommitted
Update Spy Listeners (#121)
* Update Spy Listeners Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Uncrustify Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Apply review Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Apply last pipe changes Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Fix type_object_reader Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> --------- Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> (cherry picked from commit 6a01d7d) # Conflicts: # fastddsspy_participants/include/fastddsspy_participants/participant/SpyDdsParticipant.hpp # fastddsspy_participants/src/cpp/participant/SpyDdsParticipant.cpp
1 parent b247960 commit 505817d

2 files changed

Lines changed: 135 additions & 7 deletions

File tree

fastddsspy_participants/include/fastddsspy_participants/participant/SpyDdsParticipant.hpp

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class SpyDdsParticipant : public ddspipe::participants::DynTypesParticipant
4646
std::shared_ptr<ddspipe::core::IReader> create_reader(
4747
const ddspipe::core::ITopic& topic) override;
4848

49+
<<<<<<< HEAD
4950
FASTDDSSPY_PARTICIPANTS_DllAPI
5051
virtual void on_participant_discovery(
5152
fastdds::dds::DomainParticipant* participant,
@@ -60,14 +61,62 @@ class SpyDdsParticipant : public ddspipe::participants::DynTypesParticipant
6061
virtual void on_publisher_discovery(
6162
fastdds::dds::DomainParticipant* participant,
6263
fastrtps::rtps::WriterDiscoveryInfo&& info);
64+
=======
65+
class SpyDdsParticipantListener : public ddspipe::participants::DynTypesParticipant::DynTypesRtpsListener
66+
{
67+
public:
68+
69+
FASTDDSSPY_PARTICIPANTS_DllAPI
70+
explicit SpyDdsParticipantListener(
71+
std::shared_ptr<ddspipe::participants::ParticipantConfiguration> conf,
72+
std::shared_ptr<ddspipe::core::DiscoveryDatabase> ddb,
73+
std::shared_ptr<ddspipe::participants::InternalReader> type_object_reader,
74+
std::shared_ptr<ddspipe::participants::InternalReader> participants_reader,
75+
std::shared_ptr<ddspipe::participants::InternalReader> endpoints_reader);
76+
77+
FASTDDSSPY_PARTICIPANTS_DllAPI
78+
void on_participant_discovery(
79+
fastdds::rtps::RTPSParticipant* participant,
80+
fastdds::rtps::ParticipantDiscoveryStatus reason,
81+
const fastdds::rtps::ParticipantBuiltinTopicData& info,
82+
bool& should_be_ignored) override;
83+
84+
FASTDDSSPY_PARTICIPANTS_DllAPI
85+
void on_reader_discovery(
86+
fastdds::rtps::RTPSParticipant* participant,
87+
fastdds::rtps::ReaderDiscoveryStatus reason,
88+
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
89+
bool& should_be_ignored) override;
90+
91+
FASTDDSSPY_PARTICIPANTS_DllAPI
92+
void on_writer_discovery(
93+
fastdds::rtps::RTPSParticipant* participant,
94+
fastdds::rtps::WriterDiscoveryStatus reason,
95+
const fastdds::rtps::PublicationBuiltinTopicData& info,
96+
bool& should_be_ignored) override;
97+
98+
protected:
99+
100+
void internal_notify_participant_discovered_(
101+
const ParticipantInfo& participant_discovered);
102+
103+
void internal_notify_endpoint_discovered_(
104+
const EndpointInfo& endpoint_discovered);
105+
106+
//! Participants Internal Reader
107+
std::shared_ptr<ddspipe::participants::InternalReader> participants_reader_;
108+
109+
//! Endpoint Internal Reader
110+
std::shared_ptr<ddspipe::participants::InternalReader> endpoints_reader_;
111+
112+
};
113+
>>>>>>> 6a01d7d (Update Spy Listeners (#121))
63114

64115
protected:
65116

66-
void internal_notify_participant_discovered_(
67-
const ParticipantInfo& participant_discovered);
68-
69-
void internal_notify_endpoint_discovered_(
70-
const EndpointInfo& endpoint_discovered);
117+
//! Override method from \c CommonParticipant to create the internal RTPS participant listener
118+
FASTDDSSPY_PARTICIPANTS_DllAPI
119+
std::unique_ptr<fastdds::rtps::RTPSParticipantListener> create_listener_() override;
71120

72121
bool come_from_this_participant_(
73122
const ddspipe::core::types::Guid& guid) const noexcept;

fastddsspy_participants/src/cpp/participant/SpyDdsParticipant.cpp

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,36 @@ std::shared_ptr<ddspipe::core::IReader> SpyDdsParticipant::create_reader(
5656
return ddspipe::participants::DynTypesParticipant::create_reader(topic);
5757
}
5858

59+
<<<<<<< HEAD
5960
void SpyDdsParticipant::on_participant_discovery(
6061
fastdds::dds::DomainParticipant* participant,
6162
fastrtps::rtps::ParticipantDiscoveryInfo&& discovery_info)
6263
{
6364
// If comes from this participant is not interesting
6465
if (come_from_this_participant_(discovery_info.info.m_guid))
66+
=======
67+
SpyDdsParticipant::SpyDdsParticipantListener::SpyDdsParticipantListener(
68+
std::shared_ptr<ddspipe::participants::ParticipantConfiguration> conf,
69+
std::shared_ptr<ddspipe::core::DiscoveryDatabase> ddb,
70+
std::shared_ptr<ddspipe::participants::InternalReader> type_object_reader,
71+
std::shared_ptr<ddspipe::participants::InternalReader> participants_reader,
72+
std::shared_ptr<ddspipe::participants::InternalReader> endpoints_reader)
73+
: ddspipe::participants::DynTypesParticipant::DynTypesRtpsListener(conf, ddb, type_object_reader)
74+
{
75+
// Set the internal readers
76+
participants_reader_ = participants_reader;
77+
endpoints_reader_ = endpoints_reader;
78+
}
79+
80+
void SpyDdsParticipant::SpyDdsParticipantListener::on_participant_discovery(
81+
fastdds::rtps::RTPSParticipant* participant,
82+
fastdds::rtps::ParticipantDiscoveryStatus reason,
83+
const fastdds::rtps::ParticipantBuiltinTopicData& info,
84+
bool& should_be_ignored)
85+
{
86+
// If comes from this participant is not interesting
87+
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, participant->getGuid()))
88+
>>>>>>> 6a01d7d (Update Spy Listeners (#121))
6589
{
6690
return;
6791
}
@@ -72,6 +96,7 @@ void SpyDdsParticipant::on_participant_discovery(
7296
info.name = std::string(discovery_info.info.m_participantName);
7397
info.guid = discovery_info.info.m_guid;
7498

99+
<<<<<<< HEAD
75100
internal_notify_participant_discovered_(info);
76101
}
77102

@@ -81,37 +106,82 @@ void SpyDdsParticipant::on_subscriber_discovery(
81106
{
82107
// If comes from this participant is not interesting
83108
if (come_from_this_participant_(info.info.guid()))
109+
=======
110+
ddspipe::participants::rtps::CommonParticipant::RtpsListener::on_participant_discovery(participant, reason, info,
111+
should_be_ignored);
112+
113+
internal_notify_participant_discovered_(participant_info);
114+
}
115+
116+
void SpyDdsParticipant::SpyDdsParticipantListener::on_reader_discovery(
117+
fastdds::rtps::RTPSParticipant* participant,
118+
fastdds::rtps::ReaderDiscoveryStatus reason,
119+
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
120+
bool& should_be_ignored)
121+
{
122+
// If comes from this participant is not interesting
123+
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, participant->getGuid()))
124+
>>>>>>> 6a01d7d (Update Spy Listeners (#121))
84125
{
85126
return;
86127
}
87128

129+
<<<<<<< HEAD
88130
EndpointInfo endpoint_info = ddspipe::participants::detail::create_endpoint_from_info_(info, id());
89131

90132
// If participant left or dropped, this notification arrives as well
91133
endpoint_info.active = !(info.status == fastrtps::rtps::ReaderDiscoveryInfo::DISCOVERY_STATUS::REMOVED_READER);
134+
=======
135+
EndpointInfo endpoint_info = ddspipe::participants::detail::create_endpoint_from_info_(info, configuration_->id);
136+
endpoint_info.active = (reason == fastdds::rtps::ReaderDiscoveryStatus::DISCOVERED_READER
137+
|| reason == fastdds::rtps::ReaderDiscoveryStatus::CHANGED_QOS_READER);
138+
139+
ddspipe::participants::DynTypesParticipant::DynTypesRtpsListener::on_reader_discovery(participant, reason, info,
140+
should_be_ignored);
141+
>>>>>>> 6a01d7d (Update Spy Listeners (#121))
92142

93143
internal_notify_endpoint_discovered_(endpoint_info);
94144
}
95145

146+
<<<<<<< HEAD
96147
void SpyDdsParticipant::on_publisher_discovery(
97148
fastdds::dds::DomainParticipant* participant,
98149
fastrtps::rtps::WriterDiscoveryInfo&& info)
99150
{
100151
// If comes from this participant is not interesting
101152
if (come_from_this_participant_(info.info.guid()))
153+
=======
154+
void SpyDdsParticipant::SpyDdsParticipantListener::on_writer_discovery(
155+
fastdds::rtps::RTPSParticipant* participant,
156+
fastdds::rtps::WriterDiscoveryStatus reason,
157+
const fastdds::rtps::PublicationBuiltinTopicData& info,
158+
bool& should_be_ignored)
159+
{
160+
// If comes from this participant is not interesting
161+
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, participant->getGuid()))
162+
>>>>>>> 6a01d7d (Update Spy Listeners (#121))
102163
{
103164
return;
104165
}
105166

167+
<<<<<<< HEAD
106168
EndpointInfo endpoint_info = ddspipe::participants::detail::create_endpoint_from_info_(info, id());
107169

108170
// If participant left or dropped, this notification arrives as well
109171
endpoint_info.active = !(info.status == fastrtps::rtps::WriterDiscoveryInfo::DISCOVERY_STATUS::REMOVED_WRITER);
172+
=======
173+
EndpointInfo endpoint_info = ddspipe::participants::detail::create_endpoint_from_info_(info, configuration_->id);
174+
endpoint_info.active = (reason == fastdds::rtps::WriterDiscoveryStatus::DISCOVERED_WRITER
175+
|| reason == fastdds::rtps::WriterDiscoveryStatus::CHANGED_QOS_WRITER);
176+
177+
ddspipe::participants::DynTypesParticipant::DynTypesRtpsListener::on_writer_discovery(participant, reason, info,
178+
should_be_ignored);
179+
>>>>>>> 6a01d7d (Update Spy Listeners (#121))
110180

111181
internal_notify_endpoint_discovered_(endpoint_info);
112182
}
113183

114-
void SpyDdsParticipant::internal_notify_participant_discovered_(
184+
void SpyDdsParticipant::SpyDdsParticipantListener::internal_notify_participant_discovered_(
115185
const ParticipantInfo& participant_discovered)
116186
{
117187
// Create data containing Dynamic Type
@@ -122,7 +192,7 @@ void SpyDdsParticipant::internal_notify_participant_discovered_(
122192
participants_reader_->simulate_data_reception(std::move(data));
123193
}
124194

125-
void SpyDdsParticipant::internal_notify_endpoint_discovered_(
195+
void SpyDdsParticipant::SpyDdsParticipantListener::internal_notify_endpoint_discovered_(
126196
const EndpointInfo& endpoint_discovered)
127197
{
128198
// Create data containing Dynamic Type
@@ -133,6 +203,7 @@ void SpyDdsParticipant::internal_notify_endpoint_discovered_(
133203
endpoints_reader_->simulate_data_reception(std::move(data));
134204
}
135205

206+
<<<<<<< HEAD
136207
/*
137208
* NOTE: this function is required apart from come_from_same_participant_
138209
* because this participant has 2 guids, the rtps and the dds participant ones
@@ -143,6 +214,14 @@ bool SpyDdsParticipant::come_from_this_participant_(
143214
return (guid.guid_prefix() == dds_participant_->guid().guidPrefix
144215
|| guid.guid_prefix() == rtps_participant_->getGuid().guidPrefix
145216
);
217+
=======
218+
std::unique_ptr<fastdds::rtps::RTPSParticipantListener> SpyDdsParticipant::create_listener_()
219+
{
220+
// We pass the configuration_ and discovery_database_ attributes from this method to avoid accessing virtual
221+
// attributes in the constructor
222+
return std::make_unique<SpyDdsParticipantListener>(configuration_, discovery_database_, type_object_reader_,
223+
participants_reader_, endpoints_reader_);
224+
>>>>>>> 6a01d7d (Update Spy Listeners (#121))
146225
}
147226

148227
} /* namespace participants */

0 commit comments

Comments
 (0)