From 0f3ec099d4bae1822744efd67cd1efd84492d599 Mon Sep 17 00:00:00 2001 From: Mauro Date: Fri, 2 Oct 2020 13:50:11 +0100 Subject: [PATCH] Add RMW listener APIs Add set_guard_condition_callback api Move apis - Add constness Use or discard previous events: Guard conditions Rename to set_events_executor_callback Rename Event_callback -> ExecutorEventCallback update name Add events support void return on set_events_executor_callback Revert "void return on set_events_executor_callback" Rename ExecutorEventCallback -> EventsExecutorCallback Rename set_events_executor_callback->set_listener_callback Use data types when setting callbacks Move rcutils/executor_event_types.h to rmw/ rename event types Rename executor_context->callback_context Rename callback_context->user_data Reorder APIs arguments rename rmw_listener_cb_t->rmw_listener_callback_t use void * to pass executor ptr Rework executor callback data Use RMW renamed file Signed-off-by: Alberto Soragna --- rcl/include/rcl/client.h | 10 ++++++++++ rcl/include/rcl/event.h | 9 +++++++++ rcl/include/rcl/guard_condition.h | 11 +++++++++++ rcl/include/rcl/service.h | 10 ++++++++++ rcl/include/rcl/subscription.h | 9 +++++++++ rcl/src/rcl/client.c | 13 +++++++++++++ rcl/src/rcl/event.c | 14 ++++++++++++++ rcl/src/rcl/guard_condition.c | 14 ++++++++++++++ rcl/src/rcl/service.c | 13 +++++++++++++ rcl/src/rcl/subscription.c | 12 ++++++++++++ 10 files changed, 115 insertions(+) diff --git a/rcl/include/rcl/client.h b/rcl/include/rcl/client.h index e4285a031..8be40abe7 100644 --- a/rcl/include/rcl/client.h +++ b/rcl/include/rcl/client.h @@ -28,6 +28,8 @@ extern "C" #include "rcl/node.h" #include "rcl/visibility_control.h" +#include "rmw/listener_callback_type.h" + /// Internal rcl client implementation struct. struct rcl_client_impl_t; @@ -409,6 +411,14 @@ RCL_PUBLIC bool rcl_client_is_valid(const rcl_client_t * client); +RCL_PUBLIC +RCL_WARN_UNUSED +rcl_ret_t +rcl_client_set_listener_callback( + const rcl_client_t * client, + rmw_listener_callback_t listener_callback, + const void * user_data); + #ifdef __cplusplus } #endif diff --git a/rcl/include/rcl/event.h b/rcl/include/rcl/event.h index a366dd45b..0c593d92f 100644 --- a/rcl/include/rcl/event.h +++ b/rcl/include/rcl/event.h @@ -199,6 +199,15 @@ RCL_PUBLIC bool rcl_event_is_valid(const rcl_event_t * event); +RCL_PUBLIC +RCL_WARN_UNUSED +rcl_ret_t +rcl_event_set_listener_callback( + const rcl_event_t * event, + rmw_listener_callback_t listener_callback, + const void * user_data, + bool use_previous_events); + #ifdef __cplusplus } #endif diff --git a/rcl/include/rcl/guard_condition.h b/rcl/include/rcl/guard_condition.h index a6727d3a2..092c0ca70 100644 --- a/rcl/include/rcl/guard_condition.h +++ b/rcl/include/rcl/guard_condition.h @@ -28,6 +28,8 @@ extern "C" #include "rcl/types.h" #include "rcl/visibility_control.h" +#include "rmw/listener_callback_type.h" + /// Internal rcl guard condition implementation struct. struct rcl_guard_condition_impl_t; @@ -262,6 +264,15 @@ RCL_WARN_UNUSED rmw_guard_condition_t * rcl_guard_condition_get_rmw_handle(const rcl_guard_condition_t * guard_condition); +RCL_PUBLIC +RCL_WARN_UNUSED +rcl_ret_t +rcl_guard_condition_set_listener_callback( + const rcl_guard_condition_t * guard_condition, + rmw_listener_callback_t listener_callback, + const void * user_data, + bool use_previous_events); + #ifdef __cplusplus } #endif diff --git a/rcl/include/rcl/service.h b/rcl/include/rcl/service.h index 87e182ad5..8186612ab 100644 --- a/rcl/include/rcl/service.h +++ b/rcl/include/rcl/service.h @@ -28,6 +28,8 @@ extern "C" #include "rcl/node.h" #include "rcl/visibility_control.h" +#include "rmw/listener_callback_type.h" + /// Internal rcl implementation struct. struct rcl_service_impl_t; @@ -440,6 +442,14 @@ RCL_PUBLIC bool rcl_service_is_valid(const rcl_service_t * service); +RCL_PUBLIC +RCL_WARN_UNUSED +rcl_ret_t +rcl_service_set_listener_callback( + const rcl_service_t * service, + rmw_listener_callback_t listener_callback, + const void * user_data); + #ifdef __cplusplus } #endif diff --git a/rcl/include/rcl/subscription.h b/rcl/include/rcl/subscription.h index 452cb694b..79918b151 100644 --- a/rcl/include/rcl/subscription.h +++ b/rcl/include/rcl/subscription.h @@ -28,6 +28,7 @@ extern "C" #include "rcl/node.h" #include "rcl/visibility_control.h" +#include "rmw/listener_callback_type.h" #include "rmw/message_sequence.h" /// Internal rcl implementation struct. @@ -611,6 +612,14 @@ RCL_PUBLIC bool rcl_subscription_can_loan_messages(const rcl_subscription_t * subscription); +RCL_PUBLIC +RCL_WARN_UNUSED +rcl_ret_t +rcl_subscription_set_listener_callback( + const rcl_subscription_t * subscription, + rmw_listener_callback_t listener_callback, + const void * user_data); + #ifdef __cplusplus } #endif diff --git a/rcl/src/rcl/client.c b/rcl/src/rcl/client.c index 53dc77ca1..1c35e9456 100644 --- a/rcl/src/rcl/client.c +++ b/rcl/src/rcl/client.c @@ -280,6 +280,19 @@ rcl_client_is_valid(const rcl_client_t * client) client->impl->rmw_handle, "client's rmw handle is invalid", return false); return true; } + +rcl_ret_t +rcl_client_set_listener_callback( + const rcl_client_t * client, + rmw_listener_callback_t listener_callback, + const void * user_data) +{ + return rmw_client_set_listener_callback( + client->impl->rmw_handle, + listener_callback, + user_data); +} + #ifdef __cplusplus } #endif diff --git a/rcl/src/rcl/event.c b/rcl/src/rcl/event.c index c79c60ce6..b4cf09b69 100644 --- a/rcl/src/rcl/event.c +++ b/rcl/src/rcl/event.c @@ -218,6 +218,20 @@ rcl_event_is_valid(const rcl_event_t * event) return true; } +rcl_ret_t +rcl_event_set_listener_callback( + const rcl_event_t * event, + rmw_listener_callback_t listener_callback, + const void * user_data, + bool use_previous_events) +{ + return rmw_event_set_listener_callback( + &event->impl->rmw_handle, + listener_callback, + user_data, + use_previous_events); +} + #ifdef __cplusplus } #endif diff --git a/rcl/src/rcl/guard_condition.c b/rcl/src/rcl/guard_condition.c index d7e17afda..cac4bfc42 100644 --- a/rcl/src/rcl/guard_condition.c +++ b/rcl/src/rcl/guard_condition.c @@ -186,6 +186,20 @@ rcl_guard_condition_get_rmw_handle(const rcl_guard_condition_t * guard_condition return guard_condition->impl->rmw_handle; } +rcl_ret_t +rcl_guard_condition_set_listener_callback( + const rcl_guard_condition_t * guard_condition, + rmw_listener_callback_t listener_callback, + const void * user_data, + bool use_previous_events) +{ + return rmw_guard_condition_set_listener_callback( + guard_condition->impl->rmw_handle, + listener_callback, + user_data, + use_previous_events); +} + #ifdef __cplusplus } #endif diff --git a/rcl/src/rcl/service.c b/rcl/src/rcl/service.c index 251ab66b1..dd39176a8 100644 --- a/rcl/src/rcl/service.c +++ b/rcl/src/rcl/service.c @@ -301,6 +301,19 @@ rcl_service_is_valid(const rcl_service_t * service) return true; } +rcl_ret_t +rcl_service_set_listener_callback( + const rcl_service_t * service, + rmw_listener_callback_t listener_callback, + const void * user_data) +{ + return rmw_service_set_listener_callback( + service->impl->rmw_handle, + listener_callback, + user_data); +} + + #ifdef __cplusplus } #endif diff --git a/rcl/src/rcl/subscription.c b/rcl/src/rcl/subscription.c index 611994356..57fc2dc46 100644 --- a/rcl/src/rcl/subscription.c +++ b/rcl/src/rcl/subscription.c @@ -437,6 +437,18 @@ rcl_subscription_can_loan_messages(const rcl_subscription_t * subscription) return subscription->impl->rmw_handle->can_loan_messages; } +rcl_ret_t +rcl_subscription_set_listener_callback( + const rcl_subscription_t * subscription, + rmw_listener_callback_t listener_callback, + const void * user_data) +{ + return rmw_subscription_set_listener_callback( + subscription->impl->rmw_handle, + listener_callback, + user_data); +} + #ifdef __cplusplus } #endif