|
| 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_ENTITIES_COLLECTION_HPP_ |
| 16 | +#define RCLCPP__EXECUTORS__EXECUTOR_ENTITIES_COLLECTION_HPP_ |
| 17 | + |
| 18 | +#include <deque> |
| 19 | +#include <unordered_map> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +#include "rcpputils/thread_safety_annotations.hpp" |
| 23 | + |
| 24 | +#include <rclcpp/any_executable.hpp> |
| 25 | +#include <rclcpp/node_interfaces/node_base.hpp> |
| 26 | +#include <rclcpp/callback_group.hpp> |
| 27 | +#include <rclcpp/executors/executor_notify_waitable.hpp> |
| 28 | +#include <rclcpp/visibility_control.hpp> |
| 29 | +#include <rclcpp/wait_result.hpp> |
| 30 | +#include <rclcpp/wait_set.hpp> |
| 31 | + |
| 32 | +namespace rclcpp |
| 33 | +{ |
| 34 | +namespace executors |
| 35 | +{ |
| 36 | + |
| 37 | +struct ExecutorEntitiesCollection |
| 38 | +{ |
| 39 | + struct TimerEntry |
| 40 | + { |
| 41 | + rclcpp::TimerBase::WeakPtr timer; |
| 42 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 43 | + }; |
| 44 | + using TimerCollection = std::unordered_map<const rcl_timer_t *, TimerEntry>; |
| 45 | + |
| 46 | + struct SubscriptionEntry |
| 47 | + { |
| 48 | + rclcpp::SubscriptionBase::WeakPtr subscription; |
| 49 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 50 | + }; |
| 51 | + using SubscriptionCollection = std::unordered_map<const rcl_subscription_t *, SubscriptionEntry>; |
| 52 | + |
| 53 | + struct ClientEntry |
| 54 | + { |
| 55 | + rclcpp::ClientBase::WeakPtr client; |
| 56 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 57 | + }; |
| 58 | + using ClientCollection = std::unordered_map<const rcl_client_t *, ClientEntry>; |
| 59 | + |
| 60 | + struct ServiceEntry |
| 61 | + { |
| 62 | + rclcpp::ServiceBase::WeakPtr service; |
| 63 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 64 | + }; |
| 65 | + using ServiceCollection = std::unordered_map<const rcl_service_t *, ServiceEntry>; |
| 66 | + |
| 67 | + struct WaitableEntry |
| 68 | + { |
| 69 | + rclcpp::Waitable::WeakPtr waitable; |
| 70 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 71 | + }; |
| 72 | + using WaitableCollection = std::unordered_map<const rclcpp::Waitable *, WaitableEntry>; |
| 73 | + |
| 74 | + using GuardConditionCollection = std::unordered_map<const rcl_guard_condition_t *, |
| 75 | + rclcpp::GuardCondition::WeakPtr>; |
| 76 | + |
| 77 | + TimerCollection timers; |
| 78 | + SubscriptionCollection subscriptions; |
| 79 | + ClientCollection clients; |
| 80 | + ServiceCollection services; |
| 81 | + GuardConditionCollection guard_conditions; |
| 82 | + WaitableCollection waitables; |
| 83 | + |
| 84 | + void clear(); |
| 85 | + |
| 86 | + using TimerUpdatedFunc = std::function<void (rclcpp::TimerBase::SharedPtr)>; |
| 87 | + void update_timers( |
| 88 | + const ExecutorEntitiesCollection::TimerCollection & other, |
| 89 | + TimerUpdatedFunc timer_added, |
| 90 | + TimerUpdatedFunc timer_removed); |
| 91 | + |
| 92 | + using SubscriptionUpdatedFunc = std::function<void (rclcpp::SubscriptionBase::SharedPtr)>; |
| 93 | + void update_subscriptions( |
| 94 | + const ExecutorEntitiesCollection::SubscriptionCollection & other, |
| 95 | + SubscriptionUpdatedFunc subscription_added, |
| 96 | + SubscriptionUpdatedFunc subscription_removed); |
| 97 | + |
| 98 | + using ClientUpdatedFunc = std::function<void (rclcpp::ClientBase::SharedPtr)>; |
| 99 | + void update_clients( |
| 100 | + const ExecutorEntitiesCollection::ClientCollection & other, |
| 101 | + ClientUpdatedFunc client_added, |
| 102 | + ClientUpdatedFunc client_removed); |
| 103 | + |
| 104 | + using ServiceUpdatedFunc = std::function<void (rclcpp::ServiceBase::SharedPtr)>; |
| 105 | + void update_services( |
| 106 | + const ExecutorEntitiesCollection::ServiceCollection & other, |
| 107 | + ServiceUpdatedFunc service_added, |
| 108 | + ServiceUpdatedFunc service_removed); |
| 109 | + |
| 110 | + using GuardConditionUpdatedFunc = std::function<void (rclcpp::GuardCondition::SharedPtr)>; |
| 111 | + void update_guard_conditions( |
| 112 | + const ExecutorEntitiesCollection::GuardConditionCollection & other, |
| 113 | + GuardConditionUpdatedFunc guard_condition_added, |
| 114 | + GuardConditionUpdatedFunc guard_condition_removed); |
| 115 | + |
| 116 | + using WaitableUpdatedFunc = std::function<void (rclcpp::Waitable::SharedPtr)>; |
| 117 | + void update_waitables( |
| 118 | + const ExecutorEntitiesCollection::WaitableCollection & other, |
| 119 | + WaitableUpdatedFunc waitable_added, |
| 120 | + WaitableUpdatedFunc waitable_removed); |
| 121 | +}; |
| 122 | + |
| 123 | +void |
| 124 | +build_entities_collection( |
| 125 | + const std::vector<rclcpp::CallbackGroup::WeakPtr> & callback_groups, |
| 126 | + ExecutorEntitiesCollection & collection); |
| 127 | + |
| 128 | +std::deque<rclcpp::AnyExecutable> |
| 129 | +ready_executables( |
| 130 | + const ExecutorEntitiesCollection & collection, |
| 131 | + rclcpp::WaitResult<rclcpp::WaitSet> & wait_result |
| 132 | +); |
| 133 | + |
| 134 | +} // namespace executors |
| 135 | +} // namespace rclcpp |
| 136 | + |
| 137 | +#endif // RCLCPP__EXECUTORS__EXECUTOR_ENTITIES_COLLECTION_HPP_ |
0 commit comments