From fa18df97d0a7c137d880c48c364f39039cd905e9 Mon Sep 17 00:00:00 2001 From: Ada-King Date: Tue, 21 Jul 2020 14:16:47 +0800 Subject: [PATCH 1/4] Expose qos setting for /rosout Signed-off-by: Ada-King --- rcl/include/rcl/logging_rosout.h | 13 +++++++++++++ rcl/include/rcl/node_options.h | 3 +++ rcl/src/rcl/logging_rosout.c | 11 ++++++----- rcl/src/rcl/node_options.c | 4 +++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/rcl/include/rcl/logging_rosout.h b/rcl/include/rcl/logging_rosout.h index 255511680..5a1f2b40b 100644 --- a/rcl/include/rcl/logging_rosout.h +++ b/rcl/include/rcl/logging_rosout.h @@ -26,6 +26,19 @@ extern "C" { #endif +static const rmw_qos_profile_t rcl_qos_profile_rosout_default = +{ + RMW_QOS_POLICY_HISTORY_KEEP_LAST, + 1000, + RMW_QOS_POLICY_RELIABILITY_RELIABLE, + RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL, + RMW_QOS_DEADLINE_DEFAULT, + {10, 0}, + RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT, + RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT, + false +}; + /// Initializes the rcl_logging_rosout features /** * Calling this will initialize the rcl_logging_rosout features. This function must be called diff --git a/rcl/include/rcl/node_options.h b/rcl/include/rcl/node_options.h index 9960fb2da..cc2e60e8d 100644 --- a/rcl/include/rcl/node_options.h +++ b/rcl/include/rcl/node_options.h @@ -49,6 +49,9 @@ typedef struct rcl_node_options_t /// Flag to enable rosout for this node bool enable_rosout; + + /// Middleware quality of service settings for /rosout. + rmw_qos_profile_t rosout_qos; } rcl_node_options_t; /// Return the default node options in a rcl_node_options_t. diff --git a/rcl/src/rcl/logging_rosout.c b/rcl/src/rcl/logging_rosout.c index 3585cff4b..4133a52f6 100644 --- a/rcl/src/rcl/logging_rosout.c +++ b/rcl/src/rcl/logging_rosout.c @@ -173,11 +173,12 @@ rcl_ret_t rcl_logging_rosout_init_publisher_for_node( const rosidl_message_type_support_t * type_support = rosidl_typesupport_c__get_message_type_support_handle__rcl_interfaces__msg__Log(); rcl_publisher_options_t options = rcl_publisher_get_default_options(); - // Late joining subscriptions get the last 10 seconds of logs, up to 1000 logs. - options.qos.depth = 1000; - options.qos.durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL; - options.qos.lifespan.sec = 10; - options.qos.lifespan.nsec = 0; + + // Late joining subscriptions get the user's setting of rosout qos options. + const rcl_node_options_t * node_options = rcl_node_get_options(node); + RCL_CHECK_FOR_NULL_WITH_MSG(node_options, "Node options was null.", return RCL_RET_ERROR); + + options.qos = node_options->rosout_qos; new_entry.publisher = rcl_get_zero_initialized_publisher(); status = rcl_publisher_init(&new_entry.publisher, node, type_support, ROSOUT_TOPIC_NAME, &options); diff --git a/rcl/src/rcl/node_options.c b/rcl/src/rcl/node_options.c index 9cd3f12e8..636f9acdd 100644 --- a/rcl/src/rcl/node_options.c +++ b/rcl/src/rcl/node_options.c @@ -28,9 +28,10 @@ rcl_node_options_t rcl_node_get_default_options() { // !!! MAKE SURE THAT CHANGES TO THESE DEFAULTS ARE REFLECTED IN THE HEADER DOC STRING - static rcl_node_options_t default_options = { + rcl_node_options_t default_options = { .use_global_arguments = true, .enable_rosout = true, + .rosout_qos = rcl_qos_profile_rosout_default, }; // Must set the allocator after because it is not a compile time constant. default_options.allocator = rcl_get_default_allocator(); @@ -56,6 +57,7 @@ rcl_node_options_copy( options_out->allocator = options->allocator; options_out->use_global_arguments = options->use_global_arguments; options_out->enable_rosout = options->enable_rosout; + options_out->rosout_qos = options->rosout_qos; if (NULL != options->arguments.impl) { rcl_ret_t ret = rcl_arguments_copy(&(options->arguments), &(options_out->arguments)); return ret; From 5d89c57794257f2b709f47b2308b6eda8e321ead Mon Sep 17 00:00:00 2001 From: Ada-King Date: Tue, 28 Jul 2020 10:31:57 +0800 Subject: [PATCH 2/4] Modify some details based on review Signed-off-by: Ada-King --- rcl/include/rcl/logging_rosout.h | 6 ++++++ rcl/include/rcl/node_options.h | 2 +- rcl/src/rcl/node_options.c | 5 ++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rcl/include/rcl/logging_rosout.h b/rcl/include/rcl/logging_rosout.h index 5a1f2b40b..087e981cf 100644 --- a/rcl/include/rcl/logging_rosout.h +++ b/rcl/include/rcl/logging_rosout.h @@ -26,6 +26,12 @@ extern "C" { #endif +/// The default qos profile setting for topic /rosout +/** + * - depth = 1000 + * - durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL + * - lifespan = {10, 0} + */ static const rmw_qos_profile_t rcl_qos_profile_rosout_default = { RMW_QOS_POLICY_HISTORY_KEEP_LAST, diff --git a/rcl/include/rcl/node_options.h b/rcl/include/rcl/node_options.h index cc2e60e8d..acb3f1a74 100644 --- a/rcl/include/rcl/node_options.h +++ b/rcl/include/rcl/node_options.h @@ -58,11 +58,11 @@ typedef struct rcl_node_options_t /** * The default values are: * - * - domain_id = RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID * - allocator = rcl_get_default_allocator() * - use_global_arguments = true * - enable_rosout = true * - arguments = rcl_get_zero_initialized_arguments() + * - rosout_qos = rcl_qos_profile_rosout_default */ RCL_PUBLIC rcl_node_options_t diff --git a/rcl/src/rcl/node_options.c b/rcl/src/rcl/node_options.c index 636f9acdd..046464edc 100644 --- a/rcl/src/rcl/node_options.c +++ b/rcl/src/rcl/node_options.c @@ -29,13 +29,12 @@ rcl_node_get_default_options() { // !!! MAKE SURE THAT CHANGES TO THESE DEFAULTS ARE REFLECTED IN THE HEADER DOC STRING rcl_node_options_t default_options = { + .allocator = rcl_get_default_allocator(), .use_global_arguments = true, + .arguments = rcl_get_zero_initialized_arguments(), .enable_rosout = true, .rosout_qos = rcl_qos_profile_rosout_default, }; - // Must set the allocator after because it is not a compile time constant. - default_options.allocator = rcl_get_default_allocator(); - default_options.arguments = rcl_get_zero_initialized_arguments(); return default_options; } From 3f34e2869bd170255fb7f43b2fd218114b2372fa Mon Sep 17 00:00:00 2001 From: Ada-King Date: Wed, 29 Jul 2020 10:25:18 +0800 Subject: [PATCH 3/4] Add test Signed-off-by: Ada-King --- rcl/test/rcl/test_node.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/rcl/test/rcl/test_node.cpp b/rcl/test/rcl/test_node.cpp index 965c36a71..1acf0919d 100644 --- a/rcl/test/rcl/test_node.cpp +++ b/rcl/test/rcl/test_node.cpp @@ -26,6 +26,7 @@ #include "osrf_testing_tools_cpp/memory_tools/memory_tools.hpp" #include "osrf_testing_tools_cpp/scope_exit.hpp" #include "rcl/error_handling.h" +#include "rcl/logging_rosout.h" #ifdef RMW_IMPLEMENTATION # define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX @@ -39,6 +40,28 @@ using osrf_testing_tools_cpp::memory_tools::on_unexpected_realloc; using osrf_testing_tools_cpp::memory_tools::on_unexpected_calloc; using osrf_testing_tools_cpp::memory_tools::on_unexpected_free; +bool operator==( + const rmw_time_t & lhs, + const rmw_time_t & rhs) +{ + return lhs.sec == rhs.sec && lhs.nsec == rhs.nsec; +} + +bool operator==( + const rmw_qos_profile_t & lhs, + const rmw_qos_profile_t & rhs) +{ + return lhs.history == rhs.history && + lhs.depth == rhs.depth && + lhs.reliability == rhs.reliability && + lhs.durability == rhs.durability && + lhs.deadline == rhs.deadline && + lhs.lifespan == rhs.lifespan && + lhs.liveliness == rhs.liveliness && + lhs.liveliness_lease_duration == rhs.liveliness_lease_duration && + lhs.avoid_ros_namespace_conventions == rhs.avoid_ros_namespace_conventions; +} + class CLASSNAME (TestNodeFixture, RMW_IMPLEMENTATION) : public ::testing::Test { public: @@ -723,11 +746,13 @@ TEST_F(CLASSNAME(TestNodeFixture, RMW_IMPLEMENTATION), test_rcl_node_names) { TEST_F(CLASSNAME(TestNodeFixture, RMW_IMPLEMENTATION), test_rcl_node_options) { rcl_node_options_t default_options = rcl_node_get_default_options(); rcl_node_options_t not_ini_options = rcl_node_get_default_options(); + memset(¬_ini_options.rosout_qos, 0, sizeof(rmw_qos_profile_t)); EXPECT_TRUE(default_options.use_global_arguments); EXPECT_TRUE(default_options.enable_rosout); EXPECT_TRUE(rcutils_allocator_is_valid(&(default_options.allocator))); + EXPECT_EQ(rcl_qos_profile_rosout_default, default_options.rosout_qos); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_node_options_copy(nullptr, &default_options)); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_node_options_copy(&default_options, nullptr)); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_node_options_copy(&default_options, &default_options)); @@ -740,9 +765,11 @@ TEST_F(CLASSNAME(TestNodeFixture, RMW_IMPLEMENTATION), test_rcl_node_options) { rcl_parse_arguments(argc, argv, default_options.allocator, &(default_options.arguments))); default_options.use_global_arguments = false; default_options.enable_rosout = false; + default_options.rosout_qos = rcl_qos_profile_rosout_default; EXPECT_EQ(RCL_RET_OK, rcl_node_options_copy(&default_options, ¬_ini_options)); EXPECT_FALSE(not_ini_options.use_global_arguments); EXPECT_FALSE(not_ini_options.enable_rosout); + EXPECT_EQ(rcl_qos_profile_rosout_default, not_ini_options.rosout_qos); EXPECT_EQ( rcl_arguments_get_count_unparsed(&(default_options.arguments)), rcl_arguments_get_count_unparsed(&(not_ini_options.arguments))); From 1ae0b91d248957b924da5e9f9203979c7e76fea2 Mon Sep 17 00:00:00 2001 From: Ada-King Date: Tue, 4 Aug 2020 10:04:33 +0800 Subject: [PATCH 4/4] Modify based on reviews Signed-off-by: Ada-King --- rcl/test/rcl/test_node.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rcl/test/rcl/test_node.cpp b/rcl/test/rcl/test_node.cpp index 1acf0919d..7976d7f7d 100644 --- a/rcl/test/rcl/test_node.cpp +++ b/rcl/test/rcl/test_node.cpp @@ -750,9 +750,9 @@ TEST_F(CLASSNAME(TestNodeFixture, RMW_IMPLEMENTATION), test_rcl_node_options) { EXPECT_TRUE(default_options.use_global_arguments); EXPECT_TRUE(default_options.enable_rosout); + EXPECT_EQ(rcl_qos_profile_rosout_default, default_options.rosout_qos); EXPECT_TRUE(rcutils_allocator_is_valid(&(default_options.allocator))); - EXPECT_EQ(rcl_qos_profile_rosout_default, default_options.rosout_qos); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_node_options_copy(nullptr, &default_options)); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_node_options_copy(&default_options, nullptr)); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_node_options_copy(&default_options, &default_options)); @@ -765,11 +765,11 @@ TEST_F(CLASSNAME(TestNodeFixture, RMW_IMPLEMENTATION), test_rcl_node_options) { rcl_parse_arguments(argc, argv, default_options.allocator, &(default_options.arguments))); default_options.use_global_arguments = false; default_options.enable_rosout = false; - default_options.rosout_qos = rcl_qos_profile_rosout_default; + default_options.rosout_qos = rmw_qos_profile_default; EXPECT_EQ(RCL_RET_OK, rcl_node_options_copy(&default_options, ¬_ini_options)); EXPECT_FALSE(not_ini_options.use_global_arguments); EXPECT_FALSE(not_ini_options.enable_rosout); - EXPECT_EQ(rcl_qos_profile_rosout_default, not_ini_options.rosout_qos); + EXPECT_EQ(default_options.rosout_qos, not_ini_options.rosout_qos); EXPECT_EQ( rcl_arguments_get_count_unparsed(&(default_options.arguments)), rcl_arguments_get_count_unparsed(&(not_ini_options.arguments)));