From 0fe3a8c150f9e960cae2c3cb9bbfac98b4a4e221 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Wed, 31 Mar 2021 09:51:43 +0800 Subject: [PATCH 1/6] Add rmw_publisher_wait_for_all_acked support Signed-off-by: Barry Xu --- rmw_fastrtps_cpp/src/rmw_publisher.cpp | 7 ++++ .../src/rmw_publisher.cpp | 7 ++++ .../rmw_fastrtps_shared_cpp/rmw_common.hpp | 7 ++++ rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp | 41 +++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/rmw_fastrtps_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_cpp/src/rmw_publisher.cpp index 6ee0fd154..f607f1fe4 100644 --- a/rmw_fastrtps_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_cpp/src/rmw_publisher.cpp @@ -146,6 +146,13 @@ rmw_publisher_assert_liveliness(const rmw_publisher_t * publisher) eprosima_fastrtps_identifier, publisher); } +rmw_ret_t +rmw_publisher_wait_for_all_acked(const rmw_publisher_t * publisher, rmw_time_t wait_timeout) +{ + return rmw_fastrtps_shared_cpp::__rmw_publisher_wait_for_all_acked( + eprosima_fastrtps_identifier, publisher, wait_timeout); +} + rmw_ret_t rmw_publisher_get_actual_qos( const rmw_publisher_t * publisher, diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp index 1559b42be..9eb2c6c5c 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp @@ -147,6 +147,13 @@ rmw_publisher_assert_liveliness(const rmw_publisher_t * publisher) eprosima_fastrtps_identifier, publisher); } +rmw_ret_t +rmw_publisher_wait_for_all_acked(const rmw_publisher_t * publisher, rmw_time_t wait_timeout) +{ + return rmw_fastrtps_shared_cpp::__rmw_publisher_wait_for_all_acked( + eprosima_fastrtps_identifier, publisher, wait_timeout); +} + rmw_ret_t rmw_publisher_get_actual_qos( const rmw_publisher_t * publisher, 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 7c187b31d..850cb449d 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 @@ -173,6 +173,13 @@ __rmw_publisher_assert_liveliness( const char * identifier, const rmw_publisher_t * publisher); +RMW_FASTRTPS_SHARED_CPP_PUBLIC +rmw_ret_t +__rmw_publisher_wait_for_all_acked( + const char * identifier, + const rmw_publisher_t * publisher, + rmw_time_t wait_timeout); + RMW_FASTRTPS_SHARED_CPP_PUBLIC rmw_ret_t __rmw_destroy_publisher( diff --git a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp index 73f6d0f5e..88ebbca28 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp @@ -32,6 +32,8 @@ #include "rmw_fastrtps_shared_cpp/rmw_context_impl.hpp" #include "rmw_fastrtps_shared_cpp/TypeSupport.hpp" +#include "rmw_dds_common/time_utils.hpp" + namespace rmw_fastrtps_shared_cpp { rmw_ret_t @@ -119,6 +121,45 @@ __rmw_publisher_assert_liveliness( return RMW_RET_OK; } +rmw_ret_t +__rmw_publisher_wait_for_all_acked( + const char * identifier, + const rmw_publisher_t * publisher, + rmw_time_t wait_timeout) +{ + RMW_CHECK_ARGUMENT_FOR_NULL(publisher, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_TYPE_IDENTIFIERS_MATCH( + publisher, + publisher->implementation_identifier, + identifier, + return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); + + auto info = static_cast(publisher->data); + if (nullptr == info) { + RMW_SET_ERROR_MSG("publisher internal data is invalid"); + return RMW_RET_ERROR; + } + + eprosima::fastrtps::Duration_t timeout; + + // TODO(Barry): While rmw_time_to_fastrtps() is changed to the public function, replace below + // codes. + if (rmw_time_equal(wait_timeout, RMW_DURATION_INFINITE)) { + timeout = eprosima::fastrtps::rtps::c_RTPSTimeInfinite.to_duration_t(); + } else { + rmw_time_t clamped_time = rmw_dds_common::clamp_rmw_time_to_dds_time(wait_timeout); + timeout = eprosima::fastrtps::Duration_t( + static_cast(clamped_time.sec), + static_cast(clamped_time.nsec)); + } + + if (info->publisher_->wait_for_all_acked(timeout)) { + return RMW_RET_OK; + } else { + return RMW_RET_TIMEOUT; + } +} + rmw_ret_t __rmw_publisher_get_actual_qos( const rmw_publisher_t * publisher, From ecc1e5cf6d1f4c8d92452915e710b9284e56d6a3 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Thu, 15 Apr 2021 10:21:25 +0800 Subject: [PATCH 2/6] Update codes based on rebased codes Signed-off-by: Barry Xu --- rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp index 88ebbca28..bbb0955d4 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp @@ -153,7 +153,8 @@ __rmw_publisher_wait_for_all_acked( static_cast(clamped_time.nsec)); } - if (info->publisher_->wait_for_all_acked(timeout)) { + ReturnCode_t ret = info->data_writer_->wait_for_acknowledgments(timeout); + if (ret == ReturnCode_t::RETCODE_OK) { return RMW_RET_OK; } else { return RMW_RET_TIMEOUT; From 804266543ee6ff0c36d72f593c84f6bf9e7672e3 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Sat, 17 Apr 2021 10:54:08 +0800 Subject: [PATCH 3/6] Move rmw_time_to_fastrtps to new file time_utils.cpp Signed-off-by: Barry Xu --- rmw_fastrtps_shared_cpp/src/time_utils.cpp | 30 ++++++++++++++++++++++ rmw_fastrtps_shared_cpp/src/time_utils.hpp | 22 ++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 rmw_fastrtps_shared_cpp/src/time_utils.cpp create mode 100644 rmw_fastrtps_shared_cpp/src/time_utils.hpp diff --git a/rmw_fastrtps_shared_cpp/src/time_utils.cpp b/rmw_fastrtps_shared_cpp/src/time_utils.cpp new file mode 100644 index 000000000..25f8e1ac9 --- /dev/null +++ b/rmw_fastrtps_shared_cpp/src/time_utils.cpp @@ -0,0 +1,30 @@ +// Copyright 2021 Open Source Robotics Foundation, Inc. +// +// 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_dds_common/time_utils.hpp" + +#include "time_utils.hpp" + +eprosima::fastrtps::Duration_t +rmw_time_to_fastrtps(const rmw_time_t & time) +{ + if (rmw_time_equal(time, RMW_DURATION_INFINITE)) { + return eprosima::fastrtps::rtps::c_RTPSTimeInfinite.to_duration_t(); + } + + rmw_time_t clamped_time = rmw_dds_common::clamp_rmw_time_to_dds_time(time); + return eprosima::fastrtps::Duration_t( + static_cast(clamped_time.sec), + static_cast(clamped_time.nsec)); +} diff --git a/rmw_fastrtps_shared_cpp/src/time_utils.hpp b/rmw_fastrtps_shared_cpp/src/time_utils.hpp new file mode 100644 index 000000000..674679f32 --- /dev/null +++ b/rmw_fastrtps_shared_cpp/src/time_utils.hpp @@ -0,0 +1,22 @@ +// Copyright 2021 Open Source Robotics Foundation, Inc. +// +// 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 TIME_UTILS_HPP_ +#define TIME_UTILS_HPP_ + +#include "fastdds/rtps/common/Time_t.h" + +eprosima::fastrtps::Duration_t rmw_time_to_fastrtps(const rmw_time_t & time); + +#endif // TIME_UTILS_HPP_ From f8fcdeefd435165aa7ccaa214f952825d2adbe53 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Mon, 19 Apr 2021 20:32:52 +0800 Subject: [PATCH 4/6] Update codes because rmw_time_to_fastrtps is moved Signed-off-by: Barry Xu --- rmw_fastrtps_shared_cpp/CMakeLists.txt | 1 + rmw_fastrtps_shared_cpp/src/qos.cpp | 16 +--------------- rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp | 15 ++------------- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/CMakeLists.txt b/rmw_fastrtps_shared_cpp/CMakeLists.txt index 125bc1d29..d403aae16 100644 --- a/rmw_fastrtps_shared_cpp/CMakeLists.txt +++ b/rmw_fastrtps_shared_cpp/CMakeLists.txt @@ -88,6 +88,7 @@ add_library(rmw_fastrtps_shared_cpp src/subscription.cpp src/TypeSupport_impl.cpp src/utils.cpp + src/time_utils.cpp ) target_include_directories(rmw_fastrtps_shared_cpp PUBLIC diff --git a/rmw_fastrtps_shared_cpp/src/qos.cpp b/rmw_fastrtps_shared_cpp/src/qos.cpp index 129c3be8b..c790a987b 100644 --- a/rmw_fastrtps_shared_cpp/src/qos.cpp +++ b/rmw_fastrtps_shared_cpp/src/qos.cpp @@ -19,24 +19,10 @@ #include "fastdds/dds/publisher/qos/DataWriterQos.hpp" #include "fastdds/dds/subscriber/qos/DataReaderQos.hpp" #include "fastdds/dds/topic/qos/TopicQos.hpp" -#include "fastdds/rtps/common/Time_t.h" #include "rmw/error_handling.h" -#include "rmw_dds_common/time_utils.hpp" -static -eprosima::fastrtps::Duration_t -rmw_time_to_fastrtps(const rmw_time_t & time) -{ - if (rmw_time_equal(time, RMW_DURATION_INFINITE)) { - return eprosima::fastrtps::rtps::c_RTPSTimeInfinite.to_duration_t(); - } - - rmw_time_t clamped_time = rmw_dds_common::clamp_rmw_time_to_dds_time(time); - return eprosima::fastrtps::Duration_t( - static_cast(clamped_time.sec), - static_cast(clamped_time.nsec)); -} +#include "time_utils.hpp" static bool diff --git a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp index bbb0955d4..40752345e 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp @@ -32,7 +32,7 @@ #include "rmw_fastrtps_shared_cpp/rmw_context_impl.hpp" #include "rmw_fastrtps_shared_cpp/TypeSupport.hpp" -#include "rmw_dds_common/time_utils.hpp" +#include "time_utils.hpp" namespace rmw_fastrtps_shared_cpp { @@ -140,18 +140,7 @@ __rmw_publisher_wait_for_all_acked( return RMW_RET_ERROR; } - eprosima::fastrtps::Duration_t timeout; - - // TODO(Barry): While rmw_time_to_fastrtps() is changed to the public function, replace below - // codes. - if (rmw_time_equal(wait_timeout, RMW_DURATION_INFINITE)) { - timeout = eprosima::fastrtps::rtps::c_RTPSTimeInfinite.to_duration_t(); - } else { - rmw_time_t clamped_time = rmw_dds_common::clamp_rmw_time_to_dds_time(wait_timeout); - timeout = eprosima::fastrtps::Duration_t( - static_cast(clamped_time.sec), - static_cast(clamped_time.nsec)); - } + eprosima::fastrtps::Duration_t timeout = rmw_time_to_fastrtps(wait_timeout); ReturnCode_t ret = info->data_writer_->wait_for_acknowledgments(timeout); if (ret == ReturnCode_t::RETCODE_OK) { From 5c2a7f44166fa329d40a951746c2e93bfbea558b Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Tue, 20 Apr 2021 09:28:11 +0800 Subject: [PATCH 5/6] Updated codes based on reveiw comments Signed-off-by: Barry Xu --- rmw_fastrtps_shared_cpp/CMakeLists.txt | 2 +- rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/CMakeLists.txt b/rmw_fastrtps_shared_cpp/CMakeLists.txt index d403aae16..6427ea44f 100644 --- a/rmw_fastrtps_shared_cpp/CMakeLists.txt +++ b/rmw_fastrtps_shared_cpp/CMakeLists.txt @@ -86,9 +86,9 @@ add_library(rmw_fastrtps_shared_cpp src/rmw_wait.cpp src/rmw_wait_set.cpp src/subscription.cpp + src/time_utils.cpp src/TypeSupport_impl.cpp src/utils.cpp - src/time_utils.cpp ) target_include_directories(rmw_fastrtps_shared_cpp PUBLIC diff --git a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp index 40752345e..53764b628 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp @@ -135,10 +135,6 @@ __rmw_publisher_wait_for_all_acked( return RMW_RET_INCORRECT_RMW_IMPLEMENTATION); auto info = static_cast(publisher->data); - if (nullptr == info) { - RMW_SET_ERROR_MSG("publisher internal data is invalid"); - return RMW_RET_ERROR; - } eprosima::fastrtps::Duration_t timeout = rmw_time_to_fastrtps(wait_timeout); From 51fa55660bb1eb42d6923b450770feca904232e3 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Fri, 21 May 2021 09:55:10 +0800 Subject: [PATCH 6/6] Address review comments Signed-off-by: Barry Xu --- rmw_fastrtps_shared_cpp/src/qos.cpp | 8 +++++--- rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp | 6 +++--- rmw_fastrtps_shared_cpp/src/time_utils.cpp | 5 +++++ rmw_fastrtps_shared_cpp/src/time_utils.hpp | 5 +++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/qos.cpp b/rmw_fastrtps_shared_cpp/src/qos.cpp index c790a987b..74464b778 100644 --- a/rmw_fastrtps_shared_cpp/src/qos.cpp +++ b/rmw_fastrtps_shared_cpp/src/qos.cpp @@ -105,11 +105,13 @@ bool fill_entity_qos_from_profile( } if (!is_rmw_duration_unspecified(qos_policies.lifespan)) { - entity_qos.lifespan().duration = rmw_time_to_fastrtps(qos_policies.lifespan); + entity_qos.lifespan().duration = + rmw_fastrtps_shared_cpp::rmw_time_to_fastrtps(qos_policies.lifespan); } if (!is_rmw_duration_unspecified(qos_policies.deadline)) { - entity_qos.deadline().period = rmw_time_to_fastrtps(qos_policies.deadline); + entity_qos.deadline().period = + rmw_fastrtps_shared_cpp::rmw_time_to_fastrtps(qos_policies.deadline); } switch (qos_policies.liveliness) { @@ -127,7 +129,7 @@ bool fill_entity_qos_from_profile( } if (!is_rmw_duration_unspecified(qos_policies.liveliness_lease_duration)) { entity_qos.liveliness().lease_duration = - rmw_time_to_fastrtps(qos_policies.liveliness_lease_duration); + rmw_fastrtps_shared_cpp::rmw_time_to_fastrtps(qos_policies.liveliness_lease_duration); // Docs suggest setting no higher than 0.7 * lease_duration, choosing 2/3 to give safe buffer. // See doc at https://github.com/eProsima/Fast-RTPS/blob/ diff --git a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp index 53764b628..1fae29e57 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_publisher.cpp @@ -139,11 +139,11 @@ __rmw_publisher_wait_for_all_acked( eprosima::fastrtps::Duration_t timeout = rmw_time_to_fastrtps(wait_timeout); ReturnCode_t ret = info->data_writer_->wait_for_acknowledgments(timeout); - if (ret == ReturnCode_t::RETCODE_OK) { + if (ReturnCode_t::RETCODE_OK == ret) { return RMW_RET_OK; - } else { - return RMW_RET_TIMEOUT; } + + return RMW_RET_TIMEOUT; } rmw_ret_t diff --git a/rmw_fastrtps_shared_cpp/src/time_utils.cpp b/rmw_fastrtps_shared_cpp/src/time_utils.cpp index 25f8e1ac9..2c534e72e 100644 --- a/rmw_fastrtps_shared_cpp/src/time_utils.cpp +++ b/rmw_fastrtps_shared_cpp/src/time_utils.cpp @@ -16,6 +16,9 @@ #include "time_utils.hpp" +namespace rmw_fastrtps_shared_cpp +{ + eprosima::fastrtps::Duration_t rmw_time_to_fastrtps(const rmw_time_t & time) { @@ -28,3 +31,5 @@ rmw_time_to_fastrtps(const rmw_time_t & time) static_cast(clamped_time.sec), static_cast(clamped_time.nsec)); } + +} // namespace rmw_fastrtps_shared_cpp diff --git a/rmw_fastrtps_shared_cpp/src/time_utils.hpp b/rmw_fastrtps_shared_cpp/src/time_utils.hpp index 674679f32..f22a37c84 100644 --- a/rmw_fastrtps_shared_cpp/src/time_utils.hpp +++ b/rmw_fastrtps_shared_cpp/src/time_utils.hpp @@ -17,6 +17,11 @@ #include "fastdds/rtps/common/Time_t.h" +namespace rmw_fastrtps_shared_cpp +{ + eprosima::fastrtps::Duration_t rmw_time_to_fastrtps(const rmw_time_t & time); +} // namespace rmw_fastrtps_shared_cpp + #endif // TIME_UTILS_HPP_