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
59  std::map<std::string, std::vector<std::string>>
60  get_topic_names_and_types(bool no_demangle = false) const;
61 
63  virtual
64  std::map<std::string, std::vector<std::string>>
65  get_service_names_and_types() const;
66 
68  virtual
69  std::vector<std::string>
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 *
85  get_graph_guard_condition() const;
86 
88  virtual
89  void
90  notify_graph_change();
91 
93  virtual
94  void
95  notify_shutdown();
96 
98  virtual
99  rclcpp::event::Event::SharedPtr
100  get_graph_event();
101 
103  virtual
104  void
105  wait_for_graph_change(
106  rclcpp::event::Event::SharedPtr event,
107  std::chrono::nanoseconds timeout);
108 
110  virtual
111  size_t
112  count_graph_users();
113 
114 private:
115  RCLCPP_DISABLE_COPY(NodeGraph)
116 
117 
119 
121  std::shared_ptr<rclcpp::graph_listener::GraphListener> graph_listener_;
123  std::atomic_bool should_add_to_graph_listener_;
124 
126  mutable std::mutex graph_mutex_;
128  std::condition_variable graph_cv_;
130  std::vector<rclcpp::event::Event::WeakPtr> graph_events_;
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_
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
#define RCLCPP_SMART_PTR_ALIASES_ONLY(...)
Definition: macros.hpp:66
Definition: allocator_common.hpp:24
Implementation the NodeGraph part of the Node API.
Definition: node_graph.hpp:45
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Pure virtual interface class for the NodeGraph part of the Node API.
Definition: node_graph_interface.hpp:35