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"
27 
28 namespace rclcpp
29 {
30 namespace node_interfaces
31 {
32 
35 {
36 public:
38 
40  NodeBase(
41  const std::string & node_name,
42  const std::string & namespace_,
43  rclcpp::Context::SharedPtr context,
44  const rcl_node_options_t & rcl_node_options,
45  bool use_intra_process_default,
46  bool enable_topic_statistics_default);
47 
49  virtual
50  ~NodeBase();
51 
53  const char *
54  get_name() const override;
55 
57  const char *
58  get_namespace() const override;
59 
61  const char *
62  get_fully_qualified_name() const override;
63 
65  rclcpp::Context::SharedPtr
66  get_context() override;
67 
69  rcl_node_t *
70  get_rcl_node_handle() override;
71 
73  const rcl_node_t *
74  get_rcl_node_handle() const override;
75 
78  get_shared_rcl_node_handle() override;
79 
82  get_shared_rcl_node_handle() const override;
83 
85  rclcpp::CallbackGroup::SharedPtr
87  rclcpp::CallbackGroupType group_type,
88  bool automatically_add_to_executor_with_node = true) override;
89 
91  rclcpp::CallbackGroup::SharedPtr
92  get_default_callback_group() override;
93 
95  bool
96  callback_group_in_node(rclcpp::CallbackGroup::SharedPtr group) override;
97 
100  get_callback_groups() const override;
101 
103  std::atomic_bool &
105 
108  get_notify_guard_condition() override;
109 
112  acquire_notify_guard_condition_lock() const override;
113 
115  bool
116  get_use_intra_process_default() const override;
117 
118  bool
119  get_enable_topic_statistics_default() const override;
120 
123  const std::string & name, bool is_service, bool only_expand = false) const override;
124 
125 private:
127 
128  rclcpp::Context::SharedPtr context_;
129  bool use_intra_process_default_;
130  bool enable_topic_statistics_default_;
131 
132  std::shared_ptr<rcl_node_t> node_handle_;
133 
134  rclcpp::CallbackGroup::SharedPtr default_callback_group_;
136 
137  std::atomic_bool associated_with_executor_;
138 
140  mutable std::recursive_mutex notify_guard_condition_mutex_;
142  bool notify_guard_condition_is_valid_;
143 };
144 
145 } // namespace node_interfaces
146 } // namespace rclcpp
147 
148 #endif // RCLCPP__NODE_INTERFACES__NODE_BASE_HPP_
rcl_node_t
rclcpp::node_interfaces::NodeBase::callback_group_in_node
bool callback_group_in_node(rclcpp::CallbackGroup::SharedPtr group) override
Return true if the given callback group is associated with this node.
std::string
std::shared_ptr< rcl_node_t >
rclcpp::node_interfaces::NodeBase
Implementation of the NodeBase part of the Node API.
Definition: node_base.hpp:34
RCLCPP_DISABLE_COPY
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
std::vector< rclcpp::CallbackGroup::WeakPtr >
rclcpp::node_interfaces::NodeBase::get_use_intra_process_default
bool get_use_intra_process_default() const override
Return the default preference for using intra process communication.
context.hpp
std::recursive_mutex
RCLCPP_SMART_PTR_ALIASES_ONLY
#define RCLCPP_SMART_PTR_ALIASES_ONLY(...)
Definition: macros.hpp:66
rcl_node_options_t
rcl_guard_condition_t
rclcpp::CallbackGroupType
CallbackGroupType
Definition: callback_group.hpp:43
rclcpp::node_interfaces::NodeBase::get_rcl_node_handle
rcl_node_t * get_rcl_node_handle() override
Return the rcl_node_t node handle (non-const version).
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
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
macros.hpp
rclcpp::node_interfaces::NodeBase::get_enable_topic_statistics_default
bool get_enable_topic_statistics_default() const override
Return the default preference for enabling topic statistics collection.
rclcpp::node_interfaces::NodeBase::get_associated_with_executor_atomic
std::atomic_bool & get_associated_with_executor_atomic() override
Return the atomic bool which is used to ensure only one executor is used.
node_base_interface.hpp
rclcpp::node_interfaces::NodeBase::get_notify_guard_condition
rcl_guard_condition_t * get_notify_guard_condition() override
Return guard condition that should be notified when the internal node state changes.
rcl_get_zero_initialized_guard_condition
rcl_guard_condition_t rcl_get_zero_initialized_guard_condition(void)
std::unique_lock
rclcpp::node_interfaces::NodeBase::acquire_notify_guard_condition_lock
std::unique_lock< std::recursive_mutex > acquire_notify_guard_condition_lock() const override
Acquire and return a scoped lock that protects the notify guard condition.
rclcpp::node_interfaces::NodeBase::get_fully_qualified_name
const char * get_fully_qualified_name() const override
Return the fully qualified name of the node.
rclcpp::node_interfaces::NodeBase::~NodeBase
virtual ~NodeBase()
rclcpp::node_interfaces::NodeBase::get_shared_rcl_node_handle
std::shared_ptr< rcl_node_t > get_shared_rcl_node_handle() override
Return the rcl_node_t node handle in a std::shared_ptr.
rclcpp::node_interfaces::NodeBase::get_default_callback_group
rclcpp::CallbackGroup::SharedPtr get_default_callback_group() override
Return the default callback group.
rclcpp::node_interfaces::NodeBase::resolve_topic_or_service_name
std::string resolve_topic_or_service_name(const std::string &name, bool is_service, bool only_expand=false) const override
Expand and remap a given topic or service name.
visibility_control.hpp
node.h
rclcpp::node_interfaces::NodeBase::get_callback_groups
const std::vector< rclcpp::CallbackGroup::WeakPtr > & get_callback_groups() const override
Return list of callback groups associated with this node.
rclcpp::node_interfaces::NodeBase::get_name
const char * get_name() const override
Return the name of the node.
rclcpp::node_interfaces::NodeBase::NodeBase
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, bool enable_topic_statistics_default)
rclcpp::node_interfaces::NodeBase::get_context
rclcpp::Context::SharedPtr get_context() override
Return the context of the node.
rclcpp::node_interfaces::NodeBase::get_namespace
const char * get_namespace() const override
Return the namespace of the node.
rclcpp::node_interfaces::NodeBase::create_callback_group
rclcpp::CallbackGroup::SharedPtr create_callback_group(rclcpp::CallbackGroupType group_type, bool automatically_add_to_executor_with_node=true) override
Create and return a callback group.