Skip to content

Commit d0935da

Browse files
committed
[#24061] Updated code for filter
Signed-off-by: danipiza <dpizarrogallego@gmail.com>
1 parent a1b727c commit d0935da

20 files changed

Lines changed: 179 additions & 37 deletions

File tree

ddspipe_core/include/ddspipe_core/communication/dds/DdsBridge.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ class DdsBridge : public Bridge
113113
void remove_writer(
114114
const types::ParticipantId& participant_id) noexcept;
115115

116+
DDSPIPE_CORE_DllAPI
117+
void add_partition_to_topic(
118+
std::string guid,
119+
std::string partition);
120+
116121
/**
117122
* TODO
118123
*/

ddspipe_core/include/ddspipe_core/communication/dds/Track.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class Track
251251
/**
252252
* Boolean use to update fastddsspy filter
253253
*/
254-
std::atomic<bool> is_fastddsspy;
254+
std::atomic<bool> has_filter_;
255255

256256
/**
257257
* Mutex to guard while the Track is sending a message so it could not be disabled.

ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ class DdsPipe
9898
utils::ReturnCode reload_configuration(
9999
const DdsPipeConfiguration& new_configuration);
100100

101+
/** TODO. danip
102+
* @brief Reload the filter partitions set.
103+
*
104+
* @param [in] new_filter_partition_set : new filter partition set.
105+
*
106+
* @return \c RETCODE_OK if the new std::set has been updated correctly.
107+
* @return \c RETCODE_ERROR if any other error has occurred.
108+
*
109+
* @note This method calls \c update_readers_track() of all Topic bridges, to update the DataReaders.
110+
*/
111+
// DDSPIPE_CORE_DllAPI
112+
// void reload_filter_partition(
113+
// const std::set<std::string> new_filter_partition_set);
114+
101115
/////////////////////////
102116
// ENABLING METHODS
103117
/////////////////////////
@@ -128,7 +142,7 @@ class DdsPipe
128142

129143
DDSPIPE_CORE_DllAPI
130144
void update_partitions(
131-
std::set<std::string> partitions_set);
145+
std::set<std::string> partitions_set);
132146

133147
DDSPIPE_CORE_DllAPI
134148
void update_content_filter(

ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ std::ostream& operator <<(
353353
return os;
354354
}
355355

356+
void DdsBridge::add_partition_to_topic(
357+
std::string guid,
358+
std::string partition)
359+
{
360+
topic_->partition_name[guid] = partition;
361+
}
362+
356363
} /* namespace core */
357364
} /* namespace ddspipe */
358365
} /* namespace eprosima */

ddspipe_core/src/cpp/communication/dds/Track.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Track::Track(
6363

6464
// Initialized to false, only fastddspy
6565
// will change this value
66-
is_fastddsspy = false;
66+
has_filter_ = false;
6767

6868
logDebug(DDSPIPE_TRACK, "Track " << *this << " created.");
6969
}
@@ -110,7 +110,7 @@ void Track::enable() noexcept
110110
writer_it.second->enable();
111111
}
112112

113-
if(is_fastddsspy)
113+
if(has_filter_)
114114
{
115115
reader_->update_content_topic_filter("");
116116
reader_->update_partitions(std::set<std::string>());

ddspipe_core/src/cpp/core/DdsPipe.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ utils::ReturnCode DdsPipe::reload_configuration(
131131
return reload_allowed_topics_(allowed_topics);
132132
}
133133

134+
// void DdsPipe::reload_filter_partition(
135+
// const std::set<std::string> filter_partition_set)
136+
// {
137+
// update_filter(filter_partition_set);
138+
139+
// std::vector<DdsBridge*> targets;
140+
// {
141+
// std::lock_guard<std::mutex> lock(bridges_mutex_);
142+
143+
// for (const auto& bridge : bridges_)
144+
// {
145+
// if (bridge.second)
146+
// {
147+
// targets.push_back(bridge.second.get());
148+
// }
149+
// }
150+
// }
151+
152+
// for (auto* target : targets)
153+
// {
154+
// target->update_readers_track(filter_partition_set);
155+
// }
156+
// }
157+
134158
utils::ReturnCode DdsPipe::enable() noexcept
135159
{
136160
std::lock_guard<std::mutex> lock(mutex_);
@@ -292,7 +316,40 @@ void DdsPipe::discovered_endpoint_nts_(
292316
}
293317
else if (is_endpoint_relevant_(endpoint))
294318
{
295-
discovered_topic_nts_(utils::Heritable<DdsTopic>::make_heritable(endpoint.topic));
319+
DdsTopic topic_with_partitions = endpoint.topic;
320+
topic_with_partitions.partition_name = endpoint.specific_partitions;
321+
322+
discovered_topic_nts_(utils::Heritable<DdsTopic>::make_heritable(topic_with_partitions));
323+
}
324+
else
325+
{
326+
// there is a filter.
327+
// update the track of the topic to
328+
// add the partition in the reader if it is in the filter
329+
330+
// update partitions under bridges_mutex_
331+
{
332+
std::lock_guard<std::mutex> lock(bridges_mutex_);
333+
334+
const auto bridge_it = bridges_.find(utils::Heritable<DdsTopic>::make_heritable(endpoint.topic));
335+
// add the specific partition of the endpoint in the bridges topic.
336+
if (bridge_it != bridges_.end())
337+
{
338+
std::ostringstream guid_ss;
339+
guid_ss << endpoint.guid;
340+
341+
const auto part_it = endpoint.specific_partitions.find(guid_ss.str());
342+
if (part_it != endpoint.specific_partitions.end())
343+
{
344+
bridge_it->second->add_partition_to_topic(guid_ss.str(), part_it->second);
345+
}
346+
}
347+
}
348+
// update readers outside the lock
349+
// if (!filter_partition_.empty()) // TODO. danip
350+
// {
351+
// update_readers_track(endpoint.topic.m_topic_name, filter_partition_);
352+
// }
296353
}
297354
}
298355

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class CommonParticipant : public core::IParticipant
198198
const std::shared_ptr<SimpleParticipantConfiguration>& participant_configuration,
199199
const std::shared_ptr<core::PayloadPool>& payload_pool,
200200
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database,
201-
bool is_fastddsspy);
201+
bool has_filter);
202202

203203
/////////////////////////
204204
// VIRTUAL METHODS
@@ -272,7 +272,7 @@ class CommonParticipant : public core::IParticipant
272272
//! <Topics <Writer_guid, Partitions set>>
273273
std::map<std::string, std::map<std::string, std::string>> partition_names;
274274

275-
bool is_fastddsspy_;
275+
bool has_filter_;
276276
};
277277

278278
} /* namespace dds */

ddspipe_participants/include/ddspipe_participants/participant/dds/XmlParticipant.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class XmlParticipant
3737
const std::shared_ptr<XmlParticipantConfiguration>& participant_configuration,
3838
const std::shared_ptr<core::PayloadPool>& payload_pool,
3939
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database,
40-
bool is_fastddsspy = false);
40+
bool has_filter = false);
4141

4242
/**
4343
* Specialized parent call so if it fails returns a blank one.
@@ -55,6 +55,13 @@ class XmlParticipant
5555
std::shared_ptr<core::IReader> create_reader(
5656
const core::ITopic& topic) override;
5757

58+
DDSPIPE_PARTICIPANTS_DllAPI
59+
void update_filters(
60+
const int flag,
61+
std::set<std::string> partitions = std::set<std::string>(),
62+
const std::string& topic_name = "",
63+
const std::string& expression = "");
64+
5865
protected:
5966

6067
/////////////////////////
@@ -72,6 +79,13 @@ class XmlParticipant
7279

7380
//! Participant configuration
7481
const XmlParticipantConfiguration& xml_specific_configuration_;
82+
83+
// Boolean to check if the created participant has filter
84+
bool has_filter_;
85+
// Filter partitions set
86+
std::set<std::string> partition_filter_set_;
87+
// Filter content_topicfilter dict
88+
std::map<std::string, std::string> topic_filter_dict_;
7589
};
7690

7791
} /* namespace dds */

ddspipe_participants/include/ddspipe_participants/participant/dynamic_types/XmlDynTypesParticipant.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class XmlDynTypesParticipant : public dds::XmlParticipant
6262
std::shared_ptr<XmlParticipantConfiguration> participant_configuration,
6363
std::shared_ptr<core::PayloadPool> payload_pool,
6464
std::shared_ptr<core::DiscoveryDatabase> discovery_database,
65-
bool is_fastddsspy = false);
65+
bool has_filter = false);
6666

6767
/**
6868
* @brief Creates a writer object based on the topic QoS.

ddspipe_participants/include/ddspipe_participants/reader/dds/CommonReader.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CommonReader : public BaseReader, public fastdds::dds::DataReaderListener,
118118
const std::shared_ptr<core::PayloadPool>& payload_pool,
119119
fastdds::dds::DomainParticipant* participant,
120120
fastdds::dds::Topic* topic_entity,
121-
bool is_fastddsspy);
121+
bool has_filter);
122122

123123
// Specific enable/disable do not need to be implemented
124124

@@ -185,7 +185,7 @@ class CommonReader : public BaseReader, public fastdds::dds::DataReaderListener,
185185
core::types::DdsTopic topic_;
186186
eprosima::fastdds::dds::ContentFilteredTopic* filtered_topic_;
187187
//std::string filter;
188-
bool is_fastddsspy_;
188+
bool has_filter_;
189189

190190
fastdds::dds::Subscriber* dds_subscriber_;
191191
fastdds::dds::DataReader* reader_;

0 commit comments

Comments
 (0)