From b7f0b3caf438bf067cc0bff4eb6914c3b5dc463e Mon Sep 17 00:00:00 2001 From: Miaofei Date: Mon, 16 Mar 2020 14:59:32 -0700 Subject: [PATCH 1/7] add check for whether or not event type is supported Signed-off-by: Miaofei --- rmw_fastrtps_cpp/CMakeLists.txt | 1 + rmw_fastrtps_cpp/src/rmw_event.cpp | 26 ++++++++++++++ rmw_fastrtps_shared_cpp/CMakeLists.txt | 1 + .../rmw_fastrtps_shared_cpp/rmw_common.hpp | 4 +++ .../src/custom_publisher_info.cpp | 3 ++ .../src/custom_subscriber_info.cpp | 3 ++ rmw_fastrtps_shared_cpp/src/rmw_event.cpp | 35 +++++++++++++++++++ 7 files changed, 73 insertions(+) create mode 100644 rmw_fastrtps_cpp/src/rmw_event.cpp create mode 100644 rmw_fastrtps_shared_cpp/src/rmw_event.cpp diff --git a/rmw_fastrtps_cpp/CMakeLists.txt b/rmw_fastrtps_cpp/CMakeLists.txt index 45314ad1a..497953dcf 100644 --- a/rmw_fastrtps_cpp/CMakeLists.txt +++ b/rmw_fastrtps_cpp/CMakeLists.txt @@ -57,6 +57,7 @@ add_library(rmw_fastrtps_cpp src/rmw_client.cpp src/rmw_compare_gids_equal.cpp src/rmw_count.cpp + src/rmw_event.cpp src/rmw_get_gid_for_publisher.cpp src/rmw_get_implementation_identifier.cpp src/rmw_get_serialization_format.cpp diff --git a/rmw_fastrtps_cpp/src/rmw_event.cpp b/rmw_fastrtps_cpp/src/rmw_event.cpp new file mode 100644 index 000000000..067a45352 --- /dev/null +++ b/rmw_fastrtps_cpp/src/rmw_event.cpp @@ -0,0 +1,26 @@ +// 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/rmw.h" + +#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" + +extern "C" +{ +bool +rmw_event_type_is_supported(rmw_event_type_t event_type) +{ + return rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type); +} +} // extern "C" diff --git a/rmw_fastrtps_shared_cpp/CMakeLists.txt b/rmw_fastrtps_shared_cpp/CMakeLists.txt index a8ba7c2f5..32abbcb64 100644 --- a/rmw_fastrtps_shared_cpp/CMakeLists.txt +++ b/rmw_fastrtps_shared_cpp/CMakeLists.txt @@ -55,6 +55,7 @@ add_library(rmw_fastrtps_shared_cpp src/rmw_client.cpp src/rmw_compare_gids_equal.cpp src/rmw_count.cpp + src/rmw_event.cpp src/rmw_get_gid_for_publisher.cpp src/rmw_get_topic_endpoint_info.cpp src/rmw_guard_condition.cpp diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp index a73ce8fbf..22ef60a1b 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp @@ -117,6 +117,10 @@ __rmw_get_node_names( rcutils_string_array_t * node_names, rcutils_string_array_t * node_namespaces); +RMW_FASTRTPS_SHARED_CPP_PUBLIC +bool +__rmw_event_type_is_supported(rmw_event_type_t event_type); + RMW_FASTRTPS_SHARED_CPP_PUBLIC rmw_ret_t __rmw_publish( diff --git a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp index 20305fcb2..3af3a7d3e 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include "rmw_fastrtps_shared_cpp/custom_publisher_info.hpp" +#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" EventListenerInterface * CustomPublisherInfo::getListener() const @@ -59,6 +60,7 @@ void PubListener::on_liveliness_lost( bool PubListener::hasEvent(rmw_event_type_t event_type) const { + assert(rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type)); switch (event_type) { case RMW_EVENT_LIVELINESS_LOST: return liveliness_changes_.load(std::memory_order_relaxed); @@ -72,6 +74,7 @@ bool PubListener::hasEvent(rmw_event_type_t event_type) const bool PubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info) { + assert(rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type)); std::lock_guard lock(internalMutex_); switch (event_type) { case RMW_EVENT_LIVELINESS_LOST: diff --git a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp index d3f683502..29fa8cc0e 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include "rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp" +#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" EventListenerInterface * CustomSubscriberInfo::getListener() const @@ -61,6 +62,7 @@ void SubListener::on_liveliness_changed( bool SubListener::hasEvent(rmw_event_type_t event_type) const { + assert(rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type)); switch (event_type) { case RMW_EVENT_LIVELINESS_CHANGED: return liveliness_changes_.load(std::memory_order_relaxed); @@ -74,6 +76,7 @@ bool SubListener::hasEvent(rmw_event_type_t event_type) const bool SubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info) { + assert(rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type)); std::lock_guard lock(internalMutex_); switch (event_type) { case RMW_EVENT_LIVELINESS_CHANGED: diff --git a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp new file mode 100644 index 000000000..6e786169c --- /dev/null +++ b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp @@ -0,0 +1,35 @@ +// 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 + +#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" + +static const std::unordered_set __rmw_event_type_set{ + RMW_EVENT_LIVELINESS_CHANGED, + RMW_EVENT_REQUESTED_DEADLINE_MISSED, + RMW_EVENT_LIVELINESS_LOST, + RMW_EVENT_OFFERED_DEADLINE_MISSED +}; + +namespace rmw_fastrtps_shared_cpp +{ + +bool +__rmw_event_type_is_supported(rmw_event_type_t event_type) +{ + return __rmw_event_type_set.count(event_type) > 0; +} + +} // namespace rmw_fastrtps_shared_cpp From 605734252c16c302f738480c82e075e1698fa8fd Mon Sep 17 00:00:00 2001 From: Miaofei Date: Mon, 16 Mar 2020 17:37:25 -0700 Subject: [PATCH 2/7] add rmw_publisher/subscription_event_init functions Signed-off-by: Miaofei --- rmw_fastrtps_cpp/CMakeLists.txt | 1 - rmw_fastrtps_cpp/src/rmw_event.cpp | 32 ++++++++++++++-- .../rmw_fastrtps_shared_cpp/rmw_common.hpp | 9 ++++- .../src/custom_publisher_info.cpp | 6 +-- .../src/custom_subscriber_info.cpp | 6 +-- rmw_fastrtps_shared_cpp/src/rmw_event.cpp | 37 +++++++++++++++++-- .../src/types/event_types.hpp | 22 +++++++++++ 7 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 rmw_fastrtps_shared_cpp/src/types/event_types.hpp diff --git a/rmw_fastrtps_cpp/CMakeLists.txt b/rmw_fastrtps_cpp/CMakeLists.txt index 497953dcf..45314ad1a 100644 --- a/rmw_fastrtps_cpp/CMakeLists.txt +++ b/rmw_fastrtps_cpp/CMakeLists.txt @@ -57,7 +57,6 @@ add_library(rmw_fastrtps_cpp src/rmw_client.cpp src/rmw_compare_gids_equal.cpp src/rmw_count.cpp - src/rmw_event.cpp src/rmw_get_gid_for_publisher.cpp src/rmw_get_implementation_identifier.cpp src/rmw_get_serialization_format.cpp diff --git a/rmw_fastrtps_cpp/src/rmw_event.cpp b/rmw_fastrtps_cpp/src/rmw_event.cpp index 067a45352..a47311eb2 100644 --- a/rmw_fastrtps_cpp/src/rmw_event.cpp +++ b/rmw_fastrtps_cpp/src/rmw_event.cpp @@ -16,11 +16,37 @@ #include "rmw_fastrtps_shared_cpp/rmw_common.hpp" +#include "rmw_fastrtps_cpp/identifier.hpp" + extern "C" { -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_fastrtps_shared_cpp::__rmw_init_event( + eprosima_fastrtps_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_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type); + return rmw_fastrtps_shared_cpp::__rmw_init_event( + eprosima_fastrtps_identifier, + rmw_event, + subscription->implementation_identifier, + subscription->data, + event_type); } + } // extern "C" diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp index 22ef60a1b..13da08486 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp @@ -118,8 +118,13 @@ __rmw_get_node_names( rcutils_string_array_t * node_namespaces); RMW_FASTRTPS_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); RMW_FASTRTPS_SHARED_CPP_PUBLIC rmw_ret_t diff --git a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp index 3af3a7d3e..06d3d6ca3 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "rmw_fastrtps_shared_cpp/custom_publisher_info.hpp" -#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" +#include "types/event_types.hpp" EventListenerInterface * CustomPublisherInfo::getListener() const @@ -60,7 +60,7 @@ void PubListener::on_liveliness_lost( bool PubListener::hasEvent(rmw_event_type_t event_type) const { - assert(rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type)); + assert(is_event_supported(event_type)); switch (event_type) { case RMW_EVENT_LIVELINESS_LOST: return liveliness_changes_.load(std::memory_order_relaxed); @@ -74,7 +74,7 @@ bool PubListener::hasEvent(rmw_event_type_t event_type) const bool PubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info) { - assert(rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type)); + assert(is_event_supported(event_type)); std::lock_guard lock(internalMutex_); switch (event_type) { case RMW_EVENT_LIVELINESS_LOST: diff --git a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp index 29fa8cc0e..e4003c74e 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp" -#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" +#include "types/event_types.hpp" EventListenerInterface * CustomSubscriberInfo::getListener() const @@ -62,7 +62,7 @@ void SubListener::on_liveliness_changed( bool SubListener::hasEvent(rmw_event_type_t event_type) const { - assert(rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type)); + assert(is_event_supported(event_type)); switch (event_type) { case RMW_EVENT_LIVELINESS_CHANGED: return liveliness_changes_.load(std::memory_order_relaxed); @@ -76,7 +76,7 @@ bool SubListener::hasEvent(rmw_event_type_t event_type) const bool SubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info) { - assert(rmw_fastrtps_shared_cpp::__rmw_event_type_is_supported(event_type)); + assert(is_event_supported(event_type)); std::lock_guard lock(internalMutex_); switch (event_type) { case RMW_EVENT_LIVELINESS_CHANGED: diff --git a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp index 6e786169c..00b34172b 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp @@ -14,7 +14,10 @@ #include +#include "rmw/impl/cpp/macros.hpp" + #include "rmw_fastrtps_shared_cpp/rmw_common.hpp" +#include "types/event_types.hpp" static const std::unordered_set __rmw_event_type_set{ RMW_EVENT_LIVELINESS_CHANGED, @@ -23,13 +26,41 @@ static const std::unordered_set __rmw_event_type_set{ RMW_EVENT_OFFERED_DEADLINE_MISSED }; +bool is_event_supported(rmw_event_type_t event_type) +{ + return __rmw_event_type_set.count(event_type) > 0; +} + namespace rmw_fastrtps_shared_cpp { -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_set.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; } } // namespace rmw_fastrtps_shared_cpp diff --git a/rmw_fastrtps_shared_cpp/src/types/event_types.hpp b/rmw_fastrtps_shared_cpp/src/types/event_types.hpp new file mode 100644 index 000000000..6ec329fe3 --- /dev/null +++ b/rmw_fastrtps_shared_cpp/src/types/event_types.hpp @@ -0,0 +1,22 @@ +// 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. + +#ifndef TYPES__EVENT_TYPES_HPP_ +#define TYPES__EVENT_TYPES_HPP_ + +#include "rmw/event.h" + +bool is_event_supported(rmw_event_type_t event_type); + +#endif // TYPES__EVENT_TYPES_HPP_ From 1256c70fc65a457543f637573899b77892a4df2a Mon Sep 17 00:00:00 2001 From: Miaofei Date: Mon, 16 Mar 2020 18:54:36 -0700 Subject: [PATCH 3/7] add change to CMakeLists.txt that was missed in previous commits Signed-off-by: Miaofei --- rmw_fastrtps_cpp/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/rmw_fastrtps_cpp/CMakeLists.txt b/rmw_fastrtps_cpp/CMakeLists.txt index 45314ad1a..497953dcf 100644 --- a/rmw_fastrtps_cpp/CMakeLists.txt +++ b/rmw_fastrtps_cpp/CMakeLists.txt @@ -57,6 +57,7 @@ add_library(rmw_fastrtps_cpp src/rmw_client.cpp src/rmw_compare_gids_equal.cpp src/rmw_count.cpp + src/rmw_event.cpp src/rmw_get_gid_for_publisher.cpp src/rmw_get_implementation_identifier.cpp src/rmw_get_serialization_format.cpp From 939381663c952d596c8c5fa953f02e6802d9fd34 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Tue, 17 Mar 2020 09:34:55 -0700 Subject: [PATCH 4/7] address PR comments Signed-off-by: Miaofei --- rmw_fastrtps_cpp/src/rmw_event.cpp | 2 -- rmw_fastrtps_shared_cpp/src/rmw_event.cpp | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_event.cpp b/rmw_fastrtps_cpp/src/rmw_event.cpp index a47311eb2..5f4684777 100644 --- a/rmw_fastrtps_cpp/src/rmw_event.cpp +++ b/rmw_fastrtps_cpp/src/rmw_event.cpp @@ -20,7 +20,6 @@ extern "C" { - rmw_ret_t rmw_publisher_event_init( rmw_event_t * rmw_event, @@ -48,5 +47,4 @@ rmw_subscription_event_init( subscription->data, event_type); } - } // extern "C" diff --git a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp index 00b34172b..8fa0e1ed4 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp @@ -19,7 +19,7 @@ #include "rmw_fastrtps_shared_cpp/rmw_common.hpp" #include "types/event_types.hpp" -static const std::unordered_set __rmw_event_type_set{ +static const std::unordered_set g_rmw_event_type_set{ RMW_EVENT_LIVELINESS_CHANGED, RMW_EVENT_REQUESTED_DEADLINE_MISSED, RMW_EVENT_LIVELINESS_LOST, @@ -28,7 +28,7 @@ static const std::unordered_set __rmw_event_type_set{ bool is_event_supported(rmw_event_type_t event_type) { - return __rmw_event_type_set.count(event_type) > 0; + return g_rmw_event_type_set.count(event_type) > 0; } namespace rmw_fastrtps_shared_cpp From 0cc0c8999a54816797a1f441f47665788ab544a1 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Tue, 17 Mar 2020 10:44:59 -0700 Subject: [PATCH 5/7] add missing implementations for rmw_fastrtps_dynamic_cpp Signed-off-by: Miaofei --- rmw_fastrtps_dynamic_cpp/CMakeLists.txt | 1 + rmw_fastrtps_dynamic_cpp/src/rmw_event.cpp | 50 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 rmw_fastrtps_dynamic_cpp/src/rmw_event.cpp diff --git a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt index ace635149..7c5305851 100644 --- a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt +++ b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt @@ -61,6 +61,7 @@ add_library(rmw_fastrtps_dynamic_cpp src/rmw_client.cpp src/rmw_compare_gids_equal.cpp src/rmw_count.cpp + src/rmw_event.cpp src/rmw_get_gid_for_publisher.cpp src/rmw_get_implementation_identifier.cpp src/rmw_get_serialization_format.cpp diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_event.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_event.cpp new file mode 100644 index 000000000..c4b5a72b1 --- /dev/null +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_event.cpp @@ -0,0 +1,50 @@ +// 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/rmw.h" + +#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" + +#include "rmw_fastrtps_dynamic_cpp/identifier.hpp" + +extern "C" +{ +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_fastrtps_shared_cpp::__rmw_init_event( + eprosima_fastrtps_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_fastrtps_shared_cpp::__rmw_init_event( + eprosima_fastrtps_identifier, + rmw_event, + subscription->implementation_identifier, + subscription->data, + event_type); +} +} // extern "C" From 45069f8c77c327d4eff7abf5c846463d1af02625 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Tue, 17 Mar 2020 14:14:19 -0700 Subject: [PATCH 6/7] move free function into a namespace Signed-off-by: Miaofei --- rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp | 4 ++-- rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp | 4 ++-- rmw_fastrtps_shared_cpp/src/rmw_event.cpp | 9 +++++++-- rmw_fastrtps_shared_cpp/src/types/event_types.hpp | 5 +++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp index 06d3d6ca3..5002f7dfc 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp @@ -60,7 +60,7 @@ void PubListener::on_liveliness_lost( bool PubListener::hasEvent(rmw_event_type_t event_type) const { - assert(is_event_supported(event_type)); + assert(rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)); switch (event_type) { case RMW_EVENT_LIVELINESS_LOST: return liveliness_changes_.load(std::memory_order_relaxed); @@ -74,7 +74,7 @@ bool PubListener::hasEvent(rmw_event_type_t event_type) const bool PubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info) { - assert(is_event_supported(event_type)); + assert(rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)); std::lock_guard lock(internalMutex_); switch (event_type) { case RMW_EVENT_LIVELINESS_LOST: diff --git a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp index e4003c74e..3aa0ad06a 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp @@ -62,7 +62,7 @@ void SubListener::on_liveliness_changed( bool SubListener::hasEvent(rmw_event_type_t event_type) const { - assert(is_event_supported(event_type)); + assert(rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)); switch (event_type) { case RMW_EVENT_LIVELINESS_CHANGED: return liveliness_changes_.load(std::memory_order_relaxed); @@ -76,7 +76,7 @@ bool SubListener::hasEvent(rmw_event_type_t event_type) const bool SubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info) { - assert(is_event_supported(event_type)); + assert(rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)); std::lock_guard lock(internalMutex_); switch (event_type) { case RMW_EVENT_LIVELINESS_CHANGED: diff --git a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp index 8fa0e1ed4..4ed1d9f9a 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp @@ -26,11 +26,16 @@ static const std::unordered_set g_rmw_event_type_set{ RMW_EVENT_OFFERED_DEADLINE_MISSED }; +namespace rmw_fastrtps_shared_cpp_internal +{ + bool is_event_supported(rmw_event_type_t event_type) { - return g_rmw_event_type_set.count(event_type) > 0; + return g_rmw_event_type_set.count(event_type) == 1; } +} // namespace rmw_fastrtps_shared_cpp_internal + namespace rmw_fastrtps_shared_cpp { @@ -51,7 +56,7 @@ __rmw_init_event( topic_endpoint_impl_identifier, identifier, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); - if (!::is_event_supported(event_type)) { + if (!rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)) { RMW_SET_ERROR_MSG("provided event_type is not supported by rmw_fastrtps_cpp"); return RMW_RET_UNSUPPORTED; } diff --git a/rmw_fastrtps_shared_cpp/src/types/event_types.hpp b/rmw_fastrtps_shared_cpp/src/types/event_types.hpp index 6ec329fe3..35214da66 100644 --- a/rmw_fastrtps_shared_cpp/src/types/event_types.hpp +++ b/rmw_fastrtps_shared_cpp/src/types/event_types.hpp @@ -17,6 +17,11 @@ #include "rmw/event.h" +namespace rmw_fastrtps_shared_cpp_internal +{ + bool is_event_supported(rmw_event_type_t event_type); +} // namespace rmw_fastrtps_shared_cpp_internal + #endif // TYPES__EVENT_TYPES_HPP_ From 9c0bcf6f9d4d6fbfdae7f3e3c0c03739e7703119 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Wed, 18 Mar 2020 01:02:40 -0700 Subject: [PATCH 7/7] move free function into a nested namespace Signed-off-by: Miaofei --- rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp | 4 ++-- .../src/custom_subscriber_info.cpp | 4 ++-- rmw_fastrtps_shared_cpp/src/rmw_event.cpp | 11 +++++------ rmw_fastrtps_shared_cpp/src/types/event_types.hpp | 7 +++++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp index 5002f7dfc..f38f653dd 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp @@ -60,7 +60,7 @@ void PubListener::on_liveliness_lost( bool PubListener::hasEvent(rmw_event_type_t event_type) const { - assert(rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)); + assert(rmw_fastrtps_shared_cpp::internal::is_event_supported(event_type)); switch (event_type) { case RMW_EVENT_LIVELINESS_LOST: return liveliness_changes_.load(std::memory_order_relaxed); @@ -74,7 +74,7 @@ bool PubListener::hasEvent(rmw_event_type_t event_type) const bool PubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info) { - assert(rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)); + assert(rmw_fastrtps_shared_cpp::internal::is_event_supported(event_type)); std::lock_guard lock(internalMutex_); switch (event_type) { case RMW_EVENT_LIVELINESS_LOST: diff --git a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp index 3aa0ad06a..172c20ab1 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp @@ -62,7 +62,7 @@ void SubListener::on_liveliness_changed( bool SubListener::hasEvent(rmw_event_type_t event_type) const { - assert(rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)); + assert(rmw_fastrtps_shared_cpp::internal::is_event_supported(event_type)); switch (event_type) { case RMW_EVENT_LIVELINESS_CHANGED: return liveliness_changes_.load(std::memory_order_relaxed); @@ -76,7 +76,7 @@ bool SubListener::hasEvent(rmw_event_type_t event_type) const bool SubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info) { - assert(rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)); + assert(rmw_fastrtps_shared_cpp::internal::is_event_supported(event_type)); std::lock_guard lock(internalMutex_); switch (event_type) { case RMW_EVENT_LIVELINESS_CHANGED: diff --git a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp index 4ed1d9f9a..25a8c73b8 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_event.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_event.cpp @@ -26,7 +26,9 @@ static const std::unordered_set g_rmw_event_type_set{ RMW_EVENT_OFFERED_DEADLINE_MISSED }; -namespace rmw_fastrtps_shared_cpp_internal +namespace rmw_fastrtps_shared_cpp +{ +namespace internal { bool is_event_supported(rmw_event_type_t event_type) @@ -34,10 +36,7 @@ bool is_event_supported(rmw_event_type_t event_type) return g_rmw_event_type_set.count(event_type) == 1; } -} // namespace rmw_fastrtps_shared_cpp_internal - -namespace rmw_fastrtps_shared_cpp -{ +} // namespace internal rmw_ret_t __rmw_init_event( @@ -56,7 +55,7 @@ __rmw_init_event( topic_endpoint_impl_identifier, identifier, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); - if (!rmw_fastrtps_shared_cpp_internal::is_event_supported(event_type)) { + if (!internal::is_event_supported(event_type)) { RMW_SET_ERROR_MSG("provided event_type is not supported by rmw_fastrtps_cpp"); return RMW_RET_UNSUPPORTED; } diff --git a/rmw_fastrtps_shared_cpp/src/types/event_types.hpp b/rmw_fastrtps_shared_cpp/src/types/event_types.hpp index 35214da66..8eb9d68da 100644 --- a/rmw_fastrtps_shared_cpp/src/types/event_types.hpp +++ b/rmw_fastrtps_shared_cpp/src/types/event_types.hpp @@ -17,11 +17,14 @@ #include "rmw/event.h" -namespace rmw_fastrtps_shared_cpp_internal +namespace rmw_fastrtps_shared_cpp +{ +namespace internal { bool is_event_supported(rmw_event_type_t event_type); -} // namespace rmw_fastrtps_shared_cpp_internal +} // namespace internal +} // namespace rmw_fastrtps_shared_cpp #endif // TYPES__EVENT_TYPES_HPP_