From 8271a42e4124a42537f782432246286f7f6e9088 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Mon, 16 Mar 2020 14:58:06 -0700 Subject: [PATCH 1/2] add check for whether or not event_type is supported Signed-off-by: Miaofei --- rmw/include/rmw/event.h | 17 +++++++++++++++-- rmw/src/event.c | 4 ++++ rmw/test/CMakeLists.txt | 6 ++++++ rmw/test/fake_rmw_implementation.cpp | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 rmw/test/fake_rmw_implementation.cpp diff --git a/rmw/include/rmw/event.h b/rmw/include/rmw/event.h index e24cd5df..73d6c0d6 100644 --- a/rmw/include/rmw/event.h +++ b/rmw/include/rmw/event.h @@ -67,7 +67,8 @@ rmw_get_zero_initialized_event(void); * \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 + * \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_PUBLIC @@ -84,7 +85,8 @@ rmw_publisher_event_init( * \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 + * \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_PUBLIC @@ -95,6 +97,17 @@ rmw_subscription_event_init( const rmw_subscription_t * subscription, rmw_event_type_t event_type); +/// 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_PUBLIC +RMW_WARN_UNUSED +bool +rmw_event_type_is_supported(rmw_event_type_t event_type); + /// Take an event from the event handle. /** * \param event_handle event object to take from diff --git a/rmw/src/event.c b/rmw/src/event.c index c4b3dc0a..2db57aa2 100644 --- a/rmw/src/event.c +++ b/rmw/src/event.c @@ -46,6 +46,10 @@ __rmw_init_event( RMW_SET_ERROR_MSG("expected zero-initialized rmw_event"); return RMW_RET_INVALID_ARGUMENT; } + if (!rmw_event_type_is_supported(event_type)) { + RMW_SET_ERROR_MSG("provided event_type is not supported by rmw_implementation"); + return RMW_RET_UNSUPPORTED; + } rmw_event->implementation_identifier = implementation_identifier; rmw_event->data = data; rmw_event->event_type = event_type; diff --git a/rmw/test/CMakeLists.txt b/rmw/test/CMakeLists.txt index cba7748e..f9f73fc8 100644 --- a/rmw/test/CMakeLists.txt +++ b/rmw/test/CMakeLists.txt @@ -3,6 +3,7 @@ find_package(osrf_testing_tools_cpp REQUIRED) ament_add_gmock(test_serialized_message test_serialized_message.cpp + fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -12,6 +13,7 @@ endif() ament_add_gmock(test_validate_full_topic_name test_validate_full_topic_name.cpp + fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -21,6 +23,7 @@ endif() ament_add_gmock(test_validate_node_name test_validate_node_name.cpp + fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -30,6 +33,7 @@ endif() ament_add_gmock(test_validate_namespace test_validate_namespace.cpp + fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -45,6 +49,7 @@ endif() ament_add_gmock(test_topic_endpoint_info_array test_topic_endpoint_info_array.cpp + fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -55,6 +60,7 @@ endif() ament_add_gmock(test_topic_endpoint_info test_topic_endpoint_info.cpp + fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) diff --git a/rmw/test/fake_rmw_implementation.cpp b/rmw/test/fake_rmw_implementation.cpp new file mode 100644 index 00000000..94eb141d --- /dev/null +++ b/rmw/test/fake_rmw_implementation.cpp @@ -0,0 +1,20 @@ +// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "rmw/event.h" + +bool rmw_event_type_is_supported(rmw_event_type_t /*event_type*/) +{ + return false; +} From 685b21052d56743609c5a2fefb5ee5ab0cfd0dae Mon Sep 17 00:00:00 2001 From: Miaofei Date: Mon, 16 Mar 2020 18:36:31 -0700 Subject: [PATCH 2/2] move rmw_publisher/subscription_event_init functions to rmw_implementation Signed-off-by: Miaofei --- rmw/include/rmw/event.h | 11 ------ rmw/src/event.c | 50 ---------------------------- rmw/test/CMakeLists.txt | 6 ---- rmw/test/fake_rmw_implementation.cpp | 20 ----------- 4 files changed, 87 deletions(-) delete mode 100644 rmw/test/fake_rmw_implementation.cpp diff --git a/rmw/include/rmw/event.h b/rmw/include/rmw/event.h index 73d6c0d6..bf4917aa 100644 --- a/rmw/include/rmw/event.h +++ b/rmw/include/rmw/event.h @@ -97,17 +97,6 @@ rmw_subscription_event_init( const rmw_subscription_t * subscription, rmw_event_type_t event_type); -/// 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_PUBLIC -RMW_WARN_UNUSED -bool -rmw_event_type_is_supported(rmw_event_type_t event_type); - /// Take an event from the event handle. /** * \param event_handle event object to take from diff --git a/rmw/src/event.c b/rmw/src/event.c index 2db57aa2..8005fe47 100644 --- a/rmw/src/event.c +++ b/rmw/src/event.c @@ -32,56 +32,6 @@ rmw_get_zero_initialized_event(void) return event; } -rmw_ret_t -__rmw_init_event( - rmw_event_t * rmw_event, - const char * implementation_identifier, - void * data, - const rmw_event_type_t event_type) -{ - RMW_CHECK_ARGUMENT_FOR_NULL(implementation_identifier, RMW_RET_INVALID_ARGUMENT); - RMW_CHECK_ARGUMENT_FOR_NULL(data, RMW_RET_INVALID_ARGUMENT); - RMW_CHECK_ARGUMENT_FOR_NULL(rmw_event, RMW_RET_INVALID_ARGUMENT); - if (NULL != rmw_event->implementation_identifier) { - RMW_SET_ERROR_MSG("expected zero-initialized rmw_event"); - return RMW_RET_INVALID_ARGUMENT; - } - if (!rmw_event_type_is_supported(event_type)) { - RMW_SET_ERROR_MSG("provided event_type is not supported by rmw_implementation"); - return RMW_RET_UNSUPPORTED; - } - rmw_event->implementation_identifier = implementation_identifier; - rmw_event->data = data; - rmw_event->event_type = event_type; - return RMW_RET_OK; -} - -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( - 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( - rmw_event, - subscription->implementation_identifier, - subscription->data, - event_type); -} - rmw_ret_t rmw_event_fini(rmw_event_t * rmw_event) { diff --git a/rmw/test/CMakeLists.txt b/rmw/test/CMakeLists.txt index f9f73fc8..cba7748e 100644 --- a/rmw/test/CMakeLists.txt +++ b/rmw/test/CMakeLists.txt @@ -3,7 +3,6 @@ find_package(osrf_testing_tools_cpp REQUIRED) ament_add_gmock(test_serialized_message test_serialized_message.cpp - fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -13,7 +12,6 @@ endif() ament_add_gmock(test_validate_full_topic_name test_validate_full_topic_name.cpp - fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -23,7 +21,6 @@ endif() ament_add_gmock(test_validate_node_name test_validate_node_name.cpp - fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -33,7 +30,6 @@ endif() ament_add_gmock(test_validate_namespace test_validate_namespace.cpp - fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -49,7 +45,6 @@ endif() ament_add_gmock(test_topic_endpoint_info_array test_topic_endpoint_info_array.cpp - fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) @@ -60,7 +55,6 @@ endif() ament_add_gmock(test_topic_endpoint_info test_topic_endpoint_info.cpp - fake_rmw_implementation.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) diff --git a/rmw/test/fake_rmw_implementation.cpp b/rmw/test/fake_rmw_implementation.cpp deleted file mode 100644 index 94eb141d..00000000 --- a/rmw/test/fake_rmw_implementation.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "rmw/event.h" - -bool rmw_event_type_is_supported(rmw_event_type_t /*event_type*/) -{ - return false; -}