From 3f3e440ab871a3139135a8ac60483d3fd0d7ad95 Mon Sep 17 00:00:00 2001 From: JLBuenoLopez-eProsima Date: Tue, 6 Jun 2023 11:22:08 +0200 Subject: [PATCH] Added `rcl_publisher_get_non_local_subscription_count` Signed-off-by: JLBuenoLopez-eProsima --- rcl/include/rcl/publisher.h | 27 +++++++++++++++++++++++++++ rcl/src/rcl/publisher.c | 20 ++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/rcl/include/rcl/publisher.h b/rcl/include/rcl/publisher.h index 51aa7421e..dc523ae9b 100644 --- a/rcl/include/rcl/publisher.h +++ b/rcl/include/rcl/publisher.h @@ -654,6 +654,33 @@ rcl_publisher_get_subscription_count( const rcl_publisher_t * publisher, size_t * subscription_count); +/// Get the number of non local subscriptions matched to a publisher. +/** + * Used to get the internal count of non local subscriptions matched to a publisher. + * + *
+ * Attribute | Adherence + * ------------------ | ------------- + * Allocates Memory | No + * Thread-Safe | Yes + * Uses Atomics | Maybe [1] + * Lock-Free | Maybe [1] + * [1] only if the underlying rmw doesn't make use of this feature + * + * \param[in] publisher pointer to the rcl publisher + * \param[out] non_local_subscription_count number of non local matched subscriptions + * \return #RCL_RET_OK if the count was retrieved, or + * \return #RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or + * \return #RCL_RET_PUBLISHER_INVALID if the publisher is invalid, or + * \return #RCL_RET_ERROR if an unspecified error occurs. + */ +RCL_PUBLIC +RCL_WARN_UNUSED +rcl_ret_t +rcl_publisher_get_non_local_subscription_count( + const rcl_publisher_t * publisher, + size_t * non_local_subscription_count); + /// Get the actual qos settings of the publisher. /** * Used to get the actual qos settings of the publisher. diff --git a/rcl/src/rcl/publisher.c b/rcl/src/rcl/publisher.c index 634f17241..48f3fd027 100644 --- a/rcl/src/rcl/publisher.c +++ b/rcl/src/rcl/publisher.c @@ -460,6 +460,26 @@ rcl_publisher_get_subscription_count( return RCL_RET_OK; } +rcl_ret_t +rcl_publisher_get_non_local_subscription_count( + const rcl_publisher_t * publisher, + size_t * non_local_subscription_count) +{ + if (!rcl_publisher_is_valid(publisher)) { + return RCL_RET_PUBLISHER_INVALID; + } + RCL_CHECK_ARGUMENT_FOR_NULL(non_local_subscription_count, RCL_RET_INVALID_ARGUMENT); + + rmw_ret_t ret = rmw_publisher_count_non_local_matched_subscriptions( + publisher->impl->rmw_handle, non_local_subscription_count); + + if (ret != RMW_RET_OK) { + RCL_SET_ERROR_MSG(rmw_get_error_string().str); + return rcl_convert_rmw_ret_to_rcl_ret(ret); + } + return RCL_RET_OK; +} + const rmw_qos_profile_t * rcl_publisher_get_actual_qos(const rcl_publisher_t * publisher) {