Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[21711] DataWriter/Reader get_matched_publication/subscription...() Feature implementation #5284

Merged
merged 10 commits into from
Oct 9, 2024
Prev Previous commit
Next Next commit
Refs #21711: DataWriter get_matched_subscription_data() get_matched_s…
…ubscriptions() implementation

Signed-off-by: Mario Dominguez <[email protected]>
Mario-DL committed Oct 8, 2024
commit 19914c756187f01ca64e0bbaab232b6ffb3e4dbb
13 changes: 8 additions & 5 deletions include/fastdds/dds/publisher/DataWriter.hpp
Original file line number Diff line number Diff line change
@@ -517,9 +517,9 @@ class DataWriter : public DomainEntity
*
* @param[out] subscription_data subscription data struct
* @param subscription_handle InstanceHandle_t of the subscription
* @return RETCODE_OK
* @return RETCODE_BAD_PARAMETER if the DataWriter is not matched with
* the given subscription handle, RETCODE_OK otherwise.
*
* @warning Not supported yet. Currently returns RETCODE_UNSUPPORTED
*/
RTPS_DllAPI ReturnCode_t get_matched_subscription_data(
builtin::SubscriptionBuiltinTopicData& subscription_data,
@@ -529,13 +529,16 @@ class DataWriter : public DomainEntity
* @brief Fills the given vector with the InstanceHandle_t of matched DataReaders
*
* @param[out] subscription_handles Vector where the InstanceHandle_t are returned
* @return RETCODE_OK
* @return RETCODE_OK if the operation succeeds.
*
* @note Returning an empty list is not an error, it returns RETCODE_OK.
*
* @warning Not supported yet. Currently returns RETCODE_UNSUPPORTED
*/
RTPS_DllAPI ReturnCode_t get_matched_subscriptions(
std::vector<InstanceHandle_t>& subscription_handles) const;

/**
* @note User is responsible for the memory deallocation of the returned vector.
*/
#ifndef DOXYGEN_SHOULD_SKIP_THIS
FASTDDS_DEPRECATED_UNTIL(3, "eprosima::fastdds::dds:DataWriter::get_matched_subscriptions()",
"In favor of version using std::vector<fastrtps::rtps::InstanceHandle_t>.")
19 changes: 3 additions & 16 deletions src/cpp/fastdds/publisher/DataWriter.cpp
Original file line number Diff line number Diff line change
@@ -302,32 +302,19 @@ ReturnCode_t DataWriter::get_matched_subscription_data(
builtin::SubscriptionBuiltinTopicData& subscription_data,
const InstanceHandle_t& subscription_handle) const
{
static_cast<void> (subscription_data);
static_cast<void> (subscription_handle);
return ReturnCode_t::RETCODE_UNSUPPORTED;
/*
return impl_->get_matched_subscription_data(subscription_data, subscription_handle);
*/
return impl_->get_matched_subscription_data(subscription_data, subscription_handle);
}

ReturnCode_t DataWriter::get_matched_subscriptions(
std::vector<InstanceHandle_t>& subscription_handles) const
{
static_cast<void> (subscription_handles);
return ReturnCode_t::RETCODE_UNSUPPORTED;
/*
return impl_->get_matched_subscription_data(subscription_handles);
*/
return impl_->get_matched_subscriptions(subscription_handles);
}

ReturnCode_t DataWriter::get_matched_subscriptions(
std::vector<InstanceHandle_t*>& subscription_handles) const
{
static_cast<void> (subscription_handles);
return ReturnCode_t::RETCODE_UNSUPPORTED;
/*
return impl_->get_matched_subscription_data(subscription_handles);
*/
return impl_->get_matched_subscriptions(subscription_handles);
}

ReturnCode_t DataWriter::clear_history(
63 changes: 63 additions & 0 deletions src/cpp/fastdds/publisher/DataWriterImpl.cpp
Original file line number Diff line number Diff line change
@@ -2228,6 +2228,69 @@ void DataWriterImpl::filter_is_being_removed(
}
}

ReturnCode_t DataWriterImpl::get_matched_subscription_data(
builtin::SubscriptionBuiltinTopicData& subscription_data,
const fastrtps::rtps::InstanceHandle_t& subscription_handle) const
{
fastrtps::types::ReturnCode_t ret = ReturnCode_t::RETCODE_BAD_PARAMETER;
GUID_t reader_guid = iHandle2GUID(subscription_handle);

if (writer_ && writer_->matched_reader_is_matched(reader_guid))
{
if (publisher_)
{
RTPSParticipant* rtps_participant = publisher_->rtps_participant();
if (rtps_participant &&
rtps_participant->get_subscription_info(subscription_data, reader_guid))
{
ret = ReturnCode_t::RETCODE_OK;
}
}
}

return ret;
}

ReturnCode_t DataWriterImpl::get_matched_subscriptions(
std::vector<InstanceHandle_t>& subscription_handles) const
{
ReturnCode_t ret = ReturnCode_t::RETCODE_ERROR;
std::vector<GUID_t> matched_reader_guids;
subscription_handles.clear();

if (writer_ && writer_->matched_readers_guids(matched_reader_guids))
{
for (const GUID_t& guid : matched_reader_guids)
{
subscription_handles.push_back(InstanceHandle_t(guid));
}
ret = ReturnCode_t::RETCODE_OK;
}

return ret;
}

ReturnCode_t DataWriterImpl::get_matched_subscriptions(
std::vector<InstanceHandle_t*>& subscription_handles) const
{
ReturnCode_t ret = ReturnCode_t::RETCODE_ERROR;
std::vector<GUID_t> matched_reader_guids;
subscription_handles.clear();

if (writer_ && writer_->matched_readers_guids(matched_reader_guids))
{
for (const GUID_t& guid : matched_reader_guids)
{
// Note: user is responsible for deleting the InstanceHandle_t objects
subscription_handles.push_back(new InstanceHandle_t(guid));
}

ret = ReturnCode_t::RETCODE_OK;
}

return ret;
}

bool DataWriterImpl::is_relevant(
const fastrtps::rtps::CacheChange_t& change,
const fastrtps::rtps::GUID_t& reader_guid) const
28 changes: 28 additions & 0 deletions src/cpp/fastdds/publisher/DataWriterImpl.hpp
Original file line number Diff line number Diff line change
@@ -389,6 +389,34 @@ class DataWriterImpl : protected rtps::IReaderDataFilter
void filter_is_being_removed(
const char* filter_class_name);

/**
* @brief Retrieves in a subscription associated with the DataWriter
*
* @param[out] subscription_data subscription data struct
* @param subscription_handle InstanceHandle_t of the subscription
* @return RETCODE_BAD_PARAMETER if the DataWriter is not matched with
* the given subscription handle, RETCODE_OK otherwise.
*
*/
ReturnCode_t get_matched_subscription_data(
builtin::SubscriptionBuiltinTopicData& subscription_data,
const InstanceHandle_t& subscription_handle) const;

/**
* @brief Fills the given vector with the InstanceHandle_t of matched DataReaders
*
* @param[out] subscription_handles Vector where the InstanceHandle_t are returned
* @return RETCODE_OK if the operation succeeds.
*
* @note Returning an empty list is not an error, it returns RETCODE_OK.
*
*/
ReturnCode_t get_matched_subscriptions(
std::vector<InstanceHandle_t>& subscription_handles) const;

ReturnCode_t get_matched_subscriptions(
std::vector<InstanceHandle_t*>& subscription_handles) const;

protected:

using IChangePool = eprosima::fastrtps::rtps::IChangePool;
Original file line number Diff line number Diff line change
@@ -429,6 +429,25 @@ class DataWriterImpl : protected rtps::IReaderDataFilter

}

ReturnCode_t get_matched_subscription_data(
builtin::SubscriptionBuiltinTopicData&,
const InstanceHandle_t& ) const
{
return ReturnCode_t::RETCODE_OK;
}

ReturnCode_t get_matched_subscriptions(
std::vector<InstanceHandle_t>&) const
{
return ReturnCode_t::RETCODE_OK;
}

ReturnCode_t get_matched_subscriptions(
std::vector<InstanceHandle_t*>&) const
{
return ReturnCode_t::RETCODE_OK;
}

//! Pointer to the associated Data Writer.
fastrtps::rtps::RTPSWriter* writer_ = nullptr;
Topic* topic_ = nullptr;