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/service.hpp"
25 #include "rclcpp/subscription.hpp"
26 #include "rclcpp/timer.hpp"
28 #include "rclcpp/waitable.hpp"
29 
30 namespace rclcpp
31 {
32 
33 // Forward declarations for friend statement in class CallbackGroup
34 namespace node_interfaces
35 {
36 class NodeServices;
37 class NodeTimers;
38 class NodeTopics;
39 class NodeWaitables;
40 } // namespace node_interfaces
41 
42 namespace callback_group
43 {
44 
46 {
48  Reentrant
49 };
50 
52 {
57 
58 public:
60 
62  explicit CallbackGroup(CallbackGroupType group_type);
63 
66  get_subscription_ptrs() const;
67 
70  get_timer_ptrs() const;
71 
74  get_service_ptrs() const;
75 
78  get_client_ptrs() const;
79 
82  get_waitable_ptrs() const;
83 
85  std::atomic_bool &
86  can_be_taken_from();
87 
89  const CallbackGroupType &
90  type() const;
91 
92 protected:
94 
96  void
97  add_subscription(const rclcpp::SubscriptionBase::SharedPtr subscription_ptr);
98 
100  void
101  add_timer(const rclcpp::TimerBase::SharedPtr timer_ptr);
102 
104  void
105  add_service(const rclcpp::ServiceBase::SharedPtr service_ptr);
106 
108  void
109  add_client(const rclcpp::ClientBase::SharedPtr client_ptr);
110 
112  void
113  add_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr);
114 
116  void
117  remove_waitable(const rclcpp::Waitable::SharedPtr waitable_ptr) noexcept;
118 
120  // Mutex to protect the subsequent vectors of pointers.
127  std::atomic_bool can_be_taken_from_;
128 };
129 
130 } // namespace callback_group
131 } // namespace rclcpp
132 
133 #endif // RCLCPP__CALLBACK_GROUP_HPP_
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
std::vector< rclcpp::ServiceBase::WeakPtr > service_ptrs_
Definition: callback_group.hpp:124
CallbackGroupType type_
Definition: callback_group.hpp:119
std::mutex mutex_
Definition: callback_group.hpp:121
CallbackGroupType
Definition: callback_group.hpp:45
std::vector< rclcpp::ClientBase::WeakPtr > client_ptrs_
Definition: callback_group.hpp:125
Implementation of the NodeTimers part of the Node API.
Definition: node_timers.hpp:31
Definition: allocator_common.hpp:24
std::atomic_bool can_be_taken_from_
Definition: callback_group.hpp:127
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:122
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
Definition: callback_group.hpp:51
std::vector< rclcpp::TimerBase::WeakPtr > timer_ptrs_
Definition: callback_group.hpp:123
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:126
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)