Skip to content

Commit 065776a

Browse files
authored
DataWriter/Reader get_matched_publication/subscription...() Feature implementation (#5284)
* Refs #21711: RTPSReader matched_writers_guids() implementation Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: RTPSWriter matched_readers_guids() implementation Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: ProxyDataConverters Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: RTPSParticipant get_subscription/publication_info() implementation Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: DataReader get_matched_publication_data() get_matched_publications() implementation Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: DataWriter get_matched_subscription_data() get_matched_subscriptions() implementation Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: versions.md Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: Update unsupported api tests and fastrtps_deprecated api Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: Apply Ricardo's rev Signed-off-by: Mario Dominguez <[email protected]> * Refs #21711: doxygen docs test fix Signed-off-by: Mario Dominguez <[email protected]> --------- Signed-off-by: Mario Dominguez <[email protected]>
1 parent 9729667 commit 065776a

File tree

35 files changed

+723
-83
lines changed

35 files changed

+723
-83
lines changed

include/fastdds/dds/publisher/DataWriter.hpp

+8-4
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,16 +529,20 @@ 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;
538539

539540
#ifndef DOXYGEN_SHOULD_SKIP_THIS
540541
FASTDDS_DEPRECATED_UNTIL(3, "eprosima::fastdds::dds:DataWriter::get_matched_subscriptions()",
541542
"In favor of version using std::vector<fastrtps::rtps::InstanceHandle_t>.")
543+
/**
544+
* @note User is responsible for the memory deallocation of the returned vector.
545+
*/
542546
RTPS_DllAPI ReturnCode_t get_matched_subscriptions(
543547
std::vector<InstanceHandle_t*>& subscription_handles) const;
544548
#endif // DOXYGEN_SHOULD_SKIP_THIS

include/fastdds/dds/subscriber/DataReader.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,9 @@ class DataReader : public DomainEntity
977977
*
978978
* @param[out] publication_data publication data struct
979979
* @param publication_handle InstanceHandle_t of the publication
980-
* @return RETCODE_OK
980+
* @return RETCODE_BAD_PARAMETER if the DataReader is not matched with
981+
* the given publication handle, RETCODE_OK otherwise.
981982
*
982-
* @warning Not supported yet. Currently returns RETCODE_UNSUPPORTED
983983
*/
984984
RTPS_DllAPI ReturnCode_t get_matched_publication_data(
985985
builtin::PublicationBuiltinTopicData& publication_data,
@@ -989,9 +989,10 @@ class DataReader : public DomainEntity
989989
* @brief Fills the given vector with the InstanceHandle_t of matched DataReaders
990990
*
991991
* @param[out] publication_handles Vector where the InstanceHandle_t are returned
992-
* @return RETCODE_OK
992+
* @return RETCODE_OK if the operation succeeds.
993+
*
994+
* @note Returning an empty list is not an error, it returns RETCODE_OK.
993995
*
994-
* @warning Not supported yet. Currently returns RETCODE_UNSUPPORTED
995996
*/
996997
RTPS_DllAPI ReturnCode_t get_matched_publications(
997998
std::vector<InstanceHandle_t>& publication_handles) const;

include/fastdds/rtps/participant/RTPSParticipant.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ class RTPS_DllAPI RTPSParticipant
309309
std::vector<fastdds::rtps::TransportNetmaskFilterInfo> get_netmask_filter_info() const;
310310

311311
/**
312-
* @brief Fills the provided fastdds::dds::builtin::PublicationBuiltinTopicData with the information of the
312+
* @brief Fills the provided publication data with the information of the
313313
* writer identified by writer_guid.
314314
*
315-
* @param[out] data fastdds::dds::builtin::PublicationBuiltinTopicData to fill.
315+
* @param[out] data publication data to fill.
316316
* @param[in] writer_guid GUID of the writer to get the information from.
317317
* @return True if the writer was found and the data was filled.
318318
*/
@@ -321,10 +321,10 @@ class RTPS_DllAPI RTPSParticipant
321321
const GUID_t& writer_guid) const;
322322

323323
/**
324-
* @brief Fills the provided fastdds::dds::builtin::SubscriptionBuiltinTopicData with the information of the
324+
* @brief Fills the provided subscription discovery data with the information of the
325325
* reader identified by reader_guid.
326326
*
327-
* @param[out] data fastdds::dds::builtin::SubscriptionBuiltinTopicData to fill.
327+
* @param[out] data subscription discovery data to fill.
328328
* @param[in] reader_guid GUID of the reader to get the information from.
329329
* @return True if the reader was found and the data was filled.
330330
*/

include/fastdds/rtps/reader/RTPSReader.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ class RTPSReader
282282
* @param[out] guids Vector to be filled with the GUIDs of the matched writers.
283283
* @return True if the operation was successful.
284284
*/
285-
RTPS_DllAPI bool matched_writers_guids(
286-
std::vector<GUID_t>& guids) const;
285+
RTPS_DllAPI virtual bool matched_writers_guids(
286+
std::vector<GUID_t>& guids) const = 0;
287287

288288
/*!
289289
* @brief Returns there is a clean state with all Writers.

include/fastdds/rtps/reader/StatefulReader.h

+9
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ class StatefulReader : public RTPSReader
328328
WriterProxy* writer,
329329
bool mark_as_read = true) override;
330330

331+
/**
332+
* @brief Fills the provided vector with the GUIDs of the matched writers.
333+
*
334+
* @param[out] guids Vector to be filled with the GUIDs of the matched writers.
335+
* @return True if the operation was successful.
336+
*/
337+
bool matched_writers_guids(
338+
std::vector<GUID_t>& guids) const override;
339+
331340
#ifdef FASTDDS_STATISTICS
332341
bool get_connections(
333342
fastdds::statistics::rtps::ConnectionList& connection_list) override;

include/fastdds/rtps/reader/StatelessReader.h

+9
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@ class StatelessReader : public RTPSReader
253253
WriterProxy* writer,
254254
bool mark_as_read = true) override;
255255

256+
/**
257+
* @brief Fills the provided vector with the GUIDs of the matched writers.
258+
*
259+
* @param[out] guids Vector to be filled with the GUIDs of the matched writers.
260+
* @return True if the operation was successful.
261+
*/
262+
bool matched_writers_guids(
263+
std::vector<GUID_t>& guids) const override;
264+
256265
#ifdef FASTDDS_STATISTICS
257266
bool get_connections(
258267
fastdds::statistics::rtps::ConnectionList& connection_list) override;

include/fastdds/rtps/writer/RTPSWriter.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ class RTPSWriter
323323
* @param[out] guids Vector to be filled with the GUIDs of the matched readers.
324324
* @return True if the operation was successful.
325325
*/
326-
RTPS_DllAPI bool matched_readers_guids(
327-
std::vector<GUID_t>& guids) const;
326+
RTPS_DllAPI virtual bool matched_readers_guids(
327+
std::vector<GUID_t>& guids) const = 0;
328328

329329
/**
330330
* Tries to remove a change waiting a maximum of the provided microseconds.

include/fastdds/rtps/writer/StatefulWriter.h

+9
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ class StatefulWriter : public RTPSWriter
448448
return locator_selector_async_;
449449
}
450450

451+
/**
452+
* @brief Fills the provided vector with the GUIDs of the matched readers.
453+
*
454+
* @param[out] guids Vector to be filled with the GUIDs of the matched readers.
455+
* @return True if the operation was successful.
456+
*/
457+
bool matched_readers_guids(
458+
std::vector<GUID_t>& guids) const override;
459+
451460
#ifdef FASTDDS_STATISTICS
452461
bool get_connections(
453462
fastdds::statistics::rtps::ConnectionList& connection_list) override;

include/fastdds/rtps/writer/StatelessWriter.h

+9
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ class StatelessWriter : public RTPSWriter
241241
return locator_selector_;
242242
}
243243

244+
/**
245+
* @brief Fills the provided vector with the GUIDs of the matched readers.
246+
*
247+
* @param[out] guids Vector to be filled with the GUIDs of the matched readers.
248+
* @return True if the operation was successful.
249+
*/
250+
bool matched_readers_guids(
251+
std::vector<GUID_t>& guids) const override;
252+
244253
#ifdef FASTDDS_STATISTICS
245254
bool get_connections(
246255
fastdds::statistics::rtps::ConnectionList& connection_list) override;

src/cpp/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ set(${PROJECT_NAME}_source_files
203203
rtps/builtin/liveliness/WLP.cpp
204204
rtps/builtin/liveliness/WLPListener.cpp
205205
rtps/builtin/data/ParticipantProxyData.cpp
206+
rtps/builtin/data/ProxyDataConverters.cpp
206207
rtps/builtin/data/WriterProxyData.cpp
207208
rtps/builtin/data/ReaderProxyData.cpp
208209
rtps/flowcontrol/ThroughputControllerDescriptor.cpp

src/cpp/fastdds/publisher/DataWriter.cpp

+3-16
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

+63
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.emplace_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

+28
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;

src/cpp/fastdds/subscriber/DataReader.cpp

+2-11
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,13 @@ ReturnCode_t DataReader::get_matched_publication_data(
395395
builtin::PublicationBuiltinTopicData& publication_data,
396396
const fastrtps::rtps::InstanceHandle_t& publication_handle) const
397397
{
398-
static_cast<void> (publication_data);
399-
static_cast<void> (publication_handle);
400-
return ReturnCode_t::RETCODE_UNSUPPORTED;
401-
/*
402-
return impl_->get_matched_publication_data(publication_data, publication_handle);
403-
*/
398+
return impl_->get_matched_publication_data(publication_data, publication_handle);
404399
}
405400

406401
ReturnCode_t DataReader::get_matched_publications(
407402
std::vector<InstanceHandle_t>& publication_handles) const
408403
{
409-
static_cast<void> (publication_handles);
410-
return ReturnCode_t::RETCODE_UNSUPPORTED;
411-
/*
412-
return impl_->get_matched_publication_data(publication_handles);
413-
*/
404+
return impl_->get_matched_publications(publication_handles);
414405
}
415406

416407
ReadCondition* DataReader::create_readcondition(

src/cpp/fastdds/subscriber/DataReaderImpl.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,48 @@ ReturnCode_t DataReaderImpl::get_subscription_matched_status(
11981198
return ReturnCode_t::RETCODE_OK;
11991199
}
12001200

1201+
ReturnCode_t DataReaderImpl::get_matched_publication_data(
1202+
builtin::PublicationBuiltinTopicData& publication_data,
1203+
const fastrtps::rtps::InstanceHandle_t& publication_handle) const
1204+
{
1205+
fastrtps::types::ReturnCode_t ret = ReturnCode_t::RETCODE_BAD_PARAMETER;
1206+
GUID_t writer_guid = iHandle2GUID(publication_handle);
1207+
1208+
if (reader_ && reader_->matched_writer_is_matched(writer_guid))
1209+
{
1210+
if (subscriber_)
1211+
{
1212+
RTPSParticipant* rtps_participant = subscriber_->rtps_participant();
1213+
if (rtps_participant &&
1214+
rtps_participant->get_publication_info(publication_data, writer_guid))
1215+
{
1216+
ret = ReturnCode_t::RETCODE_OK;
1217+
}
1218+
}
1219+
}
1220+
1221+
return ret;
1222+
}
1223+
1224+
ReturnCode_t DataReaderImpl::get_matched_publications(
1225+
std::vector<InstanceHandle_t>& publication_handles) const
1226+
{
1227+
ReturnCode_t ret = ReturnCode_t::RETCODE_ERROR;
1228+
std::vector<GUID_t> matched_writers_guids;
1229+
publication_handles.clear();
1230+
1231+
if (reader_ && reader_->matched_writers_guids(matched_writers_guids))
1232+
{
1233+
for (const GUID_t& guid : matched_writers_guids)
1234+
{
1235+
publication_handles.emplace_back(InstanceHandle_t(guid));
1236+
}
1237+
ret = ReturnCode_t::RETCODE_OK;
1238+
}
1239+
1240+
return ret;
1241+
}
1242+
12011243
bool DataReaderImpl::deadline_timer_reschedule()
12021244
{
12031245
assert(qos_.deadline().period != c_TimeInfinite);

0 commit comments

Comments
 (0)