ROS 2 rclcpp + rcl - jazzy  jazzy
ROS 2 C++ Client Library with ROS Client Library
first_in_first_out_scheduler.hpp
1 // Copyright 2024 Cellumation GmbH.
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 #pragma once
16 
17 #include <deque>
18 #include <memory>
19 
20 #include <vector>
21 
22 #include "ready_entity.hpp"
23 #include "scheduler.hpp"
24 #include "global_event_id_provider.hpp"
25 
26 namespace rclcpp
27 {
28 namespace executors
29 {
30 namespace cbg_executor
31 {
33 {
34 public:
36  : CallbackGroupHandle(scheduler) {}
37 
38  std::function<void(size_t)> get_ready_callback_for_entity(
39  const rclcpp::SubscriptionBase::WeakPtr & entity) final;
40  std::function<void(std::function<void()> executed_callback)> get_ready_callback_for_entity(
41  const rclcpp::TimerBase::WeakPtr & entity) final;
42  std::function<void(size_t)> get_ready_callback_for_entity(
43  const rclcpp::ClientBase::WeakPtr & entity) final;
44  std::function<void(size_t)> get_ready_callback_for_entity(
45  const rclcpp::ServiceBase::WeakPtr & entity) final;
46  std::function<void(size_t,
47  int)> get_ready_callback_for_entity(const rclcpp::Waitable::WeakPtr & entity) final;
48  std::function<void(size_t)> get_ready_callback_for_entity(
49  const CBGScheduler::CallbackEventType & entity) final;
50 
51  std::optional<CBGScheduler::ExecutableEntity> get_next_ready_entity();
52  std::optional<CBGScheduler::ExecutableEntity> get_next_ready_entity(
53  GlobalEventIdProvider::MonotonicId max_id);
54 
55  bool has_ready_entities() const final
56  {
57  return !ready_entities.empty();
58  }
59 
60 private:
61  std::deque<ReadyEntity> ready_entities;
62 };
63 
65 {
66 public:
68 
69  ExecutableEntityWithInfo get_next_ready_entity_intern() final;
70  ExecutableEntityWithInfo get_next_ready_entity_intern(
71  GlobalEventIdProvider::MonotonicId max_id) final;
72 
73 private:
74  std::unique_ptr<CallbackGroupHandle> get_handle_for_callback_group(
75  const rclcpp::CallbackGroup::SharedPtr & callback_group) final;
76 
77  std::vector<std::unique_ptr<FirstInFirstOutCallbackGroupHandle>> callback_group_handles;
78 };
79 } // namespace cbg_executor
80 } // namespace executors
81 } // namespace rclcpp
CBGScheduler(std::function< void()> sync_function)
Definition: scheduler.hpp:182
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.