ROS 2 rclcpp + rcl - jazzy  jazzy
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/topic_endpoint_info_array.h"
37 
38 namespace rclcpp
39 {
40 
41 namespace graph_listener
42 {
43 class GraphListener;
44 } // namespace graph_listener
45 
46 namespace node_interfaces
47 {
48 
51 {
52 public:
53  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeGraph)
54 
55  RCLCPP_PUBLIC
57 
58  RCLCPP_PUBLIC
59  virtual
60  ~NodeGraph();
61 
62  RCLCPP_PUBLIC
63  std::map<std::string, std::vector<std::string>>
64  get_topic_names_and_types(bool no_demangle = false) const override;
65 
66  RCLCPP_PUBLIC
67  std::map<std::string, std::vector<std::string>>
68  get_service_names_and_types() const override;
69 
70  RCLCPP_PUBLIC
71  std::map<std::string, std::vector<std::string>>
73  const std::string & node_name,
74  const std::string & namespace_) const override;
75 
76  RCLCPP_PUBLIC
77  std::map<std::string, std::vector<std::string>>
79  const std::string & node_name,
80  const std::string & namespace_) const override;
81 
82  RCLCPP_PUBLIC
83  std::map<std::string, std::vector<std::string>>
85  const std::string & node_name,
86  const std::string & namespace_,
87  bool no_demangle = false) const override;
88 
89  RCLCPP_PUBLIC
90  std::map<std::string, std::vector<std::string>>
92  const std::string & node_name,
93  const std::string & namespace_,
94  bool no_demangle = false) const override;
95 
96  RCLCPP_PUBLIC
97  std::vector<std::string>
98  get_node_names() const override;
99 
100  RCLCPP_PUBLIC
101  std::vector<std::tuple<std::string, std::string, std::string>>
102  get_node_names_with_enclaves() const override;
103 
104  RCLCPP_PUBLIC
105  std::vector<std::pair<std::string, std::string>>
106  get_node_names_and_namespaces() const override;
107 
108  RCLCPP_PUBLIC
109  size_t
110  count_publishers(const std::string & topic_name) const override;
111 
112  RCLCPP_PUBLIC
113  size_t
114  count_subscribers(const std::string & topic_name) const override;
115 
116  RCLCPP_PUBLIC
117  size_t
118  count_clients(const std::string & service_name) const override;
119 
120  RCLCPP_PUBLIC
121  size_t
122  count_services(const std::string & service_name) const override;
123 
124  RCLCPP_PUBLIC
125  const rcl_guard_condition_t *
126  get_graph_guard_condition() const override;
127 
128  RCLCPP_PUBLIC
129  void
130  notify_graph_change() override;
131 
132  RCLCPP_PUBLIC
133  void
134  notify_shutdown() override;
135 
136  RCLCPP_PUBLIC
137  rclcpp::Event::SharedPtr
138  get_graph_event() override;
139 
140  RCLCPP_PUBLIC
141  void
143  rclcpp::Event::SharedPtr event,
144  std::chrono::nanoseconds timeout) override;
145 
146  RCLCPP_PUBLIC
147  size_t
148  count_graph_users() const override;
149 
150  RCLCPP_PUBLIC
151  std::vector<rclcpp::TopicEndpointInfo>
153  const std::string & topic_name,
154  bool no_mangle = false) const override;
155 
156  RCLCPP_PUBLIC
157  std::vector<rclcpp::TopicEndpointInfo>
159  const std::string & topic_name,
160  bool no_mangle = false) const override;
161 
162 private:
163  RCLCPP_DISABLE_COPY(NodeGraph)
164 
165 
167 
169  std::shared_ptr<rclcpp::graph_listener::GraphListener> graph_listener_;
171  std::atomic_bool should_add_to_graph_listener_;
172 
174  mutable std::mutex graph_mutex_;
176  std::condition_variable graph_cv_;
178  std::vector<rclcpp::Event::WeakPtr> graph_events_;
180 
181  std::atomic_size_t graph_users_count_;
182 };
183 
184 } // namespace node_interfaces
185 } // namespace rclcpp
186 
187 #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:51
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:740
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 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:524
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:753
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:645
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:613
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:596
RCLCPP_PUBLIC void notify_shutdown() override
Notify any and all blocking node actions that shutdown has occurred.
Definition: node_graph.cpp:589
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 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:502
RCLCPP_PUBLIC void notify_graph_change() override
Notify threads waiting on graph changes.
Definition: node_graph.cpp:552
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:546
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Handle for a rcl guard condition.