ROS 2 rclcpp + rcl - jazzy  jazzy
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  topic_type_hash_(info.topic_type_hash)
59  {
60  if (!info.node_name || !info.node_namespace || !info.topic_type) {
61  throw std::invalid_argument("Constructor TopicEndpointInfo with invalid topic endpoint info");
62  }
63  node_name_ = info.node_name;
64  node_namespace_ = info.node_namespace;
65  topic_type_ = info.topic_type;
66 
67  std::copy(info.endpoint_gid, info.endpoint_gid + RMW_GID_STORAGE_SIZE, endpoint_gid_.begin());
68  }
69 
71  RCLCPP_PUBLIC
72  std::string &
73  node_name();
74 
76  RCLCPP_PUBLIC
77  const std::string &
78  node_name() const;
79 
81  RCLCPP_PUBLIC
82  std::string &
84 
86  RCLCPP_PUBLIC
87  const std::string &
88  node_namespace() const;
89 
91  RCLCPP_PUBLIC
92  std::string &
93  topic_type();
94 
96  RCLCPP_PUBLIC
97  const std::string &
98  topic_type() const;
99 
101  RCLCPP_PUBLIC
102  rclcpp::EndpointType &
103  endpoint_type();
104 
106  RCLCPP_PUBLIC
107  const rclcpp::EndpointType &
108  endpoint_type() const;
109 
111  RCLCPP_PUBLIC
112  std::array<uint8_t, RMW_GID_STORAGE_SIZE> &
113  endpoint_gid();
114 
116  RCLCPP_PUBLIC
117  const std::array<uint8_t, RMW_GID_STORAGE_SIZE> &
118  endpoint_gid() const;
119 
121  RCLCPP_PUBLIC
122  rclcpp::QoS &
123  qos_profile();
124 
126  RCLCPP_PUBLIC
127  const rclcpp::QoS &
128  qos_profile() const;
129 
131  RCLCPP_PUBLIC
132  rosidl_type_hash_t &
133  topic_type_hash();
134 
136  RCLCPP_PUBLIC
137  const rosidl_type_hash_t &
138  topic_type_hash() const;
139 
140 private:
141  std::string node_name_;
142  std::string node_namespace_;
143  std::string topic_type_;
144  rclcpp::EndpointType endpoint_type_;
145  std::array<uint8_t, RMW_GID_STORAGE_SIZE> endpoint_gid_;
146  rclcpp::QoS qos_profile_;
147  rosidl_type_hash_t topic_type_hash_;
148 };
149 
150 namespace node_interfaces
151 {
152 
155 {
156 public:
157  RCLCPP_SMART_PTR_ALIASES_ONLY(NodeGraphInterface)
158 
159  RCLCPP_PUBLIC
160  virtual
161  ~NodeGraphInterface() = default;
162 
164 
173  RCLCPP_PUBLIC
174  virtual
175  std::map<std::string, std::vector<std::string>>
176  get_topic_names_and_types(bool no_demangle = false) const = 0;
177 
179 
187  RCLCPP_PUBLIC
188  virtual
189  std::map<std::string, std::vector<std::string>>
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 
219  RCLCPP_PUBLIC
220  virtual
221  std::map<std::string, std::vector<std::string>>
223  const std::string & node_name,
224  const std::string & namespace_) const = 0;
225 
227 
237  RCLCPP_PUBLIC
238  virtual
239  std::map<std::string, std::vector<std::string>>
241  const std::string & node_name,
242  const std::string & namespace_,
243  bool no_demangle = false) const = 0;
244 
246 
256  RCLCPP_PUBLIC
257  virtual
258  std::map<std::string, std::vector<std::string>>
260  const std::string & node_name,
261  const std::string & namespace_,
262  bool no_demangle = false) const = 0;
263 
265  /*
266  * The returned names are the actual names after remap rules applied.
267  */
268  RCLCPP_PUBLIC
269  virtual
270  std::vector<std::string>
271  get_node_names() const = 0;
272 
274  /*
275  * The returned names are the actual names after remap rules applied.
276  * The enclaves contain the runtime security artifacts, those can be
277  * used to establish secured network.
278  * See https://design.ros2.org/articles/ros2_security_enclaves.html
279  */
280  RCLCPP_PUBLIC
281  virtual
282  std::vector<std::tuple<std::string, std::string, std::string>>
284 
286  /*
287  * The returned names are the actual names after remap rules applied.
288  */
289  RCLCPP_PUBLIC
290  virtual
291  std::vector<std::pair<std::string, std::string>>
293 
295  /*
296  * \param[in] topic_name the actual topic name used; it will not be automatically remapped.
297  */
298  RCLCPP_PUBLIC
299  virtual
300  size_t
301  count_publishers(const std::string & topic_name) const = 0;
302 
304  /*
305  * \param[in] topic_name the actual topic name used; it will not be automatically remapped.
306  */
307  RCLCPP_PUBLIC
308  virtual
309  size_t
310  count_subscribers(const std::string & topic_name) const = 0;
311 
313  /*
314  * \param[in] service_name the actual service name used; it will not be automatically remapped.
315  */
316  RCLCPP_PUBLIC
317  virtual
318  size_t
319  count_clients(const std::string & service_name) const = 0;
320 
322  /*
323  * \param[in] service_name the actual service name used; it will not be automatically remapped.
324  */
325  RCLCPP_PUBLIC
326  virtual
327  size_t
328  count_services(const std::string & service_name) const = 0;
329 
331  RCLCPP_PUBLIC
332  virtual
333  const rcl_guard_condition_t *
335 
337 
346  RCLCPP_PUBLIC
347  virtual
348  void
350 
352  RCLCPP_PUBLIC
353  virtual
354  void
356 
358 
363  RCLCPP_PUBLIC
364  virtual
365  rclcpp::Event::SharedPtr
367 
369 
376  RCLCPP_PUBLIC
377  virtual
378  void
380  rclcpp::Event::SharedPtr event,
381  std::chrono::nanoseconds timeout) = 0;
382 
384 
387  RCLCPP_PUBLIC
388  virtual
389  size_t
390  count_graph_users() const = 0;
391 
393 
399  RCLCPP_PUBLIC
400  virtual
401  std::vector<rclcpp::TopicEndpointInfo>
402  get_publishers_info_by_topic(const std::string & topic_name, bool no_mangle = false) const = 0;
403 
405 
411  RCLCPP_PUBLIC
412  virtual
413  std::vector<rclcpp::TopicEndpointInfo>
414  get_subscriptions_info_by_topic(const std::string & topic_name, bool no_mangle = false) const = 0;
415 };
416 
417 } // namespace node_interfaces
418 } // namespace rclcpp
419 
420 RCLCPP_NODE_INTERFACE_HELPERS_SUPPORT(rclcpp::node_interfaces::NodeGraphInterface, graph)
421 
422 #endif // RCLCPP__NODE_INTERFACES__NODE_GRAPH_INTERFACE_HPP_
Encapsulation of Quality of Service settings.
Definition: qos.hpp:116
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:765
RCLCPP_PUBLIC std::string & node_namespace()
Get a mutable reference to the node namespace.
Definition: node_graph.cpp:777
RCLCPP_PUBLIC rosidl_type_hash_t & topic_type_hash()
Get a mutable reference to the type hash of the topic endpoint.
Definition: node_graph.cpp:837
RCLCPP_PUBLIC std::string & topic_type()
Get a mutable reference to the topic type string.
Definition: node_graph.cpp:789
RCLCPP_PUBLIC rclcpp::QoS & qos_profile()
Get a mutable reference to the QoS profile of the topic endpoint.
Definition: node_graph.cpp:825
RCLCPP_PUBLIC rclcpp::EndpointType & endpoint_type()
Get a mutable reference to the topic endpoint type.
Definition: node_graph.cpp:801
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:813
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 size_t count_clients(const std::string &service_name) const =0
Return the number of clients created for a given service.
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 size_t count_services(const std::string &service_name) const =0
Return the number of services created for a given service.
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.