From 4129331c262655a3b68658341064e905d8b54316 Mon Sep 17 00:00:00 2001 From: iRobot ROS <49500531+irobot-ros@users.noreply.github.com> Date: Thu, 24 Feb 2022 08:31:41 +0000 Subject: [PATCH] Add rmw listener apis (#44) * Add stubs for setting listener callbacks Signed-off-by: Mauro Passerino * Address PR suggestions Signed-off-by: Mauro Passerino * Fix linter issues Signed-off-by: Mauro Passerino Co-authored-by: Mauro Passerino Co-authored-by: Alberto Soragna --- rmw_connextdds/src/rmw_api_impl_ndds.cpp | 39 ++++++++++ rmw_connextdds_common/CMakeLists.txt | 1 + .../include/rmw_connextdds/rmw_api_impl.hpp | 29 +++++++ .../src/common/rmw_listener.cpp | 76 +++++++++++++++++++ .../src/rmw_api_impl_rtime.cpp | 40 ++++++++++ 5 files changed, 185 insertions(+) create mode 100644 rmw_connextdds_common/src/common/rmw_listener.cpp diff --git a/rmw_connextdds/src/rmw_api_impl_ndds.cpp b/rmw_connextdds/src/rmw_api_impl_ndds.cpp index ed2e45c8..b4caf481 100644 --- a/rmw_connextdds/src/rmw_api_impl_ndds.cpp +++ b/rmw_connextdds/src/rmw_api_impl_ndds.cpp @@ -120,6 +120,14 @@ rmw_take_event( return rmw_api_connextdds_take_event(event_handle, event_info, taken); } +rmw_ret_t +rmw_event_set_callback( + rmw_event_t * event, + rmw_event_callback_t callback, + const void * user_data) +{ + return rmw_api_connextdds_event_set_callback(event, callback, user_data); +} /***************************************************************************** * Info API *****************************************************************************/ @@ -634,6 +642,27 @@ rmw_destroy_service( { return rmw_api_connextdds_destroy_service(node, service); } + +rmw_ret_t +rmw_service_set_on_new_request_callback( + rmw_service_t * rmw_service, + rmw_event_callback_t callback, + const void * user_data) +{ + return rmw_api_connextdds_service_set_on_new_request_callback( + rmw_service, callback, user_data); +} + +rmw_ret_t +rmw_client_set_on_new_response_callback( + rmw_client_t * rmw_client, + rmw_event_callback_t callback, + const void * user_data) +{ + return rmw_api_connextdds_client_set_on_new_response_callback( + rmw_client, callback, user_data); +} + /***************************************************************************** * Subscription API *****************************************************************************/ @@ -812,6 +841,16 @@ rmw_return_loaned_message_from_subscription( subscription, loaned_message); } +rmw_ret_t +rmw_subscription_set_on_new_message_callback( + rmw_subscription_t * rmw_subscription, + rmw_event_callback_t callback, + const void * user_data) +{ + return rmw_api_connextdds_subscription_set_on_new_message_callback( + rmw_subscription, callback, user_data); +} + /***************************************************************************** * WaitSet API *****************************************************************************/ diff --git a/rmw_connextdds_common/CMakeLists.txt b/rmw_connextdds_common/CMakeLists.txt index 03fd8645..925d1beb 100644 --- a/rmw_connextdds_common/CMakeLists.txt +++ b/rmw_connextdds_common/CMakeLists.txt @@ -139,6 +139,7 @@ set(RMW_CONNEXT_COMMON_SOURCE_CPP src/common/rmw_impl.cpp src/common/rmw_impl_waitset_std.cpp src/common/rmw_info.cpp + src/common/rmw_listener.cpp src/common/rmw_node.cpp src/common/rmw_publication.cpp src/common/rmw_qos.cpp diff --git a/rmw_connextdds_common/include/rmw_connextdds/rmw_api_impl.hpp b/rmw_connextdds_common/include/rmw_connextdds/rmw_api_impl.hpp index d07a97fb..ac2d82b0 100644 --- a/rmw_connextdds_common/include/rmw_connextdds/rmw_api_impl.hpp +++ b/rmw_connextdds_common/include/rmw_connextdds/rmw_api_impl.hpp @@ -86,6 +86,13 @@ rmw_api_connextdds_take_event( void * event_info, bool * taken); +RMW_CONNEXTDDS_PUBLIC +rmw_ret_t +rmw_api_connextdds_event_set_callback( + rmw_event_t * event, + rmw_event_callback_t callback, + const void * user_data); + /***************************************************************************** * Info API *****************************************************************************/ @@ -423,6 +430,21 @@ rmw_ret_t rmw_api_connextdds_destroy_service( rmw_node_t * node, rmw_service_t * service); + +RMW_CONNEXTDDS_PUBLIC +rmw_ret_t +rmw_api_connextdds_service_set_on_new_request_callback( + rmw_service_t * rmw_service, + rmw_event_callback_t callback, + const void * user_data); + +RMW_CONNEXTDDS_PUBLIC +rmw_ret_t +rmw_api_connextdds_client_set_on_new_response_callback( + rmw_client_t * rmw_client, + rmw_event_callback_t callback, + const void * user_data); + /***************************************************************************** * Subscription API *****************************************************************************/ @@ -547,6 +569,13 @@ rmw_api_connextdds_return_loaned_message_from_subscription( const rmw_subscription_t * subscription, void * loaned_message); +RMW_CONNEXTDDS_PUBLIC +rmw_ret_t +rmw_api_connextdds_subscription_set_on_new_message_callback( + rmw_subscription_t * rmw_subscription, + rmw_event_callback_t callback, + const void * user_data); + /***************************************************************************** * WaitSet API *****************************************************************************/ diff --git a/rmw_connextdds_common/src/common/rmw_listener.cpp b/rmw_connextdds_common/src/common/rmw_listener.cpp new file mode 100644 index 00000000..730eaa92 --- /dev/null +++ b/rmw_connextdds_common/src/common/rmw_listener.cpp @@ -0,0 +1,76 @@ +// Copyright 2021 Real-Time Innovations, Inc. (RTI) +// +// 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_connextdds/rmw_impl.hpp" + +/****************************************************************************** + * Event Listener API + ******************************************************************************/ +rmw_ret_t +rmw_api_connextdds_event_set_callback( + rmw_event_t * event, + rmw_event_callback_t callback, + const void * user_data) +{ + UNUSED_ARG(event); + UNUSED_ARG(callback); + UNUSED_ARG(user_data); + RMW_CONNEXT_LOG_ERROR_SET("rmw_event_set_callback not implemented") + return RMW_RET_UNSUPPORTED; +} + +/****************************************************************************** + * Service Listener API + ******************************************************************************/ +rmw_ret_t +rmw_api_connextdds_service_set_on_new_request_callback( + rmw_service_t * rmw_service, + rmw_event_callback_t callback, + const void * user_data) +{ + UNUSED_ARG(rmw_service); + UNUSED_ARG(callback); + UNUSED_ARG(user_data); + RMW_CONNEXT_LOG_ERROR_SET("rmw_service_set_on_new_request_callback not implemented") + return RMW_RET_UNSUPPORTED; +} + +rmw_ret_t +rmw_api_connextdds_client_set_on_new_response_callback( + rmw_client_t * rmw_client, + rmw_event_callback_t callback, + const void * user_data) +{ + UNUSED_ARG(rmw_client); + UNUSED_ARG(callback); + UNUSED_ARG(user_data); + RMW_CONNEXT_LOG_ERROR_SET("rmw_client_set_on_new_response_callback not implemented") + return RMW_RET_UNSUPPORTED; +} + +/****************************************************************************** + * Subscription Listener API + ******************************************************************************/ +rmw_ret_t +rmw_api_connextdds_subscription_set_on_new_message_callback( + rmw_subscription_t * rmw_subscription, + rmw_event_callback_t callback, + const void * user_data) +{ + UNUSED_ARG(rmw_subscription); + UNUSED_ARG(callback); + UNUSED_ARG(user_data); + RMW_CONNEXT_LOG_ERROR_SET("rmw_subscription_set_on_new_message_callback not implemented") + return RMW_RET_UNSUPPORTED; +} diff --git a/rmw_connextddsmicro/src/rmw_api_impl_rtime.cpp b/rmw_connextddsmicro/src/rmw_api_impl_rtime.cpp index 4c6417c3..d56d0ccf 100644 --- a/rmw_connextddsmicro/src/rmw_api_impl_rtime.cpp +++ b/rmw_connextddsmicro/src/rmw_api_impl_rtime.cpp @@ -120,6 +120,15 @@ rmw_take_event( return rmw_api_connextdds_take_event(event_handle, event_info, taken); } +rmw_ret_t +rmw_event_set_callback( + rmw_event_t * event, + rmw_event_callback_t callback, + const void * user_data) +{ + return rmw_api_connextdds_event_set_callback(event, callback, user_data); +} + /***************************************************************************** * Info API *****************************************************************************/ @@ -633,6 +642,27 @@ rmw_destroy_service( { return rmw_api_connextdds_destroy_service(node, service); } + +rmw_ret_t +rmw_service_set_on_new_request_callback( + rmw_service_t * rmw_service, + rmw_event_callback_t callback, + const void * user_data) +{ + return rmw_api_connextdds_service_set_on_new_request_callback( + rmw_service, callback, user_data); +} + +rmw_ret_t +rmw_client_set_on_new_response_callback( + rmw_client_t * rmw_client, + rmw_event_callback_t callback, + const void * user_data) +{ + return rmw_api_connextdds_client_set_on_new_response_callback( + rmw_client, callback, user_data); +} + /***************************************************************************** * Subscription API *****************************************************************************/ @@ -809,6 +839,16 @@ rmw_return_loaned_message_from_subscription( subscription, loaned_message); } +rmw_ret_t +rmw_subscription_set_on_new_message_callback( + rmw_subscription_t * rmw_subscription, + rmw_event_callback_t callback, + const void * user_data) +{ + return rmw_api_connextdds_subscription_set_on_new_message_callback( + rmw_subscription, callback, user_data); +} + /***************************************************************************** * WaitSet API *****************************************************************************/