-
Notifications
You must be signed in to change notification settings - Fork 433
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
Skeleton parameters async API #26
Conversation
@@ -19,6 +19,7 @@ | |||
#include <memory> | |||
|
|||
#include <rclcpp/node.hpp> | |||
#include <rclcpp/parameter.hpp> |
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.
Is this file missing from the PR?
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.
Just pushed, sorry!
+1 |
@@ -0,0 +1,225 @@ | |||
// Copyright 2014 Open Source Robotics Foundation, Inc. |
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.
Year should be 2015.
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.
Done.
Beside the minor comments the API looks good to me. |
@dirk-thomas thanks for the feedback! |
get_parameters( | ||
std::vector<std::string> names, | ||
std::function<void( | ||
std::shared_future<std::vector<ParameterVariant>>)> callback = nullptr) |
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 signature left me with some questions, which might just be solved with documentation:
- Why does the callback receive the future and not just the value?
- I guess because the future could result in an exception?
- Is the expectation that the call to
future.get()
in the user's callback will either raise or return the value without blocking (is the future always ready when the callback is called)?- Put another way, can the call to
future.get()
block in the user's callback?
- Put another way, can the call to
- What happens if the user doesn't call
.get()
on the future?
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.
Why does the callback receive the future and not just the value?
I guess because the future could result in an exception?
That is correct, get()
will either raise a std::future_error
exception or return the value.
http://en.cppreference.com/w/cpp/thread/future/get
http://en.cppreference.com/w/cpp/thread/future_error
Is the expectation that the call to future.get() in the user's callback will either raise or return the > value without blocking (is the future always ready when the callback is called)?
Put another way, can the call to future.get() block in the user's callback?
When the callback is fired, the std::future
is already ready. In the previous version of the parameters API or in the current code for services (https://github.com/ros2/rclcpp/blob/master/rclcpp/include/rclcpp/client.hpp#L121), the value for the related std::promise
is set before firing the callback.
What happens if the user doesn't call .get() on the future?
The callback function will be fired, but the user won't have access to the result of the operation.
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.
That all sounds find to me. Thanks.
The callback function will be fired, but the user won't have access to the result of the operation.
Ok, I was more wondering if the future's (or the value in the future's) lifecycle was dependent on .get()
being called, but I guess it doesn't.
I was also just now wondering if an exception could be silently suppressed if the user never calls .get()
and if we could do anything about it.
Is there anyway for the code to know if the future was "gotten"? If there is, then you could imagine that the code does something like:
user_callback(future);
if (future.not_gotten() && future.has_exception()) {
try {
future.get();
catch (std::execption & exc) {
log_error_stream("Unhandled exception in future: " << exc);
}
}
Another thought is that boost::asio
returns the value and the exception as parameters to the callback. It's not clear to me that this a better way to structure the callback signature, but it's worth thinking about as we work on this API.
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.
Is there anyway for the code to know if the future was "gotten"? If there is, then you could imagine that the code does something like:
I don't think there is, but I could be wrong.
Another thought is that boost::asio returns the value and the exception as parameters to the callback. It's not clear to me that this a better way to structure the callback signature, but it's worth thinking about as we work on this API.
I think that'd be a good idea.
Other than my questions about the callback taking a future, lgtm. Thanks! |
dc525c6
to
513e283
Compare
All of my comments which I think should result in a change before merge have been addressed, +1. |
Please squash before merging. |
513e283
to
e657a8f
Compare
Asoragna/make functions private
fix style of header include guard
* ros2GH-52 Extend db schema to include topic meta data - Two table db layout (messages and topics) - Messages table references topics table but without foreign key for improved write performance - Create_topic must be called for every topic prior to storing a message of this topic. - Sqlite_storage caches all known topics - At least for now the type information is stored as a simple string. * ros2GH-54 Make first rcl subscription prototype work * ros2GH-54 find type name from topic * ros2GH-54 Publish messages from database knowing only topic name and pass topic name by terminal * ros2GH-54 Refactoring of typesupport helpers * ros2GH-54 Use c++ typesupport * ros2GH-54 Use cpp typesupport and rclcpp::Node for publisher * ros2GH-54 Add raw subscription and use in rosbag_record * ros2GH-54 Add Rosbag2Node and Rosbag2Publisher classes and use them in Rosbag2::play * ros2GH-54 Rename Rosbag2Publisher to RawPublisher * ros2GH-54 Minor refactoring of Rosbag2Node * ros2GH-54 Extract and test waiting for topic into its own method * ros2GH-54 Fix read integration tests and linters * ros2GH-55 Refactor Rosbag2Node::create_raw_publisher() * ros2GH-54 Add subscription method to rosbag node * ros2GH-54 Keep subscription alive * ros2GH-54: Extract subscription to correct class * ros2GH-55 Change interface of raw_publisher to match subscriber * ros2GH-54 Add test for rosbag node * ros2GH-54 Unfriend rclcpp class * ros2GH-54 Make test more robust * ros2GH-54 Fix build * ros2GH-54 Minor cleanup and documentation * ros2GH-55 Minor refactoring + TODO comment * ros2GH-54 Change dynamic library folder on Windows * ros2GH-54 Fix build * ros2GH-54 Add shutdown to test * ros2GH-55 Add test helpers methods for usage in multiple tests * ros2GH-55 Add new method to read all topics and types in BaseReadInterface and use it in Rosbag2::play * ros2GH-55 Fix gcc and msvc * ros2GH-54 Rename raw to generic in publisher/subscriber * ros2GH-55 Check that topic and associated type in bag file are well defined before playing back messages * ros2GH-54 Prevent unnecessary error message loading storage * ros2GH-54 Fix memory leak * ros2GH-54 stabilize node test * ros2GH-55 Check if database exists when opening storage with READ_ONLY flag * ros2GH-54 Minor cleanup of subscriber * ros2GH-54 Wait a small amount of time to let node discover other nodes * Add logging to false case * ros2GH-54 Catch exceptions and exit cleanly * Use rmw_serialized_message_t and rcutils_char_array_t consistently * ros2GH-4 Refactoring for correctness - pass a few strings as const reference - throw error when no topics could be found * Improve error messages when loading plugins * alphabetical order * type_id -> type
* ros2GH-61 Read topic directly from message when playing and allow to play multiple topics * ros2GH-61 Add test for SqliteStorage and update old ones * ros2GH-62 Extend function to poll for any number of specified topics * ros2GH-62 Allow subscription to several topics * ros2GH-61 Obtain the topic name directly from the database - Uses a JOIN instead of mapping the topic_id to the name in code * ros2GH-61 Cache read row in result iterator This allows repeated dereferencing on same row without quering the database again. * ros2GH-62 Change demo-record to allow specifying multiple topics * ros2GH-62 Add test to write non-string topic + refactoring * ros2GH-62 Add test for subscription to multiple topics * ros2GH-62 Cleanup * ros2GH-62 Simplify test setup * ros2GH-61 Cleanup * ros2GH-61 consolidate storage integration test * ros2GH-62 Consolidate write integration tests * ros2GH-61 enhance read integration test to check multiple topics * ros2GH-62 Improve rosbag integration test * ros2GH-62: Polish rosbag2_rosbag_node_test * ros2GH-62 Fix cpplint * ros2GH-62 Fix memory leak in rosbag helper * ros2GH-62 Cleanup of subscriptions * ros2GH-62 do not use flaky timers in rosbag2_write_integration_test * ros2GH-62 Use rmw_serialize_message_t consistently in test helper classes * ros2GH-73 Use test_msgs in read_integration_test * ros2GH-26 Cleanup: fix alphabetic orderung
Connects to ros2/ros2#28
@dirk-thomas @tfoote @wjwwood