From f1d74a82941cf263bfed804f2f14b550c4fb9184 Mon Sep 17 00:00:00 2001 From: Miaofei Mei Date: Thu, 19 Mar 2020 13:14:53 -0700 Subject: [PATCH] Add rmw_*_event_init() functions (#397) Signed-off-by: Miaofei --- rmw_connext_cpp/src/rmw_event.cpp | 37 ++++++++++++++----- .../include/rmw_connext_shared_cpp/event.hpp | 20 ++++++++++ rmw_connext_shared_cpp/src/event.cpp | 29 +++++++++++++++ 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/rmw_connext_cpp/src/rmw_event.cpp b/rmw_connext_cpp/src/rmw_event.cpp index ced0da04..373ed44b 100644 --- a/rmw_connext_cpp/src/rmw_event.cpp +++ b/rmw_connext_cpp/src/rmw_event.cpp @@ -20,15 +20,34 @@ extern "C" { -/// Take an event from the event handle. -/** - * \param event_handle event object to take from - * \param event_info event info object to write taken data into - * \param taken boolean flag indicating if an event was taken or not - * \return `RMW_RET_OK` if successful, or - * \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or - * \return `RMW_RET_ERROR` if an unexpected error occurs. - */ +rmw_ret_t +rmw_publisher_event_init( + rmw_event_t * rmw_event, + const rmw_publisher_t * publisher, + rmw_event_type_t event_type) +{ + return __rmw_init_event( + rti_connext_identifier, + rmw_event, + publisher->implementation_identifier, + publisher->data, + event_type); +} + +rmw_ret_t +rmw_subscription_event_init( + rmw_event_t * rmw_event, + const rmw_subscription_t * subscription, + rmw_event_type_t event_type) +{ + return __rmw_init_event( + rti_connext_identifier, + rmw_event, + subscription->implementation_identifier, + subscription->data, + event_type); +} + rmw_ret_t rmw_take_event( const rmw_event_t * event_handle, diff --git a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event.hpp b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event.hpp index 5fc38170..20a2c07d 100644 --- a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event.hpp +++ b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event.hpp @@ -22,6 +22,26 @@ #include "rmw_connext_shared_cpp/visibility_control.h" +/// Initialize a rmw_event_t. +/** + * \param[in|out] rmw_event to initialize + * \param topic_endpoint_impl_identifier implementation identifier of event's parent topic endpoint + * \param data to initialize with + * \param event_type for the event to handle + * \return `RMW_RET_OK` if successful, or + * \return `RMW_RET_INVALID_ARGUMENT` if invalid argument, or + * \return `RMW_RET_UNSUPPORTED` if event_type is not supported, or + * \return `RMW_RET_ERROR` if an unexpected error occurs. + */ +RMW_CONNEXT_SHARED_CPP_PUBLIC +rmw_ret_t +__rmw_init_event( + const char * identifier, + rmw_event_t * rmw_event, + const char * topic_endpoint_impl_identifier, + void * data, + rmw_event_type_t event_type); + /// Take an event from the event handle. /** * diff --git a/rmw_connext_shared_cpp/src/event.cpp b/rmw_connext_shared_cpp/src/event.cpp index 0a168e2f..14daf181 100644 --- a/rmw_connext_shared_cpp/src/event.cpp +++ b/rmw_connext_shared_cpp/src/event.cpp @@ -20,6 +20,35 @@ #include "rmw_connext_shared_cpp/event_converter.hpp" #include "rmw_connext_shared_cpp/types.hpp" +rmw_ret_t +__rmw_init_event( + const char * identifier, + rmw_event_t * rmw_event, + const char * topic_endpoint_impl_identifier, + void * data, + rmw_event_type_t event_type) +{ + RMW_CHECK_ARGUMENT_FOR_NULL(identifier, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_ARGUMENT_FOR_NULL(rmw_event, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_ARGUMENT_FOR_NULL(topic_endpoint_impl_identifier, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_ARGUMENT_FOR_NULL(data, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_TYPE_IDENTIFIERS_MATCH( + topic endpoint, + topic_endpoint_impl_identifier, + identifier, + return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); + if (!is_event_supported(event_type)) { + RMW_SET_ERROR_MSG("provided event_type is not supported by rmw_fastrtps_cpp"); + return RMW_RET_UNSUPPORTED; + } + + rmw_event->implementation_identifier = topic_endpoint_impl_identifier; + rmw_event->data = data; + rmw_event->event_type = event_type; + + return RMW_RET_OK; +} + rmw_ret_t __rmw_take_event( const char * implementation_identifier,