15 #ifndef RCLCPP__GRAPH_LISTENER_HPP_
16 #define RCLCPP__GRAPH_LISTENER_HPP_
26 #include "rclcpp/context.hpp"
27 #include "rclcpp/guard_condition.hpp"
28 #include "rclcpp/macros.hpp"
29 #include "rclcpp/node_interfaces/node_graph_interface.hpp"
30 #include "rclcpp/visibility_control.hpp"
35 namespace graph_listener
43 : std::runtime_error(
"GraphListener already shutdown") {}
51 : std::runtime_error(
"node already added") {}
59 : std::runtime_error(
"node not found") {}
63 class GraphListener :
public std::enable_shared_from_this<GraphListener>
67 explicit GraphListener(
const rclcpp::Context::SharedPtr & parent_context);
149 shutdown(
const std::nothrow_t &) noexcept;
190 std::shared_ptr<rcl_context_t> rcl_parent_context_;
192 std::thread listener_thread_;
194 std::atomic_bool is_shutdown_;
195 mutable std::mutex shutdown_mutex_;
197 mutable std::mutex node_graph_interfaces_barrier_mutex_;
198 mutable std::mutex node_graph_interfaces_mutex_;
199 std::vector<rclcpp::node_interfaces::NodeGraphInterface *> node_graph_interfaces_;
A condition that can be waited on in a single wait set and asynchronously triggered.
Thrown when a function is called on a GraphListener that is already shutdown.
Notifies many nodes of graph changes by listening in a thread.
virtual RCLCPP_PUBLIC void start_if_not_started()
Start the graph listener's listen thread if it hasn't been started.
virtual RCLCPP_PUBLIC void run()
Main function for the listening thread.
virtual RCLCPP_PUBLIC void shutdown()
Stop the listening thread.
virtual RCLCPP_PUBLIC bool is_shutdown()
Return true if shutdown() has been called, else false.
virtual RCLCPP_PUBLIC bool has_node(rclcpp::node_interfaces::NodeGraphInterface *node_graph)
Return true if the given node is in the graph listener's list of nodes.
virtual RCLCPP_PUBLIC void add_node(rclcpp::node_interfaces::NodeGraphInterface *node_graph)
Add a node to the graph listener's list of nodes.
virtual RCLCPP_PUBLIC bool is_started()
Return true if the graph listener was started.
virtual RCLCPP_PUBLIC void remove_node(rclcpp::node_interfaces::NodeGraphInterface *node_graph)
Remove a node from the graph listener's list of nodes.
Thrown when a node has already been added to the GraphListener.
Thrown when the given node is not in the GraphListener.
Pure virtual interface class for the NodeGraph part of the Node API.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Container for subscription's, guard condition's, etc to be waited on.
RCL_PUBLIC RCL_WARN_UNUSED rcl_wait_set_t rcl_get_zero_initialized_wait_set(void)
Return a rcl_wait_set_t struct with members set to NULL.