ROS 2 rclcpp + rcl - lyrical  lyrical
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 <atomic>
19 #include <chrono>
20 #include <condition_variable>
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 #include <tuple>
26 #include <utility>
27 #include <vector>
28 
29 #include "rcl/guard_condition.h"
30 
31 #include "rclcpp/event.hpp"
32 #include "rclcpp/macros.hpp"
33 #include "rclcpp/node_interfaces/node_base_interface.hpp"
34 #include "rclcpp/node_interfaces/node_graph_interface.hpp"
35 #include "rclcpp/visibility_control.hpp"
36 #include "rmw/service_endpoint_info_array.h"
37 #include "rmw/topic_endpoint_info_array.h"
38 
39 namespace rclcpp
40 {
41 
42 namespace graph_listener
43 {
44 class GraphListener;
45 } // namespace graph_listener
46 
47 namespace node_interfaces
48 {
49 
52 {
53 public:
54  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeGraph)
55 
56  RCLCPP_PUBLIC
58 
59  RCLCPP_PUBLIC
60  virtual
61  ~NodeGraph();
62 
63  RCLCPP_PUBLIC
64  std::map<std::string, std::vector<std::string>>
65  get_topic_names_and_types(bool no_demangle = false) const override;
66 
67  RCLCPP_PUBLIC
68  std::map<std::string, std::vector<std::string>>
69  get_service_names_and_types() const override;
70 
71  RCLCPP_PUBLIC
72  std::map<std::string, std::vector<std::string>>
74  const std::string & node_name,
75  const std::string & namespace_) const override;
76 
77  RCLCPP_PUBLIC
78  std::map<std::string, std::vector<std::string>>
80  const std::string & node_name,
81  const std::string & namespace_) const override;
82 
83  RCLCPP_PUBLIC
84  std::map<std::string, std::vector<std::string>>
86  const std::string & node_name,
87  const std::string & namespace_,
88  bool no_demangle = false) const override;
89 
90  RCLCPP_PUBLIC
91  std::map<std::string, std::vector<std::string>>
93  const std::string & node_name,
94  const std::string & namespace_,
95  bool no_demangle = false) const override;
96 
97  RCLCPP_PUBLIC
98  std::vector<std::string>
99  get_node_names() const override;
100 
101  RCLCPP_PUBLIC
102  std::vector<std::tuple<std::string, std::string, std::string>>
103  get_node_names_with_enclaves() const override;
104 
105  RCLCPP_PUBLIC
106  std::vector<std::pair<std::string, std::string>>
107  get_node_names_and_namespaces() const override;
108 
109  RCLCPP_PUBLIC
110  size_t
111  count_publishers(const std::string & topic_name) const override;
112 
113  RCLCPP_PUBLIC
114  size_t
115  count_subscribers(const std::string & topic_name) const override;
116 
117  RCLCPP_PUBLIC
118  size_t
119  count_clients(const std::string & service_name) const override;
120 
121  RCLCPP_PUBLIC
122  size_t
123  count_services(const std::string & service_name) const override;
124 
125  RCLCPP_PUBLIC
126  const rcl_guard_condition_t *
127  get_graph_guard_condition() const override;
128 
129  RCLCPP_PUBLIC
130  void
131  notify_graph_change() override;
132 
133  RCLCPP_PUBLIC
134  void
135  notify_shutdown() override;
136 
137  RCLCPP_PUBLIC
138  rclcpp::Event::SharedPtr
139  get_graph_event() override;
140 
141  RCLCPP_PUBLIC
142  void
144  rclcpp::Event::SharedPtr event,
145  std::chrono::nanoseconds timeout) override;
146 
147  RCLCPP_PUBLIC
148  size_t
149  count_graph_users() const override;
150 
151  RCLCPP_PUBLIC
152  std::vector<rclcpp::TopicEndpointInfo>
154  const std::string & topic_name,
155  bool no_mangle = false) const override;
156 
157  RCLCPP_PUBLIC
158  std::vector<rclcpp::TopicEndpointInfo>
160  const std::string & topic_name,
161  bool no_mangle = false) const override;
162 
163  RCLCPP_PUBLIC
164  std::vector<rclcpp::ServiceEndpointInfo>
166  const std::string & service_name,
167  bool no_mangle = false) const override;
168 
169  RCLCPP_PUBLIC
170  std::vector<rclcpp::ServiceEndpointInfo>
172  const std::string & service_name,
173  bool no_mangle = false) const override;
174 
175 private:
176  RCLCPP_DISABLE_COPY(NodeGraph)
177 
178 
180 
182  std::atomic_bool should_add_to_graph_listener_;
183 
185  mutable std::mutex graph_mutex_;
187  std::condition_variable graph_cv_;
189  std::vector<rclcpp::Event::WeakPtr> graph_events_;
191 
192  std::atomic_size_t graph_users_count_;
193 };
194 
195 } // namespace node_interfaces
196 } // namespace rclcpp
197 
198 #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:52
RCLCPP_PUBLIC std::vector< std::string > get_node_names() const override
Return a vector of existing node names (string).
Definition: node_graph.cpp:291
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:98
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:217
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:734
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:394
RCLCPP_PUBLIC size_t count_services(const std::string &service_name) const override
Return the number of services created for a given service.
Definition: node_graph.cpp:517
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:254
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:473
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:182
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:747
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:638
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:56
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:606
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:140
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:589
RCLCPP_PUBLIC std::vector< rclcpp::ServiceEndpointInfo > get_clients_info_by_service(const std::string &service_name, bool no_mangle=false) const override
Return the service endpoint information about clients on a given service.
Definition: node_graph.cpp:851
RCLCPP_PUBLIC void notify_shutdown() override
Notify any and all blocking node actions that shutdown has occurred.
Definition: node_graph.cpp:582
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:319
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:451
RCLCPP_PUBLIC size_t count_clients(const std::string &service_name) const override
Return the number of clients created for a given service.
Definition: node_graph.cpp:495
RCLCPP_PUBLIC std::vector< rclcpp::ServiceEndpointInfo > get_servers_info_by_service(const std::string &service_name, bool no_mangle=false) const override
Return the service endpoint information about servers on a given service.
Definition: node_graph.cpp:864
RCLCPP_PUBLIC void notify_graph_change() override
Notify threads waiting on graph changes.
Definition: node_graph.cpp:545
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:539
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Handle for a rcl guard condition.