ROS 2 rclcpp + rcl - rolling  rolling-a919a6e5
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 #include <vector>
22 
23 #include "rclcpp/macros.hpp"
24 #include "rclcpp/visibility_control.hpp"
25 
26 #include "rcl/wait.h"
27 
28 namespace rclcpp
29 {
30 
31 class TimerBase;
32 
33 class Waitable
34 {
35 public:
36  RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(Waitable)
37 
38  RCLCPP_PUBLIC
39  virtual ~Waitable() = default;
40 
42 
47  RCLCPP_PUBLIC
48  virtual
49  size_t
51 
53 
58  RCLCPP_PUBLIC
59  virtual
60  size_t
62 
64 
69  RCLCPP_PUBLIC
70  virtual
71  size_t
73 
75 
80  RCLCPP_PUBLIC
81  virtual
82  size_t
84 
86 
91  RCLCPP_PUBLIC
92  virtual
93  size_t
95 
97 
102  RCLCPP_PUBLIC
103  virtual
104  size_t
106 
108 
112  RCLCPP_PUBLIC
113  virtual
114  void
116 
118 
127  RCLCPP_PUBLIC
128  virtual
129  bool
130  is_ready(const rcl_wait_set_t & wait_set) = 0;
131 
133 
161  RCLCPP_PUBLIC
162  virtual
163  std::shared_ptr<void>
164  take_data() = 0;
165 
167 
179  RCLCPP_PUBLIC
180  virtual
181  std::shared_ptr<void>
182  take_data_by_entity_id(size_t id) = 0;
183 
185 
206  RCLCPP_PUBLIC
207  virtual
208  void
209  execute(const std::shared_ptr<void> & data) = 0;
210 
212 
221  RCLCPP_PUBLIC
222  bool
223  exchange_in_use_by_wait_set_state(bool in_use_state);
224 
226 
249  RCLCPP_PUBLIC
250  virtual
251  void
252  set_on_ready_callback(std::function<void(size_t, int)> callback) = 0;
253 
255 
259  RCLCPP_PUBLIC
260  virtual
261  void
263 
265 
270  RCLCPP_PUBLIC
271  virtual
272  std::vector<std::shared_ptr<rclcpp::TimerBase>>
273  get_timers() const = 0;
274 
275 private:
276  std::atomic<bool> in_use_by_wait_set_{false};
277 }; // class Waitable
278 
279 } // namespace rclcpp
280 
281 #endif // RCLCPP__WAITABLE_HPP_
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 void execute(const std::shared_ptr< void > &data)=0
Execute data that is passed in.
virtual RCLCPP_PUBLIC std::shared_ptr< void > take_data_by_entity_id(size_t id)=0
Take the data so that it can be consumed with execute.
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 std::vector< std::shared_ptr< rclcpp::TimerBase > > get_timers() const =0
Returns all timers used by this waitable.
virtual RCLCPP_PUBLIC size_t get_number_of_ready_clients()
Get the number of ready clients.
Definition: waitable.cpp:34
virtual RCLCPP_PUBLIC void set_on_ready_callback(std::function< void(size_t, int)> callback)=0
Set a callback to be called whenever the waitable becomes ready.
virtual RCLCPP_PUBLIC bool is_ready(const rcl_wait_set_t &wait_set)=0
Check if the Waitable is ready.
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:58
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 clear_on_ready_callback()=0
Unset any callback registered via set_on_ready_callback.
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