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 "rcl/node.h"
23 #include "rclcpp/context.hpp"
24 #include "rclcpp/macros.hpp"
26 #include "rclcpp/node_options.hpp"
28 
29 namespace rclcpp
30 {
31 namespace node_interfaces
32 {
33 
36 {
37 public:
39 
41  NodeBase(
42  const std::string & node_name,
43  const std::string & namespace_,
44  rclcpp::Context::SharedPtr context,
45  const rcl_node_options_t & rcl_node_options,
46  bool use_intra_process_default);
47 
49  virtual
50  ~NodeBase();
51 
53  virtual
54  const char *
55  get_name() const;
56 
58  virtual
59  const char *
60  get_namespace() const;
61 
63  virtual
64  const char *
66 
68  virtual
69  rclcpp::Context::SharedPtr
70  get_context();
71 
73  virtual
74  rcl_node_t *
76 
78  virtual
79  const rcl_node_t *
80  get_rcl_node_handle() const;
81 
83  virtual
86 
88  virtual
91 
93  virtual
94  bool
95  assert_liveliness() const;
96 
98  virtual
99  rclcpp::callback_group::CallbackGroup::SharedPtr
101 
103  virtual
104  rclcpp::callback_group::CallbackGroup::SharedPtr
106 
108  virtual
109  bool
110  callback_group_in_node(rclcpp::callback_group::CallbackGroup::SharedPtr group);
111 
113  virtual
115  get_callback_groups() const;
116 
118  virtual
119  std::atomic_bool &
121 
123  virtual
126 
128  virtual
131 
133  virtual
134  bool
136 
137 private:
138  RCLCPP_DISABLE_COPY(NodeBase)
139 
140  rclcpp::Context::SharedPtr context_;
141  bool use_intra_process_default_;
142 
143  std::shared_ptr<rcl_node_t> node_handle_;
144 
145  rclcpp::callback_group::CallbackGroup::SharedPtr default_callback_group_;
147 
148  std::atomic_bool associated_with_executor_;
149 
151  mutable std::recursive_mutex notify_guard_condition_mutex_;
153  bool notify_guard_condition_is_valid_;
154 };
155 
156 } // namespace node_interfaces
157 } // namespace rclcpp
158 
159 #endif // RCLCPP__NODE_INTERFACES__NODE_BASE_HPP_
virtual rclcpp::callback_group::CallbackGroup::SharedPtr create_callback_group(rclcpp::callback_group::CallbackGroupType group_type)
Create and return a 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 std::unique_lock< std::recursive_mutex > acquire_notify_guard_condition_lock() const
Acquire and return a scoped lock that protects the notify guard condition.
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
#define RCLCPP_SMART_PTR_ALIASES_ONLY(...)
Definition: macros.hpp:66
CallbackGroupType
Definition: callback_group.hpp:46
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
NodeBase(const std::string &node_name, const std::string &namespace_, rclcpp::Context::SharedPtr context, const rcl_node_options_t &rcl_node_options, bool use_intra_process_default)
virtual std::shared_ptr< rcl_node_t > get_shared_rcl_node_handle()
Return the rcl_node_t node handle in a std::shared_ptr.
rcl_guard_condition_t rcl_get_zero_initialized_guard_condition(void)
virtual const char * get_fully_qualified_name() const
Return the fully qualified name of the node.
Implementation of the NodeBase part of the Node API.
Definition: node_base.hpp:35
virtual const std::vector< rclcpp::callback_group::CallbackGroup::WeakPtr > & get_callback_groups() const
Return list of callback groups associated with this node.
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
virtual const char * get_name() const
Return the name of the node.
virtual rcl_node_t * get_rcl_node_handle()
Return the rcl_node_t node handle (non-const version).
virtual rclcpp::callback_group::CallbackGroup::SharedPtr get_default_callback_group()
Return the default callback group.
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
virtual bool assert_liveliness() const
Manually assert that this Node is alive (for RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE).
virtual bool get_use_intra_process_default() const
Return the default preference for using intra process communication.
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 rcl_guard_condition_t * get_notify_guard_condition()
Return guard condition that should be notified when the internal node state changes.