From fcb2191748f0dba5850ec3c3146b2df7f8a98a1a Mon Sep 17 00:00:00 2001 From: Miaofei Date: Mon, 16 Mar 2020 14:58:52 -0700 Subject: [PATCH 1/3] add check for whether or not event type is supported Signed-off-by: Miaofei --- rmw_connext_cpp/src/rmw_event.cpp | 12 +++++++++++ .../include/rmw_connext_shared_cpp/event.hpp | 15 ++++++++++++++ .../event_converter.hpp | 8 -------- .../include/rmw_connext_shared_cpp/wait.hpp | 5 +++-- rmw_connext_shared_cpp/src/event.cpp | 17 +++++++++++++++- .../src/event_converter.cpp | 20 ++++--------------- 6 files changed, 50 insertions(+), 27 deletions(-) diff --git a/rmw_connext_cpp/src/rmw_event.cpp b/rmw_connext_cpp/src/rmw_event.cpp index ced0da04..011cedaa 100644 --- a/rmw_connext_cpp/src/rmw_event.cpp +++ b/rmw_connext_cpp/src/rmw_event.cpp @@ -20,6 +20,18 @@ extern "C" { +/// Determine if the rmw event type is supported by the underlying rmw implementation or not. +/** + * \param event_type to test if supported by underlying rmw_implementation + * \return `true` if the event_type is supported, or + * \return `false` if the event_type is not supported. + */ +bool +rmw_event_type_is_supported(rmw_event_type_t event_type) +{ + return __rmw_event_type_is_supported(event_type); +} + /// Take an event from the event handle. /** * \param event_handle event object to take from 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..1565f8bb 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 @@ -15,6 +15,8 @@ #ifndef RMW_CONNEXT_SHARED_CPP__EVENT_HPP_ #define RMW_CONNEXT_SHARED_CPP__EVENT_HPP_ +#include + #include "ndds_include.hpp" #include "rmw/types.h" @@ -22,6 +24,19 @@ #include "rmw_connext_shared_cpp/visibility_control.h" +extern const +std::unordered_map __rmw_event_type_to_dds_status_mask_map; + +/// Determine if the rmw event type is supported by the underlying rmw implementation or not. +/** + * \param event_type to test if supported by underlying rmw_implementation + * \return `true` if the event_type is supported, or + * \return `false` if the event_type is not supported. + */ +RMW_CONNEXT_SHARED_CPP_PUBLIC +bool +__rmw_event_type_is_supported(rmw_event_type_t event_type); + /// Take an event from the event handle. /** * diff --git a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event_converter.hpp b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event_converter.hpp index 6b52d9a5..6b72ff7b 100644 --- a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event_converter.hpp +++ b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event_converter.hpp @@ -33,14 +33,6 @@ RMW_CONNEXT_SHARED_CPP_PUBLIC DDS::StatusKind get_status_kind_from_rmw(rmw_event_type_t event_t); -/// Return true if the input RMW event has a corresponding DDS_StatusKind. -/** - * \param event_t input rmw event to check - * \return true if there is an RMW to DDS_StatusKind mapping, false otherwise - */ -RMW_CONNEXT_SHARED_CPP_PUBLIC -bool is_event_supported(rmw_event_type_t event_t); - /// Assign the input DDS return code to its corresponding RMW return code. /** * \param dds_return_code input DDS return code diff --git a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/wait.hpp b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/wait.hpp index 30db39d3..2b26c2fb 100644 --- a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/wait.hpp +++ b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/wait.hpp @@ -26,6 +26,7 @@ #include "rmw/types.h" #include "rmw_connext_shared_cpp/condition_error.hpp" +#include "rmw_connext_shared_cpp/event.hpp" #include "rmw_connext_shared_cpp/event_converter.hpp" #include "rmw_connext_shared_cpp/types.hpp" #include "rmw_connext_shared_cpp/visibility_control.h" @@ -53,7 +54,7 @@ __gather_event_conditions( RMW_SET_ERROR_MSG("status condition handle is null"); return RMW_RET_ERROR; } - if (is_event_supported(current_event->event_type)) { + if (__rmw_event_type_is_supported(current_event->event_type)) { auto map_pair = status_mask_map.insert( std::pair( status_condition, DDS::STATUS_MASK_NONE)); @@ -90,7 +91,7 @@ rmw_ret_t __handle_active_event_conditions(rmw_events_t * events) DDS::StatusMask status_mask = dds_entity->get_status_changes(); bool is_active = false; - if (is_event_supported(current_event->event_type)) { + if (__rmw_event_type_is_supported(current_event->event_type)) { is_active = static_cast(status_mask & get_status_kind_from_rmw(current_event->event_type)); } diff --git a/rmw_connext_shared_cpp/src/event.cpp b/rmw_connext_shared_cpp/src/event.cpp index 0a168e2f..ffce8862 100644 --- a/rmw_connext_shared_cpp/src/event.cpp +++ b/rmw_connext_shared_cpp/src/event.cpp @@ -20,6 +20,21 @@ #include "rmw_connext_shared_cpp/event_converter.hpp" #include "rmw_connext_shared_cpp/types.hpp" +/// Mapping of RMW_EVENT to the corresponding DDS_StatusKind. +const +std::unordered_map __rmw_event_type_to_dds_status_mask_map{ + {RMW_EVENT_LIVELINESS_CHANGED, DDS_LIVELINESS_CHANGED_STATUS}, + {RMW_EVENT_REQUESTED_DEADLINE_MISSED, DDS_REQUESTED_DEADLINE_MISSED_STATUS}, + {RMW_EVENT_LIVELINESS_LOST, DDS_LIVELINESS_LOST_STATUS}, + {RMW_EVENT_OFFERED_DEADLINE_MISSED, DDS_OFFERED_DEADLINE_MISSED_STATUS}, +}; + +bool +__rmw_event_type_is_supported(rmw_event_type_t event_type) +{ + return __rmw_event_type_to_dds_status_mask_map.count(event_type) > 0; +} + rmw_ret_t __rmw_take_event( const char * implementation_identifier, @@ -41,7 +56,7 @@ __rmw_take_event( rmw_ret_t ret_code = RMW_RET_UNSUPPORTED; // check if we support the input event type - if (is_event_supported(event_handle->event_type)) { + if (__rmw_event_type_is_supported(event_handle->event_type)) { // lookup status mask from rmw_event_type DDS_StatusKind status_kind = get_status_kind_from_rmw(event_handle->event_type); diff --git a/rmw_connext_shared_cpp/src/event_converter.cpp b/rmw_connext_shared_cpp/src/event_converter.cpp index cb852778..4c132a31 100644 --- a/rmw_connext_shared_cpp/src/event_converter.cpp +++ b/rmw_connext_shared_cpp/src/event_converter.cpp @@ -14,27 +14,15 @@ #include +#include "rmw_connext_shared_cpp/event.hpp" #include "rmw_connext_shared_cpp/event_converter.hpp" -/// Mapping of RMW_EVENT to the corresponding DDS_StatusKind. -static const std::unordered_map mask_map{ - {RMW_EVENT_LIVELINESS_CHANGED, DDS_LIVELINESS_CHANGED_STATUS}, - {RMW_EVENT_REQUESTED_DEADLINE_MISSED, DDS_REQUESTED_DEADLINE_MISSED_STATUS}, - {RMW_EVENT_LIVELINESS_LOST, DDS_LIVELINESS_LOST_STATUS}, - {RMW_EVENT_OFFERED_DEADLINE_MISSED, DDS_OFFERED_DEADLINE_MISSED_STATUS}, -}; - -DDS::StatusKind get_status_kind_from_rmw(const rmw_event_type_t event_t) -{ - return mask_map.at(event_t); -} - -bool is_event_supported(const rmw_event_type_t event_t) +DDS::StatusKind get_status_kind_from_rmw(rmw_event_type_t event_t) { - return mask_map.count(event_t) > 0; + return __rmw_event_type_to_dds_status_mask_map.at(event_t); } -rmw_ret_t check_dds_ret_code(const DDS::ReturnCode_t dds_return_code) +rmw_ret_t check_dds_ret_code(DDS::ReturnCode_t dds_return_code) { switch (dds_return_code) { case DDS_RETCODE_OK: From 0dcd1e725777cfe32797fba62e5c0f2a2f00787f Mon Sep 17 00:00:00 2001 From: Miaofei Date: Mon, 16 Mar 2020 18:19:35 -0700 Subject: [PATCH 2/3] add rmw_publisher/subscription_event_init functions Signed-off-by: Miaofei --- rmw_connext_cpp/src/rmw_event.cpp | 52 ++++++++++++++++--- .../include/rmw_connext_shared_cpp/event.hpp | 27 ++++++---- .../event_converter.hpp | 8 +++ .../include/rmw_connext_shared_cpp/wait.hpp | 5 +- rmw_connext_shared_cpp/src/event.cpp | 40 +++++++++----- .../src/event_converter.cpp | 20 +++++-- 6 files changed, 114 insertions(+), 38 deletions(-) diff --git a/rmw_connext_cpp/src/rmw_event.cpp b/rmw_connext_cpp/src/rmw_event.cpp index 011cedaa..6b8ef56f 100644 --- a/rmw_connext_cpp/src/rmw_event.cpp +++ b/rmw_connext_cpp/src/rmw_event.cpp @@ -20,16 +20,53 @@ extern "C" { -/// Determine if the rmw event type is supported by the underlying rmw implementation or not. + +/// Initialize a rmw publisher event. /** - * \param event_type to test if supported by underlying rmw_implementation - * \return `true` if the event_type is supported, or - * \return `false` if the event_type is not supported. + * \param[in|out] rmw_event to initialize + * \param publisher 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. */ -bool -rmw_event_type_is_supported(rmw_event_type_t event_type) +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_event_type_is_supported(event_type); + return __rmw_init_event( + rti_connext_identifier, + rmw_event, + publisher->implementation_identifier, + publisher->data, + event_type); +} + +/// Initialize a rmw subscription event. +/** + * \param[in|out] rmw_event to initialize + * \param subscription 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_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); } /// Take an event from the event handle. @@ -53,4 +90,5 @@ rmw_take_event( event_info, taken); } + } // extern "C" 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 1565f8bb..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 @@ -15,8 +15,6 @@ #ifndef RMW_CONNEXT_SHARED_CPP__EVENT_HPP_ #define RMW_CONNEXT_SHARED_CPP__EVENT_HPP_ -#include - #include "ndds_include.hpp" #include "rmw/types.h" @@ -24,18 +22,25 @@ #include "rmw_connext_shared_cpp/visibility_control.h" -extern const -std::unordered_map __rmw_event_type_to_dds_status_mask_map; - -/// Determine if the rmw event type is supported by the underlying rmw implementation or not. +/// Initialize a rmw_event_t. /** - * \param event_type to test if supported by underlying rmw_implementation - * \return `true` if the event_type is supported, or - * \return `false` if the event_type is not supported. + * \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 -bool -__rmw_event_type_is_supported(rmw_event_type_t event_type); +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/include/rmw_connext_shared_cpp/event_converter.hpp b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event_converter.hpp index 6b72ff7b..6b52d9a5 100644 --- a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event_converter.hpp +++ b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event_converter.hpp @@ -33,6 +33,14 @@ RMW_CONNEXT_SHARED_CPP_PUBLIC DDS::StatusKind get_status_kind_from_rmw(rmw_event_type_t event_t); +/// Return true if the input RMW event has a corresponding DDS_StatusKind. +/** + * \param event_t input rmw event to check + * \return true if there is an RMW to DDS_StatusKind mapping, false otherwise + */ +RMW_CONNEXT_SHARED_CPP_PUBLIC +bool is_event_supported(rmw_event_type_t event_t); + /// Assign the input DDS return code to its corresponding RMW return code. /** * \param dds_return_code input DDS return code diff --git a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/wait.hpp b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/wait.hpp index 2b26c2fb..30db39d3 100644 --- a/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/wait.hpp +++ b/rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/wait.hpp @@ -26,7 +26,6 @@ #include "rmw/types.h" #include "rmw_connext_shared_cpp/condition_error.hpp" -#include "rmw_connext_shared_cpp/event.hpp" #include "rmw_connext_shared_cpp/event_converter.hpp" #include "rmw_connext_shared_cpp/types.hpp" #include "rmw_connext_shared_cpp/visibility_control.h" @@ -54,7 +53,7 @@ __gather_event_conditions( RMW_SET_ERROR_MSG("status condition handle is null"); return RMW_RET_ERROR; } - if (__rmw_event_type_is_supported(current_event->event_type)) { + if (is_event_supported(current_event->event_type)) { auto map_pair = status_mask_map.insert( std::pair( status_condition, DDS::STATUS_MASK_NONE)); @@ -91,7 +90,7 @@ rmw_ret_t __handle_active_event_conditions(rmw_events_t * events) DDS::StatusMask status_mask = dds_entity->get_status_changes(); bool is_active = false; - if (__rmw_event_type_is_supported(current_event->event_type)) { + if (is_event_supported(current_event->event_type)) { is_active = static_cast(status_mask & get_status_kind_from_rmw(current_event->event_type)); } diff --git a/rmw_connext_shared_cpp/src/event.cpp b/rmw_connext_shared_cpp/src/event.cpp index ffce8862..14daf181 100644 --- a/rmw_connext_shared_cpp/src/event.cpp +++ b/rmw_connext_shared_cpp/src/event.cpp @@ -20,19 +20,33 @@ #include "rmw_connext_shared_cpp/event_converter.hpp" #include "rmw_connext_shared_cpp/types.hpp" -/// Mapping of RMW_EVENT to the corresponding DDS_StatusKind. -const -std::unordered_map __rmw_event_type_to_dds_status_mask_map{ - {RMW_EVENT_LIVELINESS_CHANGED, DDS_LIVELINESS_CHANGED_STATUS}, - {RMW_EVENT_REQUESTED_DEADLINE_MISSED, DDS_REQUESTED_DEADLINE_MISSED_STATUS}, - {RMW_EVENT_LIVELINESS_LOST, DDS_LIVELINESS_LOST_STATUS}, - {RMW_EVENT_OFFERED_DEADLINE_MISSED, DDS_OFFERED_DEADLINE_MISSED_STATUS}, -}; - -bool -__rmw_event_type_is_supported(rmw_event_type_t event_type) +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) { - return __rmw_event_type_to_dds_status_mask_map.count(event_type) > 0; + 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 @@ -56,7 +70,7 @@ __rmw_take_event( rmw_ret_t ret_code = RMW_RET_UNSUPPORTED; // check if we support the input event type - if (__rmw_event_type_is_supported(event_handle->event_type)) { + if (is_event_supported(event_handle->event_type)) { // lookup status mask from rmw_event_type DDS_StatusKind status_kind = get_status_kind_from_rmw(event_handle->event_type); diff --git a/rmw_connext_shared_cpp/src/event_converter.cpp b/rmw_connext_shared_cpp/src/event_converter.cpp index 4c132a31..cb852778 100644 --- a/rmw_connext_shared_cpp/src/event_converter.cpp +++ b/rmw_connext_shared_cpp/src/event_converter.cpp @@ -14,15 +14,27 @@ #include -#include "rmw_connext_shared_cpp/event.hpp" #include "rmw_connext_shared_cpp/event_converter.hpp" -DDS::StatusKind get_status_kind_from_rmw(rmw_event_type_t event_t) +/// Mapping of RMW_EVENT to the corresponding DDS_StatusKind. +static const std::unordered_map mask_map{ + {RMW_EVENT_LIVELINESS_CHANGED, DDS_LIVELINESS_CHANGED_STATUS}, + {RMW_EVENT_REQUESTED_DEADLINE_MISSED, DDS_REQUESTED_DEADLINE_MISSED_STATUS}, + {RMW_EVENT_LIVELINESS_LOST, DDS_LIVELINESS_LOST_STATUS}, + {RMW_EVENT_OFFERED_DEADLINE_MISSED, DDS_OFFERED_DEADLINE_MISSED_STATUS}, +}; + +DDS::StatusKind get_status_kind_from_rmw(const rmw_event_type_t event_t) +{ + return mask_map.at(event_t); +} + +bool is_event_supported(const rmw_event_type_t event_t) { - return __rmw_event_type_to_dds_status_mask_map.at(event_t); + return mask_map.count(event_t) > 0; } -rmw_ret_t check_dds_ret_code(DDS::ReturnCode_t dds_return_code) +rmw_ret_t check_dds_ret_code(const DDS::ReturnCode_t dds_return_code) { switch (dds_return_code) { case DDS_RETCODE_OK: From 5f669d733bb6e53020aef4f24e2867e020bf1041 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Tue, 17 Mar 2020 09:35:06 -0700 Subject: [PATCH 3/3] address PR comments Signed-off-by: Miaofei --- rmw_connext_cpp/src/rmw_event.cpp | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/rmw_connext_cpp/src/rmw_event.cpp b/rmw_connext_cpp/src/rmw_event.cpp index 6b8ef56f..373ed44b 100644 --- a/rmw_connext_cpp/src/rmw_event.cpp +++ b/rmw_connext_cpp/src/rmw_event.cpp @@ -20,17 +20,6 @@ extern "C" { - -/// Initialize a rmw publisher event. -/** - * \param[in|out] rmw_event to initialize - * \param publisher 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_ret_t rmw_publisher_event_init( rmw_event_t * rmw_event, @@ -45,16 +34,6 @@ rmw_publisher_event_init( event_type); } -/// Initialize a rmw subscription event. -/** - * \param[in|out] rmw_event to initialize - * \param subscription 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_ret_t rmw_subscription_event_init( rmw_event_t * rmw_event, @@ -69,15 +48,6 @@ rmw_subscription_event_init( event_type); } -/// 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_take_event( const rmw_event_t * event_handle, @@ -90,5 +60,4 @@ rmw_take_event( event_info, taken); } - } // extern "C"