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 <utility>
24 #include <vector>
25 
26 #include "rcl/guard_condition.h"
27 
28 #include "rclcpp/event.hpp"
29 #include "rclcpp/macros.hpp"
34 
35 namespace rclcpp
36 {
37 
38 namespace graph_listener
39 {
40 class GraphListener;
41 } // namespace graph_listener
42 
43 namespace node_interfaces
44 {
45 
48 {
49 public:
51 
54 
56  virtual
57  ~NodeGraph();
58 
61  get_topic_names_and_types(bool no_demangle = false) const override;
62 
65  get_service_names_and_types() const override;
66 
70  const std::string & node_name,
71  const std::string & namespace_) const override;
72 
75  get_node_names() const override;
76 
79  get_node_names_and_namespaces() const override;
80 
82  size_t
83  count_publishers(const std::string & topic_name) const override;
84 
86  size_t
87  count_subscribers(const std::string & topic_name) const override;
88 
90  const rcl_guard_condition_t *
91  get_graph_guard_condition() const override;
92 
94  void
95  notify_graph_change() override;
96 
98  void
99  notify_shutdown() override;
100 
102  rclcpp::Event::SharedPtr
103  get_graph_event() override;
104 
106  void
108  rclcpp::Event::SharedPtr event,
109  std::chrono::nanoseconds timeout) override;
110 
112  size_t
113  count_graph_users() override;
114 
118  const std::string & topic_name,
119  bool no_mangle = false) const override;
120 
124  const std::string & topic_name,
125  bool no_mangle = false) const override;
126 
127 private:
129 
130 
132 
136  std::atomic_bool should_add_to_graph_listener_;
137 
139  mutable std::mutex graph_mutex_;
141  std::condition_variable graph_cv_;
145 
146  std::atomic_size_t graph_users_count_;
147 };
148 
149 } // namespace node_interfaces
150 } // namespace rclcpp
151 
152 #endif // RCLCPP__NODE_INTERFACES__NODE_GRAPH_HPP_
rclcpp::node_interfaces::NodeGraph::get_graph_event
rclcpp::Event::SharedPtr get_graph_event() override
Return a graph event, which will be set anytime a graph change occurs.
rclcpp::node_interfaces::NodeGraph::get_service_names_and_types_by_node
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 override
Return a map of existing service names to list of service types for a specific node.
node_graph_interface.hpp
rclcpp::node_interfaces::NodeGraph::~NodeGraph
virtual ~NodeGraph()
std::string
std::shared_ptr< rclcpp::graph_listener::GraphListener >
rclcpp::node_interfaces::NodeGraph::count_publishers
size_t count_publishers(const std::string &topic_name) const override
Return the number of publishers that are advertised on a given topic.
RCLCPP_DISABLE_COPY
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
std::vector< std::string >
std::chrono::nanoseconds
RCLCPP_SMART_PTR_ALIASES_ONLY
#define RCLCPP_SMART_PTR_ALIASES_ONLY(...)
Definition: macros.hpp:66
event.hpp
rcl_guard_condition_t
rclcpp::node_interfaces::NodeGraph::get_service_names_and_types
std::map< std::string, std::vector< std::string > > get_service_names_and_types() const override
Return a map of existing service names to list of service types.
rclcpp::node_interfaces::NodeGraph::get_subscriptions_info_by_topic
std::vector< rclcpp::TopicEndpointInfo > get_subscriptions_info_by_topic(const std::string &topic_name, bool no_mangle=false) const override
Return the topic endpoint information about subscriptions on a given topic.
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
rclcpp::node_interfaces::NodeGraph::get_topic_names_and_types
std::map< std::string, std::vector< std::string > > get_topic_names_and_types(bool no_demangle=false) const override
Return a map of existing topic names to list of topic types.
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::node_interfaces::NodeBaseInterface
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
topic_endpoint_info_array.h
macros.hpp
node_base_interface.hpp
rclcpp::node_interfaces::NodeGraph
Implementation the NodeGraph part of the Node API.
Definition: node_graph.hpp:47
rclcpp::node_interfaces::NodeGraph::get_publishers_info_by_topic
std::vector< rclcpp::TopicEndpointInfo > get_publishers_info_by_topic(const std::string &topic_name, bool no_mangle=false) const override
Return the topic endpoint information about publishers on a given topic.
std::map
rclcpp::node_interfaces::NodeGraph::get_graph_guard_condition
const rcl_guard_condition_t * get_graph_guard_condition() const override
Return the rcl guard condition which is triggered when the ROS graph changes.
rclcpp::node_interfaces::NodeGraph::wait_for_graph_change
void wait_for_graph_change(rclcpp::Event::SharedPtr event, std::chrono::nanoseconds timeout) override
Wait for a graph event to occur by waiting on an Event to become set.
rclcpp::node_interfaces::NodeGraph::notify_shutdown
void notify_shutdown() override
Notify any and all blocking node actions that shutdown has occurred.
rclcpp::node_interfaces::NodeGraph::NodeGraph
NodeGraph(rclcpp::node_interfaces::NodeBaseInterface *node_base)
rclcpp::node_interfaces::NodeGraph::get_node_names_and_namespaces
std::vector< std::pair< std::string, std::string > > get_node_names_and_namespaces() const override
Return a vector of existing node names and namespaces (pair of string).
rclcpp::node_interfaces::NodeGraph::count_graph_users
size_t count_graph_users() override
Return the number of on loan graph events, see get_graph_event().
visibility_control.hpp
std::condition_variable
rclcpp::node_interfaces::NodeGraph::get_node_names
std::vector< std::string > get_node_names() const override
Return a vector of existing node names (string).
rclcpp::node_interfaces::NodeGraphInterface
Pure virtual interface class for the NodeGraph part of the Node API.
Definition: node_graph_interface.hpp:136
std::mutex
rclcpp::node_interfaces::NodeGraph::notify_graph_change
void notify_graph_change() override
Notify threads waiting on graph changes.
rclcpp::node_interfaces::NodeGraph::count_subscribers
size_t count_subscribers(const std::string &topic_name) const override
Return the number of subscribers who have created a subscription for a given topic.