Skip to content

Commit 728249f

Browse files
committed
Refs #21711: DataReader get_matched_publication_data() get_matched_publications() implementation
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
1 parent 1d026ce commit 728249f

4 files changed

Lines changed: 80 additions & 15 deletions

File tree

include/fastdds/dds/subscriber/DataReader.hpp

Lines changed: 5 additions & 4 deletions
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;

src/cpp/fastdds/subscriber/DataReader.cpp

Lines changed: 2 additions & 11 deletions
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

Lines changed: 42 additions & 0 deletions
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.push_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);

src/cpp/fastdds/subscriber/DataReaderImpl.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class ReadConditionImpl;
7575

7676
} // namespace detail
7777

78+
namespace builtin {
79+
80+
struct PublicationBuiltinTopicData;
81+
82+
} // namespace builtin
83+
7884
/**
7985
* Class DataReader, contains the actual implementation of the behaviour of the Subscriber.
8086
* @ingroup FASTDDS_MODULE
@@ -237,6 +243,31 @@ class DataReaderImpl
237243
ReturnCode_t get_subscription_matched_status(
238244
SubscriptionMatchedStatus& status);
239245

246+
/**
247+
* @brief Retrieves in a publication associated with the DataWriter
248+
*
249+
* @param[out] publication_data publication data struct
250+
* @param publication_handle InstanceHandle_t of the publication
251+
* @return RETCODE_BAD_PARAMETER if the DataReader is not matched with
252+
* the given publication handle, RETCODE_OK otherwise.
253+
*
254+
*/
255+
ReturnCode_t get_matched_publication_data(
256+
builtin::PublicationBuiltinTopicData& publication_data,
257+
const fastrtps::rtps::InstanceHandle_t& publication_handle) const;
258+
259+
/**
260+
* @brief Fills the given vector with the InstanceHandle_t of matched DataReaders
261+
*
262+
* @param[out] publication_handles Vector where the InstanceHandle_t are returned
263+
* @return RETCODE_OK if the operation succeeds.
264+
*
265+
* @note Returning an empty list is not an error, it returns RETCODE_OK.
266+
*
267+
*/
268+
ReturnCode_t get_matched_publications(
269+
std::vector<InstanceHandle_t>& publication_handles) const;
270+
240271
ReturnCode_t get_requested_deadline_missed_status(
241272
fastrtps::RequestedDeadlineMissedStatus& status);
242273

0 commit comments

Comments
 (0)