From 91753dcc9ad7dc7c21d77eda0684ff646ad5994b Mon Sep 17 00:00:00 2001 From: Andrea Sorbini Date: Fri, 5 Mar 2021 13:06:17 -0800 Subject: [PATCH] * Add QoS profile API. * Use time utils from rmw_dds_common when available. --- rmw_connextdds/src/rmw_api_impl_ndds.cpp | 22 +++++++++++++ rmw_connextdds_common/CMakeLists.txt | 1 + .../include/rmw_connextdds/context.hpp | 5 +++ .../include/rmw_connextdds/rmw_api_impl.hpp | 13 ++++++++ .../include/rmw_connextdds/static_config.hpp | 10 ++++++ rmw_connextdds_common/src/common/rmw_impl.cpp | 18 ++++++++--- rmw_connextdds_common/src/common/rmw_qos.cpp | 32 +++++++++++++++++++ .../src/rmw_api_impl_rtime.cpp | 21 ++++++++++++ 8 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 rmw_connextdds_common/src/common/rmw_qos.cpp diff --git a/rmw_connextdds/src/rmw_api_impl_ndds.cpp b/rmw_connextdds/src/rmw_api_impl_ndds.cpp index 81e499ef..e080a123 100644 --- a/rmw_connextdds/src/rmw_api_impl_ndds.cpp +++ b/rmw_connextdds/src/rmw_api_impl_ndds.cpp @@ -910,3 +910,25 @@ rmw_wait( return rmw_api_connextdds_wait( subs, gcs, srvs, cls, evs, wait_set, wait_timeout); } + + +/****************************************************************************** + * QoS Profile functions + ******************************************************************************/ +#if RMW_CONNEXT_HAVE_QOS_PROFILE_API +rmw_ret_t +rmw_qos_profile_check_compatible( + const rmw_qos_profile_t publisher_profile, + const rmw_qos_profile_t subscription_profile, + rmw_qos_compatibility_type_t * compatibility, + char * reason, + size_t reason_size) +{ + return rmw_api_connextdds_qos_profile_check_compatible( + publisher_profile, + subscription_profile, + compatibility, + reason, + reason_size); +} +#endif /* RMW_CONNEXT_HAVE_QOS_PROFILE_API */ diff --git a/rmw_connextdds_common/CMakeLists.txt b/rmw_connextdds_common/CMakeLists.txt index b8b573c3..b97800e4 100644 --- a/rmw_connextdds_common/CMakeLists.txt +++ b/rmw_connextdds_common/CMakeLists.txt @@ -157,6 +157,7 @@ set(RMW_CONNEXT_COMMON_SOURCE_CPP src/common/rmw_info.cpp src/common/rmw_node.cpp src/common/rmw_publication.cpp + src/common/rmw_qos.cpp src/common/rmw_serde.cpp src/common/rmw_service.cpp src/common/rmw_subscription.cpp diff --git a/rmw_connextdds_common/include/rmw_connextdds/context.hpp b/rmw_connextdds_common/include/rmw_connextdds/context.hpp index 1bdce46e..d15341cd 100644 --- a/rmw_connextdds_common/include/rmw_connextdds/context.hpp +++ b/rmw_connextdds_common/include/rmw_connextdds/context.hpp @@ -47,6 +47,11 @@ #include "rmw_connextdds_common/msg/participant_entities_info.hpp" #endif /* RMW_CONNEXT_HAVE_PKG_RMW_DDS_COMMON */ +#if RMW_CONNEXT_HAVE_QOS_PROFILE_API +#include "rmw/qos_profiles.h" +#include "rmw_dds_common/qos.hpp" +#endif /* RMW_CONNEXT_HAVE_QOS_PROFILE_API */ + #include "rcutils/strdup.h" #if RMW_CONNEXT_HAVE_SCOPE_EXIT 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 747ce9dd..9971d4a3 100644 --- a/rmw_connextdds_common/include/rmw_connextdds/rmw_api_impl.hpp +++ b/rmw_connextdds_common/include/rmw_connextdds/rmw_api_impl.hpp @@ -604,5 +604,18 @@ rmw_api_connextdds_wait( rmw_wait_set_t * wait_set, const rmw_time_t * wait_timeout); +/****************************************************************************** + * QoS Profile functions + ******************************************************************************/ +#if RMW_CONNEXT_HAVE_QOS_PROFILE_API +rmw_ret_t +rmw_api_connextdds_qos_profile_check_compatible( + const rmw_qos_profile_t publisher_profile, + const rmw_qos_profile_t subscription_profile, + rmw_qos_compatibility_type_t * compatibility, + char * reason, + size_t reason_size); +#endif /* RMW_CONNEXT_HAVE_QOS_PROFILE_API */ + #endif // RMW_CONNEXTDDS__RMW_API_IMPL_HPP_ diff --git a/rmw_connextdds_common/include/rmw_connextdds/static_config.hpp b/rmw_connextdds_common/include/rmw_connextdds/static_config.hpp index 5d75722c..1d4612eb 100644 --- a/rmw_connextdds_common/include/rmw_connextdds/static_config.hpp +++ b/rmw_connextdds_common/include/rmw_connextdds/static_config.hpp @@ -301,6 +301,16 @@ (RMW_CONNEXT_RELEASE >= RMW_CONNEXT_RELEASE_DASHING) #endif /* RMW_CONNEXT_HAVE_INTRO_TYPE_SUPPORT */ +#ifndef RMW_CONNEXT_HAVE_QOS_PROFILE_API +#define RMW_CONNEXT_HAVE_QOS_PROFILE_API \ + (RMW_CONNEXT_RELEASE > RMW_CONNEXT_RELEASE_FOXY) +#endif /* RMW_CONNEXT_HAVE_INTRO_TYPE_SUPPORT */ + +#ifndef RMW_CONNEXT_HAVE_TIME_UTILS +#define RMW_CONNEXT_HAVE_TIME_UTILS \ + (RMW_CONNEXT_RELEASE > RMW_CONNEXT_RELEASE_FOXY) +#endif /* RMW_CONNEXT_HAVE_TIME_UTILS */ + #include "resource_limits.hpp" #endif // RMW_CONNEXTDDS__STATIC_CONFIG_HPP_ diff --git a/rmw_connextdds_common/src/common/rmw_impl.cpp b/rmw_connextdds_common/src/common/rmw_impl.cpp index 97dce06e..a4f3b5d9 100644 --- a/rmw_connextdds_common/src/common/rmw_impl.cpp +++ b/rmw_connextdds_common/src/common/rmw_impl.cpp @@ -21,6 +21,10 @@ #include "rmw_connextdds/graph_cache.hpp" +#if RMW_CONNEXT_HAVE_TIME_UTILS +#include "rmw_dds_common/time_utils.hpp" +#endif /* RMW_CONNEXT_HAVE_TIME_UTILS */ + #define ROS_SERVICE_REQUESTER_PREFIX_STR "rq" #define ROS_SERVICE_RESPONSE_PREFIX_STR "rr" @@ -34,10 +38,16 @@ rmw_connextdds_duration_from_ros_time( DDS_Duration_t * const duration, const rmw_time_t * const ros_time) { - // TODO(asorbini) This function ignores possible overflows which - // occur if (ros_time->sec > INT32_MAX || ros_time->nsec > UINT32_MAX) - duration->sec = static_cast(ros_time->sec); - duration->nanosec = static_cast(ros_time->nsec); +#if RMW_CONNEXT_HAVE_TIME_UTILS + rmw_time_t in_time = rmw_dds_common::clamp_rmw_time_to_dds_time(*ros_time); +#else + // TODO(asorbini) In older versions, this function ignores possible overflows + // which occur if (ros_time->sec > INT32_MAX || ros_time->nsec > UINT32_MAX) + rmw_time_t in_time = *ros_time; +#endif /* RMW_CONNEXT_HAVE_TIME_UTILS */ + + duration->sec = static_cast(in_time.sec); + duration->nanosec = static_cast(in_time.nsec); return RMW_RET_OK; } diff --git a/rmw_connextdds_common/src/common/rmw_qos.cpp b/rmw_connextdds_common/src/common/rmw_qos.cpp new file mode 100644 index 00000000..8fdd1ca3 --- /dev/null +++ b/rmw_connextdds_common/src/common/rmw_qos.cpp @@ -0,0 +1,32 @@ +// Copyright 2020 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" + +/****************************************************************************** + * QoS Profile functions + ******************************************************************************/ +#if RMW_CONNEXT_HAVE_QOS_PROFILE_API +rmw_ret_t +rmw_api_connextdds_qos_profile_check_compatible( + const rmw_qos_profile_t publisher_profile, + const rmw_qos_profile_t subscription_profile, + rmw_qos_compatibility_type_t * compatibility, + char * reason, + size_t reason_size) +{ + return rmw_dds_common::qos_profile_check_compatible( + publisher_profile, subscription_profile, compatibility, reason, reason_size); +} +#endif /* RMW_CONNEXT_HAVE_QOS_PROFILE_API */ diff --git a/rmw_connextddsmicro/src/rmw_api_impl_rtime.cpp b/rmw_connextddsmicro/src/rmw_api_impl_rtime.cpp index 81e499ef..9b22efca 100644 --- a/rmw_connextddsmicro/src/rmw_api_impl_rtime.cpp +++ b/rmw_connextddsmicro/src/rmw_api_impl_rtime.cpp @@ -910,3 +910,24 @@ rmw_wait( return rmw_api_connextdds_wait( subs, gcs, srvs, cls, evs, wait_set, wait_timeout); } + +/****************************************************************************** + * QoS Profile functions + ******************************************************************************/ +#if RMW_CONNEXT_HAVE_QOS_PROFILE_API +rmw_ret_t +rmw_qos_profile_check_compatible( + const rmw_qos_profile_t publisher_profile, + const rmw_qos_profile_t subscription_profile, + rmw_qos_compatibility_type_t * compatibility, + char * reason, + size_t reason_size) +{ + return rmw_api_connextdds_qos_profile_check_compatible( + publisher_profile, + subscription_profile, + compatibility, + reason, + reason_size); +} +#endif /* RMW_CONNEXT_HAVE_QOS_PROFILE_API */