19 #include "scheduler.hpp"
20 #include "global_event_id_provider.hpp"
21 #include "rclcpp/executors/events_cbg_executor/events_cbg_executor.hpp"
27 namespace cbg_executor
33 rclcpp::TimerBase::WeakPtr timer_ptr;
35 std::function<void()> timer_was_executed;
39 return timer_ptr.expired();
47 explicit ReadyEntity(
const rclcpp::SubscriptionBase::WeakPtr ptr)
49 explicit ReadyEntity(
const ReadyTimerWithExecutedCallback & timer)
51 explicit ReadyEntity(
const rclcpp::ServiceBase::WeakPtr ptr)
52 : entity(ptr), id(GlobalEventIdProvider::get_next_id()) {}
53 explicit ReadyEntity(
const rclcpp::ClientBase::WeakPtr ptr)
54 : entity(ptr), id(GlobalEventIdProvider::get_next_id()) {}
55 explicit ReadyEntity(
const CBGScheduler::WaitableWithEventType & ev)
56 : entity(ev), id(GlobalEventIdProvider::get_next_id()) {}
57 explicit ReadyEntity(
const CBGScheduler::CallbackEventType & ev)
58 : entity(ev), id(GlobalEventIdProvider::get_next_id()) {}
60 std::function<void()> get_execute_function()
const
62 return std::visit([](
auto && entity) -> std::function<
void()> {
63 using T = std::decay_t<decltype(entity)>;
64 if constexpr (std::is_same_v<T, rclcpp::SubscriptionBase::WeakPtr>) {
65 rclcpp::SubscriptionBase::SharedPtr shr_ptr = entity.lock();
67 return std::function<void()>();
69 return [shr_ptr = std::move(shr_ptr)]() {
72 }
else if constexpr (std::is_same_v<T, ReadyTimerWithExecutedCallback>) {
73 auto shr_ptr = entity.timer_ptr.lock();
75 return std::function<void()>();
78 return [shr_ptr = std::move(shr_ptr),
79 timer_executed_cb = entity.timer_was_executed]() {
80 auto data = shr_ptr->call();
91 }
else if constexpr (std::is_same_v<T, rclcpp::ServiceBase::WeakPtr>) {
92 auto shr_ptr = entity.lock();
94 return std::function<void()>();
96 return [shr_ptr = std::move(shr_ptr)]() {
99 }
else if constexpr (std::is_same_v<T, rclcpp::ClientBase::WeakPtr>) {
100 auto shr_ptr = entity.lock();
102 return std::function<void()>();
104 return [shr_ptr = std::move(shr_ptr)]() {
107 }
else if constexpr (std::is_same_v<T, CBGScheduler::WaitableWithEventType>) {
108 auto shr_ptr_in = entity.waitable.lock();
110 return std::function<void()>();
113 return [shr_ptr = std::move(shr_ptr_in),
114 event_type = entity.internal_event_type]() {
115 auto data = shr_ptr->take_data_by_entity_id(event_type);
116 shr_ptr->execute(data);
118 }
else if constexpr (std::is_same_v<T, CBGScheduler::CallbackEventType>) {
119 return entity.callback;
124 GlobalEventIdProvider::MonotonicId id;
131 return std::visit([](
const auto & entity) {
return entity.expired();}, entity);
static RCLCPP_PUBLIC void execute_timer(const rclcpp::TimerBase::SharedPtr &timer, const std::shared_ptr< void > &data_ptr)
Run timer executable.
static RCLCPP_PUBLIC void execute_client(const rclcpp::ClientBase::SharedPtr &client)
Run service client executable.
static RCLCPP_PUBLIC void execute_service(const rclcpp::ServiceBase::SharedPtr &service)
Run service server executable.
static RCLCPP_PUBLIC void execute_subscription(const rclcpp::SubscriptionBase::SharedPtr &subscription)
Run subscription executable.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.