ROS 2 rclcpp + rcl - jazzy  jazzy
ROS 2 C++ Client Library with ROS Client Library
executor_notify_waitable.hpp
1 // Copyright 2023 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__EXECUTORS__EXECUTOR_NOTIFY_WAITABLE_HPP_
16 #define RCLCPP__EXECUTORS__EXECUTOR_NOTIFY_WAITABLE_HPP_
17 
18 #include <functional>
19 #include <memory>
20 #include <mutex>
21 #include <set>
22 
23 #include "rclcpp/guard_condition.hpp"
24 #include "rclcpp/waitable.hpp"
25 
26 namespace rclcpp
27 {
28 namespace executors
29 {
30 
34 {
35 public:
36  RCLCPP_SMART_PTR_DEFINITIONS(ExecutorNotifyWaitable)
37 
38  // Constructor
43  RCLCPP_PUBLIC
44  explicit ExecutorNotifyWaitable(std::function<void(void)> on_execute_callback = {});
45 
46  // Destructor
47  RCLCPP_PUBLIC
48  ~ExecutorNotifyWaitable() override = default;
49 
50  RCLCPP_PUBLIC
52 
53  RCLCPP_PUBLIC
55 
57 
60  RCLCPP_PUBLIC
61  void
62  add_to_wait_set(rcl_wait_set_t & wait_set) override;
63 
65 
69  RCLCPP_PUBLIC
70  bool
71  is_ready(const rcl_wait_set_t & wait_set) override;
72 
74 
78  RCLCPP_PUBLIC
79  void
80  execute(const std::shared_ptr<void> & data) override;
81 
83 
86  RCLCPP_PUBLIC
87  std::shared_ptr<void>
88  take_data() override;
89 
91 
96  RCLCPP_PUBLIC
97  std::shared_ptr<void>
98  take_data_by_entity_id(size_t id) override;
99 
101 
105  RCLCPP_PUBLIC
106  void
107  set_on_ready_callback(std::function<void(size_t, int)> callback) override;
108 
110 
113  RCLCPP_PUBLIC
114  void
115  add_guard_condition(rclcpp::GuardCondition::WeakPtr guard_condition);
116 
118 
121  RCLCPP_PUBLIC
122  void
123  clear_on_ready_callback() override;
124 
126 
129  RCLCPP_PUBLIC
130  void
131  remove_guard_condition(rclcpp::GuardCondition::WeakPtr weak_guard_condition);
132 
134 
137  RCLCPP_PUBLIC
138  size_t
140 
141 private:
143  std::function<void(void)> execute_callback_;
144 
145  std::mutex guard_condition_mutex_;
146 
147  std::function<void(size_t)> on_ready_callback_;
148 
150  std::set<rclcpp::GuardCondition::WeakPtr,
151  std::owner_less<rclcpp::GuardCondition::WeakPtr>> notify_guard_conditions_;
152 };
153 
154 } // namespace executors
155 } // namespace rclcpp
156 
157 #endif // RCLCPP__EXECUTORS__EXECUTOR_NOTIFY_WAITABLE_HPP_
RCLCPP_PUBLIC std::shared_ptr< void > take_data_by_entity_id(size_t id) override
Take the data from an entity ID so that it can be consumed with execute.
RCLCPP_PUBLIC void execute(const std::shared_ptr< void > &data) override
Perform work associated with the waitable.
RCLCPP_PUBLIC void add_guard_condition(rclcpp::GuardCondition::WeakPtr guard_condition)
Add a guard condition to be waited on.
RCLCPP_PUBLIC size_t get_number_of_ready_guard_conditions() override
Get the number of ready guard_conditions.
RCLCPP_PUBLIC std::shared_ptr< void > take_data() override
Retrieve data to be used in the next execute call.
RCLCPP_PUBLIC ExecutorNotifyWaitable(std::function< void(void)> on_execute_callback={})
RCLCPP_PUBLIC void add_to_wait_set(rcl_wait_set_t &wait_set) override
Add conditions to the wait set.
RCLCPP_PUBLIC void set_on_ready_callback(std::function< void(size_t, int)> callback) override
Set a callback to be called whenever the waitable becomes ready.
RCLCPP_PUBLIC void clear_on_ready_callback() override
Unset any callback registered via set_on_ready_callback.
RCLCPP_PUBLIC bool is_ready(const rcl_wait_set_t &wait_set) override
Check conditions against the wait set.
RCLCPP_PUBLIC void remove_guard_condition(rclcpp::GuardCondition::WeakPtr weak_guard_condition)
Remove a guard condition from being waited on.
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