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/node_interfaces/detail/node_interfaces_helpers.hpp"
33 #include "rclcpp/qos.hpp"
34 #include "rclcpp/visibility_control.hpp"
35 
36 namespace rclcpp
37 {
38 
39 enum class EndpointType
40 {
41  Invalid = RMW_ENDPOINT_INVALID,
42  Publisher = RMW_ENDPOINT_PUBLISHER,
43  Subscription = RMW_ENDPOINT_SUBSCRIPTION
44 };
45 
51 {
52 public:
54  RCLCPP_PUBLIC
56  : endpoint_type_(static_cast<rclcpp::EndpointType>(info.endpoint_type)),
57  qos_profile_({info.qos_profile.history, info.qos_profile.depth}, info.qos_profile)
58  {
59  if (!info.node_name || !info.node_namespace || !info.topic_type) {
60  throw std::invalid_argument("Constructor TopicEndpointInfo with invalid topic endpoint info");
61  }
62  node_name_ = info.node_name;
63  node_namespace_ = info.node_namespace;
64  topic_type_ = info.topic_type;
65 
66  std::copy(info.endpoint_gid, info.endpoint_gid + RMW_GID_STORAGE_SIZE, endpoint_gid_.begin());
67  }
68 
70  RCLCPP_PUBLIC
71  std::string &
72  node_name();
73 
75  RCLCPP_PUBLIC
76  const std::string &
77  node_name() const;
78 
80  RCLCPP_PUBLIC
81  std::string &
83 
85  RCLCPP_PUBLIC
86  const std::string &
87  node_namespace() const;
88 
90  RCLCPP_PUBLIC
91  std::string &
92  topic_type();
93 
95  RCLCPP_PUBLIC
96  const std::string &
97  topic_type() const;
98 
100  RCLCPP_PUBLIC
101  rclcpp::EndpointType &
102  endpoint_type();
103 
105  RCLCPP_PUBLIC
106  const rclcpp::EndpointType &
107  endpoint_type() const;
108 
110  RCLCPP_PUBLIC
111  std::array<uint8_t, RMW_GID_STORAGE_SIZE> &
112  endpoint_gid();
113 
115  RCLCPP_PUBLIC
116  const std::array<uint8_t, RMW_GID_STORAGE_SIZE> &
117  endpoint_gid() const;
118 
120  RCLCPP_PUBLIC
121  rclcpp::QoS &
122  qos_profile();
123 
125  RCLCPP_PUBLIC
126  const rclcpp::QoS &
127  qos_profile() const;
128 
129 private:
130  std::string node_name_;
131  std::string node_namespace_;
132  std::string topic_type_;
133  rclcpp::EndpointType endpoint_type_;
134  std::array<uint8_t, RMW_GID_STORAGE_SIZE> endpoint_gid_;
135  rclcpp::QoS qos_profile_;
136 };
137 
138 namespace node_interfaces
139 {
140 
143 {
144 public:
145  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeGraphInterface)
146 
147  RCLCPP_PUBLIC
148  virtual
149  ~NodeGraphInterface() = default;
150 
152 
161  RCLCPP_PUBLIC
162  virtual
163  std::map<std::string, std::vector<std::string>>
164  get_topic_names_and_types(bool no_demangle = false) const = 0;
165 
167 
175  RCLCPP_PUBLIC
176  virtual
177  std::map<std::string, std::vector<std::string>>
179 
181 
190  RCLCPP_PUBLIC
191  virtual
192  std::map<std::string, std::vector<std::string>>
194  const std::string & node_name,
195  const std::string & namespace_) const = 0;
196 
198 
207  RCLCPP_PUBLIC
208  virtual
209  std::map<std::string, std::vector<std::string>>
211  const std::string & node_name,
212  const std::string & namespace_) const = 0;
213 
215 
225  RCLCPP_PUBLIC
226  virtual
227  std::map<std::string, std::vector<std::string>>
229  const std::string & node_name,
230  const std::string & namespace_,
231  bool no_demangle = false) const = 0;
232 
234 
244  RCLCPP_PUBLIC
245  virtual
246  std::map<std::string, std::vector<std::string>>
248  const std::string & node_name,
249  const std::string & namespace_,
250  bool no_demangle = false) const = 0;
251 
253  /*
254  * The returned names are the actual names after remap rules applied.
255  */
256  RCLCPP_PUBLIC
257  virtual
258  std::vector<std::string>
259  get_node_names() const = 0;
260 
262  /*
263  * The returned names are the actual names after remap rules applied.
264  * The enclaves contain the runtime security artifacts, those can be
265  * used to establish secured network.
266  * See https://design.ros2.org/articles/ros2_security_enclaves.html
267  */
268  RCLCPP_PUBLIC
269  virtual
270  std::vector<std::tuple<std::string, std::string, std::string>>
272 
274  /*
275  * The returned names are the actual names after remap rules applied.
276  */
277  RCLCPP_PUBLIC
278  virtual
279  std::vector<std::pair<std::string, std::string>>
281 
283  /*
284  * \param[in] topic_name the actual topic name used; it will not be automatically remapped.
285  */
286  RCLCPP_PUBLIC
287  virtual
288  size_t
289  count_publishers(const std::string & topic_name) const = 0;
290 
292  /*
293  * \param[in] topic_name the actual topic name used; it will not be automatically remapped.
294  */
295  RCLCPP_PUBLIC
296  virtual
297  size_t
298  count_subscribers(const std::string & topic_name) const = 0;
299 
301  RCLCPP_PUBLIC
302  virtual
303  const rcl_guard_condition_t *
305 
307 
316  RCLCPP_PUBLIC
317  virtual
318  void
320 
322  RCLCPP_PUBLIC
323  virtual
324  void
326 
328 
333  RCLCPP_PUBLIC
334  virtual
335  rclcpp::Event::SharedPtr
337 
339 
346  RCLCPP_PUBLIC
347  virtual
348  void
350  rclcpp::Event::SharedPtr event,
351  std::chrono::nanoseconds timeout) = 0;
352 
354 
357  RCLCPP_PUBLIC
358  virtual
359  size_t
360  count_graph_users() const = 0;
361 
363 
369  RCLCPP_PUBLIC
370  virtual
371  std::vector<rclcpp::TopicEndpointInfo>
372  get_publishers_info_by_topic(const std::string & topic_name, bool no_mangle = false) const = 0;
373 
375 
381  RCLCPP_PUBLIC
382  virtual
383  std::vector<rclcpp::TopicEndpointInfo>
384  get_subscriptions_info_by_topic(const std::string & topic_name, bool no_mangle = false) const = 0;
385 };
386 
387 } // namespace node_interfaces
388 } // namespace rclcpp
389 
390 RCLCPP_NODE_INTERFACE_HELPERS_SUPPORT(rclcpp::node_interfaces::NodeGraphInterface, graph)
391 
392 #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.