From 8e8671404e3afa8261f84354ae7f56196b679ada Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Sun, 15 Sep 2019 16:48:39 -0700 Subject: [PATCH] can_loan_messages for subscription Signed-off-by: Karsten Knese --- rcl/include/rcl/subscription.h | 9 +++++++++ rcl/src/rcl/publisher.c | 2 +- rcl/src/rcl/subscription.c | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/rcl/include/rcl/subscription.h b/rcl/include/rcl/subscription.h index bb45ce855..fd5bd1527 100644 --- a/rcl/include/rcl/subscription.h +++ b/rcl/include/rcl/subscription.h @@ -471,6 +471,15 @@ RCL_WARN_UNUSED const rmw_qos_profile_t * rcl_subscription_get_actual_qos(const rcl_subscription_t * subscription); +/// Check if subscription instance can loan messages. +/** + * Depending on the middleware and the message type, this will return true if the middleware + * can allocate a ROS message instance. + */ +RCL_PUBLIC +bool +rcl_subscription_can_loan_messages(const rcl_subscription_t * subscription); + #ifdef __cplusplus } #endif diff --git a/rcl/src/rcl/publisher.c b/rcl/src/rcl/publisher.c index d50dbbaf1..5156a2ad3 100644 --- a/rcl/src/rcl/publisher.c +++ b/rcl/src/rcl/publisher.c @@ -250,7 +250,7 @@ rcl_allocate_loaned_message( size_t message_size) { if (!rcl_publisher_is_valid(publisher)) { - return RCL_RET_PUBLISHER_INVALID; // error already set + return NULL; // error already set } return rmw_allocate_loaned_message(publisher->impl->rmw_handle, type_support, message_size); } diff --git a/rcl/src/rcl/subscription.c b/rcl/src/rcl/subscription.c index b881502f3..235bae153 100644 --- a/rcl/src/rcl/subscription.c +++ b/rcl/src/rcl/subscription.c @@ -379,6 +379,15 @@ rcl_subscription_get_actual_qos(const rcl_subscription_t * subscription) return &subscription->impl->actual_qos; } +bool +rcl_subscription_can_loan_messages(const rcl_subscription_t * subscription) +{ + if (!rcl_subscription_is_valid(subscription)) { + return false; // error message already set + } + return subscription->impl->rmw_handle->can_loan_messages; +} + #ifdef __cplusplus } #endif