Skip to content

Commit

Permalink
Add specific return code for non existent node (ros2#492)
Browse files Browse the repository at this point in the history
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored Sep 17, 2019
1 parent 17598ff commit fa20448
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions rcl/include/rcl/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef rmw_names_and_types_t rcl_names_and_types_t;
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_NODE_INVALID_NAME` if the node name is invalid, or
* \return `RCL_RET_NODE_INVALID_NAMESPACE` if the node namespace is invalid, or
* \return `RCL_RET_NODE_NAME_NON_EXISTENT` if the node name wasn't found, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
Expand Down Expand Up @@ -126,6 +127,7 @@ rcl_get_publisher_names_and_types_by_node(
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_NODE_INVALID_NAME` if the node name is invalid, or
* \return `RCL_RET_NODE_INVALID_NAMESPACE` if the node namespace is invalid, or
* \return `RCL_RET_NODE_NAME_NON_EXISTENT` if the node name wasn't found, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
Expand Down Expand Up @@ -174,6 +176,7 @@ rcl_get_subscriber_names_and_types_by_node(
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_NODE_INVALID_NAME` if the node name is invalid, or
* \return `RCL_RET_NODE_INVALID_NAMESPACE` if the node namespace is invalid, or
* \return `RCL_RET_NODE_NAME_NON_EXISTENT` if the node name wasn't found, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
Expand Down Expand Up @@ -221,6 +224,7 @@ rcl_get_service_names_and_types_by_node(
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_NODE_INVALID_NAME` if the node name is invalid, or
* \return `RCL_RET_NODE_INVALID_NAMESPACE` if the node namespace is invalid, or
* \return `RCL_RET_NODE_NAME_NON_EXISTENT` if the node name wasn't found, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
Expand Down
2 changes: 2 additions & 0 deletions rcl/include/rcl/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ typedef rmw_ret_t rcl_ret_t;
#define RCL_RET_NODE_INVALID 200
#define RCL_RET_NODE_INVALID_NAME 201
#define RCL_RET_NODE_INVALID_NAMESPACE 202
/// Failed to find node name
#define RCL_RET_NODE_NAME_NON_EXISTENT 203

// rcl publisher specific ret codes in 3XX
/// Invalid rcl_publisher_t given return code.
Expand Down
2 changes: 2 additions & 0 deletions rcl/src/rcl/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ rcl_convert_rmw_ret_to_rcl_ret(rmw_ret_t rmw_ret)
return RCL_RET_BAD_ALLOC;
case RMW_RET_UNSUPPORTED:
return RCL_RET_UNSUPPORTED;
case RMW_RET_NODE_NAME_NON_EXISTENT:
return RCL_RET_NODE_NAME_NON_EXISTENT;
default:
return RCL_RET_ERROR;
}
Expand Down
17 changes: 9 additions & 8 deletions rcl/test/rcl/test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ TEST_F(
// unknown node name
ret = rcl_get_publisher_names_and_types_by_node(
this->node_ptr, &allocator, false, unknown_node_name, "", &nat);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_NODE_NAME_NON_EXISTENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
// unknown node namespace
ret = rcl_get_publisher_names_and_types_by_node(
this->node_ptr, &allocator, false, this->test_graph_node_name, unknown_node_ns, &nat);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_NODE_NAME_NON_EXISTENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
// valid call
ret = rcl_get_publisher_names_and_types_by_node(
Expand Down Expand Up @@ -414,12 +414,12 @@ TEST_F(
// unknown node name
ret = rcl_get_subscriber_names_and_types_by_node(
this->node_ptr, &allocator, false, unknown_node_name, "", &nat);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_NODE_NAME_NON_EXISTENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
// unknown node namespace
ret = rcl_get_subscriber_names_and_types_by_node(
this->node_ptr, &allocator, false, this->test_graph_node_name, unknown_node_ns, &nat);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_NODE_NAME_NON_EXISTENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
// valid call
ret = rcl_get_subscriber_names_and_types_by_node(
Expand Down Expand Up @@ -496,12 +496,12 @@ TEST_F(
// unknown node name
ret = rcl_get_service_names_and_types_by_node(
this->node_ptr, &allocator, unknown_node_name, "", &nat);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_NODE_NAME_NON_EXISTENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
// unknown node namespace
ret = rcl_get_service_names_and_types_by_node(
this->node_ptr, &allocator, this->test_graph_node_name, unknown_node_ns, &nat);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_NODE_NAME_NON_EXISTENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
// valid call
ret = rcl_get_service_names_and_types_by_node(
Expand All @@ -525,6 +525,7 @@ TEST_F(
rcl_node_t zero_node = rcl_get_zero_initialized_node();
const char * unknown_node_name = "test_rcl_get_client_names_and_types_by_node";
const char * unknown_node_ns = "/test/namespace";

rcl_names_and_types_t nat = rcl_get_zero_initialized_names_and_types();
// invalid node
ret = rcl_get_client_names_and_types_by_node(
Expand Down Expand Up @@ -578,12 +579,12 @@ TEST_F(
// unknown node name
ret = rcl_get_client_names_and_types_by_node(
this->node_ptr, &allocator, unknown_node_name, "", &nat);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_NODE_NAME_NON_EXISTENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
// unknown node namespace
ret = rcl_get_client_names_and_types_by_node(
this->node_ptr, &allocator, this->test_graph_node_name, unknown_node_ns, &nat);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_NODE_NAME_NON_EXISTENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
// valid call
ret = rcl_get_client_names_and_types_by_node(
Expand Down

0 comments on commit fa20448

Please sign in to comment.