rclcpp  master
C++ ROS Client Library API
callback_group.hpp
Go to the documentation of this file.
1 // Copyright 2014 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__CALLBACK_GROUP_HPP_
16 #define RCLCPP__CALLBACK_GROUP_HPP_
17 
18 #include <atomic>
19 #include <mutex>
20 #include <string>
21 #include <vector>
22 
23 #include "rclcpp/client.hpp"
24 #include "rclcpp/publisher.hpp"
25 #include "rclcpp/service.hpp"
26 #include "rclcpp/subscription.hpp"
27 #include "rclcpp/timer.hpp"
29 #include "rclcpp/waitable.hpp"
30 
31 namespace rclcpp
32 {
33 
34 // Forward declarations for friend statement in class CallbackGroup
35 namespace node_interfaces
36 {
37 class NodeServices;
38 class NodeTimers;
39 class NodeTopics;
40 class NodeWaitables;
41 } // namespace node_interfaces
42 
43 namespace callback_group
44 {
45 
47 {
49  Reentrant
50 };
51 
53 {
58 
59 public:
61 
63  explicit CallbackGroup(CallbackGroupType group_type);
64 
67  get_subscription_ptrs() const;
68 
71  get_timer_ptrs() const;
72 
75  get_service_ptrs() const;
76 
79  get_client_ptrs() const;
80 
83  get_waitable_ptrs() const;
84 
86  std::atomic_bool &
87  can_be_taken_from();
88 
90  const CallbackGroupType &
91  type() const;
92 
93 protected:
95 
97  void
98  add_publisher(const rclcpp::PublisherBase::SharedPtr publisher_ptr);
99 
101  void
102  add_subscription(const rclcpp::SubscriptionBase::SharedPtr subscription_ptr);
103 
105  void
106  add_timer(const rclcpp::TimerBase::SharedPtr timer_ptr);
107 
109  void
110  add_service(const rclcpp::ServiceBase::SharedPtr service_ptr);
111 
113  void
114  add_client(const rclcpp::ClientBase::SharedPtr client_ptr);
115 
117  void
118  add_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr);
119 
121  void
122  remove_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr) noexcept;
123 
125  // Mutex to protect the subsequent vectors of pointers.
132  std::atomic_bool can_be_taken_from_;
133 };
134 
135 } // namespace callback_group
136 } // namespace rclcpp
137 
138 #endif // RCLCPP__CALLBACK_GROUP_HPP_
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
std::vector< rclcpp::ServiceBase::WeakPtr > service_ptrs_
Definition: callback_group.hpp:129
CallbackGroupType type_
Definition: callback_group.hpp:124
std::mutex mutex_
Definition: callback_group.hpp:126
CallbackGroupType
Definition: callback_group.hpp:46
std::vector< rclcpp::ClientBase::WeakPtr > client_ptrs_
Definition: callback_group.hpp:130
Implementation of the NodeTimers part of the Node API.
Definition: node_timers.hpp:31
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
std::atomic_bool can_be_taken_from_
Definition: callback_group.hpp:132
Implementation of the NodeServices part of the Node API.
Definition: node_services.hpp:32
std::vector< rclcpp::SubscriptionBase::WeakPtr > subscription_ptrs_
Definition: callback_group.hpp:127
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
Definition: callback_group.hpp:52
std::vector< rclcpp::TimerBase::WeakPtr > timer_ptrs_
Definition: callback_group.hpp:128
virtual void remove_waitable(rclcpp::Waitable::SharedPtr waitable_ptr, rclcpp::callback_group::CallbackGroup::SharedPtr group) noexcept
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
std::vector< rclcpp::Waitable::WeakPtr > waitable_ptrs_
Definition: callback_group.hpp:131
Implementation of the NodeTopics part of the Node API.
Definition: node_topics.hpp:36
Implementation of the NodeWaitables part of the Node API.
Definition: node_waitables.hpp:32
virtual void add_waitable(rclcpp::Waitable::SharedPtr waitable_base_ptr, rclcpp::callback_group::CallbackGroup::SharedPtr group)