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 
62  const std::vector<rclcpp::subscription::SubscriptionBase::WeakPtr> &
63  get_subscription_ptrs() const;
64 
66  const std::vector<rclcpp::timer::TimerBase::WeakPtr> &
67  get_timer_ptrs() const;
68 
70  const std::vector<rclcpp::service::ServiceBase::WeakPtr> &
71  get_service_ptrs() const;
72 
74  const std::vector<rclcpp::client::ClientBase::WeakPtr> &
75  get_client_ptrs() const;
76 
78  std::atomic_bool &
79  can_be_taken_from();
80 
82  const CallbackGroupType &
83  type() const;
84 
85 protected:
87 
89  void
90  add_subscription(const rclcpp::subscription::SubscriptionBase::SharedPtr subscription_ptr);
91 
93  void
94  add_timer(const rclcpp::timer::TimerBase::SharedPtr timer_ptr);
95 
97  void
98  add_service(const rclcpp::service::ServiceBase::SharedPtr service_ptr);
99 
101  void
102  add_client(const rclcpp::client::ClientBase::SharedPtr client_ptr);
103 
105  // Mutex to protect the subsequent vectors of pointers.
106  mutable std::mutex mutex_;
107  std::vector<rclcpp::subscription::SubscriptionBase::WeakPtr> subscription_ptrs_;
108  std::vector<rclcpp::timer::TimerBase::WeakPtr> timer_ptrs_;
109  std::vector<rclcpp::service::ServiceBase::WeakPtr> service_ptrs_;
110  std::vector<rclcpp::client::ClientBase::WeakPtr> client_ptrs_;
111  std::atomic_bool can_be_taken_from_;
112 };
113 
114 } // namespace callback_group
115 } // namespace rclcpp
116 
117 #endif // RCLCPP__CALLBACK_GROUP_HPP_
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
CallbackGroupType type_
Definition: callback_group.hpp:104
std::mutex mutex_
Definition: callback_group.hpp:106
CallbackGroupType
Definition: callback_group.hpp:43
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:111
Implementation of the NodeServices part of the Node API.
Definition: node_services.hpp:32
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
Definition: callback_group.hpp:49
virtual void add_subscription(rclcpp::subscription::SubscriptionBase::SharedPtr subscription, rclcpp::callback_group::CallbackGroup::SharedPtr callback_group)
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
std::vector< rclcpp::service::ServiceBase::WeakPtr > service_ptrs_
Definition: callback_group.hpp:109
Implementation of the NodeTopics part of the Node API.
Definition: node_topics.hpp:36
std::vector< rclcpp::timer::TimerBase::WeakPtr > timer_ptrs_
Definition: callback_group.hpp:108
std::vector< rclcpp::client::ClientBase::WeakPtr > client_ptrs_
Definition: callback_group.hpp:110
std::vector< rclcpp::subscription::SubscriptionBase::WeakPtr > subscription_ptrs_
Definition: callback_group.hpp:107