@@ -35,6 +35,25 @@ namespace dds {
3535
3636using namespace eprosima ::ddspipe::core::types;
3737
38+ static void apply_reader_partitions_ (
39+ fastdds::dds::PartitionQosPolicy& partition_qos,
40+ const std::set<std::string>& partitions_filter)
41+ {
42+ partition_qos.clear ();
43+
44+ // Empty filter means no filter: subscribe to all partitions
45+ if (partitions_filter.empty ())
46+ {
47+ partition_qos.push_back (" *" );
48+ return ;
49+ }
50+
51+ for (const std::string& partition : partitions_filter)
52+ {
53+ partition_qos.push_back (partition.c_str ());
54+ }
55+ }
56+
3857CommonReader::~CommonReader ()
3958{
4059 // This variables should be set, otherwise the creation should have fail
@@ -76,22 +95,11 @@ void CommonReader::init(
7695 << participant_id_ << " in topic " << topic_ << " ." );
7796 }
7897
79- // If the reader has an active filter
80- // change the qos partition before creating the datareader.
81- if (partitions_set.size () > 0 )
82- {
83- // Get the current subscriber qos
84- fastdds::dds::SubscriberQos sub_qos = dds_subscriber_->get_qos ();
85- // Remove all partitions from the qos
86- sub_qos.partition ().clear ();
87- // Add the filter partitions
88- for (const std::string& partition: partitions_set)
89- {
90- sub_qos.partition ().push_back (partition.c_str ());
91- }
92- // Update the subscriber qos
93- dds_subscriber_->set_qos (sub_qos);
94- }
98+ // Update subscriber partitions before creating the datareader
99+ // Empty filter means subscribe to all partitions ("*")
100+ fastdds::dds::SubscriberQos sub_qos = dds_subscriber_->get_qos ();
101+ apply_reader_partitions_ (sub_qos.partition (), partitions_set);
102+ dds_subscriber_->set_qos (sub_qos);
95103
96104 auto topic_tmp = dds_participant_->find_topic (topic_.topic_name (), 10 );
97105
@@ -263,10 +271,6 @@ void CommonReader::enable_nts_() noexcept
263271fastdds::dds::SubscriberQos CommonReader::reckon_subscriber_qos_ () const
264272{
265273 fastdds::dds::SubscriberQos qos = dds_participant_->get_default_subscriber_qos ();
266- if (topic_.topic_qos .has_partitions ())
267- {
268- qos.partition ().push_back (" *" );
269- }
270274 qos.entity_factory ().autoenable_created_entities = false ;
271275 return qos;
272276}
@@ -393,12 +397,7 @@ void CommonReader::update_partitions(
393397 const std::set<std::string>& partitions_set)
394398{
395399 fastdds::dds::SubscriberQos sub_qos = dds_subscriber_->get_qos ();
396- sub_qos.partition ().clear ();
397- for (const std::string& partition: partitions_set)
398- {
399- sub_qos.partition ().push_back (partition.c_str ());
400- }
401-
400+ apply_reader_partitions_ (sub_qos.partition (), partitions_set);
402401 dds_subscriber_->set_qos (sub_qos);
403402}
404403
0 commit comments