-
Notifications
You must be signed in to change notification settings - Fork 430
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
Proposal for NodeHandle concept that simplifies calling APIs with node-like objects #831
Comments
In your example, does How is this different from How does What would happen if the interfaces were coming from two places? Like if instead of a node class which has a Base and Services interface inside it, I instead had just a MockBase and MockServices as separate objects? Can a How does this overlap with or work along with these existing helper functions:
Which are used like this:
|
I'm ok with any of the styles proposed, maintaining the current helper functions or creating a
Examples of places where we're not using the helper functions (in some of them, they need a shared pointer and not a raw pointer):
I left some similar comments in a related discussion that proposed another alternative for this (adding an is_pointer thing): |
I think that's all fair feedback about the existing methods. They sort of evolved into that. I think always taking a NodeT & (not pointer or shared pointer) is ok (though Node's are basically always shared pointers right now), and always returning a shared pointer (or at least having a separate function that can do that) to the interface object is also a good idea to limit what's possible. |
* Add warnings Signed-off-by: Audrow Nash <audrow.nash@gmail.com> * Fix conversion warning by casting to size_t Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
I think we can close this issue with the merge of #2041 |
Feature request
Feature description
This is an idea to simplify code that calls APIs using node interfaces. It proposes adding template classes
NodeHandle<>
andNodeHandle<>::SharedPtr
who are given placeholder types that indicate the needed node interfaces.When node interfaces are just needed for the lifetime of the call
create_service()
needs aNodeBaseInterface
andNodeServicesInterface
. It doesn't need shared pointers to these interfaces; it just needs them for the duration of the call.Before:
after
When node interfaces are needed long term
tf2_ros::TransformListener
needs the node base interface for a long time, so it holds a shared pointer.It currently does some logic in the header file and some in the cpp file, but the intent of this proposal is to enable moving all of it to the cpp file.
Before
After
Implementation considerations
Placeholder types should be created for each node interface. The purpose of these is to make the type of a
NodeHandle
more readable. In my opinionrclcpp::NodeHandle<Base>
is easier to read thanrclcpp::NodeHandleBase<node_interfaces::NodeBaseInterface>
.The types passed to
NodeHandle<>
would indicate the interfaces needed by a method.rclcpp::NodeHandle<Base, Topics>
would replaceget_node_base_interface
andget_node_topics_interface()
. Using similar template magic, it would get the base and topics interface off of whatever it's given at compile time. Code would access the interfaces withnode_handle.base()
ornode_handle.topics()
and those would return raw pointers to the interfaces.rclcpp::NodeHandle<Base, Topics>::SharedPtr
is a little more interesting becauseget_node_*_interface()
don't address this use case, and I've seen it a couple times while porting packages. Some API's need shared pointers to the node interfaces so they can keep them alive for a while.NodeHandle<>::SharedPtr
should be a shared pointer to an object that holds shared pointers to the interfaces. Interfaces would be accessed vianode_handle->base()
andnode_handle->topics()
, but the return type would be a shared pointer instead of a raw pointer. Since the return type is different, this is probably a different class internally (NodeHandle<>::SharedPtr = std::shared_ptr<NodeHandleCopyable<>>
).The text was updated successfully, but these errors were encountered: