Description
This will be long, and might be better suited for the discourse, let me know.
Currently rclcpp only supports registering one param_change_callback
, and if you try to register a second one, it overwrites the first callback.
The problem with having multiple callbacks is supporting atomically setting parameters. Currently the callbacks that are registered do two things, verify that the parameters are within any constraints, as well as update the operation of the node to work with the new parameters (if verification passed). With only one callback per node, this all works fine, and the parameters are updated atomically across the node.
(Ex of current callback: https://github.com/rohbotics/turtlebot2_demo/blob/0f33a3c3caadd13fe89be060690d6e4b797cd2ba/turtlebot2_drivers/src/kobuki_node.cpp#L42)
With multiple callbacks, this approach doesn't work any more, the parameters can only be atomic per registered callbacks. Here are some proposals I have to fix this.
A: Namespacing
Figure out how we are going to namespace parameters within the node, and then only support atomic operations on parameters within a single namespace, and allow for one callback per namespace.
Pros: Easy to interface with at an API level.
Cons: Pretty restrictive, could be hard to implement cleanly/correctly
B: Seperation of Concerns
After discussing with @tfoote, this is the approach that we came up with. The user will provide two functions, one that only verifies the parameter updates, which provides another function that will actually execute updating the operation of the node with the new parameters. This could be made easier with dynamic-configure ish code generation.
Pros: Keeps atomicity support everywhere
Cons: Could be messy from a user perspective (without code gen)
C: Make Atomicity Optional
Not every node requires support for atomically setting a group of variables, so make support for it optional. For nodes that want support they can use approach B, and those who don't can use basic callbacks that verify and set parameters.
Pros: Easy to add parameters without worrying about atomicity
Cons: Might make nobody bother with atomic parameter updates
Footnote: there should also be a way to de-register callbacks if we support multiple