Skip to content
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

Merged
merged 9 commits into from
Apr 8, 2017
Merged

add concept of node namespace to rcl API #112

merged 9 commits into from
Apr 8, 2017

Conversation

wjwwood
Copy link
Member

@wjwwood wjwwood commented Mar 29, 2017

This not only exposes the node namespace in the API (via the rcl_node_init() and rcl_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

also validate node name and node namespace
@wjwwood wjwwood added enhancement New feature or request in progress Actively being worked on (Kanban column) labels Mar 29, 2017
@wjwwood wjwwood self-assigned this Mar 29, 2017
rcl_node_init(
rcl_node_t * node,
const char * name,
const char * name_space,
Copy link
Contributor

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.

Copy link
Member Author

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.

@wjwwood wjwwood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Mar 30, 2017
* 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.
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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...
}

Copy link
Member Author

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.
Copy link
Contributor

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.

Copy link
Member Author

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.

EXPECT_EQ(RCL_RET_OK, ret);
}

// Node namespace which is not absolute.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thinking as above.

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds fine to me.

// 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);
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (strlen(namespace_) > 0) {
validation_result = 0;
invalid_index = 0;
ret = rmw_validate_topic_name(namespace_, &validation_result, &invalid_index);
Copy link
Member

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)?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wjwwood
Copy link
Member Author

wjwwood commented Apr 7, 2017

In 33e7a35 I started using rmw_validate_namespace().

@Karsten1987 I also made rcl_node_init() more flexible in 33e7a35 to allow: "", "/", and "foo/bar".

Also @Karsten1987 , another possible use case for utilities_strcat which takes an allocator:

394048d#diff-b1ed1b132e1e72fee905fe7bc3b4c62bR111

Copy link
Member

@dirk-thomas dirk-thomas left a 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.

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";
Copy link
Member

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.

Copy link
Member Author

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

@wjwwood wjwwood merged commit 64f1b16 into master Apr 8, 2017
@wjwwood wjwwood deleted the node_namespace branch April 8, 2017 09:04
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Apr 8, 2017
ivanpauno pushed a commit that referenced this pull request Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants