Skip to content

Commit c1b44ab

Browse files
committed
Refs #21711: DataWriter get_matched_subscription_data() get_matched_subscriptions() implementation
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
1 parent 728249f commit c1b44ab

5 files changed

Lines changed: 121 additions & 21 deletions

File tree

include/fastdds/dds/publisher/DataWriter.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,9 @@ class DataWriter : public DomainEntity
517517
*
518518
* @param[out] subscription_data subscription data struct
519519
* @param subscription_handle InstanceHandle_t of the subscription
520-
* @return RETCODE_OK
520+
* @return RETCODE_BAD_PARAMETER if the DataWriter is not matched with
521+
* the given subscription handle, RETCODE_OK otherwise.
521522
*
522-
* @warning Not supported yet. Currently returns RETCODE_UNSUPPORTED
523523
*/
524524
RTPS_DllAPI ReturnCode_t get_matched_subscription_data(
525525
builtin::SubscriptionBuiltinTopicData& subscription_data,
@@ -529,13 +529,16 @@ class DataWriter : public DomainEntity
529529
* @brief Fills the given vector with the InstanceHandle_t of matched DataReaders
530530
*
531531
* @param[out] subscription_handles Vector where the InstanceHandle_t are returned
532-
* @return RETCODE_OK
532+
* @return RETCODE_OK if the operation succeeds.
533+
*
534+
* @note Returning an empty list is not an error, it returns RETCODE_OK.
533535
*
534-
* @warning Not supported yet. Currently returns RETCODE_UNSUPPORTED
535536
*/
536537
RTPS_DllAPI ReturnCode_t get_matched_subscriptions(
537538
std::vector<InstanceHandle_t>& subscription_handles) const;
538-
539+
/**
540+
* @note User is responsible for the memory deallocation of the returned vector.
541+
*/
539542
#ifndef DOXYGEN_SHOULD_SKIP_THIS
540543
FASTDDS_DEPRECATED_UNTIL(3, "eprosima::fastdds::dds:DataWriter::get_matched_subscriptions()",
541544
"In favor of version using std::vector<fastrtps::rtps::InstanceHandle_t>.")

src/cpp/fastdds/publisher/DataWriter.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,32 +302,19 @@ ReturnCode_t DataWriter::get_matched_subscription_data(
302302
builtin::SubscriptionBuiltinTopicData& subscription_data,
303303
const InstanceHandle_t& subscription_handle) const
304304
{
305-
static_cast<void> (subscription_data);
306-
static_cast<void> (subscription_handle);
307-
return ReturnCode_t::RETCODE_UNSUPPORTED;
308-
/*
309-
return impl_->get_matched_subscription_data(subscription_data, subscription_handle);
310-
*/
305+
return impl_->get_matched_subscription_data(subscription_data, subscription_handle);
311306
}
312307

313308
ReturnCode_t DataWriter::get_matched_subscriptions(
314309
std::vector<InstanceHandle_t>& subscription_handles) const
315310
{
316-
static_cast<void> (subscription_handles);
317-
return ReturnCode_t::RETCODE_UNSUPPORTED;
318-
/*
319-
return impl_->get_matched_subscription_data(subscription_handles);
320-
*/
311+
return impl_->get_matched_subscriptions(subscription_handles);
321312
}
322313

323314
ReturnCode_t DataWriter::get_matched_subscriptions(
324315
std::vector<InstanceHandle_t*>& subscription_handles) const
325316
{
326-
static_cast<void> (subscription_handles);
327-
return ReturnCode_t::RETCODE_UNSUPPORTED;
328-
/*
329-
return impl_->get_matched_subscription_data(subscription_handles);
330-
*/
317+
return impl_->get_matched_subscriptions(subscription_handles);
331318
}
332319

333320
ReturnCode_t DataWriter::clear_history(

src/cpp/fastdds/publisher/DataWriterImpl.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,69 @@ void DataWriterImpl::filter_is_being_removed(
22282228
}
22292229
}
22302230

2231+
ReturnCode_t DataWriterImpl::get_matched_subscription_data(
2232+
builtin::SubscriptionBuiltinTopicData& subscription_data,
2233+
const fastrtps::rtps::InstanceHandle_t& subscription_handle) const
2234+
{
2235+
fastrtps::types::ReturnCode_t ret = ReturnCode_t::RETCODE_BAD_PARAMETER;
2236+
GUID_t reader_guid = iHandle2GUID(subscription_handle);
2237+
2238+
if (writer_ && writer_->matched_reader_is_matched(reader_guid))
2239+
{
2240+
if (publisher_)
2241+
{
2242+
RTPSParticipant* rtps_participant = publisher_->rtps_participant();
2243+
if (rtps_participant &&
2244+
rtps_participant->get_subscription_info(subscription_data, reader_guid))
2245+
{
2246+
ret = ReturnCode_t::RETCODE_OK;
2247+
}
2248+
}
2249+
}
2250+
2251+
return ret;
2252+
}
2253+
2254+
ReturnCode_t DataWriterImpl::get_matched_subscriptions(
2255+
std::vector<InstanceHandle_t>& subscription_handles) const
2256+
{
2257+
ReturnCode_t ret = ReturnCode_t::RETCODE_ERROR;
2258+
std::vector<GUID_t> matched_reader_guids;
2259+
subscription_handles.clear();
2260+
2261+
if (writer_ && writer_->matched_readers_guids(matched_reader_guids))
2262+
{
2263+
for (const GUID_t& guid : matched_reader_guids)
2264+
{
2265+
subscription_handles.push_back(InstanceHandle_t(guid));
2266+
}
2267+
ret = ReturnCode_t::RETCODE_OK;
2268+
}
2269+
2270+
return ret;
2271+
}
2272+
2273+
ReturnCode_t DataWriterImpl::get_matched_subscriptions(
2274+
std::vector<InstanceHandle_t*>& subscription_handles) const
2275+
{
2276+
ReturnCode_t ret = ReturnCode_t::RETCODE_ERROR;
2277+
std::vector<GUID_t> matched_reader_guids;
2278+
subscription_handles.clear();
2279+
2280+
if (writer_ && writer_->matched_readers_guids(matched_reader_guids))
2281+
{
2282+
for (const GUID_t& guid : matched_reader_guids)
2283+
{
2284+
// Note: user is responsible for deleting the InstanceHandle_t objects
2285+
subscription_handles.push_back(new InstanceHandle_t(guid));
2286+
}
2287+
2288+
ret = ReturnCode_t::RETCODE_OK;
2289+
}
2290+
2291+
return ret;
2292+
}
2293+
22312294
bool DataWriterImpl::is_relevant(
22322295
const fastrtps::rtps::CacheChange_t& change,
22332296
const fastrtps::rtps::GUID_t& reader_guid) const

src/cpp/fastdds/publisher/DataWriterImpl.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,34 @@ class DataWriterImpl : protected rtps::IReaderDataFilter
389389
void filter_is_being_removed(
390390
const char* filter_class_name);
391391

392+
/**
393+
* @brief Retrieves in a subscription associated with the DataWriter
394+
*
395+
* @param[out] subscription_data subscription data struct
396+
* @param subscription_handle InstanceHandle_t of the subscription
397+
* @return RETCODE_BAD_PARAMETER if the DataWriter is not matched with
398+
* the given subscription handle, RETCODE_OK otherwise.
399+
*
400+
*/
401+
ReturnCode_t get_matched_subscription_data(
402+
builtin::SubscriptionBuiltinTopicData& subscription_data,
403+
const InstanceHandle_t& subscription_handle) const;
404+
405+
/**
406+
* @brief Fills the given vector with the InstanceHandle_t of matched DataReaders
407+
*
408+
* @param[out] subscription_handles Vector where the InstanceHandle_t are returned
409+
* @return RETCODE_OK if the operation succeeds.
410+
*
411+
* @note Returning an empty list is not an error, it returns RETCODE_OK.
412+
*
413+
*/
414+
ReturnCode_t get_matched_subscriptions(
415+
std::vector<InstanceHandle_t>& subscription_handles) const;
416+
417+
ReturnCode_t get_matched_subscriptions(
418+
std::vector<InstanceHandle_t*>& subscription_handles) const;
419+
392420
protected:
393421

394422
using IChangePool = eprosima::fastrtps::rtps::IChangePool;

test/unittest/statistics/dds/StatisticsDomainParticipantStatusQueryableTests/mock/fastdds/publisher/DataWriterImpl.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,25 @@ class DataWriterImpl : protected rtps::IReaderDataFilter
429429

430430
}
431431

432+
ReturnCode_t get_matched_subscription_data(
433+
builtin::SubscriptionBuiltinTopicData&,
434+
const InstanceHandle_t& ) const
435+
{
436+
return ReturnCode_t::RETCODE_OK;
437+
}
438+
439+
ReturnCode_t get_matched_subscriptions(
440+
std::vector<InstanceHandle_t>&) const
441+
{
442+
return ReturnCode_t::RETCODE_OK;
443+
}
444+
445+
ReturnCode_t get_matched_subscriptions(
446+
std::vector<InstanceHandle_t*>&) const
447+
{
448+
return ReturnCode_t::RETCODE_OK;
449+
}
450+
432451
//! Pointer to the associated Data Writer.
433452
fastrtps::rtps::RTPSWriter* writer_ = nullptr;
434453
Topic* topic_ = nullptr;

0 commit comments

Comments
 (0)