From 4110b12b27161b4732022eee07c751aaf996bac2 Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Fri, 4 Oct 2019 14:18:39 -0700 Subject: [PATCH 01/17] Added functions to get qos policies - rcl_get_qos_for_publishers to get the qos policies for all publishers to a topic - rcl_get_qos_for_subscribers to get the qos policies for all subscribers to a topic Signed-off-by: Jaison Titus --- rcl/include/rcl/graph.h | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/rcl/include/rcl/graph.h b/rcl/include/rcl/graph.h index 28b13a4f7..8848c95a9 100644 --- a/rcl/include/rcl/graph.h +++ b/rcl/include/rcl/graph.h @@ -524,6 +524,93 @@ rcl_count_subscribers( const char * topic_name, size_t * count); +/// Returns a list of all publishers to a topic. +/// Each element in the list will contain the publisher's name and its respective qos profile. +/** + * The `node` parameter must point to a valid node. + * + * The `topic_name` parameter must not be `NULL`. + * + * The `publishers` parameter must point to a valid struct of type rmw_participants_t. + * The `count` field inside the struct must be set to 0 + * The `participants` field inside the struct must be set to null. + * The `publishers` parameter is the output for this function and will be set. + * + * The topic name is not automatically remapped by this function. + * If there is a publisher created with topic name `foo` and remap rule `foo:=bar` then calling + * this with `topic_name` set to `bar` will return a list with 1 publisher, and with `topic_name` set to `foo` + * will return a list with 0 publishers. + * /sa rcl_remap_topic_name() + * + *
+ * Attribute | Adherence + * ------------------ | ------------- + * Allocates Memory | Yes + * Thread-Safe | No + * Uses Atomics | No + * Lock-Free | Maybe [1] + * [1] implementation may need to protect the data structure with a lock + * + * \param[in] node the handle to the node being used to query the ROS graph + * \param[in] topic_name the name of the topic in question + * \param[out] publishers a struct representing a list of publishers with their qos profile. + * \return `RCL_RET_OK` if the query was successful, or + * \return `RCL_RET_NODE_INVALID` if the node is invalid, or + * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or + * \return `RCL_RET_ERROR` if an unspecified error occurs. + */ +RCL_PUBLIC +RCL_WARN_UNUSED +rcl_ret_t +rcl_get_qos_for_publishers( + const rcl_node_t * node, + const char * topic_name, + rmw_participants_t * publishers); + +/// Returns a list of all subscribers to a topic. +/// Each element in the list will contain the subscriber's name and its respective qos profile. +/** + * The `node` parameter must point to a valid node. + * + * The `topic_name` parameter must not be `NULL`. + * + * The `subscriber` parameter must point to a valid struct of type rmw_participants_t. + * The `count` field inside the struct must be set to 0 + * The `participants` field inside the struct must be set to null. + * The `subscribers` parameter is the output for this function and will be set. + * + * The topic name is not automatically remapped by this function. + * If there is a subscriber created with topic name `foo` and remap rule `foo:=bar` then calling + * this with `topic_name` set to `bar` will return a list with 1 subscriber , and with `topic_name` set to `foo` + * will return a list with 0 subscribers. + * /sa rcl_remap_topic_name() + * + *
+ * Attribute | Adherence + * ------------------ | ------------- + * Allocates Memory | Yes + * Thread-Safe | No + * Uses Atomics | No + * Lock-Free | Maybe [1] + * [1] implementation may need to protect the data structure with a lock + * + * \param[in] node the handle to the node being used to query the ROS graph + * \param[in] topic_name the name of the topic in question + * \param[out] subscribers a struct representing a list of subscribers with their qos profile. + * \return `RCL_RET_OK` if the query was successful, or + * \return `RCL_RET_NODE_INVALID` if the node is invalid, or + * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or + * \return `RCL_RET_ERROR` if an unspecified error occurs. + */ +RCL_PUBLIC +RCL_WARN_UNUSED +rcl_ret_t +rcl_get_qos_for_subscribers( + const rcl_node_t * node, + const char * topic_name, + rmw_participants_t * subscribers); + + /// Check if a service server is available for the given service client. /** * This function will return true for `is_available` if there is a service server From 05ab30ea2e7e219cbdbdbb39b4a9294a91686b06 Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Mon, 7 Oct 2019 16:59:54 -0700 Subject: [PATCH 02/17] - Implemented - rcl_get_publishers_info_by_topic - rcl_get_subscriptions_info_by_topic - Wrote tests for the same Note: colcon build --packages-up-to rcl && colcon test --packages-select rcl && colcon test-result --verbose --test-result-base build/rcl runs successfully without any errors or failures. Signed-off-by: Jaison Titus --- rcl/include/rcl/graph.h | 81 ++++++++++------ rcl/src/rcl/graph.c | 76 +++++++++++++++ rcl/test/rcl/test_graph.cpp | 179 ++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+), 27 deletions(-) diff --git a/rcl/include/rcl/graph.h b/rcl/include/rcl/graph.h index 8848c95a9..242fcc50e 100644 --- a/rcl/include/rcl/graph.h +++ b/rcl/include/rcl/graph.h @@ -525,22 +525,29 @@ rcl_count_subscribers( size_t * count); /// Returns a list of all publishers to a topic. -/// Each element in the list will contain the publisher's name and its respective qos profile. +/// Each element in the list will contain the node name, node namespace, topic type, +/// gid and the qos profile of the publisher. /** * The `node` parameter must point to a valid node. * * The `topic_name` parameter must not be `NULL`. * - * The `publishers` parameter must point to a valid struct of type rmw_participants_t. - * The `count` field inside the struct must be set to 0 - * The `participants` field inside the struct must be set to null. - * The `publishers` parameter is the output for this function and will be set. + * The `no_mangle` parameter determines if the provided topic_name should be + * expanded to its fully qualified name. * - * The topic name is not automatically remapped by this function. - * If there is a publisher created with topic name `foo` and remap rule `foo:=bar` then calling - * this with `topic_name` set to `bar` will return a list with 1 publisher, and with `topic_name` set to `foo` - * will return a list with 0 publishers. - * /sa rcl_remap_topic_name() + * It is the responsibility of the caller to ensure that `publishers_info` parameter points + * to a valid struct of type rmw_topic_info_array_t. The `count` field inside the struct + * must be set to 0 and the `info_array` field inside the struct must be set to null. + * @see rmw_get_zero_initialized_topic_info_array + * + * The `allocator` will be used to allocate memory to the `info_array` member + * inside of `publishers_info`. + * Moreover, every const char * member inside of + * rmw_topic_info_t will be allocated memory and assigned a copied value. + * @see rmw_topic_info_set_node_name and the likes. + * However, it is the responsibility of the caller to + * reclaim any allocated resources to `publishers_info` to avoid leaking memory. + * @see rmw_topic_info_array_fini * *
* Attribute | Adherence @@ -552,38 +559,52 @@ rcl_count_subscribers( * [1] implementation may need to protect the data structure with a lock * * \param[in] node the handle to the node being used to query the ROS graph + * \param[in] allocator allocator to be used when allocating space for + * the array inside publishers_info * \param[in] topic_name the name of the topic in question - * \param[out] publishers a struct representing a list of publishers with their qos profile. + * \param[in] no_mangle if true, the topic_name will be expanded to its fully qualified name. + * \param[out] publishers_info a struct representing a list of publisher information. * \return `RCL_RET_OK` if the query was successful, or * \return `RCL_RET_NODE_INVALID` if the node is invalid, or * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or + * \return `RCL_RET_BAD_ALLOC` if memory allocation fails, or * \return `RCL_RET_ERROR` if an unspecified error occurs. */ RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t -rcl_get_qos_for_publishers( +rcl_get_publishers_info_by_topic( const rcl_node_t * node, + rcutils_allocator_t * allocator, const char * topic_name, - rmw_participants_t * publishers); + bool no_mangle, + rmw_topic_info_array_t * publishers_info); + -/// Returns a list of all subscribers to a topic. -/// Each element in the list will contain the subscriber's name and its respective qos profile. +/// Returns a list of all subscriptions to a topic. +/// Each element in the list will contain the node name, node namespace, topic type, +/// gid and the qos profile of the subscription. /** * The `node` parameter must point to a valid node. * * The `topic_name` parameter must not be `NULL`. * - * The `subscriber` parameter must point to a valid struct of type rmw_participants_t. - * The `count` field inside the struct must be set to 0 - * The `participants` field inside the struct must be set to null. - * The `subscribers` parameter is the output for this function and will be set. + * The `no_mangle` parameter determines if the provided topic_name should be + * expanded to its fully qualified name. * - * The topic name is not automatically remapped by this function. - * If there is a subscriber created with topic name `foo` and remap rule `foo:=bar` then calling - * this with `topic_name` set to `bar` will return a list with 1 subscriber , and with `topic_name` set to `foo` - * will return a list with 0 subscribers. - * /sa rcl_remap_topic_name() + * It is the responsibility of the caller to ensure that `subscriptions_info` parameter points + * to a valid struct of type rmw_topic_info_array_t. The `count` field inside the struct + * must be set to 0 and the `info_array` field inside the struct must be set to null. + * @see rmw_get_zero_initialized_topic_info_array + * + * The `allocator` will be used to allocate memory to the `info_array` member + * inside of `subscriptions_info`. + * Moreover, every const char * member inside of + * rmw_topic_info_t will be allocated memory and assigned a copied value. + * @see rmw_topic_info_set_node_name and the likes. + * However, it is the responsibility of the caller to + * reclaim any allocated resources to `subscriptions_info` to avoid leaking memory. + * @see rmw_topic_info_array_fini * *
* Attribute | Adherence @@ -595,20 +616,26 @@ rcl_get_qos_for_publishers( * [1] implementation may need to protect the data structure with a lock * * \param[in] node the handle to the node being used to query the ROS graph + * \param[in] allocator allocator to be used when allocating space for + * the array inside publishers_info * \param[in] topic_name the name of the topic in question - * \param[out] subscribers a struct representing a list of subscribers with their qos profile. + * \param[in] no_mangle if true, the topic_name will be expanded to its fully qualified name. + * \param[out] subscriptions_info a struct representing a list of subscriptions information. * \return `RCL_RET_OK` if the query was successful, or * \return `RCL_RET_NODE_INVALID` if the node is invalid, or * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or + * \return `RCL_RET_BAD_ALLOC` if memory allocation fails, or * \return `RCL_RET_ERROR` if an unspecified error occurs. */ RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t -rcl_get_qos_for_subscribers( +rcl_get_subscriptions_info_by_topic( const rcl_node_t * node, + rcutils_allocator_t * allocator, const char * topic_name, - rmw_participants_t * subscribers); + bool no_mangle, + rmw_topic_info_array_t * subscriptions_info); /// Check if a service server is available for the given service client. diff --git a/rcl/src/rcl/graph.c b/rcl/src/rcl/graph.c index 331d78027..7929baa4d 100644 --- a/rcl/src/rcl/graph.c +++ b/rcl/src/rcl/graph.c @@ -28,6 +28,7 @@ extern "C" #include "rmw/get_topic_names_and_types.h" #include "rmw/names_and_types.h" #include "rmw/rmw.h" +#include "rmw/topic_info_array.h" #include "rmw/validate_namespace.h" #include "rmw/validate_node_name.h" @@ -375,6 +376,81 @@ rcl_count_subscribers( return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } + +typedef rmw_ret_t (* get_topic_info_func)( + const rmw_node_t * node, + rcutils_allocator_t * allocator, + const char * topic_name, + bool no_mangle, + rmw_topic_info_array_t * info_array); + +rcl_ret_t +__rcl_get_info_by_topic( + const rcl_node_t * node, + rcutils_allocator_t * allocator, + const char * topic_name, + bool no_mangle, + rmw_topic_info_array_t * info_array, + get_topic_info_func get_topic_info) +{ + if (!rcl_node_is_valid(node)) { + RCL_SET_ERROR_MSG("Invalid node provided."); + return RCL_RET_NODE_INVALID; + } + const rcl_node_options_t * node_options = rcl_node_get_options(node); + if (!node_options) { + RCL_SET_ERROR_MSG("Node options are invalid."); + return RCL_RET_NODE_INVALID; // shouldn't happen, but error is already set if so + } + RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT); + RCL_CHECK_ARGUMENT_FOR_NULL(topic_name, RCL_RET_INVALID_ARGUMENT); + rcl_ret_t rcl_ret = rcl_convert_rmw_ret_to_rcl_ret(rmw_topic_info_array_check_zero(info_array)); + if (rcl_ret != RCL_RET_OK) { + RCL_SET_ERROR_MSG_WITH_FORMAT_STRING( + "rmw_topic_info_array_t must be zero initialized: %s,\n" + "Use rmw_get_zero_initialized_topic_info_array", + rmw_get_error_string().str); + rmw_reset_error(); + return rcl_ret; + } + rmw_ret_t rmw_ret = get_topic_info( + rcl_node_get_rmw_handle(node), + allocator, + topic_name, + no_mangle, + info_array); + rcl_ret = rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); + if (rcl_ret != RCL_RET_OK) { + RCL_SET_ERROR_MSG(rmw_get_error_string().str); + rmw_reset_error(); + } + return rcl_ret; +} + +rcl_ret_t +rcl_get_publishers_info_by_topic( + const rcl_node_t * node, + rcutils_allocator_t * allocator, + const char * topic_name, + bool no_mangle, + rmw_topic_info_array_t * publishers_info) +{ + return __rcl_get_info_by_topic(node, allocator, topic_name, no_mangle, publishers_info, + rmw_get_publishers_info_by_topic); +} + +rcl_ret_t +rcl_get_subscriptions_info_by_topic( + const rcl_node_t * node, + rcutils_allocator_t * allocator, + const char * topic_name, + bool no_mangle, + rmw_topic_info_array_t * subscriptions_info) +{ + return __rcl_get_info_by_topic(node, allocator, topic_name, no_mangle, subscriptions_info, + rmw_get_subscriptions_info_by_topic); +} + rcl_ret_t rcl_service_server_is_available( const rcl_node_t * node, diff --git a/rcl/test/rcl/test_graph.cpp b/rcl/test/rcl/test_graph.cpp index 28f7cdae7..680e634c5 100644 --- a/rcl/test/rcl/test_graph.cpp +++ b/rcl/test/rcl/test_graph.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,9 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test rcl_wait_set_t * wait_set_ptr; const char * test_graph_node_name = "test_graph_node"; + std::unique_ptr topic_info_array; + const char * const topic_name = "valid_topic_name"; + void SetUp() { rcl_ret_t ret; @@ -101,6 +105,8 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test ret = rcl_wait_set_init( this->wait_set_ptr, 0, 1, 0, 0, 0, 0, this->context_ptr, rcl_get_default_allocator()); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + this->topic_info_array = std::make_unique(); } void TearDown() @@ -1321,3 +1327,176 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_rcl_service_server_ wait_for_service_state_to_change(false, is_available); ASSERT_FALSE(is_available); } + + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_null_node) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(nullptr, + &allocator, this->topic_name, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_null_node) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(nullptr, + &allocator, this->topic_name, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_invalid_node) +{ + // this->old_node_ptr is a pointer to an invalid node. + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(this->old_node_ptr, + &allocator, this->topic_name, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_invalid_node) +{ + // this->old_node_ptr is a pointer to an invalid node. + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(this->old_node_ptr, + &allocator, this->topic_name, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_null_allocator) +{ + const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, nullptr, this->topic_name, + false, + this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_null_allocator) +{ + const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, nullptr, this->topic_name, + false, + this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_null_topic) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, + &allocator, nullptr, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_null_topic) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + &allocator, nullptr, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_null_participants) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, + &allocator, this->topic_name, false, nullptr); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_null_participants) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + &allocator, this->topic_name, false, nullptr); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_invalid_participants) +{ + // this participant is invalid as the pointer "participants" inside is expected to be null. + const auto & temp_info_array = this->topic_info_array.get(); + temp_info_array->info_array = + reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + free(temp_info_array->info_array); + }); + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, + &allocator, this->topic_name, false, temp_info_array); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_invalid_participants) +{ + // this participant is invalid as the pointer "participants" inside is expected to be null. + const auto & temp_info_array = this->topic_info_array.get(); + temp_info_array->info_array = + reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + free(temp_info_array->info_array); + }); + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + &allocator, this->topic_name, false, temp_info_array); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} From 25e580ba587146a8640f2beb8c08e532c273d2f8 Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Mon, 18 Nov 2019 09:32:30 -0800 Subject: [PATCH 03/17] Better error handling and avoiding error message replacement in __rcl_get_info_by_topic Signed-off-by: Jaison Titus --- rcl/src/rcl/graph.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/rcl/src/rcl/graph.c b/rcl/src/rcl/graph.c index 7929baa4d..16108756c 100644 --- a/rcl/src/rcl/graph.c +++ b/rcl/src/rcl/graph.c @@ -394,37 +394,38 @@ __rcl_get_info_by_topic( get_topic_info_func get_topic_info) { if (!rcl_node_is_valid(node)) { - RCL_SET_ERROR_MSG("Invalid node provided."); - return RCL_RET_NODE_INVALID; + return RCL_RET_NODE_INVALID; // error already set. } const rcl_node_options_t * node_options = rcl_node_get_options(node); if (!node_options) { - RCL_SET_ERROR_MSG("Node options are invalid."); return RCL_RET_NODE_INVALID; // shouldn't happen, but error is already set if so } RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(topic_name, RCL_RET_INVALID_ARGUMENT); - rcl_ret_t rcl_ret = rcl_convert_rmw_ret_to_rcl_ret(rmw_topic_info_array_check_zero(info_array)); - if (rcl_ret != RCL_RET_OK) { + rmw_error_string_t error_string; + rmw_ret_t rmw_ret = rmw_topic_info_array_check_zero(info_array); + if (rmw_ret != RMW_RET_OK) { + error_string = rmw_get_error_string(); + rmw_reset_error(); RCL_SET_ERROR_MSG_WITH_FORMAT_STRING( "rmw_topic_info_array_t must be zero initialized: %s,\n" "Use rmw_get_zero_initialized_topic_info_array", - rmw_get_error_string().str); - rmw_reset_error(); - return rcl_ret; + error_string.str); + return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } - rmw_ret_t rmw_ret = get_topic_info( + rmw_ret = get_topic_info( rcl_node_get_rmw_handle(node), allocator, topic_name, no_mangle, info_array); - rcl_ret = rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); - if (rcl_ret != RCL_RET_OK) { - RCL_SET_ERROR_MSG(rmw_get_error_string().str); + if (rmw_ret != RMW_RET_OK) { + error_string = rmw_get_error_string(); + rmw_reset_error(); + RCL_SET_ERROR_MSG(error_string.str); rmw_reset_error(); } - return rcl_ret; + return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } rcl_ret_t From 56c7d8be626f35d871122380d4812b73ca95fece Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Mon, 18 Nov 2019 15:23:52 -0800 Subject: [PATCH 04/17] Fixed linter issues Signed-off-by: Jaison Titus --- rcl/src/rcl/graph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcl/src/rcl/graph.c b/rcl/src/rcl/graph.c index 16108756c..7f12eb6e9 100644 --- a/rcl/src/rcl/graph.c +++ b/rcl/src/rcl/graph.c @@ -394,7 +394,7 @@ __rcl_get_info_by_topic( get_topic_info_func get_topic_info) { if (!rcl_node_is_valid(node)) { - return RCL_RET_NODE_INVALID; // error already set. + return RCL_RET_NODE_INVALID; // error already set. } const rcl_node_options_t * node_options = rcl_node_get_options(node); if (!node_options) { From f8a7b02571707fb40140826fedbd7d98549e0ff0 Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Tue, 19 Nov 2019 13:17:17 -0800 Subject: [PATCH 05/17] - Removed tests for info_by_topic functions from test_graph to test_info_by_topic to prevent timeouts on test_graph Signed-off-by: Jaison Titus --- rcl/test/CMakeLists.txt | 8 + rcl/test/rcl/test_graph.cpp | 173 ----------------- rcl/test/rcl/test_info_by_topic.cpp | 287 ++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 173 deletions(-) create mode 100644 rcl/test/rcl/test_info_by_topic.cpp diff --git a/rcl/test/CMakeLists.txt b/rcl/test/CMakeLists.txt index 401cc3b62..c89cfd6c2 100644 --- a/rcl/test/CMakeLists.txt +++ b/rcl/test/CMakeLists.txt @@ -101,6 +101,14 @@ function(test_target_function) ${AMENT_GTEST_ARGS} ) + rcl_add_custom_gtest(test_info_by_topic${target_suffix} + SRCS rcl/test_info_by_topic.cpp + ENV ${rmw_implementation_env_var} + APPEND_LIBRARY_DIRS ${extra_lib_dirs} + LIBRARIES ${PROJECT_NAME} + AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" "test_msgs" + ) + rcl_add_custom_gtest(test_count_matched${target_suffix} SRCS rcl/test_count_matched.cpp ENV ${rmw_implementation_env_var} diff --git a/rcl/test/rcl/test_graph.cpp b/rcl/test/rcl/test_graph.cpp index 680e634c5..ff54880d0 100644 --- a/rcl/test/rcl/test_graph.cpp +++ b/rcl/test/rcl/test_graph.cpp @@ -1327,176 +1327,3 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_rcl_service_server_ wait_for_service_state_to_change(false, is_available); ASSERT_FALSE(is_available); } - - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_publishers_info_by_topic_null_node) -{ - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(nullptr, - &allocator, this->topic_name, false, this->topic_info_array.get()); - EXPECT_EQ(RCL_RET_NODE_INVALID, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_subscriptions_info_by_topic_null_node) -{ - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(nullptr, - &allocator, this->topic_name, false, this->topic_info_array.get()); - EXPECT_EQ(RCL_RET_NODE_INVALID, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_publishers_info_by_topic_invalid_node) -{ - // this->old_node_ptr is a pointer to an invalid node. - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(this->old_node_ptr, - &allocator, this->topic_name, false, this->topic_info_array.get()); - EXPECT_EQ(RCL_RET_NODE_INVALID, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_subscriptions_info_by_topic_invalid_node) -{ - // this->old_node_ptr is a pointer to an invalid node. - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(this->old_node_ptr, - &allocator, this->topic_name, false, this->topic_info_array.get()); - EXPECT_EQ(RCL_RET_NODE_INVALID, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_publishers_info_by_topic_null_allocator) -{ - const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, nullptr, this->topic_name, - false, - this->topic_info_array.get()); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_subscriptions_info_by_topic_null_allocator) -{ - const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, nullptr, this->topic_name, - false, - this->topic_info_array.get()); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_publishers_info_by_topic_null_topic) -{ - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, - &allocator, nullptr, false, this->topic_info_array.get()); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_subscriptions_info_by_topic_null_topic) -{ - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, - &allocator, nullptr, false, this->topic_info_array.get()); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_publishers_info_by_topic_null_participants) -{ - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, - &allocator, this->topic_name, false, nullptr); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_subscriptions_info_by_topic_null_participants) -{ - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, - &allocator, this->topic_name, false, nullptr); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_publishers_info_by_topic_invalid_participants) -{ - // this participant is invalid as the pointer "participants" inside is expected to be null. - const auto & temp_info_array = this->topic_info_array.get(); - temp_info_array->info_array = - reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); - OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ - free(temp_info_array->info_array); - }); - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, - &allocator, this->topic_name, false, temp_info_array); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); -} - -/* - * This does not test content of the response. - * It only tests if the return code is the one expected. - */ -TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), - test_rcl_get_subscriptions_info_by_topic_invalid_participants) -{ - // this participant is invalid as the pointer "participants" inside is expected to be null. - const auto & temp_info_array = this->topic_info_array.get(); - temp_info_array->info_array = - reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); - OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ - free(temp_info_array->info_array); - }); - rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, - &allocator, this->topic_name, false, temp_info_array); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); -} diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp new file mode 100644 index 000000000..835dea07a --- /dev/null +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -0,0 +1,287 @@ +// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// 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 _WIN32 +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "rcl/error_handling.h" +#include "rcl/graph.h" +#include "rcl/rcl.h" + +#include "rcutils/logging_macros.h" +#include "rcutils/logging.h" + +#include "test_msgs/msg/basic_types.h" +#include "test_msgs/srv/basic_types.h" + +#include "osrf_testing_tools_cpp/scope_exit.hpp" + +#ifdef RMW_IMPLEMENTATION +# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX +# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) +#else +# define CLASSNAME(NAME, SUFFIX) NAME +#endif + +class CLASSNAME (TestInfoByTopicFixture, RMW_IMPLEMENTATION) : public ::testing::Test +{ +public: + rcl_context_t * old_context_ptr; + rcl_context_t * context_ptr; + rcl_node_t * old_node_ptr; + rcl_node_t * node_ptr; + const char * test_graph_node_name = "test_graph_node"; + std::unique_ptr topic_info_array; + const char * const topic_name = "valid_topic_name"; + + void SetUp() + { + rcl_ret_t ret; + rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); + ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str; + }); + this->old_context_ptr = new rcl_context_t; + *this->old_context_ptr = rcl_get_zero_initialized_context(); + ret = rcl_init(0, nullptr, &init_options, this->old_context_ptr); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + this->old_node_ptr = new rcl_node_t; + *this->old_node_ptr = rcl_get_zero_initialized_node(); + const char * old_name = "old_node_name"; + rcl_node_options_t node_options = rcl_node_get_default_options(); + ret = rcl_node_init(this->old_node_ptr, old_name, "", this->old_context_ptr, &node_options); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + ret = rcl_shutdown(this->old_context_ptr); // after this, the old_node_ptr should be invalid + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + this->context_ptr = new rcl_context_t; + *this->context_ptr = rcl_get_zero_initialized_context(); + + ret = rcl_init(0, nullptr, &init_options, this->context_ptr); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + this->node_ptr = new rcl_node_t; + *this->node_ptr = rcl_get_zero_initialized_node(); + const char * name = "test_graph_node"; + ret = rcl_node_init(this->node_ptr, name, "", this->context_ptr, &node_options); + ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + this->topic_info_array = std::make_unique(); + } + + void TearDown() + { + rcl_ret_t ret; + ret = rcl_node_fini(this->old_node_ptr); + delete this->old_node_ptr; + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + ret = rcl_node_fini(this->node_ptr); + delete this->node_ptr; + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + + ret = rcl_shutdown(this->context_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + ret = rcl_context_fini(this->context_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + delete this->context_ptr; + ret = rcl_context_fini(this->old_context_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + delete this->old_context_ptr; + } +}; + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_null_node) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(nullptr, + &allocator, this->topic_name, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_null_node) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(nullptr, + &allocator, this->topic_name, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_invalid_node) +{ + // this->old_node_ptr is a pointer to an invalid node. + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(this->old_node_ptr, + &allocator, this->topic_name, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_invalid_node) +{ + // this->old_node_ptr is a pointer to an invalid node. + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(this->old_node_ptr, + &allocator, this->topic_name, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_NODE_INVALID, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_null_allocator) +{ + const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, nullptr, this->topic_name, + false, + this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_null_allocator) +{ + const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, nullptr, this->topic_name, + false, + this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_null_topic) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, + &allocator, nullptr, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_null_topic) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + &allocator, nullptr, false, this->topic_info_array.get()); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_null_participants) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, + &allocator, this->topic_name, false, nullptr); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_null_participants) +{ + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + &allocator, this->topic_name, false, nullptr); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_info_by_topic_invalid_participants) +{ + // this participant is invalid as the pointer "participants" inside is expected to be null. + const auto & temp_info_array = this->topic_info_array.get(); + temp_info_array->info_array = + reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + free(temp_info_array->info_array); + }); + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, + &allocator, this->topic_name, false, temp_info_array); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} + +/* + * This does not test content of the response. + * It only tests if the return code is the one expected. + */ +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_subscriptions_info_by_topic_invalid_participants) +{ + // this participant is invalid as the pointer "participants" inside is expected to be null. + const auto & temp_info_array = this->topic_info_array.get(); + temp_info_array->info_array = + reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + free(temp_info_array->info_array); + }); + rcl_allocator_t allocator = rcl_get_default_allocator(); + const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + &allocator, this->topic_name, false, temp_info_array); + EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); +} From 86de8eb78d63215f902f74585dda92c28ff1d698 Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Tue, 19 Nov 2019 13:39:26 -0800 Subject: [PATCH 06/17] Removed unused headers from test_info_by_topic.cpp Signed-off-by: Jaison Titus --- rcl/src/rcl/graph.c | 1 - rcl/test/rcl/test_graph.cpp | 6 ------ rcl/test/rcl/test_info_by_topic.cpp | 12 ------------ 3 files changed, 19 deletions(-) diff --git a/rcl/src/rcl/graph.c b/rcl/src/rcl/graph.c index 7f12eb6e9..59665c9c6 100644 --- a/rcl/src/rcl/graph.c +++ b/rcl/src/rcl/graph.c @@ -423,7 +423,6 @@ __rcl_get_info_by_topic( error_string = rmw_get_error_string(); rmw_reset_error(); RCL_SET_ERROR_MSG(error_string.str); - rmw_reset_error(); } return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } diff --git a/rcl/test/rcl/test_graph.cpp b/rcl/test/rcl/test_graph.cpp index ff54880d0..28f7cdae7 100644 --- a/rcl/test/rcl/test_graph.cpp +++ b/rcl/test/rcl/test_graph.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -64,9 +63,6 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test rcl_wait_set_t * wait_set_ptr; const char * test_graph_node_name = "test_graph_node"; - std::unique_ptr topic_info_array; - const char * const topic_name = "valid_topic_name"; - void SetUp() { rcl_ret_t ret; @@ -105,8 +101,6 @@ class CLASSNAME (TestGraphFixture, RMW_IMPLEMENTATION) : public ::testing::Test ret = rcl_wait_set_init( this->wait_set_ptr, 0, 1, 0, 0, 0, 0, this->context_ptr, rcl_get_default_allocator()); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - - this->topic_info_array = std::make_unique(); } void TearDown() diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp index 835dea07a..22603818a 100644 --- a/rcl/test/rcl/test_info_by_topic.cpp +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -18,24 +18,12 @@ #include -#include -#include -#include #include -#include -#include -#include #include "rcl/error_handling.h" #include "rcl/graph.h" #include "rcl/rcl.h" -#include "rcutils/logging_macros.h" -#include "rcutils/logging.h" - -#include "test_msgs/msg/basic_types.h" -#include "test_msgs/srv/basic_types.h" - #include "osrf_testing_tools_cpp/scope_exit.hpp" #ifdef RMW_IMPLEMENTATION From 60ef38dd7849d482ec03fb6ac05cd09a5ea3ccde Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Tue, 19 Nov 2019 14:38:22 -0800 Subject: [PATCH 07/17] Increased TIMEOUT for test_info_by_topic Signed-off-by: Jaison Titus --- rcl/test/CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rcl/test/CMakeLists.txt b/rcl/test/CMakeLists.txt index c89cfd6c2..7c183d14b 100644 --- a/rcl/test/CMakeLists.txt +++ b/rcl/test/CMakeLists.txt @@ -101,12 +101,19 @@ function(test_target_function) ${AMENT_GTEST_ARGS} ) + set(AMENT_GTEST_ARGS "") + # TODO(mm318): why rmw_connext tests run much slower than rmw_fastrtps and rmw_opensplice tests + if(rmw_implementation STREQUAL "rmw_connext_cpp") + message(STATUS "Increasing test_info_by_topic${target_suffix} test timeout.") + set(AMENT_GTEST_ARGS TIMEOUT 120) + endif() rcl_add_custom_gtest(test_info_by_topic${target_suffix} SRCS rcl/test_info_by_topic.cpp ENV ${rmw_implementation_env_var} APPEND_LIBRARY_DIRS ${extra_lib_dirs} LIBRARIES ${PROJECT_NAME} - AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" "test_msgs" + AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" + ${AMENT_GTEST_ARGS} ) rcl_add_custom_gtest(test_count_matched${target_suffix} From 94af1726a0faeaec466af291449e940025728dd5 Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Fri, 22 Nov 2019 16:20:00 -0800 Subject: [PATCH 08/17] - Better comments in the test - Following naming convention for func typedefs Signed-off-by: Jaison Titus --- rcl/src/rcl/graph.c | 4 ++-- rcl/test/rcl/test_info_by_topic.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rcl/src/rcl/graph.c b/rcl/src/rcl/graph.c index 59665c9c6..00896ded3 100644 --- a/rcl/src/rcl/graph.c +++ b/rcl/src/rcl/graph.c @@ -377,7 +377,7 @@ rcl_count_subscribers( } -typedef rmw_ret_t (* get_topic_info_func)( +typedef rmw_ret_t (* get_topic_info_func_t)( const rmw_node_t * node, rcutils_allocator_t * allocator, const char * topic_name, @@ -391,7 +391,7 @@ __rcl_get_info_by_topic( const char * topic_name, bool no_mangle, rmw_topic_info_array_t * info_array, - get_topic_info_func get_topic_info) + get_topic_info_func_t get_topic_info) { if (!rcl_node_is_valid(node)) { return RCL_RET_NODE_INVALID; // error already set. diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp index 22603818a..6db48ecf9 100644 --- a/rcl/test/rcl/test_info_by_topic.cpp +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -241,7 +241,8 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_publishers_info_by_topic_invalid_participants) { - // this participant is invalid as the pointer "participants" inside is expected to be null. + // temp_info_array is invalid because it is expected to be zero initialized + // and the info_array variable inside it is expected to be null. const auto & temp_info_array = this->topic_info_array.get(); temp_info_array->info_array = reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); @@ -261,7 +262,8 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_subscriptions_info_by_topic_invalid_participants) { - // this participant is invalid as the pointer "participants" inside is expected to be null. + // temp_info_array is invalid because it is expected to be zero initialized + // and the info_array variable inside it is expected to be null. const auto & temp_info_array = this->topic_info_array.get(); temp_info_array->info_array = reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); From 03cc14ac6bc006df512853487bb9d80b3434a5c2 Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Sat, 23 Nov 2019 12:33:27 -0800 Subject: [PATCH 09/17] Added tests to verify the output of rmw_get_info_by_topic functions Signed-off-by: Jaison Titus --- rcl/test/CMakeLists.txt | 2 +- rcl/test/rcl/test_info_by_topic.cpp | 103 +++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/rcl/test/CMakeLists.txt b/rcl/test/CMakeLists.txt index 7c183d14b..f534ee5cf 100644 --- a/rcl/test/CMakeLists.txt +++ b/rcl/test/CMakeLists.txt @@ -112,7 +112,7 @@ function(test_target_function) ENV ${rmw_implementation_env_var} APPEND_LIBRARY_DIRS ${extra_lib_dirs} LIBRARIES ${PROJECT_NAME} - AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" + AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" "test_msgs" ${AMENT_GTEST_ARGS} ) diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp index 6db48ecf9..e40824c34 100644 --- a/rcl/test/rcl/test_info_by_topic.cpp +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -19,11 +19,18 @@ #include #include +#include #include "rcl/error_handling.h" #include "rcl/graph.h" #include "rcl/rcl.h" +#include "rmw/topic_info_array.h" +#include "rmw/error_handling.h" + +#include "test_msgs/msg/strings.h" +#include "rosidl_generator_c/string_functions.h" + #include "osrf_testing_tools_cpp/scope_exit.hpp" #ifdef RMW_IMPLEMENTATION @@ -43,9 +50,10 @@ class CLASSNAME (TestInfoByTopicFixture, RMW_IMPLEMENTATION) : public ::testing: const char * test_graph_node_name = "test_graph_node"; std::unique_ptr topic_info_array; const char * const topic_name = "valid_topic_name"; - + bool is_fastrtps; void SetUp() { + is_fastrtps = (std::string(rmw_get_implementation_identifier()).find("rmw_fastrtps") == 0); rcl_ret_t ret; rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); @@ -100,6 +108,21 @@ class CLASSNAME (TestInfoByTopicFixture, RMW_IMPLEMENTATION) : public ::testing: EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; delete this->old_context_ptr; } + + void assert_qos_equality(rmw_qos_profile_t qos_profile1, rmw_qos_profile_t qos_profile2) + { + EXPECT_EQ(qos_profile1.deadline.sec, qos_profile2.deadline.sec); + EXPECT_EQ(qos_profile1.deadline.nsec, qos_profile2.deadline.nsec); + EXPECT_EQ(qos_profile1.lifespan.sec, qos_profile2.lifespan.sec); + EXPECT_EQ(qos_profile1.lifespan.nsec, qos_profile2.lifespan.nsec); + EXPECT_EQ(qos_profile1.reliability, qos_profile2.reliability); + EXPECT_EQ(qos_profile1.liveliness, qos_profile2.liveliness); + EXPECT_EQ(qos_profile1.liveliness_lease_duration.sec, + qos_profile2.liveliness_lease_duration.sec); + EXPECT_EQ(qos_profile1.liveliness_lease_duration.nsec, + qos_profile2.liveliness_lease_duration.nsec); + EXPECT_EQ(qos_profile1.durability, qos_profile2.durability); + } }; /* @@ -275,3 +298,81 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), &allocator, this->topic_name, false, temp_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } + +TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), + test_rcl_get_publishers_subscription_info_by_topic) +{ + // This is implemented only in fastrtps currently. + if (!is_fastrtps) { + GTEST_SKIP(); + } + rmw_qos_profile_t default_qos_profile; + default_qos_profile.history = RMW_QOS_POLICY_HISTORY_KEEP_LAST; + default_qos_profile.depth = 0; + default_qos_profile.reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT; + default_qos_profile.durability = RMW_QOS_POLICY_DURABILITY_VOLATILE; + default_qos_profile.lifespan = {10, 0}; + default_qos_profile.deadline = {11, 0}; + default_qos_profile.liveliness_lease_duration = {20, 0}; + default_qos_profile.liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC; + + rcl_ret_t ret; + const rosidl_message_type_support_t * ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings); + rcl_allocator_t allocator = rcl_get_default_allocator(); + + rcl_publisher_t publisher = rcl_get_zero_initialized_publisher(); + rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options(); + publisher_options.qos = default_qos_profile; + ret = rcl_publisher_init( + &publisher, + this->node_ptr, + ts, + this->topic_name, + &publisher_options); + ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; + + rcl_subscription_t subscription = rcl_get_zero_initialized_subscription(); + rcl_subscription_options_t subscription_options = rcl_subscription_get_default_options(); + subscription_options.qos = default_qos_profile; + ret = rcl_subscription_init( + &subscription, + this->node_ptr, + ts, + this->topic_name, + &subscription_options); + ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; + std::string fqdn = this->topic_name; + fqdn = "/" + fqdn; + // Get publishers info by topic + rmw_topic_info_array_t topic_info_array_pub = rmw_get_zero_initialized_topic_info_array(); + ret = rcl_get_publishers_info_by_topic(this->node_ptr, + &allocator, fqdn.c_str(), false, &topic_info_array_pub); + EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; + EXPECT_EQ(topic_info_array_pub.count, 1u) << "Expected one publisher"; + rmw_topic_info_t topic_info_pub = topic_info_array_pub.info_array[0]; + EXPECT_STREQ(topic_info_pub.node_name, this->test_graph_node_name); + EXPECT_STREQ(topic_info_pub.node_namespace, "/"); + EXPECT_STREQ(topic_info_pub.topic_type, "test_msgs::msg::dds_::Strings_"); + assert_qos_equality(topic_info_pub.qos_profile, default_qos_profile); + + rmw_topic_info_array_t topic_info_array_sub = rmw_get_zero_initialized_topic_info_array(); + ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + &allocator, fqdn.c_str(), false, &topic_info_array_sub); + EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; + EXPECT_EQ(topic_info_array_sub.count, 1u) << "Expected one subscription"; + rmw_topic_info_t topic_info_sub = topic_info_array_sub.info_array[0]; + EXPECT_STREQ(topic_info_sub.node_name, this->test_graph_node_name); + EXPECT_STREQ(topic_info_sub.node_namespace, "/"); + EXPECT_STREQ(topic_info_sub.topic_type, "test_msgs::msg::dds_::Strings_"); + assert_qos_equality(topic_info_sub.qos_profile, default_qos_profile); + + // clean up + rmw_ret_t rmw_ret = rmw_topic_info_array_fini(&topic_info_array_pub, &allocator); + EXPECT_EQ(rmw_ret, RMW_RET_OK) << rmw_get_error_string().str; + rmw_ret = rmw_topic_info_array_fini(&topic_info_array_sub, &allocator); + EXPECT_EQ(rmw_ret, RMW_RET_OK) << rmw_get_error_string().str; + ret = rcl_subscription_fini(&subscription, this->node_ptr); + EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; + ret = rcl_publisher_fini(&publisher, this->node_ptr); + EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; +} From dee951bad165feb07c7dd8c2987a7e26d69249b9 Mon Sep 17 00:00:00 2001 From: Jaison Titus Date: Tue, 26 Nov 2019 18:02:07 -0800 Subject: [PATCH 10/17] Handles changes to the headers in rmw Signed-off-by: Jaison Titus --- rcl/include/rcl/graph.h | 1 + rcl/src/rcl/graph.c | 1 + 2 files changed, 2 insertions(+) diff --git a/rcl/include/rcl/graph.h b/rcl/include/rcl/graph.h index 242fcc50e..be51ce5cc 100644 --- a/rcl/include/rcl/graph.h +++ b/rcl/include/rcl/graph.h @@ -22,6 +22,7 @@ extern "C" #include #include +#include #include "rcutils/types.h" diff --git a/rcl/src/rcl/graph.c b/rcl/src/rcl/graph.c index 00896ded3..f94b4c3e3 100644 --- a/rcl/src/rcl/graph.c +++ b/rcl/src/rcl/graph.c @@ -25,6 +25,7 @@ extern "C" #include "rmw/error_handling.h" #include "rmw/get_node_info_and_types.h" #include "rmw/get_service_names_and_types.h" +#include "rmw/get_topic_info.h" #include "rmw/get_topic_names_and_types.h" #include "rmw/names_and_types.h" #include "rmw/rmw.h" From 3b6531ea96e9688b9aa539a21b0c2ca19822f1f4 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Fri, 13 Dec 2019 18:39:38 -0800 Subject: [PATCH 11/17] address PR comments Signed-off-by: Miaofei --- rcl/include/rcl/graph.h | 4 +- rcl/test/rcl/test_info_by_topic.cpp | 114 +++++++++++++--------------- 2 files changed, 55 insertions(+), 63 deletions(-) diff --git a/rcl/include/rcl/graph.h b/rcl/include/rcl/graph.h index be51ce5cc..663848e91 100644 --- a/rcl/include/rcl/graph.h +++ b/rcl/include/rcl/graph.h @@ -544,7 +544,7 @@ rcl_count_subscribers( * The `allocator` will be used to allocate memory to the `info_array` member * inside of `publishers_info`. * Moreover, every const char * member inside of - * rmw_topic_info_t will be allocated memory and assigned a copied value. + * rmw_topic_info_t will be assigned a copied value on allocated memory. * @see rmw_topic_info_set_node_name and the likes. * However, it is the responsibility of the caller to * reclaim any allocated resources to `publishers_info` to avoid leaking memory. @@ -601,7 +601,7 @@ rcl_get_publishers_info_by_topic( * The `allocator` will be used to allocate memory to the `info_array` member * inside of `subscriptions_info`. * Moreover, every const char * member inside of - * rmw_topic_info_t will be allocated memory and assigned a copied value. + * rmw_topic_info_t will be assigned a copied value on allocated memory. * @see rmw_topic_info_set_node_name and the likes. * However, it is the responsibility of the caller to * reclaim any allocated resources to `subscriptions_info` to avoid leaking memory. diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp index e40824c34..5b5a53097 100644 --- a/rcl/test/rcl/test_info_by_topic.cpp +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -43,14 +43,15 @@ class CLASSNAME (TestInfoByTopicFixture, RMW_IMPLEMENTATION) : public ::testing::Test { public: - rcl_context_t * old_context_ptr; - rcl_context_t * context_ptr; - rcl_node_t * old_node_ptr; - rcl_node_t * node_ptr; + rcl_context_t old_context; + rcl_context_t context; + rcl_node_t old_node; + rcl_node_t node; const char * test_graph_node_name = "test_graph_node"; - std::unique_ptr topic_info_array; + rmw_topic_info_array_t topic_info_array; const char * const topic_name = "valid_topic_name"; bool is_fastrtps; + void SetUp() { is_fastrtps = (std::string(rmw_get_implementation_identifier()).find("rmw_fastrtps") == 0); @@ -61,52 +62,44 @@ class CLASSNAME (TestInfoByTopicFixture, RMW_IMPLEMENTATION) : public ::testing: OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str; }); - this->old_context_ptr = new rcl_context_t; - *this->old_context_ptr = rcl_get_zero_initialized_context(); - ret = rcl_init(0, nullptr, &init_options, this->old_context_ptr); + this->old_context = rcl_get_zero_initialized_context(); + ret = rcl_init(0, nullptr, &init_options, &this->old_context); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - this->old_node_ptr = new rcl_node_t; - *this->old_node_ptr = rcl_get_zero_initialized_node(); + this->old_node = rcl_get_zero_initialized_node(); const char * old_name = "old_node_name"; rcl_node_options_t node_options = rcl_node_get_default_options(); - ret = rcl_node_init(this->old_node_ptr, old_name, "", this->old_context_ptr, &node_options); + ret = rcl_node_init(&this->old_node, old_name, "", &this->old_context, &node_options); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - ret = rcl_shutdown(this->old_context_ptr); // after this, the old_node_ptr should be invalid + ret = rcl_shutdown(&this->old_context); // after this, the old_node should be invalid EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - this->context_ptr = new rcl_context_t; - *this->context_ptr = rcl_get_zero_initialized_context(); + this->context = rcl_get_zero_initialized_context(); - ret = rcl_init(0, nullptr, &init_options, this->context_ptr); + ret = rcl_init(0, nullptr, &init_options, &this->context); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - this->node_ptr = new rcl_node_t; - *this->node_ptr = rcl_get_zero_initialized_node(); + this->node = rcl_get_zero_initialized_node(); const char * name = "test_graph_node"; - ret = rcl_node_init(this->node_ptr, name, "", this->context_ptr, &node_options); + ret = rcl_node_init(&this->node, name, "", &this->context, &node_options); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - - this->topic_info_array = std::make_unique(); } void TearDown() { rcl_ret_t ret; - ret = rcl_node_fini(this->old_node_ptr); - delete this->old_node_ptr; + ret = rcl_node_fini(&this->old_node); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - ret = rcl_node_fini(this->node_ptr); - delete this->node_ptr; + ret = rcl_node_fini(&this->node); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - ret = rcl_shutdown(this->context_ptr); + ret = rcl_shutdown(&this->context); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - ret = rcl_context_fini(this->context_ptr); + ret = rcl_context_fini(&this->context); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - delete this->context_ptr; - ret = rcl_context_fini(this->old_context_ptr); + + ret = rcl_shutdown(&this->old_context); + ret = rcl_context_fini(&this->old_context); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - delete this->old_context_ptr; } void assert_qos_equality(rmw_qos_profile_t qos_profile1, rmw_qos_profile_t qos_profile2) @@ -134,7 +127,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_publishers_info_by_topic(nullptr, - &allocator, this->topic_name, false, this->topic_info_array.get()); + &allocator, this->topic_name, false, &this->topic_info_array); EXPECT_EQ(RCL_RET_NODE_INVALID, ret); } @@ -147,7 +140,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_subscriptions_info_by_topic(nullptr, - &allocator, this->topic_name, false, this->topic_info_array.get()); + &allocator, this->topic_name, false, &this->topic_info_array); EXPECT_EQ(RCL_RET_NODE_INVALID, ret); } @@ -158,10 +151,10 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_publishers_info_by_topic_invalid_node) { - // this->old_node_ptr is a pointer to an invalid node. + // this->old_node is an invalid node. rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(this->old_node_ptr, - &allocator, this->topic_name, false, this->topic_info_array.get()); + const auto ret = rcl_get_publishers_info_by_topic(&this->old_node, + &allocator, this->topic_name, false, &this->topic_info_array); EXPECT_EQ(RCL_RET_NODE_INVALID, ret); } @@ -172,10 +165,10 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_subscriptions_info_by_topic_invalid_node) { - // this->old_node_ptr is a pointer to an invalid node. + // this->old_node is an invalid node. rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(this->old_node_ptr, - &allocator, this->topic_name, false, this->topic_info_array.get()); + const auto ret = rcl_get_subscriptions_info_by_topic(&this->old_node, + &allocator, this->topic_name, false, &this->topic_info_array); EXPECT_EQ(RCL_RET_NODE_INVALID, ret); } @@ -186,9 +179,9 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_publishers_info_by_topic_null_allocator) { - const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, nullptr, this->topic_name, + const auto ret = rcl_get_publishers_info_by_topic(&this->node, nullptr, this->topic_name, false, - this->topic_info_array.get()); + &this->topic_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -199,9 +192,9 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_subscriptions_info_by_topic_null_allocator) { - const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, nullptr, this->topic_name, + const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, nullptr, this->topic_name, false, - this->topic_info_array.get()); + &this->topic_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -213,8 +206,8 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_publishers_info_by_topic_null_topic) { rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, - &allocator, nullptr, false, this->topic_info_array.get()); + const auto ret = rcl_get_publishers_info_by_topic(&this->node, + &allocator, nullptr, false, &this->topic_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -226,8 +219,8 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_subscriptions_info_by_topic_null_topic) { rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, - &allocator, nullptr, false, this->topic_info_array.get()); + const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, + &allocator, nullptr, false, &this->topic_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -239,7 +232,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_publishers_info_by_topic_null_participants) { rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, + const auto ret = rcl_get_publishers_info_by_topic(&this->node, &allocator, this->topic_name, false, nullptr); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -252,7 +245,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_subscriptions_info_by_topic_null_participants) { rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, &allocator, this->topic_name, false, nullptr); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -266,14 +259,14 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { // temp_info_array is invalid because it is expected to be zero initialized // and the info_array variable inside it is expected to be null. - const auto & temp_info_array = this->topic_info_array.get(); + const auto & temp_info_array = &this->topic_info_array; temp_info_array->info_array = - reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); + static_cast(calloc(1, sizeof(rmw_topic_info_t))); OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ free(temp_info_array->info_array); }); rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_publishers_info_by_topic(this->node_ptr, + const auto ret = rcl_get_publishers_info_by_topic(&this->node, &allocator, this->topic_name, false, temp_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -287,14 +280,14 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { // temp_info_array is invalid because it is expected to be zero initialized // and the info_array variable inside it is expected to be null. - const auto & temp_info_array = this->topic_info_array.get(); + const auto & temp_info_array = &this->topic_info_array; temp_info_array->info_array = - reinterpret_cast(calloc(1, sizeof(rmw_topic_info_t))); + static_cast(calloc(1, sizeof(rmw_topic_info_t))); OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ free(temp_info_array->info_array); }); rcl_allocator_t allocator = rcl_get_default_allocator(); - const auto ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, &allocator, this->topic_name, false, temp_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -325,7 +318,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), publisher_options.qos = default_qos_profile; ret = rcl_publisher_init( &publisher, - this->node_ptr, + &this->node, ts, this->topic_name, &publisher_options); @@ -336,16 +329,15 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), subscription_options.qos = default_qos_profile; ret = rcl_subscription_init( &subscription, - this->node_ptr, + &this->node, ts, this->topic_name, &subscription_options); ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; - std::string fqdn = this->topic_name; - fqdn = "/" + fqdn; + const std::string fqdn = std::string("/") + this->topic_name; // Get publishers info by topic rmw_topic_info_array_t topic_info_array_pub = rmw_get_zero_initialized_topic_info_array(); - ret = rcl_get_publishers_info_by_topic(this->node_ptr, + ret = rcl_get_publishers_info_by_topic(&this->node, &allocator, fqdn.c_str(), false, &topic_info_array_pub); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; EXPECT_EQ(topic_info_array_pub.count, 1u) << "Expected one publisher"; @@ -356,7 +348,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), assert_qos_equality(topic_info_pub.qos_profile, default_qos_profile); rmw_topic_info_array_t topic_info_array_sub = rmw_get_zero_initialized_topic_info_array(); - ret = rcl_get_subscriptions_info_by_topic(this->node_ptr, + ret = rcl_get_subscriptions_info_by_topic(&this->node, &allocator, fqdn.c_str(), false, &topic_info_array_sub); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; EXPECT_EQ(topic_info_array_sub.count, 1u) << "Expected one subscription"; @@ -371,8 +363,8 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), EXPECT_EQ(rmw_ret, RMW_RET_OK) << rmw_get_error_string().str; rmw_ret = rmw_topic_info_array_fini(&topic_info_array_sub, &allocator); EXPECT_EQ(rmw_ret, RMW_RET_OK) << rmw_get_error_string().str; - ret = rcl_subscription_fini(&subscription, this->node_ptr); + ret = rcl_subscription_fini(&subscription, &this->node); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; - ret = rcl_publisher_fini(&publisher, this->node_ptr); + ret = rcl_publisher_fini(&publisher, &this->node); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; } From fcd26b617200e59445d93b9393b36b14c97c63be Mon Sep 17 00:00:00 2001 From: Miaofei Date: Fri, 13 Dec 2019 18:40:04 -0800 Subject: [PATCH 12/17] fix unit test failures Signed-off-by: Miaofei --- rcl/test/rcl/test_info_by_topic.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp index 5b5a53097..aae86759d 100644 --- a/rcl/test/rcl/test_info_by_topic.cpp +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -268,7 +268,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_publishers_info_by_topic(&this->node, &allocator, this->topic_name, false, temp_info_array); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); + EXPECT_EQ(RCL_RET_ERROR, ret); } /* @@ -289,7 +289,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, &allocator, this->topic_name, false, temp_info_array); - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); + EXPECT_EQ(RCL_RET_ERROR, ret); } TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), From 713b1ec71096d27e71ec5dbf874378ce331d2456 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Wed, 18 Dec 2019 12:16:08 -0800 Subject: [PATCH 13/17] address PR comments Signed-off-by: Miaofei --- rcl/include/rcl/graph.h | 22 +++++++++++---------- rcl/test/rcl/test_info_by_topic.cpp | 30 ++++++++++++++--------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/rcl/include/rcl/graph.h b/rcl/include/rcl/graph.h index 663848e91..383e8cf4f 100644 --- a/rcl/include/rcl/graph.h +++ b/rcl/include/rcl/graph.h @@ -421,8 +421,8 @@ rcl_names_and_types_fini(rcl_names_and_types_t * names_and_types); * * \param[in] node the handle to the node being used to query the ROS graph * \param[in] allocator used to control allocation and deallocation of names - * \param[out] node_names struct storing discovered node names. - * \param[out] node_namesspaces struct storing discovered node namespaces. + * \param[out] node_names struct storing discovered node names + * \param[out] node_namesspaces struct storing discovered node namespaces * \return `RCL_RET_OK` if the query was successful, or * \return `RCL_RET_ERROR` if an unspecified error occurs. */ @@ -537,8 +537,9 @@ rcl_count_subscribers( * expanded to its fully qualified name. * * It is the responsibility of the caller to ensure that `publishers_info` parameter points - * to a valid struct of type rmw_topic_info_array_t. The `count` field inside the struct - * must be set to 0 and the `info_array` field inside the struct must be set to null. + * to a valid struct of type rmw_topic_info_array_t. + * The `count` field inside the struct must be set to 0 and the `info_array` field inside + * the struct must be set to null. * @see rmw_get_zero_initialized_topic_info_array * * The `allocator` will be used to allocate memory to the `info_array` member @@ -563,8 +564,8 @@ rcl_count_subscribers( * \param[in] allocator allocator to be used when allocating space for * the array inside publishers_info * \param[in] topic_name the name of the topic in question - * \param[in] no_mangle if true, the topic_name will be expanded to its fully qualified name. - * \param[out] publishers_info a struct representing a list of publisher information. + * \param[in] no_mangle if true, the topic_name will be expanded to its fully qualified name + * \param[out] publishers_info a struct representing a list of publisher information * \return `RCL_RET_OK` if the query was successful, or * \return `RCL_RET_NODE_INVALID` if the node is invalid, or * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or @@ -594,8 +595,9 @@ rcl_get_publishers_info_by_topic( * expanded to its fully qualified name. * * It is the responsibility of the caller to ensure that `subscriptions_info` parameter points - * to a valid struct of type rmw_topic_info_array_t. The `count` field inside the struct - * must be set to 0 and the `info_array` field inside the struct must be set to null. + * to a valid struct of type rmw_topic_info_array_t. + * The `count` field inside the struct must be set to 0 and the `info_array` field inside + * the struct must be set to null. * @see rmw_get_zero_initialized_topic_info_array * * The `allocator` will be used to allocate memory to the `info_array` member @@ -620,8 +622,8 @@ rcl_get_publishers_info_by_topic( * \param[in] allocator allocator to be used when allocating space for * the array inside publishers_info * \param[in] topic_name the name of the topic in question - * \param[in] no_mangle if true, the topic_name will be expanded to its fully qualified name. - * \param[out] subscriptions_info a struct representing a list of subscriptions information. + * \param[in] no_mangle if true, the topic_name will be expanded to its fully qualified name + * \param[out] subscriptions_info a struct representing a list of subscriptions information * \return `RCL_RET_OK` if the query was successful, or * \return `RCL_RET_NODE_INVALID` if the node is invalid, or * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp index aae86759d..420759f82 100644 --- a/rcl/test/rcl/test_info_by_topic.cpp +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -97,7 +97,11 @@ class CLASSNAME (TestInfoByTopicFixture, RMW_IMPLEMENTATION) : public ::testing: ret = rcl_context_fini(&this->context); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; - ret = rcl_shutdown(&this->old_context); + // old_context was supposed to have been shutdown already during SetUp() + if (rcl_context_is_valid(&this->old_context)) { + ret = rcl_shutdown(&this->old_context); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; + } ret = rcl_context_fini(&this->old_context); EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; } @@ -257,17 +261,15 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_publishers_info_by_topic_invalid_participants) { - // temp_info_array is invalid because it is expected to be zero initialized + // topic_info_array is invalid because it is expected to be zero initialized // and the info_array variable inside it is expected to be null. - const auto & temp_info_array = &this->topic_info_array; - temp_info_array->info_array = - static_cast(calloc(1, sizeof(rmw_topic_info_t))); + this->topic_info_array.info_array = new rmw_topic_info_t(); OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ - free(temp_info_array->info_array); + free(this->topic_info_array.info_array); }); rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_publishers_info_by_topic(&this->node, - &allocator, this->topic_name, false, temp_info_array); + &allocator, this->topic_name, false, &this->topic_info_array); EXPECT_EQ(RCL_RET_ERROR, ret); } @@ -278,17 +280,15 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_subscriptions_info_by_topic_invalid_participants) { - // temp_info_array is invalid because it is expected to be zero initialized + // topic_info_array is invalid because it is expected to be zero initialized // and the info_array variable inside it is expected to be null. - const auto & temp_info_array = &this->topic_info_array; - temp_info_array->info_array = - static_cast(calloc(1, sizeof(rmw_topic_info_t))); + this->topic_info_array.info_array = new rmw_topic_info_t(); OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ - free(temp_info_array->info_array); + free(this->topic_info_array.info_array); }); rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, - &allocator, this->topic_name, false, temp_info_array); + &allocator, this->topic_name, false, &this->topic_info_array); EXPECT_EQ(RCL_RET_ERROR, ret); } @@ -344,7 +344,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), rmw_topic_info_t topic_info_pub = topic_info_array_pub.info_array[0]; EXPECT_STREQ(topic_info_pub.node_name, this->test_graph_node_name); EXPECT_STREQ(topic_info_pub.node_namespace, "/"); - EXPECT_STREQ(topic_info_pub.topic_type, "test_msgs::msg::dds_::Strings_"); + EXPECT_STREQ(topic_info_pub.topic_type, "test_msgs/msg/Strings"); assert_qos_equality(topic_info_pub.qos_profile, default_qos_profile); rmw_topic_info_array_t topic_info_array_sub = rmw_get_zero_initialized_topic_info_array(); @@ -355,7 +355,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), rmw_topic_info_t topic_info_sub = topic_info_array_sub.info_array[0]; EXPECT_STREQ(topic_info_sub.node_name, this->test_graph_node_name); EXPECT_STREQ(topic_info_sub.node_namespace, "/"); - EXPECT_STREQ(topic_info_sub.topic_type, "test_msgs::msg::dds_::Strings_"); + EXPECT_STREQ(topic_info_sub.topic_type, "test_msgs/msg/Strings"); assert_qos_equality(topic_info_sub.qos_profile, default_qos_profile); // clean up From a90c33a49c29960ab9c9c2acae7af680bb52747a Mon Sep 17 00:00:00 2001 From: Miaofei Date: Thu, 9 Jan 2020 16:05:34 -0800 Subject: [PATCH 14/17] address more PR comments Signed-off-by: Miaofei --- rcl/include/rcl/graph.h | 30 ++++++++++++++---------------- rcl/src/rcl/graph.c | 19 ++++++++++++++----- rcl/test/rcl/test_graph.cpp | 4 ++-- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/rcl/include/rcl/graph.h b/rcl/include/rcl/graph.h index 383e8cf4f..8fbb6af8f 100644 --- a/rcl/include/rcl/graph.h +++ b/rcl/include/rcl/graph.h @@ -525,9 +525,7 @@ rcl_count_subscribers( const char * topic_name, size_t * count); -/// Returns a list of all publishers to a topic. -/// Each element in the list will contain the node name, node namespace, topic type, -/// gid and the qos profile of the publisher. +/// Return a list of all publishers to a topic. /** * The `node` parameter must point to a valid node. * @@ -536,20 +534,22 @@ rcl_count_subscribers( * The `no_mangle` parameter determines if the provided topic_name should be * expanded to its fully qualified name. * + * Each element in the `publishers_info` array will contain the node name, node namespace, + * topic type, gid and the qos profile of the publisher. * It is the responsibility of the caller to ensure that `publishers_info` parameter points * to a valid struct of type rmw_topic_info_array_t. * The `count` field inside the struct must be set to 0 and the `info_array` field inside * the struct must be set to null. - * @see rmw_get_zero_initialized_topic_info_array + * \see rmw_get_zero_initialized_topic_info_array * * The `allocator` will be used to allocate memory to the `info_array` member * inside of `publishers_info`. * Moreover, every const char * member inside of * rmw_topic_info_t will be assigned a copied value on allocated memory. - * @see rmw_topic_info_set_node_name and the likes. + * \see rmw_topic_info_set_node_name and the likes. * However, it is the responsibility of the caller to * reclaim any allocated resources to `publishers_info` to avoid leaking memory. - * @see rmw_topic_info_array_fini + * \see rmw_topic_info_array_fini * *
* Attribute | Adherence @@ -582,32 +582,31 @@ rcl_get_publishers_info_by_topic( bool no_mangle, rmw_topic_info_array_t * publishers_info); - -/// Returns a list of all subscriptions to a topic. -/// Each element in the list will contain the node name, node namespace, topic type, -/// gid and the qos profile of the subscription. +/// Return a list of all subscriptions to a topic. /** * The `node` parameter must point to a valid node. * * The `topic_name` parameter must not be `NULL`. * - * The `no_mangle` parameter determines if the provided topic_name should be - * expanded to its fully qualified name. + * The `no_mangle` parameter determines whether or not the provided topic_name should be + * converted to its underlying middleware name. * + * Each element in the `subscriptions_info` array will contain the node name, node namespace, + * topic type, gid and the qos profile of the subscription. * It is the responsibility of the caller to ensure that `subscriptions_info` parameter points * to a valid struct of type rmw_topic_info_array_t. * The `count` field inside the struct must be set to 0 and the `info_array` field inside * the struct must be set to null. - * @see rmw_get_zero_initialized_topic_info_array + * \see rmw_get_zero_initialized_topic_info_array * * The `allocator` will be used to allocate memory to the `info_array` member * inside of `subscriptions_info`. * Moreover, every const char * member inside of * rmw_topic_info_t will be assigned a copied value on allocated memory. - * @see rmw_topic_info_set_node_name and the likes. + * \see rmw_topic_info_set_node_name and the likes. * However, it is the responsibility of the caller to * reclaim any allocated resources to `subscriptions_info` to avoid leaking memory. - * @see rmw_topic_info_array_fini + * \see rmw_topic_info_array_fini * *
* Attribute | Adherence @@ -640,7 +639,6 @@ rcl_get_subscriptions_info_by_topic( bool no_mangle, rmw_topic_info_array_t * subscriptions_info); - /// Check if a service server is available for the given service client. /** * This function will return true for `is_available` if there is a service server diff --git a/rcl/src/rcl/graph.c b/rcl/src/rcl/graph.c index f94b4c3e3..ba8dba582 100644 --- a/rcl/src/rcl/graph.c +++ b/rcl/src/rcl/graph.c @@ -377,7 +377,6 @@ rcl_count_subscribers( return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } - typedef rmw_ret_t (* get_topic_info_func_t)( const rmw_node_t * node, rcutils_allocator_t * allocator, @@ -436,8 +435,13 @@ rcl_get_publishers_info_by_topic( bool no_mangle, rmw_topic_info_array_t * publishers_info) { - return __rcl_get_info_by_topic(node, allocator, topic_name, no_mangle, publishers_info, - rmw_get_publishers_info_by_topic); + return __rcl_get_info_by_topic( + node, + allocator, + topic_name, + no_mangle, + publishers_info, + rmw_get_publishers_info_by_topic); } rcl_ret_t @@ -448,8 +452,13 @@ rcl_get_subscriptions_info_by_topic( bool no_mangle, rmw_topic_info_array_t * subscriptions_info) { - return __rcl_get_info_by_topic(node, allocator, topic_name, no_mangle, subscriptions_info, - rmw_get_subscriptions_info_by_topic); + return __rcl_get_info_by_topic( + node, + allocator, + topic_name, + no_mangle, + subscriptions_info, + rmw_get_subscriptions_info_by_topic); } rcl_ret_t diff --git a/rcl/test/rcl/test_graph.cpp b/rcl/test/rcl/test_graph.cpp index 28f7cdae7..68d3403a1 100644 --- a/rcl/test/rcl/test_graph.cpp +++ b/rcl/test/rcl/test_graph.cpp @@ -916,8 +916,8 @@ class NodeGraphMultiNodeFixture : public CLASSNAME(TestGraphFixture, RMW_IMPLEME /** * Verify the number of subsystems each node should have. * - * @param node_state expected state of node - * @param remote_node_state expected state of remote node + * \param node_state expected state of node + * \param remote_node_state expected state of remote node */ void VerifySubsystemCount( const expected_node_state && node_state, From 01ab30423d3a4869e78385ab528c623bf8d5c109 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Thu, 9 Jan 2020 23:44:01 -0800 Subject: [PATCH 15/17] rename *topic_info* to *topic_endpoint_info* Signed-off-by: Miaofei --- rcl/include/rcl/graph.h | 26 +++++----- rcl/src/rcl/graph.c | 24 +++++----- rcl/test/rcl/test_info_by_topic.cpp | 74 ++++++++++++++--------------- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/rcl/include/rcl/graph.h b/rcl/include/rcl/graph.h index 8fbb6af8f..9bb37d67e 100644 --- a/rcl/include/rcl/graph.h +++ b/rcl/include/rcl/graph.h @@ -22,7 +22,7 @@ extern "C" #include #include -#include +#include #include "rcutils/types.h" @@ -537,19 +537,19 @@ rcl_count_subscribers( * Each element in the `publishers_info` array will contain the node name, node namespace, * topic type, gid and the qos profile of the publisher. * It is the responsibility of the caller to ensure that `publishers_info` parameter points - * to a valid struct of type rmw_topic_info_array_t. + * to a valid struct of type rmw_topic_endpoint_info_array_t. * The `count` field inside the struct must be set to 0 and the `info_array` field inside * the struct must be set to null. - * \see rmw_get_zero_initialized_topic_info_array + * \see rmw_get_zero_initialized_topic_endpoint_info_array * * The `allocator` will be used to allocate memory to the `info_array` member * inside of `publishers_info`. * Moreover, every const char * member inside of - * rmw_topic_info_t will be assigned a copied value on allocated memory. - * \see rmw_topic_info_set_node_name and the likes. + * rmw_topic_endpoint_info_t will be assigned a copied value on allocated memory. + * \see rmw_topic_endpoint_info_set_node_name and the likes. * However, it is the responsibility of the caller to * reclaim any allocated resources to `publishers_info` to avoid leaking memory. - * \see rmw_topic_info_array_fini + * \see rmw_topic_endpoint_info_array_fini * *
* Attribute | Adherence @@ -580,7 +580,7 @@ rcl_get_publishers_info_by_topic( rcutils_allocator_t * allocator, const char * topic_name, bool no_mangle, - rmw_topic_info_array_t * publishers_info); + rmw_topic_endpoint_info_array_t * publishers_info); /// Return a list of all subscriptions to a topic. /** @@ -594,19 +594,19 @@ rcl_get_publishers_info_by_topic( * Each element in the `subscriptions_info` array will contain the node name, node namespace, * topic type, gid and the qos profile of the subscription. * It is the responsibility of the caller to ensure that `subscriptions_info` parameter points - * to a valid struct of type rmw_topic_info_array_t. + * to a valid struct of type rmw_topic_endpoint_info_array_t. * The `count` field inside the struct must be set to 0 and the `info_array` field inside * the struct must be set to null. - * \see rmw_get_zero_initialized_topic_info_array + * \see rmw_get_zero_initialized_topic_endpoint_info_array * * The `allocator` will be used to allocate memory to the `info_array` member * inside of `subscriptions_info`. * Moreover, every const char * member inside of - * rmw_topic_info_t will be assigned a copied value on allocated memory. - * \see rmw_topic_info_set_node_name and the likes. + * rmw_topic_endpoint_info_t will be assigned a copied value on allocated memory. + * \see rmw_topic_endpoint_info_set_node_name and the likes. * However, it is the responsibility of the caller to * reclaim any allocated resources to `subscriptions_info` to avoid leaking memory. - * \see rmw_topic_info_array_fini + * \see rmw_topic_endpoint_info_array_fini * *
* Attribute | Adherence @@ -637,7 +637,7 @@ rcl_get_subscriptions_info_by_topic( rcutils_allocator_t * allocator, const char * topic_name, bool no_mangle, - rmw_topic_info_array_t * subscriptions_info); + rmw_topic_endpoint_info_array_t * subscriptions_info); /// Check if a service server is available for the given service client. /** diff --git a/rcl/src/rcl/graph.c b/rcl/src/rcl/graph.c index ba8dba582..43ab9dcc2 100644 --- a/rcl/src/rcl/graph.c +++ b/rcl/src/rcl/graph.c @@ -25,11 +25,11 @@ extern "C" #include "rmw/error_handling.h" #include "rmw/get_node_info_and_types.h" #include "rmw/get_service_names_and_types.h" -#include "rmw/get_topic_info.h" +#include "rmw/get_topic_endpoint_info.h" #include "rmw/get_topic_names_and_types.h" #include "rmw/names_and_types.h" #include "rmw/rmw.h" -#include "rmw/topic_info_array.h" +#include "rmw/topic_endpoint_info_array.h" #include "rmw/validate_namespace.h" #include "rmw/validate_node_name.h" @@ -377,12 +377,12 @@ rcl_count_subscribers( return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } -typedef rmw_ret_t (* get_topic_info_func_t)( +typedef rmw_ret_t (* get_topic_endpoint_info_func_t)( const rmw_node_t * node, rcutils_allocator_t * allocator, const char * topic_name, bool no_mangle, - rmw_topic_info_array_t * info_array); + rmw_topic_endpoint_info_array_t * info_array); rcl_ret_t __rcl_get_info_by_topic( @@ -390,8 +390,8 @@ __rcl_get_info_by_topic( rcutils_allocator_t * allocator, const char * topic_name, bool no_mangle, - rmw_topic_info_array_t * info_array, - get_topic_info_func_t get_topic_info) + rmw_topic_endpoint_info_array_t * info_array, + get_topic_endpoint_info_func_t get_topic_endpoint_info) { if (!rcl_node_is_valid(node)) { return RCL_RET_NODE_INVALID; // error already set. @@ -403,17 +403,17 @@ __rcl_get_info_by_topic( RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(topic_name, RCL_RET_INVALID_ARGUMENT); rmw_error_string_t error_string; - rmw_ret_t rmw_ret = rmw_topic_info_array_check_zero(info_array); + rmw_ret_t rmw_ret = rmw_topic_endpoint_info_array_check_zero(info_array); if (rmw_ret != RMW_RET_OK) { error_string = rmw_get_error_string(); rmw_reset_error(); RCL_SET_ERROR_MSG_WITH_FORMAT_STRING( - "rmw_topic_info_array_t must be zero initialized: %s,\n" - "Use rmw_get_zero_initialized_topic_info_array", + "rmw_topic_endpoint_info_array_t must be zero initialized: %s,\n" + "Use rmw_get_zero_initialized_topic_endpoint_info_array", error_string.str); return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } - rmw_ret = get_topic_info( + rmw_ret = get_topic_endpoint_info( rcl_node_get_rmw_handle(node), allocator, topic_name, @@ -433,7 +433,7 @@ rcl_get_publishers_info_by_topic( rcutils_allocator_t * allocator, const char * topic_name, bool no_mangle, - rmw_topic_info_array_t * publishers_info) + rmw_topic_endpoint_info_array_t * publishers_info) { return __rcl_get_info_by_topic( node, @@ -450,7 +450,7 @@ rcl_get_subscriptions_info_by_topic( rcutils_allocator_t * allocator, const char * topic_name, bool no_mangle, - rmw_topic_info_array_t * subscriptions_info) + rmw_topic_endpoint_info_array_t * subscriptions_info) { return __rcl_get_info_by_topic( node, diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp index 420759f82..8bb845601 100644 --- a/rcl/test/rcl/test_info_by_topic.cpp +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -25,7 +25,7 @@ #include "rcl/graph.h" #include "rcl/rcl.h" -#include "rmw/topic_info_array.h" +#include "rmw/topic_endpoint_info_array.h" #include "rmw/error_handling.h" #include "test_msgs/msg/strings.h" @@ -48,7 +48,7 @@ class CLASSNAME (TestInfoByTopicFixture, RMW_IMPLEMENTATION) : public ::testing: rcl_node_t old_node; rcl_node_t node; const char * test_graph_node_name = "test_graph_node"; - rmw_topic_info_array_t topic_info_array; + rmw_topic_endpoint_info_array_t topic_endpoint_info_array; const char * const topic_name = "valid_topic_name"; bool is_fastrtps; @@ -131,7 +131,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_publishers_info_by_topic(nullptr, - &allocator, this->topic_name, false, &this->topic_info_array); + &allocator, this->topic_name, false, &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_NODE_INVALID, ret); } @@ -144,7 +144,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_subscriptions_info_by_topic(nullptr, - &allocator, this->topic_name, false, &this->topic_info_array); + &allocator, this->topic_name, false, &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_NODE_INVALID, ret); } @@ -158,7 +158,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), // this->old_node is an invalid node. rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_publishers_info_by_topic(&this->old_node, - &allocator, this->topic_name, false, &this->topic_info_array); + &allocator, this->topic_name, false, &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_NODE_INVALID, ret); } @@ -172,7 +172,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), // this->old_node is an invalid node. rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_subscriptions_info_by_topic(&this->old_node, - &allocator, this->topic_name, false, &this->topic_info_array); + &allocator, this->topic_name, false, &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_NODE_INVALID, ret); } @@ -185,7 +185,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { const auto ret = rcl_get_publishers_info_by_topic(&this->node, nullptr, this->topic_name, false, - &this->topic_info_array); + &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -198,7 +198,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, nullptr, this->topic_name, false, - &this->topic_info_array); + &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -211,7 +211,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_publishers_info_by_topic(&this->node, - &allocator, nullptr, false, &this->topic_info_array); + &allocator, nullptr, false, &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -224,7 +224,7 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), { rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, - &allocator, nullptr, false, &this->topic_info_array); + &allocator, nullptr, false, &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret); } @@ -261,15 +261,15 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_publishers_info_by_topic_invalid_participants) { - // topic_info_array is invalid because it is expected to be zero initialized + // topic_endpoint_info_array is invalid because it is expected to be zero initialized // and the info_array variable inside it is expected to be null. - this->topic_info_array.info_array = new rmw_topic_info_t(); + this->topic_endpoint_info_array.info_array = new rmw_topic_endpoint_info_t(); OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ - free(this->topic_info_array.info_array); + free(this->topic_endpoint_info_array.info_array); }); rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_publishers_info_by_topic(&this->node, - &allocator, this->topic_name, false, &this->topic_info_array); + &allocator, this->topic_name, false, &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_ERROR, ret); } @@ -280,15 +280,15 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), test_rcl_get_subscriptions_info_by_topic_invalid_participants) { - // topic_info_array is invalid because it is expected to be zero initialized + // topic_endpoint_info_array is invalid because it is expected to be zero initialized // and the info_array variable inside it is expected to be null. - this->topic_info_array.info_array = new rmw_topic_info_t(); + this->topic_endpoint_info_array.info_array = new rmw_topic_endpoint_info_t(); OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ - free(this->topic_info_array.info_array); + free(this->topic_endpoint_info_array.info_array); }); rcl_allocator_t allocator = rcl_get_default_allocator(); const auto ret = rcl_get_subscriptions_info_by_topic(&this->node, - &allocator, this->topic_name, false, &this->topic_info_array); + &allocator, this->topic_name, false, &this->topic_endpoint_info_array); EXPECT_EQ(RCL_RET_ERROR, ret); } @@ -336,32 +336,32 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; const std::string fqdn = std::string("/") + this->topic_name; // Get publishers info by topic - rmw_topic_info_array_t topic_info_array_pub = rmw_get_zero_initialized_topic_info_array(); + rmw_topic_endpoint_info_array_t topic_endpoint_info_array_pub = rmw_get_zero_initialized_topic_endpoint_info_array(); ret = rcl_get_publishers_info_by_topic(&this->node, - &allocator, fqdn.c_str(), false, &topic_info_array_pub); + &allocator, fqdn.c_str(), false, &topic_endpoint_info_array_pub); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; - EXPECT_EQ(topic_info_array_pub.count, 1u) << "Expected one publisher"; - rmw_topic_info_t topic_info_pub = topic_info_array_pub.info_array[0]; - EXPECT_STREQ(topic_info_pub.node_name, this->test_graph_node_name); - EXPECT_STREQ(topic_info_pub.node_namespace, "/"); - EXPECT_STREQ(topic_info_pub.topic_type, "test_msgs/msg/Strings"); - assert_qos_equality(topic_info_pub.qos_profile, default_qos_profile); - - rmw_topic_info_array_t topic_info_array_sub = rmw_get_zero_initialized_topic_info_array(); + EXPECT_EQ(topic_endpoint_info_array_pub.count, 1u) << "Expected one publisher"; + rmw_topic_endpoint_info_t topic_endpoint_info_pub = topic_endpoint_info_array_pub.info_array[0]; + EXPECT_STREQ(topic_endpoint_info_pub.node_name, this->test_graph_node_name); + EXPECT_STREQ(topic_endpoint_info_pub.node_namespace, "/"); + EXPECT_STREQ(topic_endpoint_info_pub.topic_type, "test_msgs/msg/Strings"); + assert_qos_equality(topic_endpoint_info_pub.qos_profile, default_qos_profile); + + rmw_topic_endpoint_info_array_t topic_endpoint_info_array_sub = rmw_get_zero_initialized_topic_endpoint_info_array(); ret = rcl_get_subscriptions_info_by_topic(&this->node, - &allocator, fqdn.c_str(), false, &topic_info_array_sub); + &allocator, fqdn.c_str(), false, &topic_endpoint_info_array_sub); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; - EXPECT_EQ(topic_info_array_sub.count, 1u) << "Expected one subscription"; - rmw_topic_info_t topic_info_sub = topic_info_array_sub.info_array[0]; - EXPECT_STREQ(topic_info_sub.node_name, this->test_graph_node_name); - EXPECT_STREQ(topic_info_sub.node_namespace, "/"); - EXPECT_STREQ(topic_info_sub.topic_type, "test_msgs/msg/Strings"); - assert_qos_equality(topic_info_sub.qos_profile, default_qos_profile); + EXPECT_EQ(topic_endpoint_info_array_sub.count, 1u) << "Expected one subscription"; + rmw_topic_endpoint_info_t topic_endpoint_info_sub = topic_endpoint_info_array_sub.info_array[0]; + EXPECT_STREQ(topic_endpoint_info_sub.node_name, this->test_graph_node_name); + EXPECT_STREQ(topic_endpoint_info_sub.node_namespace, "/"); + EXPECT_STREQ(topic_endpoint_info_sub.topic_type, "test_msgs/msg/Strings"); + assert_qos_equality(topic_endpoint_info_sub.qos_profile, default_qos_profile); // clean up - rmw_ret_t rmw_ret = rmw_topic_info_array_fini(&topic_info_array_pub, &allocator); + rmw_ret_t rmw_ret = rmw_topic_endpoint_info_array_fini(&topic_endpoint_info_array_pub, &allocator); EXPECT_EQ(rmw_ret, RMW_RET_OK) << rmw_get_error_string().str; - rmw_ret = rmw_topic_info_array_fini(&topic_info_array_sub, &allocator); + rmw_ret = rmw_topic_endpoint_info_array_fini(&topic_endpoint_info_array_sub, &allocator); EXPECT_EQ(rmw_ret, RMW_RET_OK) << rmw_get_error_string().str; ret = rcl_subscription_fini(&subscription, &this->node); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; From 200b78bf8b67f9627c521fc583995f3791c22ea2 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Thu, 9 Jan 2020 23:57:21 -0800 Subject: [PATCH 16/17] fix formatting Signed-off-by: Miaofei --- rcl/test/rcl/test_info_by_topic.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rcl/test/rcl/test_info_by_topic.cpp b/rcl/test/rcl/test_info_by_topic.cpp index 8bb845601..69f0118c8 100644 --- a/rcl/test/rcl/test_info_by_topic.cpp +++ b/rcl/test/rcl/test_info_by_topic.cpp @@ -336,7 +336,8 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; const std::string fqdn = std::string("/") + this->topic_name; // Get publishers info by topic - rmw_topic_endpoint_info_array_t topic_endpoint_info_array_pub = rmw_get_zero_initialized_topic_endpoint_info_array(); + rmw_topic_endpoint_info_array_t topic_endpoint_info_array_pub = + rmw_get_zero_initialized_topic_endpoint_info_array(); ret = rcl_get_publishers_info_by_topic(&this->node, &allocator, fqdn.c_str(), false, &topic_endpoint_info_array_pub); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; @@ -347,7 +348,8 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), EXPECT_STREQ(topic_endpoint_info_pub.topic_type, "test_msgs/msg/Strings"); assert_qos_equality(topic_endpoint_info_pub.qos_profile, default_qos_profile); - rmw_topic_endpoint_info_array_t topic_endpoint_info_array_sub = rmw_get_zero_initialized_topic_endpoint_info_array(); + rmw_topic_endpoint_info_array_t topic_endpoint_info_array_sub = + rmw_get_zero_initialized_topic_endpoint_info_array(); ret = rcl_get_subscriptions_info_by_topic(&this->node, &allocator, fqdn.c_str(), false, &topic_endpoint_info_array_sub); EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str; @@ -359,7 +361,8 @@ TEST_F(CLASSNAME(TestInfoByTopicFixture, RMW_IMPLEMENTATION), assert_qos_equality(topic_endpoint_info_sub.qos_profile, default_qos_profile); // clean up - rmw_ret_t rmw_ret = rmw_topic_endpoint_info_array_fini(&topic_endpoint_info_array_pub, &allocator); + rmw_ret_t rmw_ret = + rmw_topic_endpoint_info_array_fini(&topic_endpoint_info_array_pub, &allocator); EXPECT_EQ(rmw_ret, RMW_RET_OK) << rmw_get_error_string().str; rmw_ret = rmw_topic_endpoint_info_array_fini(&topic_endpoint_info_array_sub, &allocator); EXPECT_EQ(rmw_ret, RMW_RET_OK) << rmw_get_error_string().str; From dc73872bdb0cd44455c21ea4e3614a8edcaaf4d0 Mon Sep 17 00:00:00 2001 From: Miaofei Date: Fri, 10 Jan 2020 09:53:38 -0800 Subject: [PATCH 17/17] update the docstring regarding no_mangle as suggested Signed-off-by: Miaofei --- rcl/include/rcl/graph.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rcl/include/rcl/graph.h b/rcl/include/rcl/graph.h index 9bb37d67e..9309e169b 100644 --- a/rcl/include/rcl/graph.h +++ b/rcl/include/rcl/graph.h @@ -531,8 +531,11 @@ rcl_count_subscribers( * * The `topic_name` parameter must not be `NULL`. * - * The `no_mangle` parameter determines if the provided topic_name should be - * expanded to its fully qualified name. + * When the `no_mangle` parameter is `true`, the provided `topic_name` should be a valid topic name + * for the middleware (useful when combining ROS with native middleware (e.g. DDS) apps). + * When the `no_mangle` parameter is `false`, the provided `topic_name` should follow + * ROS topic name conventions. + * In either case, the topic name should always be fully qualified. * * Each element in the `publishers_info` array will contain the node name, node namespace, * topic type, gid and the qos profile of the publisher. @@ -588,8 +591,11 @@ rcl_get_publishers_info_by_topic( * * The `topic_name` parameter must not be `NULL`. * - * The `no_mangle` parameter determines whether or not the provided topic_name should be - * converted to its underlying middleware name. + * When the `no_mangle` parameter is `true`, the provided `topic_name` should be a valid topic name + * for the middleware (useful when combining ROS with native middleware (e.g. DDS) apps). + * When the `no_mangle` parameter is `false`, the provided `topic_name` should follow + * ROS topic name conventions. + * In either case, the topic name should always be fully qualified. * * Each element in the `subscriptions_info` array will contain the node name, node namespace, * topic type, gid and the qos profile of the subscription.