From c8eb812b0e06b4b3500b189a6fba0c2e36ed5805 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 1 Mar 2022 10:51:16 +0100 Subject: [PATCH 1/2] Use get_publication_matched_status on rmw_publisher. Signed-off-by: Miguel Company --- .../custom_publisher_info.hpp | 24 ------------------- rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp | 6 +++-- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_publisher_info.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_publisher_info.hpp index 37db4ca2c..37c6a4b0a 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_publisher_info.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_publisher_info.hpp @@ -22,7 +22,6 @@ #include "fastdds/dds/core/status/BaseStatus.hpp" #include "fastdds/dds/core/status/DeadlineMissedStatus.hpp" -#include "fastdds/dds/core/status/PublicationMatchedStatus.hpp" #include "fastdds/dds/publisher/DataWriter.hpp" #include "fastdds/dds/publisher/DataWriterListener.hpp" #include "fastdds/dds/topic/Topic.hpp" @@ -69,20 +68,6 @@ class PubListener : public EventListenerInterface, public eprosima::fastdds::dds } // DataWriterListener implementation - RMW_FASTRTPS_SHARED_CPP_PUBLIC - void - on_publication_matched( - eprosima::fastdds::dds::DataWriter * /* writer */, - const eprosima::fastdds::dds::PublicationMatchedStatus & info) final - { - std::lock_guard lock(internalMutex_); - if (info.current_count_change == 1) { - subscriptions_.insert(eprosima::fastrtps::rtps::iHandle2GUID(info.last_subscription_handle)); - } else if (info.current_count_change == -1) { - subscriptions_.erase(eprosima::fastrtps::rtps::iHandle2GUID(info.last_subscription_handle)); - } - } - RMW_FASTRTPS_SHARED_CPP_PUBLIC void on_offered_deadline_missed( @@ -116,12 +101,6 @@ class PubListener : public EventListenerInterface, public eprosima::fastdds::dds takeNextEvent(rmw_event_type_t event_type, void * event_info) final; // PubListener API - size_t subscriptionCount() - { - std::lock_guard lock(internalMutex_); - return subscriptions_.size(); - } - void attachCondition(std::mutex * conditionMutex, std::condition_variable * conditionVariable) { @@ -141,9 +120,6 @@ class PubListener : public EventListenerInterface, public eprosima::fastdds::dds private: mutable std::mutex internalMutex_; - std::set subscriptions_ - RCPPUTILS_TSA_GUARDED_BY(internalMutex_); - std::atomic_bool deadline_changes_; eprosima::fastdds::dds::OfferedDeadlineMissedStatus offered_deadline_missed_status_ RCPPUTILS_TSA_GUARDED_BY(internalMutex_); diff --git a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp index 1fae29e57..5755aa79b 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp @@ -20,6 +20,7 @@ #include "rmw/impl/cpp/macros.hpp" #include "rmw/rmw.h" +#include "fastdds/dds/core/status/PublicationMatchedStatus.hpp" #include "fastdds/dds/publisher/DataWriter.hpp" #include "fastdds/dds/publisher/qos/DataWriterQos.hpp" @@ -93,8 +94,9 @@ __rmw_publisher_count_matched_subscriptions( size_t * subscription_count) { auto info = static_cast(publisher->data); - - *subscription_count = info->listener_->subscriptionCount(); + eprosima::fastdds::dds::PublicationMatchedStatus status{}; + info->data_writer_->get_publication_matched_status(status); + *subscription_count = status.current_count; return RMW_RET_OK; } From 9d55fd7883d1dc8a40e652fec4102bed9bf5ee3b Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 1 Mar 2022 11:19:26 +0100 Subject: [PATCH 2/2] Use get_subscription_matched_status on rmw_subscription. Signed-off-by: Miguel Company --- .../custom_subscriber_info.hpp | 17 ----------------- .../src/rmw_subscription.cpp | 6 ++++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp index 9ffe65f2a..1dd688929 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp @@ -26,7 +26,6 @@ #include "fastdds/dds/core/status/DeadlineMissedStatus.hpp" #include "fastdds/dds/core/status/LivelinessChangedStatus.hpp" -#include "fastdds/dds/core/status/SubscriptionMatchedStatus.hpp" #include "fastdds/dds/subscriber/DataReader.hpp" #include "fastdds/dds/subscriber/DataReaderListener.hpp" #include "fastdds/dds/topic/TypeSupport.hpp" @@ -89,14 +88,6 @@ class SubListener : public EventListenerInterface, public eprosima::fastdds::dds eprosima::fastdds::dds::DataReader * reader, const eprosima::fastdds::dds::SubscriptionMatchedStatus & info) final { - { - std::lock_guard lock(internalMutex_); - if (info.current_count_change == 1) { - publishers_.insert(eprosima::fastrtps::rtps::iHandle2GUID(info.last_publication_handle)); - } else if (info.current_count_change == -1) { - publishers_.erase(eprosima::fastrtps::rtps::iHandle2GUID(info.last_publication_handle)); - } - } update_has_data(reader); } @@ -188,12 +179,6 @@ class SubListener : public EventListenerInterface, public eprosima::fastdds::dds data_.store(has_data, std::memory_order_relaxed); } - size_t publisherCount() - { - std::lock_guard lock(internalMutex_); - return publishers_.size(); - } - // Provide handlers to perform an action when a // new event from this listener has ocurred void @@ -242,8 +227,6 @@ class SubListener : public EventListenerInterface, public eprosima::fastdds::dds std::mutex * conditionMutex_ RCPPUTILS_TSA_GUARDED_BY(internalMutex_); std::condition_variable * conditionVariable_ RCPPUTILS_TSA_GUARDED_BY(internalMutex_); - std::set publishers_ RCPPUTILS_TSA_GUARDED_BY(internalMutex_); - rmw_event_callback_t on_new_message_cb_{nullptr}; std::mutex on_new_message_m_; size_t qos_depth_; diff --git a/rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp index b89f7531e..a469172f7 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp @@ -20,6 +20,7 @@ #include "rmw/error_handling.h" #include "rmw/rmw.h" +#include "fastdds/dds/core/status/SubscriptionMatchedStatus.hpp" #include "fastdds/dds/subscriber/DataReader.hpp" #include "fastdds/dds/subscriber/qos/DataReaderQos.hpp" @@ -87,8 +88,9 @@ __rmw_subscription_count_matched_publishers( size_t * publisher_count) { auto info = static_cast(subscription->data); - - *publisher_count = info->listener_->publisherCount(); + eprosima::fastdds::dds::SubscriptionMatchedStatus status{}; + info->data_reader_->get_subscription_matched_status(status); + *publisher_count = status.current_count; return RMW_RET_OK; }