15 #ifndef RCLCPP__WAIT_SET_POLICIES__SEQUENTIAL_SYNCHRONIZATION_HPP_
16 #define RCLCPP__WAIT_SET_POLICIES__SEQUENTIAL_SYNCHRONIZATION_HPP_
23 #include "rclcpp/client.hpp"
24 #include "rclcpp/exceptions.hpp"
25 #include "rclcpp/guard_condition.hpp"
26 #include "rclcpp/macros.hpp"
27 #include "rclcpp/service.hpp"
28 #include "rclcpp/subscription_base.hpp"
29 #include "rclcpp/subscription_wait_set_mask.hpp"
30 #include "rclcpp/timer.hpp"
31 #include "rclcpp/visibility_control.hpp"
32 #include "rclcpp/wait_result.hpp"
33 #include "rclcpp/wait_result_kind.hpp"
34 #include "rclcpp/wait_set_policies/detail/synchronization_policy_common.hpp"
35 #include "rclcpp/waitable.hpp"
39 namespace wait_set_policies
54 const std::array<std::shared_ptr<rclcpp::GuardCondition>, 0> &
57 static const std::array<std::shared_ptr<rclcpp::GuardCondition>, 0> empty{};
67 std::shared_ptr<rclcpp::SubscriptionBase> && subscription,
71 > add_subscription_function)
74 add_subscription_function(std::move(subscription), mask);
83 std::shared_ptr<rclcpp::SubscriptionBase> && subscription,
87 > remove_subscription_function)
90 remove_subscription_function(std::move(subscription), mask);
99 std::shared_ptr<rclcpp::GuardCondition> && guard_condition,
100 std::function<
void(std::shared_ptr<rclcpp::GuardCondition>&&)> add_guard_condition_function)
103 add_guard_condition_function(std::move(guard_condition));
112 std::shared_ptr<rclcpp::GuardCondition> && guard_condition,
113 std::function<
void(std::shared_ptr<rclcpp::GuardCondition>&&)> remove_guard_condition_function)
116 remove_guard_condition_function(std::move(guard_condition));
125 std::shared_ptr<rclcpp::TimerBase> && timer,
126 std::function<
void(std::shared_ptr<rclcpp::TimerBase>&&)> add_timer_function)
129 add_timer_function(std::move(timer));
138 std::shared_ptr<rclcpp::TimerBase> && timer,
139 std::function<
void(std::shared_ptr<rclcpp::TimerBase>&&)> remove_timer_function)
142 remove_timer_function(std::move(timer));
151 std::shared_ptr<rclcpp::ClientBase> && client,
152 std::function<
void(std::shared_ptr<rclcpp::ClientBase>&&)> add_client_function)
155 add_client_function(std::move(client));
164 std::shared_ptr<rclcpp::ClientBase> && client,
165 std::function<
void(std::shared_ptr<rclcpp::ClientBase>&&)> remove_client_function)
168 remove_client_function(std::move(client));
177 std::shared_ptr<rclcpp::ServiceBase> && service,
178 std::function<
void(std::shared_ptr<rclcpp::ServiceBase>&&)> add_service_function)
181 add_service_function(std::move(service));
190 std::shared_ptr<rclcpp::ServiceBase> && service,
191 std::function<
void(std::shared_ptr<rclcpp::ServiceBase>&&)> remove_service_function)
194 remove_service_function(std::move(service));
203 std::shared_ptr<rclcpp::Waitable> && waitable,
204 std::shared_ptr<void> && associated_entity,
206 void(std::shared_ptr<rclcpp::Waitable>&&, std::shared_ptr<void> &&)
207 > add_waitable_function)
210 add_waitable_function(std::move(waitable), std::move(associated_entity));
219 std::shared_ptr<rclcpp::Waitable> && waitable,
220 std::function<
void(std::shared_ptr<rclcpp::Waitable>&&)> remove_waitable_function)
223 remove_waitable_function(std::move(waitable));
234 prune_deleted_entities_function();
238 template<
class WaitResultT>
241 std::chrono::nanoseconds time_to_wait_ns,
242 std::function<
void()> rebuild_rcl_wait_set,
244 std::function<WaitResultT(WaitResultKind wait_result_kind)> create_wait_result)
256 auto start = std::chrono::steady_clock::now();
257 std::function<bool()> should_loop = this->create_loop_predicate(time_to_wait_ns, start);
267 rebuild_rcl_wait_set();
277 auto time_left_to_wait_ns = this->calculate_time_left_to_wait(time_to_wait_ns, start);
284 return create_wait_result(WaitResultKind::Ready);
290 return create_wait_result(WaitResultKind::Empty);
293 rclcpp::exceptions::throw_from_rcl_error(ret,
"rcl_wait() failed");
295 }
while (should_loop());
298 return create_wait_result(WaitResultKind::Timeout);
302 sync_wait_result_acquire()
308 sync_wait_result_release()
Options used to determine what parts of a subscription get added to or removed from a wait set.
WaitSet policy that explicitly provides no thread synchronization.
void sync_add_service(std::shared_ptr< rclcpp::ServiceBase > &&service, std::function< void(std::shared_ptr< rclcpp::ServiceBase > &&)> add_service_function)
Add service without thread-safety.
void sync_remove_service(std::shared_ptr< rclcpp::ServiceBase > &&service, std::function< void(std::shared_ptr< rclcpp::ServiceBase > &&)> remove_service_function)
Remove service without thread-safety.
void sync_add_timer(std::shared_ptr< rclcpp::TimerBase > &&timer, std::function< void(std::shared_ptr< rclcpp::TimerBase > &&)> add_timer_function)
Add timer without thread-safety.
void sync_remove_client(std::shared_ptr< rclcpp::ClientBase > &&client, std::function< void(std::shared_ptr< rclcpp::ClientBase > &&)> remove_client_function)
Remove client without thread-safety.
void sync_prune_deleted_entities(std::function< void()> prune_deleted_entities_function)
Prune deleted entities without thread-safety.
void sync_add_subscription(std::shared_ptr< rclcpp::SubscriptionBase > &&subscription, const rclcpp::SubscriptionWaitSetMask &mask, std::function< void(std::shared_ptr< rclcpp::SubscriptionBase > &&, const rclcpp::SubscriptionWaitSetMask &) > add_subscription_function)
Add subscription without thread-safety.
void sync_remove_waitable(std::shared_ptr< rclcpp::Waitable > &&waitable, std::function< void(std::shared_ptr< rclcpp::Waitable > &&)> remove_waitable_function)
Remove waitable without thread-safety.
WaitResultT sync_wait(std::chrono::nanoseconds time_to_wait_ns, std::function< void()> rebuild_rcl_wait_set, std::function< rcl_wait_set_t &()> get_rcl_wait_set, std::function< WaitResultT(WaitResultKind wait_result_kind)> create_wait_result)
Implements wait without any thread-safety.
void sync_remove_subscription(std::shared_ptr< rclcpp::SubscriptionBase > &&subscription, const rclcpp::SubscriptionWaitSetMask &mask, std::function< void(std::shared_ptr< rclcpp::SubscriptionBase > &&, const rclcpp::SubscriptionWaitSetMask &) > remove_subscription_function)
Remove guard condition without thread-safety.
const std::array< std::shared_ptr< rclcpp::GuardCondition >, 0 > & get_extra_guard_conditions()
Return any "extra" guard conditions needed to implement the synchronization policy.
void sync_add_client(std::shared_ptr< rclcpp::ClientBase > &&client, std::function< void(std::shared_ptr< rclcpp::ClientBase > &&)> add_client_function)
Add client without thread-safety.
void sync_add_guard_condition(std::shared_ptr< rclcpp::GuardCondition > &&guard_condition, std::function< void(std::shared_ptr< rclcpp::GuardCondition > &&)> add_guard_condition_function)
Add guard condition without thread-safety.
void sync_add_waitable(std::shared_ptr< rclcpp::Waitable > &&waitable, std::shared_ptr< void > &&associated_entity, std::function< void(std::shared_ptr< rclcpp::Waitable > &&, std::shared_ptr< void > &&) > add_waitable_function)
Add waitable without thread-safety.
void sync_remove_timer(std::shared_ptr< rclcpp::TimerBase > &&timer, std::function< void(std::shared_ptr< rclcpp::TimerBase > &&)> remove_timer_function)
Remove timer without thread-safety.
void sync_remove_guard_condition(std::shared_ptr< rclcpp::GuardCondition > &&guard_condition, std::function< void(std::shared_ptr< rclcpp::GuardCondition > &&)> remove_guard_condition_function)
Remove guard condition without thread-safety.
Common structure for synchronization policies.
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.
#define RCL_RET_WAIT_SET_EMPTY
Given rcl_wait_set_t is empty return code.
#define RCL_RET_OK
Success return code.
#define RCL_RET_TIMEOUT
Timeout occurred return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_wait(rcl_wait_set_t *wait_set, int64_t timeout)
Block until the wait set is ready or until the timeout has been exceeded.