-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add concept of node namespace to rcl API #112
Conversation
also validate node name and node namespace
rcl/include/rcl/node.h
Outdated
rcl_node_init( | ||
rcl_node_t * node, | ||
const char * name, | ||
const char * name_space, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not putting name_space
into rcl_node_options_t
? We can expose this struct on a high level language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had two reasons for placing it like this.
The first was because I believe the namespace should be of elevated importance (similar to node name). Your same argument could be made for name
, specifically that it should also be in the options struct, but to emulate the interface of ROS 1, node name and node namespace are high level concepts.
On the technical side, it is nice that the options structure remains a POD. As soon as I add a pointer (like a const char *
) it is no longer "trivially copyable" (borrowing a term from C++).
That all being said, I don't feel strongly about it. I definitely agree that most options should end up in the structure, but in this instance I made a decision to leave it out.
rcl/include/rcl/node.h
Outdated
* Even though this is a namespace, with additional relative namespace and/or | ||
* a basename to follow, the namespace string passed here should not include | ||
* a trailing forward slash. | ||
* For an empty namespace, an empty string, i.e. "", should be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth mentioning that NULL
is considered an error here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea: dce05d6
return ret; | ||
} | ||
if (validation_result != RMW_NODE_NAME_VALID) { | ||
const char * msg = rmw_node_name_validation_result_string(validation_result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this was discussed in another PR already. But why not apply the same logic as above here?
// sets the error message inside
ret = rmw_node_name_validation_result_string(validation_result);
if (ret != RMW_RET_OK) // or similar for this use-case
{
RCL_GET_ERROR_MSG_SAFE...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rmw_node_name_validation_result_string()
returns the validation issue description as a string, because I didn't want to force it into being an error. Also, this way you can formulate the error however you want (possibly using the input topic name and the violation index to make a better error message).
EXPECT_EQ(RCL_RET_OK, ret); | ||
} | ||
|
||
// Node namespace with a trailing / which is not allowed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is not allowed by design, but I wonder if we should manually filter this constraint to be allowed. It looks to me like a rather easy check for the last character. Just an idea, nothing critical to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather leave this kind of flexibility to the top level API's (like rclcpp and rclpy). Each corner case makes it harder to describe and harder to test, so I'd like to keep rcl
simple by avoiding them. That's just my personal preference though. I have no problem with allowing this exception to the rule here or in the higher level API's.
rcl/test/rcl/test_node.cpp
Outdated
EXPECT_EQ(RCL_RET_OK, ret); | ||
} | ||
|
||
// Node namespace which is not absolute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thinking as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I add some "smoothing" here when I do the code which expands topics and stuff automatically (upcoming prs)? That way I can reuse those functions to automatically remove trailing /
and add leading /
if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds fine to me.
rcl/src/rcl/node.c
Outdated
// Make sure the node name is valid before allocating memory. | ||
int validation_result = 0; | ||
size_t invalid_index = 0; | ||
ret = rmw_validate_node_name(name, &validation_result, &invalid_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since invalid_index
isn't used it would be good to make the argument optional in the rmw_validate_node_name
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rcl/src/rcl/node.c
Outdated
if (strlen(namespace_) > 0) { | ||
validation_result = 0; | ||
invalid_index = 0; | ||
ret = rmw_validate_topic_name(namespace_, &validation_result, &invalid_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the namespace_
alone is not a FQN yet (it doesn't contain the topic name at the end, right?) doesn't this need a separate validation function (rmw_validate_namespace
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is either /
or it is a valid FQN, so the topic name validation function is sufficient once I account for the /
case. The code as written (and documented and tested) covers all the cases for namespace that I'm aware of. I don't think we need a separate namespace validation function myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A namespace can be empty. A topic name can't be. So both types have separate validation criteria, right? Therefore I would suggest to create separate validation functions for them. These implementation could share common functionality though if that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 33e7a35 I started using @Karsten1987 I also made Also @Karsten1987 , another possible use case for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beside the comment this LGTM.
rcl/src/rcl/node.c
Outdated
if (validation_result != RMW_NAMESPACE_VALID) { | ||
const char * msg = rmw_namespace_validation_result_string(validation_result); | ||
if (!msg) { | ||
msg = "unknown validation_result, this should not happen"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if the message included the value of validation_result
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the change in rmw
: f0bec07
This not only exposes the node namespace in the API (via the
rcl_node_init()
andrcl_node_get_namespace()
functions), but it also validates the node name and the new namespace arguments.This also relies on ros2/rmw#93 to help validate the node namespace.
Connects to ros2/rmw#95