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 
29 namespace rclcpp
30 {
31 
32 // Forward declarations for friend statement in class CallbackGroup
33 namespace node_interfaces
34 {
35 class NodeServices;
36 class NodeTimers;
37 class NodeTopics;
38 } // namespace node_interfaces
39 
40 namespace callback_group
41 {
42 
44 {
46  Reentrant
47 };
48 
50 {
54 
55 public:
57 
59  explicit CallbackGroup(CallbackGroupType group_type);
60 
63  get_subscription_ptrs() const;
64 
67  get_timer_ptrs() const;
68 
71  get_service_ptrs() const;
72 
75  get_client_ptrs() const;
76 
78  std::atomic_bool &
80 
82  const CallbackGroupType &
83  type() const;
84 
85 protected:
87 
89  void
90  add_subscription(const rclcpp::SubscriptionBase::SharedPtr subscription_ptr);
91 
93  void
94  add_timer(const rclcpp::TimerBase::SharedPtr timer_ptr);
95 
97  void
98  add_service(const rclcpp::ServiceBase::SharedPtr service_ptr);
99 
101  void
102  add_client(const rclcpp::ClientBase::SharedPtr client_ptr);
103 
105  // Mutex to protect the subsequent vectors of pointers.
111  std::atomic_bool can_be_taken_from_;
112 };
113 
114 } // namespace callback_group
115 } // namespace rclcpp
116 
117 #endif // RCLCPP__CALLBACK_GROUP_HPP_
Implementation of the NodeTimers part of the Node API.
Definition: node_timers.hpp:31
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
void add_service(const rclcpp::ServiceBase::SharedPtr service_ptr)
const CallbackGroupType & type() const
std::vector< rclcpp::SubscriptionBase::WeakPtr > subscription_ptrs_
Definition: callback_group.hpp:107
CallbackGroupType
Definition: callback_group.hpp:43
std::mutex mutex_
Definition: callback_group.hpp:106
Definition: allocator_common.hpp:24
std::vector< rclcpp::ServiceBase::WeakPtr > service_ptrs_
Definition: callback_group.hpp:109
Implementation of the NodeServices part of the Node API.
Definition: node_services.hpp:32
Definition: callback_group.hpp:49
void add_subscription(const rclcpp::SubscriptionBase::SharedPtr subscription_ptr)
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
const std::vector< rclcpp::ServiceBase::WeakPtr > & get_service_ptrs() const
std::vector< rclcpp::TimerBase::WeakPtr > timer_ptrs_
Definition: callback_group.hpp:108
CallbackGroupType type_
Definition: callback_group.hpp:104
CallbackGroup(CallbackGroupType group_type)
void add_timer(const rclcpp::TimerBase::SharedPtr timer_ptr)
const std::vector< rclcpp::TimerBase::WeakPtr > & get_timer_ptrs() const
Implementation of the NodeTopics part of the Node API.
Definition: node_topics.hpp:36
std::vector< rclcpp::ClientBase::WeakPtr > client_ptrs_
Definition: callback_group.hpp:110
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
std::atomic_bool & can_be_taken_from()
const std::vector< rclcpp::ClientBase::WeakPtr > & get_client_ptrs() const
void add_client(const rclcpp::ClientBase::SharedPtr client_ptr)
std::atomic_bool can_be_taken_from_
Definition: callback_group.hpp:111
const std::vector< rclcpp::SubscriptionBase::WeakPtr > & get_subscription_ptrs() const