-
Notifications
You must be signed in to change notification settings - Fork 418
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
add wait_for_service() and service_is_ready() to Client #222
Conversation
642174d
to
7f74cb9
Compare
9a3afec
to
760efde
Compare
} // release the nodes_ lock | ||
|
||
// Wait for graph changes or interrupt. | ||
ret = rcl_wait(&wait_set_, -1); // block for ever until one of the |
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.
Incomplete comment here.
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 needs review. @jacquelinekay already reviewed in some while helping me find and fix a bug. A few things I want to highlight and to "request comments" about:
I think that's all I wanted to highlight. Thanks in advance for reviews. |
} | ||
// server is not ready, loop if there is time left | ||
time_to_wait = timeout - (std::chrono::steady_clock::now() - start); | ||
} while (timeout < std::chrono::nanoseconds(0) || time_to_wait > std::chrono::nanoseconds(0)); |
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.
What happens in this loop when the program receives SIGINT/CTRL-C?
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's a good question... Currently I think it will not wake up, because neither node_->wait_for_graph_change
nor this loop will consider rclcpp::ok
or be notified by the shutdown call or signal processor.
What do you think the behavior of this function should be in that case? I'll need to adjust the documentation to be something like "returns true if graph changed or false if the timeout expired or rclcpp::shutdown occurred". But then you can't easily tell which happened timeout or shutdown, though I guess if you check rclcpp::ok
after getting false
back from this function and be reasonably sure that was the cause or not.
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 think it's fine to check for !rclcpp::ok()
in the while predicate and return false in that case. A return value of false means "we stopped waiting and the client was not ready." If you want a finer level of granularity we could add error codes (client_ready, timeout, interrupted) but I don't think that's necessary right now.
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.
Ok, I added this behavior in 25e17b0 and I added a test in ros2/system_tests@268f54a.
My major questions are about what happens in the do/while loop on CTRL-C, and the ownership of the Node pointer in Client. Otherwise it looks good. |
acab9e5
to
25e17b0
Compare
+1 |
1 similar comment
+1 |
this essentially protects the notify_guard_condition_
a660203
to
b105fe6
Compare
I rebased and refactored the thread synchronization. |
* add wait_for_service() and service_is_ready() to Client * fix compile on Linux (maybe Windows) * use visibility macros for Windows * prevent unreasonable uncrustify change * fixup comment * add GraphListener::is_shutdown() * disable copy on GraphListener * use weak_ptr<Node> in client, throw if invalid * ensure blocking wait_for_service wakes on rclcpp::shutdown/sigint * rethrow exceptions after reporting them in thread * lock ~Node() against notify_graph_change() this essentially protects the notify_guard_condition_ * adjust thread sync strategy * style * moving initialization of wait set around, fix double free * only fini wait set if started * use rclcpp::shutdown to ensure graph listener resources clean up before static destruction * uncrustify
* add missing documentation * remove unnecessary visibility and warning macros
Replacement for #221
Connects to ros2/ros2#215