ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
node_graph_interface.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_INTERFACE_HPP_
16 #define RCLCPP__NODE_INTERFACES__NODE_GRAPH_INTERFACE_HPP_
17 
18 #include <algorithm>
19 #include <array>
20 #include <chrono>
21 #include <map>
22 #include <string>
23 #include <tuple>
24 #include <utility>
25 #include <vector>
26 
27 #include "rcl/graph.h"
28 #include "rcl/guard_condition.h"
29 
30 #include "rclcpp/event.hpp"
31 #include "rclcpp/macros.hpp"
32 #include "rclcpp/qos.hpp"
33 #include "rclcpp/visibility_control.hpp"
34 
35 namespace rclcpp
36 {
37 
38 enum class EndpointType
39 {
40  Invalid = RMW_ENDPOINT_INVALID,
41  Publisher = RMW_ENDPOINT_PUBLISHER,
42  Subscription = RMW_ENDPOINT_SUBSCRIPTION
43 };
44 
50 {
51 public:
53  RCLCPP_PUBLIC
55  : node_name_(info.node_name),
56  node_namespace_(info.node_namespace),
57  topic_type_(info.topic_type),
58  endpoint_type_(static_cast<rclcpp::EndpointType>(info.endpoint_type)),
59  qos_profile_({info.qos_profile.history, info.qos_profile.depth}, info.qos_profile)
60  {
61  std::copy(info.endpoint_gid, info.endpoint_gid + RMW_GID_STORAGE_SIZE, endpoint_gid_.begin());
62  }
63 
65  RCLCPP_PUBLIC
66  std::string &
67  node_name();
68 
70  RCLCPP_PUBLIC
71  const std::string &
72  node_name() const;
73 
75  RCLCPP_PUBLIC
76  std::string &
78 
80  RCLCPP_PUBLIC
81  const std::string &
82  node_namespace() const;
83 
85  RCLCPP_PUBLIC
86  std::string &
87  topic_type();
88 
90  RCLCPP_PUBLIC
91  const std::string &
92  topic_type() const;
93 
95  RCLCPP_PUBLIC
96  rclcpp::EndpointType &
97  endpoint_type();
98 
100  RCLCPP_PUBLIC
101  const rclcpp::EndpointType &
102  endpoint_type() const;
103 
105  RCLCPP_PUBLIC
106  std::array<uint8_t, RMW_GID_STORAGE_SIZE> &
107  endpoint_gid();
108 
110  RCLCPP_PUBLIC
111  const std::array<uint8_t, RMW_GID_STORAGE_SIZE> &
112  endpoint_gid() const;
113 
115  RCLCPP_PUBLIC
116  rclcpp::QoS &
117  qos_profile();
118 
120  RCLCPP_PUBLIC
121  const rclcpp::QoS &
122  qos_profile() const;
123 
124 private:
125  std::string node_name_;
126  std::string node_namespace_;
127  std::string topic_type_;
128  rclcpp::EndpointType endpoint_type_;
129  std::array<uint8_t, RMW_GID_STORAGE_SIZE> endpoint_gid_;
130  rclcpp::QoS qos_profile_;
131 };
132 
133 namespace node_interfaces
134 {
135 
138 {
139 public:
140  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeGraphInterface)
141 
142  RCLCPP_PUBLIC
143  virtual
144  ~NodeGraphInterface() = default;
145 
147 
156  RCLCPP_PUBLIC
157  virtual
158  std::map<std::string, std::vector<std::string>>
159  get_topic_names_and_types(bool no_demangle = false) const = 0;
160 
162 
170  RCLCPP_PUBLIC
171  virtual
172  std::map<std::string, std::vector<std::string>>
174 
176 
185  RCLCPP_PUBLIC
186  virtual
187  std::map<std::string, std::vector<std::string>>
189  const std::string & node_name,
190  const std::string & namespace_) const = 0;
191 
193 
202  RCLCPP_PUBLIC
203  virtual
204  std::map<std::string, std::vector<std::string>>
206  const std::string & node_name,
207  const std::string & namespace_) const = 0;
208 
210 
220  RCLCPP_PUBLIC
221  virtual
222  std::map<std::string, std::vector<std::string>>
224  const std::string & node_name,
225  const std::string & namespace_,
226  bool no_demangle = false) const = 0;
227 
229 
239  RCLCPP_PUBLIC
240  virtual
241  std::map<std::string, std::vector<std::string>>
243  const std::string & node_name,
244  const std::string & namespace_,
245  bool no_demangle = false) const = 0;
246 
248  /*
249  * The returned names are the actual names after remap rules applied.
250  */
251  RCLCPP_PUBLIC
252  virtual
253  std::vector<std::string>
254  get_node_names() const = 0;
255 
257  /*
258  * The returned names are the actual names after remap rules applied.
259  * The enclaves contain the runtime security artifacts, those can be
260  * used to establish secured network.
261  * See https://design.ros2.org/articles/ros2_security_enclaves.html
262  */
263  RCLCPP_PUBLIC
264  virtual
265  std::vector<std::tuple<std::string, std::string, std::string>>
267 
269  /*
270  * The returned names are the actual names after remap rules applied.
271  */
272  RCLCPP_PUBLIC
273  virtual
274  std::vector<std::pair<std::string, std::string>>
276 
278  /*
279  * \param[in] topic_name the actual topic name used; it will not be automatically remapped.
280  */
281  RCLCPP_PUBLIC
282  virtual
283  size_t
284  count_publishers(const std::string & topic_name) const = 0;
285 
287  /*
288  * \param[in] topic_name the actual topic name used; it will not be automatically remapped.
289  */
290  RCLCPP_PUBLIC
291  virtual
292  size_t
293  count_subscribers(const std::string & topic_name) const = 0;
294 
296  RCLCPP_PUBLIC
297  virtual
298  const rcl_guard_condition_t *
300 
302 
311  RCLCPP_PUBLIC
312  virtual
313  void
315 
317  RCLCPP_PUBLIC
318  virtual
319  void
321 
323 
328  RCLCPP_PUBLIC
329  virtual
330  rclcpp::Event::SharedPtr
332 
334 
341  RCLCPP_PUBLIC
342  virtual
343  void
345  rclcpp::Event::SharedPtr event,
346  std::chrono::nanoseconds timeout) = 0;
347 
349 
352  RCLCPP_PUBLIC
353  virtual
354  size_t
355  count_graph_users() const = 0;
356 
358 
364  RCLCPP_PUBLIC
365  virtual
366  std::vector<rclcpp::TopicEndpointInfo>
367  get_publishers_info_by_topic(const std::string & topic_name, bool no_mangle = false) const = 0;
368 
370 
376  RCLCPP_PUBLIC
377  virtual
378  std::vector<rclcpp::TopicEndpointInfo>
379  get_subscriptions_info_by_topic(const std::string & topic_name, bool no_mangle = false) const = 0;
380 };
381 
382 } // namespace node_interfaces
383 } // namespace rclcpp
384 
385 #endif // RCLCPP__NODE_INTERFACES__NODE_GRAPH_INTERFACE_HPP_
Encapsulation of Quality of Service settings.
Definition: qos.hpp:111
RCLCPP_PUBLIC TopicEndpointInfo(const rcl_topic_endpoint_info_t &info)
Construct a TopicEndpointInfo from a rcl_topic_endpoint_info_t.
RCLCPP_PUBLIC std::string & node_name()
Get a mutable reference to the node name.
Definition: node_graph.cpp:722
RCLCPP_PUBLIC std::string & node_namespace()
Get a mutable reference to the node namespace.
Definition: node_graph.cpp:734
RCLCPP_PUBLIC std::string & topic_type()
Get a mutable reference to the topic type string.
Definition: node_graph.cpp:746
RCLCPP_PUBLIC rclcpp::QoS & qos_profile()
Get a mutable reference to the QoS profile of the topic endpoint.
Definition: node_graph.cpp:782
RCLCPP_PUBLIC rclcpp::EndpointType & endpoint_type()
Get a mutable reference to the topic endpoint type.
Definition: node_graph.cpp:758
RCLCPP_PUBLIC std::array< uint8_t, RMW_GID_STORAGE_SIZE > & endpoint_gid()
Get a mutable reference to the GID of the topic endpoint.
Definition: node_graph.cpp:770
Pure virtual interface class for the NodeGraph part of the Node API.
virtual RCLCPP_PUBLIC rclcpp::Event::SharedPtr get_graph_event()=0
Return a graph event, which will be set anytime a graph change occurs.
virtual 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 =0
Return a map of existing service names and types with a specific node.
virtual 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 =0
Return a map of existing topic names to list of topic types for a specific node.
virtual RCLCPP_PUBLIC std::vector< std::pair< std::string, std::string > > get_node_names_and_namespaces() const =0
Return a vector of existing node names and namespaces (pair of string).
virtual RCLCPP_PUBLIC std::vector< rclcpp::TopicEndpointInfo > get_subscriptions_info_by_topic(const std::string &topic_name, bool no_mangle=false) const =0
Return the topic endpoint information about subscriptions on a given topic.
virtual 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 =0
Return a map of existing topic names to list of topic types for a specific node.
virtual RCLCPP_PUBLIC void notify_shutdown()=0
Notify any and all blocking node actions that shutdown has occurred.
virtual RCLCPP_PUBLIC std::vector< std::tuple< std::string, std::string, std::string > > get_node_names_with_enclaves() const =0
Return a vector of existing node names, namespaces and enclaves (tuple of string).
virtual RCLCPP_PUBLIC size_t count_subscribers(const std::string &topic_name) const =0
Return the number of subscribers who have created a subscription for a given topic.
virtual 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 =0
Return a map of existing service names to list of service types for a specific node.
virtual RCLCPP_PUBLIC std::vector< rclcpp::TopicEndpointInfo > get_publishers_info_by_topic(const std::string &topic_name, bool no_mangle=false) const =0
Return the topic endpoint information about publishers on a given topic.
virtual RCLCPP_PUBLIC void notify_graph_change()=0
Notify threads waiting on graph changes.
virtual RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_service_names_and_types() const =0
Return a map of existing service names to list of service types.
virtual RCLCPP_PUBLIC std::vector< std::string > get_node_names() const =0
Return a vector of existing node names (string).
virtual RCLCPP_PUBLIC size_t count_graph_users() const =0
Return the number of on loan graph events, see get_graph_event().
virtual RCLCPP_PUBLIC void wait_for_graph_change(rclcpp::Event::SharedPtr event, std::chrono::nanoseconds timeout)=0
Wait for a graph event to occur by waiting on an Event to become set.
virtual RCLCPP_PUBLIC std::map< std::string, std::vector< std::string > > get_topic_names_and_types(bool no_demangle=false) const =0
Return a map of existing topic names to list of topic types.
virtual RCLCPP_PUBLIC const rcl_guard_condition_t * get_graph_guard_condition() const =0
Return the rcl guard condition which is triggered when the ROS graph changes.
virtual RCLCPP_PUBLIC size_t count_publishers(const std::string &topic_name) const =0
Return the number of publishers that are advertised on a given topic.
rmw_topic_endpoint_info_t rcl_topic_endpoint_info_t
Definition: graph.h:45
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Handle for a rcl guard condition.