Skip to content

Commit 2832d11

Browse files
committed
Update Spy Listeners
Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
1 parent 4406d92 commit 2832d11

2 files changed

Lines changed: 72 additions & 36 deletions

File tree

fastddsspy_participants/include/fastddsspy_participants/participant/SpyDdsParticipant.hpp

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,55 @@ class SpyDdsParticipant : public ddspipe::participants::DynTypesParticipant
5454
std::shared_ptr<ddspipe::core::IReader> create_reader(
5555
const ddspipe::core::ITopic& topic) override;
5656

57-
FASTDDSSPY_PARTICIPANTS_DllAPI
58-
void on_participant_discovery(
59-
fastdds::rtps::RTPSParticipant* participant,
60-
fastdds::rtps::ParticipantDiscoveryStatus reason,
61-
const fastdds::rtps::ParticipantBuiltinTopicData& info,
62-
bool& should_be_ignored) override;
57+
class SpyDdsParticipantListener : public ddspipe::participants::DynTypesParticipant::DynTypesRtpsListener
58+
{
59+
public:
6360

64-
FASTDDSSPY_PARTICIPANTS_DllAPI
65-
void on_reader_discovery(
66-
fastdds::rtps::RTPSParticipant* participant,
67-
fastdds::rtps::ReaderDiscoveryStatus reason,
68-
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
69-
bool& should_be_ignored) override;
61+
explicit SpyDdsParticipantListener(
62+
std::shared_ptr<ddspipe::participants::InternalReader> participants_reader,
63+
std::shared_ptr<ddspipe::participants::InternalReader> endpoints_reader);
7064

71-
FASTDDSSPY_PARTICIPANTS_DllAPI
72-
void on_writer_discovery(
73-
fastdds::rtps::RTPSParticipant* participant,
74-
fastdds::rtps::WriterDiscoveryStatus reason,
75-
const fastdds::rtps::PublicationBuiltinTopicData& info,
76-
bool& should_be_ignored) override;
65+
FASTDDSSPY_PARTICIPANTS_DllAPI
66+
void on_participant_discovery(
67+
fastdds::rtps::RTPSParticipant* participant,
68+
fastdds::rtps::ParticipantDiscoveryStatus reason,
69+
const fastdds::rtps::ParticipantBuiltinTopicData& info,
70+
bool& should_be_ignored) override;
7771

78-
protected:
72+
FASTDDSSPY_PARTICIPANTS_DllAPI
73+
void on_reader_discovery(
74+
fastdds::rtps::RTPSParticipant* participant,
75+
fastdds::rtps::ReaderDiscoveryStatus reason,
76+
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
77+
bool& should_be_ignored) override;
78+
79+
FASTDDSSPY_PARTICIPANTS_DllAPI
80+
void on_writer_discovery(
81+
fastdds::rtps::RTPSParticipant* participant,
82+
fastdds::rtps::WriterDiscoveryStatus reason,
83+
const fastdds::rtps::PublicationBuiltinTopicData& info,
84+
bool& should_be_ignored) override;
85+
86+
protected:
7987

80-
void internal_notify_participant_discovered_(
81-
const ParticipantInfo& participant_discovered);
88+
void internal_notify_participant_discovered_(
89+
const ParticipantInfo& participant_discovered);
90+
91+
void internal_notify_endpoint_discovered_(
92+
const EndpointInfo& endpoint_discovered);
93+
94+
//! Participants Internal Reader
95+
std::shared_ptr<ddspipe::participants::InternalReader> participants_reader_;
96+
97+
//! Endpoint Internal Reader
98+
std::shared_ptr<ddspipe::participants::InternalReader> endpoints_reader_;
99+
100+
};
101+
102+
protected:
82103

83-
void internal_notify_endpoint_discovered_(
84-
const EndpointInfo& endpoint_discovered);
104+
//! Override method from \c CommonParticipant to create the internal RTPS participant listener
105+
std::unique_ptr<fastdds::rtps::RTPSParticipantListener> create_listener_() override;
85106

86107
//! Participants Internal Reader
87108
std::shared_ptr<ddspipe::participants::InternalReader> participants_reader_;

fastddsspy_participants/src/cpp/participant/SpyDdsParticipant.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,24 @@ std::shared_ptr<ddspipe::core::IReader> SpyDdsParticipant::create_reader(
5454
return ddspipe::participants::DynTypesParticipant::create_reader(topic);
5555
}
5656

57-
void SpyDdsParticipant::on_participant_discovery(
57+
SpyDdsParticipant::SpyDdsParticipantListener::SpyDdsParticipantListener(
58+
std::shared_ptr<ddspipe::participants::InternalReader> participants_reader,
59+
std::shared_ptr<ddspipe::participants::InternalReader> endpoints_reader)
60+
: ddspipe::participants::DynTypesParticipant::DynTypesRtpsListener(configuration_, discovery_database_, configuration_->id)
61+
{
62+
// Set the internal readers
63+
participants_reader_ = participants_reader;
64+
endpoints_reader_ = endpoints_reader;
65+
}
66+
67+
void SpyDdsParticipant::SpyDdsParticipantListener::on_participant_discovery(
5868
fastdds::rtps::RTPSParticipant* participant,
5969
fastdds::rtps::ParticipantDiscoveryStatus reason,
6070
const fastdds::rtps::ParticipantBuiltinTopicData& info,
6171
bool& should_be_ignored)
6272
{
6373
// If comes from this participant is not interesting
64-
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, rtps_participant_->getGuid()))
74+
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, participant->getGuid()))
6575
{
6676
return;
6777
}
@@ -72,55 +82,55 @@ void SpyDdsParticipant::on_participant_discovery(
7282
participant_info.name = std::string(info.participant_name);
7383
participant_info.guid = info.guid;
7484

75-
ddspipe::participants::rtps::CommonParticipant::on_participant_discovery(participant, reason, info,
85+
ddspipe::participants::rtps::CommonParticipant::RtpsListener::on_participant_discovery(participant, reason, info,
7686
should_be_ignored);
7787

7888
internal_notify_participant_discovered_(participant_info);
7989
}
8090

81-
void SpyDdsParticipant::on_reader_discovery(
91+
void SpyDdsParticipant::SpyDdsParticipantListener::on_reader_discovery(
8292
fastdds::rtps::RTPSParticipant* participant,
8393
fastdds::rtps::ReaderDiscoveryStatus reason,
8494
const fastdds::rtps::SubscriptionBuiltinTopicData& info,
8595
bool& should_be_ignored)
8696
{
8797
// If comes from this participant is not interesting
88-
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, rtps_participant_->getGuid()))
98+
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, participant->getGuid()))
8999
{
90100
return;
91101
}
92102

93-
EndpointInfo endpoint_info = ddspipe::participants::detail::create_endpoint_from_info_(info, id());
103+
EndpointInfo endpoint_info = ddspipe::participants::detail::create_endpoint_from_info_(info, configuration_->id);
94104
endpoint_info.active = (reason == fastdds::rtps::ReaderDiscoveryStatus::DISCOVERED_READER
95105
|| reason == fastdds::rtps::ReaderDiscoveryStatus::CHANGED_QOS_READER);
96106

97-
ddspipe::participants::DynTypesParticipant::on_reader_discovery(participant, reason, info, should_be_ignored);
107+
ddspipe::participants::DynTypesParticipant::DynTypesRtpsListener::on_reader_discovery(participant, reason, info, should_be_ignored);
98108

99109
internal_notify_endpoint_discovered_(endpoint_info);
100110
}
101111

102-
void SpyDdsParticipant::on_writer_discovery(
112+
void SpyDdsParticipant::SpyDdsParticipantListener::on_writer_discovery(
103113
fastdds::rtps::RTPSParticipant* participant,
104114
fastdds::rtps::WriterDiscoveryStatus reason,
105115
const fastdds::rtps::PublicationBuiltinTopicData& info,
106116
bool& should_be_ignored)
107117
{
108118
// If comes from this participant is not interesting
109-
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, rtps_participant_->getGuid()))
119+
if (ddspipe::participants::detail::come_from_same_participant_(info.guid, participant->getGuid()))
110120
{
111121
return;
112122
}
113123

114-
EndpointInfo endpoint_info = ddspipe::participants::detail::create_endpoint_from_info_(info, id());
124+
EndpointInfo endpoint_info = ddspipe::participants::detail::create_endpoint_from_info_(info, configuration_->id);
115125
endpoint_info.active = (reason == fastdds::rtps::WriterDiscoveryStatus::DISCOVERED_WRITER
116126
|| reason == fastdds::rtps::WriterDiscoveryStatus::CHANGED_QOS_WRITER);
117127

118-
ddspipe::participants::DynTypesParticipant::on_writer_discovery(participant, reason, info, should_be_ignored);
128+
ddspipe::participants::DynTypesParticipant::DynTypesRtpsListener::on_writer_discovery(participant, reason, info, should_be_ignored);
119129

120130
internal_notify_endpoint_discovered_(endpoint_info);
121131
}
122132

123-
void SpyDdsParticipant::internal_notify_participant_discovered_(
133+
void SpyDdsParticipant::SpyDdsParticipantListener::internal_notify_participant_discovered_(
124134
const ParticipantInfo& participant_discovered)
125135
{
126136
// Create data containing Dynamic Type
@@ -131,7 +141,7 @@ void SpyDdsParticipant::internal_notify_participant_discovered_(
131141
participants_reader_->simulate_data_reception(std::move(data));
132142
}
133143

134-
void SpyDdsParticipant::internal_notify_endpoint_discovered_(
144+
void SpyDdsParticipant::SpyDdsParticipantListener::internal_notify_endpoint_discovered_(
135145
const EndpointInfo& endpoint_discovered)
136146
{
137147
// Create data containing Dynamic Type
@@ -142,6 +152,11 @@ void SpyDdsParticipant::internal_notify_endpoint_discovered_(
142152
endpoints_reader_->simulate_data_reception(std::move(data));
143153
}
144154

155+
std::unique_ptr<fastdds::rtps::RTPSParticipantListener> SpyDdsParticipant::create_listener_()
156+
{
157+
return std::make_unique<SpyDdsParticipantListener>(participants_reader_, endpoints_reader_);
158+
}
159+
145160
} /* namespace participants */
146161
} /* namespace spy */
147162
} /* namespace eprosima */

0 commit comments

Comments
 (0)