-
Notifications
You must be signed in to change notification settings - Fork 334
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 loaned message listener. #526
base: rolling
Are you sure you want to change the base?
Conversation
Signed-off-by: Lei Liu <[email protected]>
Signed-off-by: Lei Liu <[email protected]>
During my test for zero copy, I found there's only talker_loaned_message, so I add a pair for it, hope it's useful. |
isn't that an exact duplicate of the listener demo? While I am all up for consistency, I am not really a fan of copying code. |
Thanks for your reply! |
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.
Besides the inline comments, I think it is important to point out what the expectation of this example is. That is, in what circumstances should the user expect this to be zero-copy? How would they verify this is the case?
// Create a callback function for when messages are received. | ||
// Variations of this function also exist using, for example UniquePtr for zero-copy transport. | ||
setvbuf(stdout, NULL, _IONBF, BUFSIZ); |
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 we have this in our other examples, but it actually isn't necessary anymore. Since Foxy, we print out all RCLCPP_*
output to stderr. So just remove this.
auto callback = | ||
[this](const std_msgs::msg::Float64::SharedPtr msg) -> void |
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 it is import to have a comment that shows that this can only be zero-copy for fixed-sized types.
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.
You could print some information about the listener in the constructor of this class and print whether the middleware supports zero-copy.
We could enhance the talker class by printing the pointer address of the message to be published and print the pointer address of the message you get here in the callback. In the case of zero-copy these addresses are the same.
That way we can demonstrate both, a loaned message where the middleware allocates all messages and a zero-copy transport in case the middleware supports it.
{ | ||
// Create a Listener class that subclasses the generic rclcpp::Node base class. | ||
// The main function below will instantiate the class as a ROS node. | ||
class LoanedMessageListener : public rclcpp::Node |
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.
Personally, I would rename this class. The fact that it is a loaned message under the hood isn't super-interesting to the user. What's more interesting is that it is zero-copy, so I'd rename this to ZeroCopyListener
or whatever.
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 kind of disagree with this. We have the equivalent talker which is called LoanedMessageTalker
and I believe this pattern makes sense, nonetheless for consistency - we also have a pair of SerializedMessage[Talker|Listener]
.
The idiom of a loaned message is needed for zero-copy, but you can perfectly fine use a loaned message without the middleware supporting zero-copy.
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 kind of disagree with this. We have the equivalent talker which is called
LoanedMessageTalker
and I believe this pattern makes sense, nonetheless for consistency - we also have a pair ofSerializedMessage[Talker|Listener]
.The idiom of a loaned message is needed for zero-copy, but you can perfectly fine use a loaned message without the middleware supporting zero-copy.
OK, that makes sense. I think the thing I'm stuck on here is how the user knows that loaning is happening, and what they should expect different when loaning is used.
This makes total sense. Thanks for the clarification. |
Signed-off-by: Lei Liu [email protected]