ROS 2 rclcpp + rcl - lyrical  lyrical
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:
35  explicit FirstInFirstOutCallbackGroupHandle(CBGScheduler & scheduler, CallbackGroupType type)
36  : CallbackGroupHandle(scheduler, type)
37  {
38  }
39 
40  std::function<void(size_t)> get_ready_callback_for_entity(
41  const rclcpp::SubscriptionBase::WeakPtr & entity) final;
42  std::function<void(std::function<void()> executed_callback)> get_ready_callback_for_entity(
43  const rclcpp::TimerBase::WeakPtr & entity) final;
44  std::function<void(size_t)> get_ready_callback_for_entity(
45  const rclcpp::ClientBase::WeakPtr & entity) final;
46  std::function<void(size_t)> get_ready_callback_for_entity(
47  const rclcpp::ServiceBase::WeakPtr & entity) final;
48  std::function<void(size_t,
49  int)> get_ready_callback_for_entity(const rclcpp::Waitable::WeakPtr & entity) final;
50  std::function<void(size_t)> get_ready_callback_for_entity(
51  const CBGScheduler::CallbackEventType & entity) final;
52 
53  std::optional<CBGScheduler::ExecutableEntity> get_next_ready_entity();
54  std::optional<CBGScheduler::ExecutableEntity> get_next_ready_entity(
55  GlobalEventIdProvider::MonotonicId max_id);
56 
57  bool has_ready_entities() const final
58  {
59  return !ready_entities.empty();
60  }
61 
62 private:
63  std::deque<ReadyEntity> ready_entities;
64 };
65 
67 {
68 public:
70 
71  ExecutableEntityWithInfo get_next_ready_entity_intern() final;
72  ExecutableEntityWithInfo get_next_ready_entity_intern(
73  GlobalEventIdProvider::MonotonicId max_id) final;
74 
75 private:
76  std::unique_ptr<CallbackGroupHandle> get_handle_for_callback_group(
77  const rclcpp::CallbackGroup::SharedPtr & callback_group) final;
78 
79  std::vector<std::unique_ptr<FirstInFirstOutCallbackGroupHandle>> callback_group_handles;
80 };
81 } // namespace cbg_executor
82 } // namespace executors
83 } // namespace rclcpp
CBGScheduler(std::function< void()> sync_function)
Definition: scheduler.hpp:194
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.