-
Notifications
You must be signed in to change notification settings - Fork 412
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
Added new constructors for SyncParameterClient #612
Added new constructors for SyncParameterClient #612
Conversation
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.
Thanks for starting this pr, I have some requested changes and unfortunately we're past the point in the Crystal release where this could be included, instead it will go into post Crystal (for the D-turtle release) and therefore this pr might have to wait for a few days/weeks while we finish the release.
rclcpp::Node * node, | ||
const std::string & remote_node_name, | ||
const rmw_qos_profile_t & qos_profile) | ||
: executor_(executor), node_(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.
This is dangerous, because you're creating a shared pointer to Node (in node_
) from a pointer that is already owned by another shared pointer (node
is the pointer and all nodes are created as shared pointers to support std::enable_shared_from_this
).
The SyncParametersClient needs to be changed to hold a raw pointer (optionally or always) rather than always having a shared pointer to node which cannot be safely fulfilled with a raw pointer as input.
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 changed the SyncParametersClient member node_ to a raw pointer.
SyncParametersClient has still constructors which accept a raw or shared pointer to a node.
@@ -185,6 +185,19 @@ class SyncParametersClient | |||
const std::string & remote_node_name = "", | |||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters); | |||
|
|||
RCLCPP_PUBLIC | |||
explicit SyncParametersClient( | |||
rclcpp::Node * 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.
Instead a signature which took the component parts of the node that this client needs would be better, e.g. maybe the NodeParameterInterface
and the NodeBaseInterface
(and perhaps others?).
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 keep a signature like this one which simply extracted those components from a rclcpp::Node
and delegated them to another constructor. That way this could be more easily used with other forms of Node's like rclcpp_lifecycle::LifecycleNode
.
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.
From what I have understood, SyncParameterClient only uses NodeBaseInterface
for calling spin_until_future_complete
.
All the other interfaces are used by AsyncParameterClient and are "extracted" from the node pointer in the AsyncParameterClient constructor.
I do not get what's the advantage of having a SyncParameterClient constructor signature which takes interfaces, since all the logic using them is contained in the AsyncParameterClient
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 do not get what's the advantage of having a SyncParameterClient constructor signature which takes interfaces, since all the logic using them is contained in the AsyncParameterClient.
Doesn't the SyncParameterClient create an AsyncParameterClient internally? Therefore it needs those parts to pass to the constructor of the AsyncParameterClient (specifically this one:
rclcpp/rclcpp/include/rclcpp/parameter_client.hpp
Lines 49 to 56 in 69d7e69
RCLCPP_PUBLIC | |
AsyncParametersClient( | |
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface, | |
const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface, | |
const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface, | |
const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface, | |
const std::string & remote_node_name = "", | |
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters); |
As to why the parts rather than an rclcpp::Node
pointer only, the reason is that this won't be only used with rclcpp::Node
, for instance if you wanted to use it with rclcpp_lifecycle::LifecycleNode
(which does not inherit from rclcpp::Node
), or some user defined node that doesn't inherit from rclcpp::Node
, then you'd want the constructor that takes the interfaces.
If you want to be resilient to changes in the AsyncParameterClient's constructor, you could try to use perfect forwarding to forward the arguments that are only used by the AsyncParameterClient, but that makes it harder to document imo.
You can still have convenience constructors that take common node base types like rclcpp::Node
and just extract the interfaces needed and then delegates to the other constructor.
In the last commit I took into account the possibility for objects which does not inherit from I had to change again the Now there are 5 constructors for SyncParameterClient and 3 constructors for AsyncParameterClient. These are examples of flow for the SyncParameterClient:
The just added "executor + interfaces constructor" instantiates the AsyncParameterClient using the provided interfaces. I just noticed that there is a failed test (it was present also with the last commit, but I did not saw it since I only tested rclcpp package). |
Thanks! I'll give it a look.
It may or may not be related, we do occasionally have flaky tests, @jacobperron and @sloretz do either of you know if that is a known flaky test? |
I'm not aware of any flaky tests in rclcpp_action.
|
@jacobperron yes, you are right, now the checks are marked as passed. I repeated all the rclcpp tests more than one time and apparently sometimes errors in the rclcpp_action package arise. |
The failing tests are due to another unrelated issue, so I'll merge this. Thanks @alsora! |
* added new constructors for sync parameter client * sync param client now has raw ptr member instead of shared ptr * fixed pointer style * allow objects which do not inherit from node to create a sync parameters client
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
…to find bagfiles in incorrectly-written metadata (ros2#612) * Deduplicate sequentialcompressionreader business logic, add fallback to find bagfiles in incorrectly-written metadata Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Following issue #599
Allows to create SyncParameterClient in a class which inherits from rclcpp::Node