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