ROS 2 rclcpp + rcl - jazzy  jazzy
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 
104 #ifdef __GNUC__
105 #pragma GCC diagnostic push
106 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
107 #endif
109 
112  [[deprecated("Use add_to_wait_set(rcl_wait_set_t & wait_set) signature")]]
113  RCLCPP_PUBLIC
114  virtual
115  void
116  add_to_wait_set(rcl_wait_set_t * wait_set);
117 #ifdef __GNUC__
118 #pragma GCC diagnostic pop
119 #endif
120 
122 
126  RCLCPP_PUBLIC
127  virtual
128  void
129  add_to_wait_set(rcl_wait_set_t & wait_set);
130 
131 #ifdef __GNUC__
132 #pragma GCC diagnostic push
133 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
134 #endif
136 
139  [[deprecated("Use is_ready(const rcl_wait_set_t & wait_set) signature")]]
140  RCLCPP_PUBLIC
141  virtual
142  bool
143  is_ready(rcl_wait_set_t * wait_set);
144 #ifdef __GNUC__
145 #pragma GCC diagnostic pop
146 #endif
147 
149 
158  RCLCPP_PUBLIC
159  virtual
160  bool
161  is_ready(const rcl_wait_set_t & wait_set);
162 
164 
192  RCLCPP_PUBLIC
193  virtual
194  std::shared_ptr<void>
195  take_data() = 0;
196 
198 
210  RCLCPP_PUBLIC
211  virtual
212  std::shared_ptr<void>
213  take_data_by_entity_id(size_t id);
214 
215 #ifdef __GNUC__
216 #pragma GCC diagnostic push
217 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
218 #endif
220 
223  [[deprecated("Use execute(const std::shared_ptr<void> & data) signature")]]
224  RCLCPP_PUBLIC
225  virtual
226  void
227  execute(std::shared_ptr<void> & data);
228 #ifdef __GNUC__
229 #pragma GCC diagnostic pop
230 #endif
231 
233 
254  RCLCPP_PUBLIC
255  virtual
256  void
257  execute(const std::shared_ptr<void> & data);
258 
260 
269  RCLCPP_PUBLIC
270  bool
271  exchange_in_use_by_wait_set_state(bool in_use_state);
272 
274 
297  RCLCPP_PUBLIC
298  virtual
299  void
300  set_on_ready_callback(std::function<void(size_t, int)> callback);
301 
303 
307  RCLCPP_PUBLIC
308  virtual
309  void
311 
312 private:
313  std::atomic<bool> in_use_by_wait_set_{false};
314 }; // class Waitable
315 
316 } // namespace rclcpp
317 
318 #endif // RCLCPP__WAITABLE_HPP_
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 size_t get_number_of_ready_timers()
Get the number of ready timers.
Definition: waitable.cpp:28
virtual RCLCPP_PUBLIC void execute(std::shared_ptr< void > &data)
Deprecated.
Definition: waitable.cpp:143
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 bool is_ready(rcl_wait_set_t *wait_set)
Deprecated.
Definition: waitable.cpp:116
virtual RCLCPP_PUBLIC void clear_on_ready_callback()
Unset any callback registered via set_on_ready_callback.
Definition: waitable.cpp:83
virtual RCLCPP_PUBLIC void add_to_wait_set(rcl_wait_set_t *wait_set)
Deprecated.
Definition: waitable.cpp:91
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