ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
waitable.hpp
1 // Copyright 2018 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__WAITABLE_HPP_
16 #define RCLCPP__WAITABLE_HPP_
17 
18 #include <atomic>
19 #include <functional>
20 #include <memory>
21 
22 #include "rclcpp/macros.hpp"
23 #include "rclcpp/visibility_control.hpp"
24 
25 #include "rcl/wait.h"
26 
27 namespace rclcpp
28 {
29 
30 class Waitable
31 {
32 public:
33  RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(Waitable)
34 
35  RCLCPP_PUBLIC
36  virtual ~Waitable() = default;
37 
39 
44  RCLCPP_PUBLIC
45  virtual
46  size_t
48 
50 
55  RCLCPP_PUBLIC
56  virtual
57  size_t
59 
61 
66  RCLCPP_PUBLIC
67  virtual
68  size_t
70 
72 
77  RCLCPP_PUBLIC
78  virtual
79  size_t
81 
83 
88  RCLCPP_PUBLIC
89  virtual
90  size_t
92 
94 
99  RCLCPP_PUBLIC
100  virtual
101  size_t
103 
105 
109  RCLCPP_PUBLIC
110  virtual
111  void
113 
115 
124  RCLCPP_PUBLIC
125  virtual
126  bool
127  is_ready(rcl_wait_set_t * wait_set) = 0;
128 
130 
158  RCLCPP_PUBLIC
159  virtual
160  std::shared_ptr<void>
161  take_data() = 0;
162 
164 
176  RCLCPP_PUBLIC
177  virtual
178  std::shared_ptr<void>
179  take_data_by_entity_id(size_t id);
180 
182 
203  RCLCPP_PUBLIC
204  virtual
205  void
206  execute(std::shared_ptr<void> & data) = 0;
207 
209 
218  RCLCPP_PUBLIC
219  bool
220  exchange_in_use_by_wait_set_state(bool in_use_state);
221 
223 
246  RCLCPP_PUBLIC
247  virtual
248  void
249  set_on_ready_callback(std::function<void(size_t, int)> callback);
250 
252 
256  RCLCPP_PUBLIC
257  virtual
258  void
260 
261 private:
262  std::atomic<bool> in_use_by_wait_set_{false};
263 }; // class Waitable
264 
265 } // namespace rclcpp
266 
267 #endif // RCLCPP__WAITABLE_HPP_
virtual RCLCPP_PUBLIC void execute(std::shared_ptr< void > &data)=0
Execute data that is passed in.
virtual RCLCPP_PUBLIC void add_to_wait_set(rcl_wait_set_t *wait_set)=0
Add the Waitable to a wait set.
virtual RCLCPP_PUBLIC size_t get_number_of_ready_guard_conditions()
Get the number of ready guard_conditions.
Definition: waitable.cpp:52
virtual RCLCPP_PUBLIC bool is_ready(rcl_wait_set_t *wait_set)=0
Check if the Waitable is ready.
virtual RCLCPP_PUBLIC size_t get_number_of_ready_timers()
Get the number of ready timers.
Definition: waitable.cpp:28
virtual RCLCPP_PUBLIC std::shared_ptr< void > take_data_by_entity_id(size_t id)
Take the data so that it can be consumed with execute.
Definition: waitable.cpp:58
virtual RCLCPP_PUBLIC size_t get_number_of_ready_clients()
Get the number of ready clients.
Definition: waitable.cpp:34
virtual RCLCPP_PUBLIC void clear_on_ready_callback()
Unset any callback registered via set_on_ready_callback.
Definition: waitable.cpp:83
virtual RCLCPP_PUBLIC size_t get_number_of_ready_events()
Get the number of ready events.
Definition: waitable.cpp:40
RCLCPP_PUBLIC bool exchange_in_use_by_wait_set_state(bool in_use_state)
Exchange the "in use by wait set" state for this timer.
Definition: waitable.cpp:67
virtual RCLCPP_PUBLIC size_t get_number_of_ready_subscriptions()
Get the number of ready subscriptions.
Definition: waitable.cpp:22
virtual RCLCPP_PUBLIC size_t get_number_of_ready_services()
Get the number of ready services.
Definition: waitable.cpp:46
virtual RCLCPP_PUBLIC void set_on_ready_callback(std::function< void(size_t, int)> callback)
Set a callback to be called whenever the waitable becomes ready.
Definition: waitable.cpp:73
virtual RCLCPP_PUBLIC std::shared_ptr< void > take_data()=0
Take the data so that it can be consumed with execute.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Container for subscription's, guard condition's, etc to be waited on.
Definition: wait.h:42