Skip to content

Get parameter map (#575) (crystal-backport)#619

Merged
clalancette merged 3 commits intocrystalfrom
crystal-backport-575
Jan 29, 2019
Merged

Get parameter map (#575) (crystal-backport)#619
clalancette merged 3 commits intocrystalfrom
crystal-backport-575

Conversation

@clalancette
Copy link
Copy Markdown
Contributor

This is the backport of 99dd031 onto the crystal branch, since I'd like to get it into the 2nd crystal sync ros2/ros2#647 . There are no differences between this change and the one that was merged onto master, and this change only adds an API, so there is no API break.

  • Add in the ability to get parameters in a map.

Any parameters that have a "." in them will be considered to
be part of a "map" (though they can also be get and set
individually). This PR adds two new template specializations
to the public node API so that it can take a map, and store
the list of values (so setting the parameter with a name of
"foo" and a key of "x" will end up with a parameter of "foo.x").
It also adds an API to get all of the keys corresponding to
a prefix, and returing that as a map (so a get of "foo" will
get all parameters that begin with "foo."). Note that all
parameters within the map must have the same type, otherwise
an rclcpp::ParameterTypeException will be thrown.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

  • Fix style problems pointed out by uncrustify/cpplint.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

  • Move tests for set_parameter_if_not_set/get_parameter map to rclcpp.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

  • Rename get_parameter -> get_parameters.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

  • Add in documentation from review.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

* Add in the ability to get parameters in a map.

Any parameters that have a "." in them will be considered to
be part of a "map" (though they can also be get and set
individually).  This PR adds two new template specializations
to the public node API so that it can take a map, and store
the list of values (so setting the parameter with a name of
"foo" and a key of "x" will end up with a parameter of "foo.x").
It also adds an API to get all of the keys corresponding to
a prefix, and returing that as a map (so a get of "foo" will
get all parameters that begin with "foo.").  Note that all
parameters within the map must have the same type, otherwise
an rclcpp::ParameterTypeException will be thrown.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Fix style problems pointed out by uncrustify/cpplint.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Move tests for set_parameter_if_not_set/get_parameter map to rclcpp.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Rename get_parameter -> get_parameters.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

* Add in documentation from review.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette clalancette added in progress Actively being worked on (Kanban column) in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jan 17, 2019
@clalancette clalancette changed the title Get parameter map (#575) Get parameter map (#575) (crystal-backport) Jan 17, 2019
@dirk-thomas
Copy link
Copy Markdown
Member

This is the backport of 99dd031 onto the crystal branch, since I'd like to get it into the 2nd crystal sync

Is there a specific use case / problem why this additional API is needed in Crystal?

@clalancette
Copy link
Copy Markdown
Contributor Author

Is there a specific use case / problem why this additional API is needed in Crystal?

Yes, it's so that we can release ros2/teleop_twist_joy#8 into Crystal (once it has been approved/merged).

rclcpp::Parameter & parameter) const;

RCLCPP_PUBLIC
virtual
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think adding a virtual method breaks ABI

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great catch. You are completely right; this does break ABI.

I've been trying to find a workaround here (essentially by bubbling the API up through the layers), but I haven't found anything that works yet. Any thoughts on ways to maybe workaround this (just for the Crystal branch)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Never mind, I found another way. Update to this PR coming.

* \return false otherwise.
*/
RCLCPP_PUBLIC
virtual
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment about adding a virtual method

This way, we don't break ABI in crystal.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@dirk-thomas
Copy link
Copy Markdown
Member

Since this patch has changed from a backport to a modified patch with different logic can you please describe how the backported change is different than what is available on master and if you are planning to update the code on master to match this patch or if it should stay as it is.

@clalancette
Copy link
Copy Markdown
Contributor Author

Since this patch has changed from a backport to a modified patch with different logic can you please describe how the backported change is different than what is available on master and if you are planning to update the code on master to match this patch or if it should stay as it is.

Right. For whatever reason when I did the original patch, I totally missed that list_parameters existed, which more-or-less provides the same functionality as get_parameters_by_prefix. The main benefit to using get_parameters_by_prefix is that it is atomic; it takes the mutex, iterates over all of the keys with the prefix, gets their values, and stuffs them in the map to be returned. When using list_parameters as in this patch, the mutex is taken to get the list of parameters with the prefix, but then it is dropped. We then have to call get_parameter in a loop to get the value for each parameter. This leads to a possible TOCTTOU bug, where we could fetch the list of parameters, one is deleted, and then we try to get_parameter on the now-deleted parameter.

My view on it is that we should keep get_parameters_by_prefix for master since it is atomic (and slightly faster), but we can live with the (probably rare) race in crystal to make sure we don't break ABI. Thoughts?

@dirk-thomas
Copy link
Copy Markdown
Member

I am not convinced if it is worth introducing a new API into Crystal in a patch release which will not be present in master / future distros.

@clalancette
Copy link
Copy Markdown
Contributor Author

I am not convinced if it is worth introducing a new API into Crystal in a patch release which will not be present in master / future distros.

But that's not what would happen here.

On master, #575 added the following new APIs:

  • Node class:
    • set_parameters_if_not_set
    • get_parameters
  • NodeParameters class:
    • get_parameters_by_prefix

In Crystal, this PR would add the following new APIs:

  • Node class:
    • set_parameters_if_not_set
    • get_parameters

So the APIs are compatible, its just that code that compiles against master would be able to call get_parameters slightly faster and with atomicity. Either way, code that calls set_parameters_if_not_set or get_parameters would work across Crystal and master.

@dirk-thomas
Copy link
Copy Markdown
Member

So the APIs are compatible, its just that code that compiles against master would be able to call get_parameters slightly faster and with atomicity.

Do you mean get_parameters_by_prefix here?

If get_parameters_by_prefix is so much better should get_parameters be removed so that users don't accidentally call a function which isn't really safe to use?

@clalancette
Copy link
Copy Markdown
Contributor Author

If get_parameters_by_prefix is so much better should get_parameters be removed so that users don't accidentally call a function which isn't really safe to use?

get_parameters_by_prefix is really an implementation detail of how to get parameters from the lower-level NodeParameters class. Users should really be interacting with the top-level Node APIs, which are get_parameters and set_parameters_if_not_set. On crystal, the Node API for get_parameters will be imlpemented by calling list_parameters, followed by a call to get_parameter for each of the returned values (this PR). This has the benefit of using existing APIs (preserving ABI), but has the downside that fetching the set of values with a prefix isn't atomic. On master, get_parameters is implemented by calling get_parameters_by_prefix, which has the downside of needing to change ABI, but has the benefit of fetching the set of values atomically.

In my mind, the question is really whether we want to add get_parameters_by_prefix to master at all. I think we do, since it provides atomicity of fetching the set of values, but I would definitely listen to arguments against that.

@clalancette clalancette merged commit cd6f195 into crystal Jan 29, 2019
@clalancette clalancette deleted the crystal-backport-575 branch January 29, 2019 21:05
@clalancette clalancette removed the in review Waiting for review (Kanban column) label Jan 29, 2019
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
* Zero-initialize message_info prior to taking

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* Added test for timestamp presence

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* move message_info test to a new test file

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* Add conditional timestamp test to normal subscriber test

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* Remove dedicated timestamp test

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* Use rmw_time_point_value_t instead of rmw_time_t

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* Use rcutils for cross-platform compatibility.

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* Style fix.

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* More style fix.

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* test fastrtps_dynamic properly; also cmake linter error

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* Expect timestamps on cyclonedds as well

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>

* Distinguish received timestamp support.

Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
…the first one. (ros2#619)

* Fix --topics flag for ros2 bag play being ignored for all bags after the first one.

Signed-off-by: Aleksandr Rozhdestvenskii <hexonxons@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants