rclcpp  master
C++ ROS Client Library API
node_base.hpp
Go to the documentation of this file.
1 // Copyright 2016 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_BASE_HPP_
16 #define RCLCPP__NODE_INTERFACES__NODE_BASE_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "rclcpp/context.hpp"
23 #include "rclcpp/macros.hpp"
26 
27 namespace rclcpp
28 {
29 namespace node_interfaces
30 {
31 
34 {
35 public:
37 
39  NodeBase(
40  const std::string & node_name,
41  const std::string & namespace_,
42  rclcpp::Context::SharedPtr context,
43  const std::vector<std::string> & arguments,
44  bool use_global_arguments);
45 
47  virtual
48  ~NodeBase();
49 
51  virtual
52  const char *
53  get_name() const;
54 
56  virtual
57  const char *
58  get_namespace() const;
59 
61  virtual
62  rclcpp::Context::SharedPtr
63  get_context();
64 
66  virtual
67  rcl_node_t *
69 
71  virtual
72  const rcl_node_t *
73  get_rcl_node_handle() const;
74 
76  virtual
79 
81  virtual
84 
86  virtual
87  rclcpp::callback_group::CallbackGroup::SharedPtr
89 
91  virtual
92  rclcpp::callback_group::CallbackGroup::SharedPtr
94 
96  virtual
97  bool
98  callback_group_in_node(rclcpp::callback_group::CallbackGroup::SharedPtr group);
99 
101  virtual
103  get_callback_groups() const;
104 
106  virtual
107  std::atomic_bool &
109 
111  virtual
114 
116  virtual
119 
120 private:
122 
123  rclcpp::Context::SharedPtr context_;
124 
125  std::shared_ptr<rcl_node_t> node_handle_;
126 
127  rclcpp::callback_group::CallbackGroup::SharedPtr default_callback_group_;
129 
130  std::atomic_bool associated_with_executor_;
131 
133  mutable std::recursive_mutex notify_guard_condition_mutex_;
135  bool notify_guard_condition_is_valid_;
136 };
137 
138 } // namespace node_interfaces
139 } // namespace rclcpp
140 
141 #endif // RCLCPP__NODE_INTERFACES__NODE_BASE_HPP_
virtual const std::vector< rclcpp::callback_group::CallbackGroup::WeakPtr > & get_callback_groups() const
Return list of callback groups associated with this node.
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
#define RCLCPP_SMART_PTR_ALIASES_ONLY(...)
Definition: macros.hpp:66
CallbackGroupType
Definition: callback_group.hpp:43
Definition: allocator_common.hpp:24
virtual const char * get_name() const
Return the name of the node.
rcl_guard_condition_t rcl_get_zero_initialized_guard_condition(void)
Implementation of the NodeBase part of the Node API.
Definition: node_base.hpp:33
NodeBase(const std::string &node_name, const std::string &namespace_, rclcpp::Context::SharedPtr context, const std::vector< std::string > &arguments, bool use_global_arguments)
virtual std::unique_lock< std::recursive_mutex > acquire_notify_guard_condition_lock() const
Acquire and return a scoped lock that protects the notify guard condition.
virtual std::atomic_bool & get_associated_with_executor_atomic()
Return the atomic bool which is used to ensure only one executor is used.
virtual const char * get_namespace() const
Return the namespace of the node.
virtual std::shared_ptr< rcl_node_t > get_shared_rcl_node_handle()
Return the rcl_node_t node handle in a std::shared_ptr.
virtual rcl_node_t * get_rcl_node_handle()
Return the rcl_node_t node handle (non-const version).
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
virtual rclcpp::callback_group::CallbackGroup::SharedPtr get_default_callback_group()
Return the default callback group.
virtual bool callback_group_in_node(rclcpp::callback_group::CallbackGroup::SharedPtr group)
Return true if the given callback group is associated with this node.
virtual rclcpp::Context::SharedPtr get_context()
Return the context of the node.
virtual rcl_guard_condition_t * get_notify_guard_condition()
Return guard condition that should be notified when the internal node state changes.
virtual rclcpp::callback_group::CallbackGroup::SharedPtr create_callback_group(rclcpp::callback_group::CallbackGroupType group_type)
Create and return a callback group.