From 5af95c7095fa87466ef0a2e3000bec8956374dab Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Thu, 27 Aug 2020 12:54:49 -0300 Subject: [PATCH] Ensure compliant matched pub/sub count API. (#424) Signed-off-by: Michel Hidalgo --- rmw_fastrtps_cpp/src/rmw_publisher.cpp | 8 ++++++++ rmw_fastrtps_cpp/src/rmw_subscription.cpp | 8 ++++++++ rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp | 8 ++++++++ rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp | 8 ++++++++ rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp | 8 ++------ rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp | 9 +++------ 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_cpp/src/rmw_publisher.cpp index 2c3b606ed..4f5fc611c 100644 --- a/rmw_fastrtps_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_cpp/src/rmw_publisher.cpp @@ -123,6 +123,14 @@ rmw_publisher_count_matched_subscriptions( const rmw_publisher_t * publisher, size_t * subscription_count) { + RMW_CHECK_ARGUMENT_FOR_NULL(publisher, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_TYPE_IDENTIFIERS_MATCH( + publisher, + publisher->implementation_identifier, + eprosima_fastrtps_identifier, + return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); + RMW_CHECK_ARGUMENT_FOR_NULL(subscription_count, RMW_RET_INVALID_ARGUMENT); + return rmw_fastrtps_shared_cpp::__rmw_publisher_count_matched_subscriptions( publisher, subscription_count); } diff --git a/rmw_fastrtps_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_cpp/src/rmw_subscription.cpp index 712f6f909..a27f326ff 100644 --- a/rmw_fastrtps_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_cpp/src/rmw_subscription.cpp @@ -119,6 +119,14 @@ rmw_subscription_count_matched_publishers( const rmw_subscription_t * subscription, size_t * publisher_count) { + RMW_CHECK_ARGUMENT_FOR_NULL(subscription, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_TYPE_IDENTIFIERS_MATCH( + subscription, + subscription->implementation_identifier, + eprosima_fastrtps_identifier, + return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); + RMW_CHECK_ARGUMENT_FOR_NULL(publisher_count, RMW_RET_INVALID_ARGUMENT); + return rmw_fastrtps_shared_cpp::__rmw_subscription_count_matched_publishers( subscription, publisher_count); } diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp index 52ce14713..baaedcba5 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp @@ -127,6 +127,14 @@ rmw_publisher_count_matched_subscriptions( const rmw_publisher_t * publisher, size_t * subscription_count) { + RMW_CHECK_ARGUMENT_FOR_NULL(publisher, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_TYPE_IDENTIFIERS_MATCH( + publisher, + publisher->implementation_identifier, + eprosima_fastrtps_identifier, + return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); + RMW_CHECK_ARGUMENT_FOR_NULL(subscription_count, RMW_RET_INVALID_ARGUMENT); + return rmw_fastrtps_shared_cpp::__rmw_publisher_count_matched_subscriptions( publisher, subscription_count); } diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp index fad3f4ba9..00873ceba 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp @@ -122,6 +122,14 @@ rmw_subscription_count_matched_publishers( const rmw_subscription_t * subscription, size_t * publisher_count) { + RMW_CHECK_ARGUMENT_FOR_NULL(subscription, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_TYPE_IDENTIFIERS_MATCH( + subscription, + subscription->implementation_identifier, + eprosima_fastrtps_identifier, + return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); + RMW_CHECK_ARGUMENT_FOR_NULL(publisher_count, RMW_RET_INVALID_ARGUMENT); + return rmw_fastrtps_shared_cpp::__rmw_subscription_count_matched_publishers( subscription, publisher_count); } diff --git a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp index afa4b2e61..fb8cd2a49 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp @@ -87,13 +87,9 @@ __rmw_publisher_count_matched_subscriptions( const rmw_publisher_t * publisher, size_t * subscription_count) { - RMW_CHECK_ARGUMENT_FOR_NULL(publisher, RMW_RET_INVALID_ARGUMENT); - RMW_CHECK_ARGUMENT_FOR_NULL(subscription_count, RMW_RET_INVALID_ARGUMENT); - auto info = static_cast(publisher->data); - if (info != nullptr) { - *subscription_count = info->listener_->subscriptionCount(); - } + + *subscription_count = info->listener_->subscriptionCount(); return RMW_RET_OK; } diff --git a/rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp index 95c425207..4ce18ac5e 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_subscription.cpp @@ -85,13 +85,10 @@ __rmw_subscription_count_matched_publishers( const rmw_subscription_t * subscription, size_t * publisher_count) { - RMW_CHECK_ARGUMENT_FOR_NULL(subscription, RMW_RET_INVALID_ARGUMENT); - RMW_CHECK_ARGUMENT_FOR_NULL(publisher_count, RMW_RET_INVALID_ARGUMENT); - auto info = static_cast(subscription->data); - if (info != nullptr) { - *publisher_count = info->listener_->publisherCount(); - } + + *publisher_count = info->listener_->publisherCount(); + return RMW_RET_OK; }