ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
node_graph.hpp
1 // Copyright 2016-2017 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__NODE_INTERFACES__NODE_GRAPH_HPP_
16 #define RCLCPP__NODE_INTERFACES__NODE_GRAPH_HPP_
17 
18 #include <chrono>
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <tuple>
24 #include <utility>
25 #include <vector>
26 
27 #include "rcl/guard_condition.h"
28 
29 #include "rclcpp/event.hpp"
30 #include "rclcpp/macros.hpp"
31 #include "rclcpp/node_interfaces/node_base_interface.hpp"
32 #include "rclcpp/node_interfaces/node_graph_interface.hpp"
33 #include "rclcpp/visibility_control.hpp"
34 #include "rmw/topic_endpoint_info_array.h"
35 
36 namespace rclcpp
37 {
38 
39 namespace graph_listener
40 {
41 class GraphListener;
42 } // namespace graph_listener
43 
44 namespace node_interfaces
45 {
46 
49 {
50 public:
51  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeGraph)
52 
53  RCLCPP_PUBLIC
55 
56  RCLCPP_PUBLIC
57  virtual
58  ~NodeGraph();
59 
60  RCLCPP_PUBLIC
61  std::map<std::string, std::vector<std::string>>
62  get_topic_names_and_types(bool no_demangle = false) const override;
63 
64  RCLCPP_PUBLIC
65  std::map<std::string, std::vector<std::string>>
66  get_service_names_and_types() const override;
67 
68  RCLCPP_PUBLIC
69  std::map<std::string, std::vector<std::string>>
71  const std::string & node_name,
72  const std::string & namespace_) const override;
73 
74  RCLCPP_PUBLIC
75  std::map<std::string, std::vector<std::string>>
77  const std::string & node_name,
78  const std::string & namespace_) const override;
79 
80  RCLCPP_PUBLIC
81  std::map<std::string, std::vector<std::string>>
83  const std::string & node_name,
84  const std::string & namespace_,
85  bool no_demangle = false) const override;
86 
87  RCLCPP_PUBLIC
88  std::map<std::string, std::vector<std::string>>
90  const std::string & node_name,
91  const std::string & namespace_,
92  bool no_demangle = false) const override;
93 
94  RCLCPP_PUBLIC
95  std::vector<std::string>
96  get_node_names() const override;
97 
98  RCLCPP_PUBLIC
99  std::vector<std::tuple<std::string, std::string, std::string>>
100  get_node_names_with_enclaves() const override;
101 
102  RCLCPP_PUBLIC
103  std::vector<std::pair<std::string, std::string>>
104  get_node_names_and_namespaces() const override;
105 
106  RCLCPP_PUBLIC
107  size_t
108  count_publishers(const std::string & topic_name) const override;
109 
110  RCLCPP_PUBLIC
111  size_t
112  count_subscribers(const std::string & topic_name) const override;
113 
114  RCLCPP_PUBLIC
115  const rcl_guard_condition_t *
116  get_graph_guard_condition() const override;
117 
118  RCLCPP_PUBLIC
119  void
120  notify_graph_change() override;
121 
122  RCLCPP_PUBLIC
123  void
124  notify_shutdown() override;
125 
126  RCLCPP_PUBLIC
127  rclcpp::Event::SharedPtr
128  get_graph_event() override;
129 
130  RCLCPP_PUBLIC
131  void
133  rclcpp::Event::SharedPtr event,
134  std::chrono::nanoseconds timeout) override;
135 
136  RCLCPP_PUBLIC
137  size_t
138  count_graph_users() const override;
139 
140  RCLCPP_PUBLIC
141  std::vector<rclcpp::TopicEndpointInfo>
143  const std::string & topic_name,
144  bool no_mangle = false) const override;
145 
146  RCLCPP_PUBLIC
147  std::vector<rclcpp::TopicEndpointInfo>
149  const std::string & topic_name,
150  bool no_mangle = false) const override;
151 
152 private:
153  RCLCPP_DISABLE_COPY(NodeGraph)
154 
155 
157 
159  std::shared_ptr<rclcpp::graph_listener::GraphListener> graph_listener_;
161  std::atomic_bool should_add_to_graph_listener_;
162 
164  mutable std::mutex graph_mutex_;
166  std::condition_variable graph_cv_;
168  std::vector<rclcpp::Event::WeakPtr> graph_events_;
170 
171  std::atomic_size_t graph_users_count_;
172 };
173 
174 } // namespace node_interfaces
175 } // namespace rclcpp
176 
177 #endif // RCLCPP__NODE_INTERFACES__NODE_GRAPH_HPP_
Pure virtual interface class for the NodeBase part of the Node API.
Pure virtual interface class for the NodeGraph part of the Node API.
Implementation the NodeGraph part of the Node API.
Definition: node_graph.hpp:49
RCLCPP_PUBLIC std::vector< std::string > get_node_names() const override
Return a vector of existing node names (string).
Definition: node_graph.cpp:293
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_service_names_and_types() const override
Return a map of existing service names to list of service types.
Definition: node_graph.cpp:100
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_publisher_names_and_types_by_node(const std::string &node_name, const std::string &namespace_, bool no_demangle=false) const override
Return a map of existing topic names to list of topic types for a specific node.
Definition: node_graph.cpp:219
RCLCPP_PUBLIC std::vector< rclcpp::TopicEndpointInfo > get_publishers_info_by_topic(const std::string &topic_name, bool no_mangle=false) const override
Return the topic endpoint information about publishers on a given topic.
Definition: node_graph.cpp:697
RCLCPP_PUBLIC std::vector< std::pair< std::string, std::string > > get_node_names_and_namespaces() const override
Return a vector of existing node names and namespaces (pair of string).
Definition: node_graph.cpp:396
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_subscriber_names_and_types_by_node(const std::string &node_name, const std::string &namespace_, bool no_demangle=false) const override
Return a map of existing topic names to list of topic types for a specific node.
Definition: node_graph.cpp:256
RCLCPP_PUBLIC size_t count_subscribers(const std::string &topic_name) const override
Return the number of subscribers who have created a subscription for a given topic.
Definition: node_graph.cpp:480
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_client_names_and_types_by_node(const std::string &node_name, const std::string &namespace_) const override
Return a map of existing service names and types with a specific node.
Definition: node_graph.cpp:184
RCLCPP_PUBLIC std::vector< rclcpp::TopicEndpointInfo > get_subscriptions_info_by_topic(const std::string &topic_name, bool no_mangle=false) const override
Return the topic endpoint information about subscriptions on a given topic.
Definition: node_graph.cpp:710
RCLCPP_PUBLIC size_t count_graph_users() const override
Return the number of on loan graph events, see get_graph_event().
Definition: node_graph.cpp:602
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_topic_names_and_types(bool no_demangle=false) const override
Return a map of existing topic names to list of topic types.
Definition: node_graph.cpp:58
RCLCPP_PUBLIC void wait_for_graph_change(rclcpp::Event::SharedPtr event, std::chrono::nanoseconds timeout) override
Wait for a graph event to occur by waiting on an Event to become set.
Definition: node_graph.cpp:570
RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_service_names_and_types_by_node(const std::string &node_name, const std::string &namespace_) const override
Return a map of existing service names to list of service types for a specific node.
Definition: node_graph.cpp:142
RCLCPP_PUBLIC rclcpp::Event::SharedPtr get_graph_event() override
Return a graph event, which will be set anytime a graph change occurs.
Definition: node_graph.cpp:553
RCLCPP_PUBLIC void notify_shutdown() override
Notify any and all blocking node actions that shutdown has occurred.
Definition: node_graph.cpp:546
RCLCPP_PUBLIC std::vector< std::tuple< std::string, std::string, std::string > > get_node_names_with_enclaves() const override
Return a vector of existing node names, namespaces and enclaves (tuple of string).
Definition: node_graph.cpp:321
RCLCPP_PUBLIC size_t count_publishers(const std::string &topic_name) const override
Return the number of publishers that are advertised on a given topic.
Definition: node_graph.cpp:458
RCLCPP_PUBLIC void notify_graph_change() override
Notify threads waiting on graph changes.
Definition: node_graph.cpp:508
RCLCPP_PUBLIC const rcl_guard_condition_t * get_graph_guard_condition() const override
Return the rcl guard condition which is triggered when the ROS graph changes.
Definition: node_graph.cpp:502
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Handle for a rcl guard condition.