rclcpp  master
C++ ROS Client Library API
node_graph.hpp
Go to the documentation of this file.
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 <chrono>
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 
25 #include "rcl/guard_condition.h"
26 
27 #include "rclcpp/event.hpp"
28 #include "rclcpp/macros.hpp"
32 
33 namespace rclcpp
34 {
35 
36 namespace graph_listener
37 {
38 class GraphListener;
39 } // namespace graph_listener
40 
41 namespace node_interfaces
42 {
43 
46 {
47 public:
49 
52 
54  virtual
55  ~NodeGraph();
56 
58  virtual
60  get_topic_names_and_types(bool no_demangle = false) const;
61 
63  virtual
66 
68  virtual
70  get_node_names() const;
71 
73  virtual
74  size_t
75  count_publishers(const std::string & topic_name) const;
76 
78  virtual
79  size_t
80  count_subscribers(const std::string & topic_name) const;
81 
83  virtual
84  const rcl_guard_condition_t *
86 
88  virtual
89  void
91 
93  virtual
94  void
96 
98  virtual
99  rclcpp::Event::SharedPtr
100  get_graph_event();
101 
103  virtual
104  void
106  rclcpp::Event::SharedPtr event,
107  std::chrono::nanoseconds timeout);
108 
110  virtual
111  size_t
113 
114 private:
116 
117 
119 
123  std::atomic_bool should_add_to_graph_listener_;
124 
126  mutable std::mutex graph_mutex_;
128  std::condition_variable graph_cv_;
132 
133  std::atomic_size_t graph_users_count_;
134 };
135 
136 } // namespace node_interfaces
137 } // namespace rclcpp
138 
139 #endif // RCLCPP__NODE_INTERFACES__NODE_GRAPH_HPP_
virtual void notify_graph_change()
Notify threads waiting on graph changes.
virtual std::map< std::string, std::vector< std::string > > get_topic_names_and_types(bool no_demangle=false) const
Return a map of existing topic names to list of topic types.
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
Implementation the NodeGraph part of the Node API.
Definition: node_graph.hpp:45
virtual void notify_shutdown()
Notify any and all blocking node actions that shutdown has occurred.
#define RCLCPP_SMART_PTR_ALIASES_ONLY(...)
Definition: macros.hpp:66
virtual size_t count_graph_users()
Return the number of on loan graph events, see get_graph_event().
Definition: allocator_common.hpp:24
virtual std::vector< std::string > get_node_names() const
Return a vector of existing node names (string).
virtual size_t count_publishers(const std::string &topic_name) const
Return the number of publishers that are advertised on a given topic.
virtual rclcpp::Event::SharedPtr get_graph_event()
Return a graph event, which will be set anytime a graph change occurs.
virtual const rcl_guard_condition_t * get_graph_guard_condition() const
Return the rcl guard condition which is triggered when the ROS graph changes.
Pure virtual interface class for the NodeGraph part of the Node API.
Definition: node_graph_interface.hpp:35
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
NodeGraph(rclcpp::node_interfaces::NodeBaseInterface *node_base)
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
virtual std::map< std::string, std::vector< std::string > > get_service_names_and_types() const
Return a map of existing service names to list of service types.
virtual void wait_for_graph_change(rclcpp::Event::SharedPtr event, std::chrono::nanoseconds timeout)
Wait for a graph event to occur by waiting on an Event to become set.
virtual size_t count_subscribers(const std::string &topic_name) const
Return the number of subscribers who have created a subscription for a given topic.