From 965dfbed327fdd77a9401ad5344a36888ca7b575 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 18 Feb 2021 14:59:35 -0800 Subject: [PATCH 1/5] Add RMW function to check QoS compatibility Implements https://github.com/ros2/rmw/pull/299 Depends on https://github.com/ros2/rmw_dds_common/pull/45 Signed-off-by: Jacob Perron --- rmw_fastrtps_cpp/CMakeLists.txt | 1 + rmw_fastrtps_cpp/src/rmw_qos.cpp | 32 +++++++++++++++++ rmw_fastrtps_dynamic_cpp/CMakeLists.txt | 1 + rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp | 32 +++++++++++++++++ rmw_fastrtps_shared_cpp/CMakeLists.txt | 1 + .../rmw_fastrtps_shared_cpp/rmw_common.hpp | 9 +++++ rmw_fastrtps_shared_cpp/src/rmw_qos.cpp | 34 +++++++++++++++++++ 7 files changed, 110 insertions(+) create mode 100644 rmw_fastrtps_cpp/src/rmw_qos.cpp create mode 100644 rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp create mode 100644 rmw_fastrtps_shared_cpp/src/rmw_qos.cpp diff --git a/rmw_fastrtps_cpp/CMakeLists.txt b/rmw_fastrtps_cpp/CMakeLists.txt index f92952380..3b376b9cc 100644 --- a/rmw_fastrtps_cpp/CMakeLists.txt +++ b/rmw_fastrtps_cpp/CMakeLists.txt @@ -73,6 +73,7 @@ add_library(rmw_fastrtps_cpp src/rmw_node_names.cpp src/rmw_publish.cpp src/rmw_publisher.cpp + src/rmw_qos.cpp src/rmw_request.cpp src/rmw_response.cpp src/rmw_serialize.cpp diff --git a/rmw_fastrtps_cpp/src/rmw_qos.cpp b/rmw_fastrtps_cpp/src/rmw_qos.cpp new file mode 100644 index 000000000..54b087544 --- /dev/null +++ b/rmw_fastrtps_cpp/src/rmw_qos.cpp @@ -0,0 +1,32 @@ +// 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_fastrtps_shared_cpp/rmw_common.hpp" + +extern "C" +{ + +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_fastrtps_shared_cpp::__rmw_qos_profile_check_compatible( + publisher_profile, subscription_profile, compatibility, reason, reason_size); +} + +} // extern "C" diff --git a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt index 44517187f..ec43fe20f 100644 --- a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt +++ b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt @@ -76,6 +76,7 @@ add_library(rmw_fastrtps_dynamic_cpp src/rmw_node_names.cpp src/rmw_publish.cpp src/rmw_publisher.cpp + src/rmw_qos.cpp src/rmw_request.cpp src/rmw_response.cpp src/rmw_serialize.cpp diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp new file mode 100644 index 000000000..54b087544 --- /dev/null +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp @@ -0,0 +1,32 @@ +// 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_fastrtps_shared_cpp/rmw_common.hpp" + +extern "C" +{ + +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_fastrtps_shared_cpp::__rmw_qos_profile_check_compatible( + publisher_profile, subscription_profile, compatibility, reason, reason_size); +} + +} // extern "C" diff --git a/rmw_fastrtps_shared_cpp/CMakeLists.txt b/rmw_fastrtps_shared_cpp/CMakeLists.txt index 805d75e4f..71c39d2e6 100644 --- a/rmw_fastrtps_shared_cpp/CMakeLists.txt +++ b/rmw_fastrtps_shared_cpp/CMakeLists.txt @@ -71,6 +71,7 @@ add_library(rmw_fastrtps_shared_cpp src/rmw_node_names.cpp src/rmw_publish.cpp src/rmw_publisher.cpp + src/rmw_qos.cpp src/rmw_request.cpp src/rmw_response.cpp src/rmw_security_logging.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 e925c5a18..1a9a0148b 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 @@ -392,6 +392,15 @@ __rmw_get_subscriptions_info_by_topic( bool no_mangle, rmw_topic_endpoint_info_array_t * subscriptions_info); +RMW_FASTRTPS_SHARED_CPP_PUBLIC +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); + } // namespace rmw_fastrtps_shared_cpp #endif // RMW_FASTRTPS_SHARED_CPP__RMW_COMMON_HPP_ diff --git a/rmw_fastrtps_shared_cpp/src/rmw_qos.cpp b/rmw_fastrtps_shared_cpp/src/rmw_qos.cpp new file mode 100644 index 000000000..155529aa0 --- /dev/null +++ b/rmw_fastrtps_shared_cpp/src/rmw_qos.cpp @@ -0,0 +1,34 @@ +// 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/types.h" + +#include "rmw_dds_common/qos.hpp" + +namespace rmw_fastrtps_shared_cpp +{ + +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_dds_common::qos_profile_check_compatible( + publisher_profile, subscription_profile, compatibility, reason, reason_size); +} + +} // namespace rmw_fastrtps_shared_cpp From fe8ab7d621b3d78f96152db9aa23245ffeea2408 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 22 Feb 2021 18:04:29 -0800 Subject: [PATCH 2/5] Add tests to exercise new API Signed-off-by: Jacob Perron --- rmw_fastrtps_shared_cpp/test/CMakeLists.txt | 6 ++ .../test_qos_profile_check_compatible.cpp | 101 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 rmw_fastrtps_shared_cpp/test/test_qos_profile_check_compatible.cpp diff --git a/rmw_fastrtps_shared_cpp/test/CMakeLists.txt b/rmw_fastrtps_shared_cpp/test/CMakeLists.txt index 0876a218a..ef660b2fe 100644 --- a/rmw_fastrtps_shared_cpp/test/CMakeLists.txt +++ b/rmw_fastrtps_shared_cpp/test/CMakeLists.txt @@ -35,6 +35,12 @@ if(TARGET test_names) target_link_libraries(test_names ${PROJECT_NAME}) endif() +ament_add_gtest(test_qos_profile_check_compatible test_qos_profile_check_compatible.cpp) +if(TARGET test_qos_profile_check_compatible) + ament_target_dependencies(test_qos_profile_check_compatible rmw) + target_link_libraries(test_qos_profile_check_compatible ${PROJECT_NAME}) +endif() + ament_add_gtest(test_logging test_logging.cpp) if(TARGET test_logging) ament_target_dependencies(test_logging diff --git a/rmw_fastrtps_shared_cpp/test/test_qos_profile_check_compatible.cpp b/rmw_fastrtps_shared_cpp/test/test_qos_profile_check_compatible.cpp new file mode 100644 index 000000000..66f56b507 --- /dev/null +++ b/rmw_fastrtps_shared_cpp/test/test_qos_profile_check_compatible.cpp @@ -0,0 +1,101 @@ +// Copyright 2020 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 + +#include "rmw/qos_profiles.h" +#include "rmw/types.h" + +#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" + +TEST(TestQoSProfileCheckCompatible, compatible) +{ + rmw_qos_profile_t qos_profile = { + RMW_QOS_POLICY_HISTORY_KEEP_LAST, + 5, // history depth + RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT, + RMW_QOS_POLICY_DURABILITY_VOLATILE, + {1, 0}, // deadline + {1, 0}, // lifespan + RMW_QOS_POLICY_LIVELINESS_AUTOMATIC, + {1, 0}, // liveliness lease duration + false // avoid_ros_namespace_conventions + }; + + rmw_qos_compatibility_type_t compatibility; + rmw_ret_t ret = rmw_fastrtps_shared_cpp::__rmw_qos_profile_check_compatible( + qos_profile, + qos_profile, + &compatibility, + nullptr, + 0u); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(compatibility, RMW_QOS_COMPATIBILITY_OK); +} + +TEST(TestQoSProfileCheckCompatible, incompatible) +{ + rmw_qos_profile_t pub_profile = { + RMW_QOS_POLICY_HISTORY_KEEP_LAST, + 5, // history depth + RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT, + RMW_QOS_POLICY_DURABILITY_VOLATILE, + {1, 0}, // deadline + {1, 0}, // lifespan + RMW_QOS_POLICY_LIVELINESS_AUTOMATIC, + {1, 0}, // liveliness lease duration + false // avoid_ros_namespace_conventions + }; + + rmw_qos_profile_t sub_profile = pub_profile; + sub_profile.reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE; + + rmw_qos_compatibility_type_t compatibility; + rmw_ret_t ret = rmw_fastrtps_shared_cpp::__rmw_qos_profile_check_compatible( + pub_profile, + sub_profile, + &compatibility, + nullptr, + 0u); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(compatibility, RMW_QOS_COMPATIBILITY_ERROR); +} + +TEST(TestQoSProfileCheckCompatible, warn_compatible) +{ + rmw_qos_profile_t pub_profile = { + RMW_QOS_POLICY_HISTORY_KEEP_LAST, + 5, // history depth + RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT, + RMW_QOS_POLICY_DURABILITY_VOLATILE, + {1, 0}, // deadline + {1, 0}, // lifespan + RMW_QOS_POLICY_LIVELINESS_AUTOMATIC, + {1, 0}, // liveliness lease duration + false // avoid_ros_namespace_conventions + }; + + rmw_qos_profile_t sub_profile = pub_profile; + sub_profile.reliability = RMW_QOS_POLICY_RELIABILITY_UNKNOWN; + + rmw_qos_compatibility_type_t compatibility; + rmw_ret_t ret = rmw_fastrtps_shared_cpp::__rmw_qos_profile_check_compatible( + pub_profile, + sub_profile, + &compatibility, + nullptr, + 0u); + EXPECT_EQ(ret, RMW_RET_OK); + EXPECT_EQ(compatibility, RMW_QOS_COMPATIBILITY_WARNING); +} From aff788f568a8653c5dbcf11e845b6064d7f5b066 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 22 Feb 2021 18:05:32 -0800 Subject: [PATCH 3/5] Fix copyright date Signed-off-by: Jacob Perron --- .../test/test_qos_profile_check_compatible.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_fastrtps_shared_cpp/test/test_qos_profile_check_compatible.cpp b/rmw_fastrtps_shared_cpp/test/test_qos_profile_check_compatible.cpp index 66f56b507..0fbfeb1eb 100644 --- a/rmw_fastrtps_shared_cpp/test/test_qos_profile_check_compatible.cpp +++ b/rmw_fastrtps_shared_cpp/test/test_qos_profile_check_compatible.cpp @@ -1,4 +1,4 @@ -// Copyright 2020 Open Source Robotics Foundation, Inc. +// 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. From 80bc48148edc4149532808e4b8269492eb8b73fd Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Tue, 23 Feb 2021 10:23:01 -0800 Subject: [PATCH 4/5] Fix lint Signed-off-by: Jacob Perron --- rmw_fastrtps_cpp/src/rmw_qos.cpp | 2 -- rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_qos.cpp b/rmw_fastrtps_cpp/src/rmw_qos.cpp index 54b087544..ed42def5a 100644 --- a/rmw_fastrtps_cpp/src/rmw_qos.cpp +++ b/rmw_fastrtps_cpp/src/rmw_qos.cpp @@ -16,7 +16,6 @@ extern "C" { - rmw_ret_t rmw_qos_profile_check_compatible( const rmw_qos_profile_t publisher_profile, @@ -28,5 +27,4 @@ rmw_qos_profile_check_compatible( return rmw_fastrtps_shared_cpp::__rmw_qos_profile_check_compatible( publisher_profile, subscription_profile, compatibility, reason, reason_size); } - } // extern "C" diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp index 54b087544..ed42def5a 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_qos.cpp @@ -16,7 +16,6 @@ extern "C" { - rmw_ret_t rmw_qos_profile_check_compatible( const rmw_qos_profile_t publisher_profile, @@ -28,5 +27,4 @@ rmw_qos_profile_check_compatible( return rmw_fastrtps_shared_cpp::__rmw_qos_profile_check_compatible( publisher_profile, subscription_profile, compatibility, reason, reason_size); } - } // extern "C" From 16e2e16fb2e94ce8b76fd50187f544a6af823c0b Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Tue, 23 Feb 2021 12:34:35 -0800 Subject: [PATCH 5/5] Include header with function declaration This resolves a linker error related to the function, but I'm not sure why exactly. Signed-off-by: Jacob Perron --- rmw_fastrtps_shared_cpp/src/rmw_qos.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rmw_fastrtps_shared_cpp/src/rmw_qos.cpp b/rmw_fastrtps_shared_cpp/src/rmw_qos.cpp index 155529aa0..3a635d013 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_qos.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_qos.cpp @@ -16,6 +16,8 @@ #include "rmw_dds_common/qos.hpp" +#include "rmw_fastrtps_shared_cpp/rmw_common.hpp" + namespace rmw_fastrtps_shared_cpp {