Compare commits
2 Commits
runtime_in
...
jacob/wait
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50ba777fdb | ||
|
|
921d439e32 |
@@ -124,6 +124,13 @@ public:
|
||||
const std::string & topic_name,
|
||||
bool no_mangle = false) const override;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
wait_for_publishers(
|
||||
const std::string & topic_name,
|
||||
size_t count,
|
||||
const std::chrono::nanoseconds & timeout) const override;
|
||||
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(NodeGraph)
|
||||
|
||||
|
||||
@@ -299,6 +299,29 @@ public:
|
||||
virtual
|
||||
std::vector<rclcpp::TopicEndpointInfo>
|
||||
get_subscriptions_info_by_topic(const std::string & topic_name, bool no_mangle = false) const = 0;
|
||||
|
||||
/// Wait for a number of publishers to be available on a topic.
|
||||
/**
|
||||
* This function will block until the provided number of publishers are available or a timeout occurs.
|
||||
*
|
||||
* TODO(jacobperron): Detect this scenario and throw an exception
|
||||
* This function should not be called concurrently with a running GraphListener.
|
||||
* E.g. Do not call this after calling `rclcpp::GraphListener::get_graph_event()`.
|
||||
* If this happens an exception is thrown.
|
||||
*
|
||||
* \param[in] topic_name the topic to check for publishers. It will not be automatically remapped.
|
||||
* \param[in] count the number of publishers to wait for.
|
||||
* \param[in] timeout elapsed time to wait for publishers.
|
||||
* \return `true` if the number of publishers is greater than or equal to the provided count, or
|
||||
* `false` if a timeout occurs.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
bool
|
||||
wait_for_publishers(
|
||||
const std::string & topic_name,
|
||||
size_t count,
|
||||
const std::chrono::nanoseconds & timeout) const = 0;
|
||||
};
|
||||
|
||||
} // namespace node_interfaces
|
||||
|
||||
@@ -533,6 +533,31 @@ NodeGraph::get_subscriptions_info_by_topic(
|
||||
rcl_get_subscriptions_info_by_topic);
|
||||
}
|
||||
|
||||
bool
|
||||
NodeGraph::wait_for_publishers(
|
||||
const std::string & topic_name,
|
||||
size_t count,
|
||||
const std::chrono::nanoseconds & timeout) const
|
||||
{
|
||||
// TODO(jacobperron): Guard against concurrent use of graph guard condition
|
||||
// (e.g. with GraphListener)
|
||||
// rcl_wait_for_publishers() also uses the graph guard condition
|
||||
auto rcl_node_handle = node_base_->get_rcl_node_handle();
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
bool success = false;
|
||||
rcl_ret_t ret = rcl_wait_for_publishers(
|
||||
rcl_node_handle,
|
||||
&allocator,
|
||||
topic_name.c_str(),
|
||||
count,
|
||||
timeout.count(),
|
||||
&success);
|
||||
if (ret != RCL_RET_OK && ret != RCL_RET_TIMEOUT) {
|
||||
throw_from_rcl_error(ret, "error while waiting for publishers");
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
std::string &
|
||||
rclcpp::TopicEndpointInfo::node_name()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user