|
| 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 | + rclcpp::TimerBase::WeakPtr timer; |
| 41 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 42 | + }; |
| 43 | + using TimerCollection = std::unordered_map<const rcl_timer_t *, TimerEntry>; |
| 44 | + |
| 45 | + struct SubscriptionEntry{ |
| 46 | + rclcpp::SubscriptionBase::WeakPtr subscription; |
| 47 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 48 | + }; |
| 49 | + using SubscriptionCollection = std::unordered_map<const rcl_subscription_t *, SubscriptionEntry>; |
| 50 | + |
| 51 | + struct ClientEntry { |
| 52 | + rclcpp::ClientBase::WeakPtr client; |
| 53 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 54 | + }; |
| 55 | + using ClientCollection = std::unordered_map<const rcl_client_t *, ClientEntry>; |
| 56 | + |
| 57 | + struct ServiceEntry { |
| 58 | + rclcpp::ServiceBase::WeakPtr service; |
| 59 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 60 | + }; |
| 61 | + using ServiceCollection = std::unordered_map<const rcl_service_t *, ServiceEntry>; |
| 62 | + |
| 63 | + struct WaitableEntry { |
| 64 | + rclcpp::Waitable::WeakPtr waitable; |
| 65 | + rclcpp::CallbackGroup::WeakPtr callback_group; |
| 66 | + }; |
| 67 | + using WaitableCollection = std::unordered_map<const rclcpp::Waitable *, WaitableEntry>; |
| 68 | + |
| 69 | + using GuardConditionCollection = std::unordered_map<const rcl_guard_condition_t *, |
| 70 | + rclcpp::GuardCondition::WeakPtr>; |
| 71 | + |
| 72 | + TimerCollection timers; |
| 73 | + SubscriptionCollection subscriptions; |
| 74 | + ClientCollection clients; |
| 75 | + ServiceCollection services; |
| 76 | + GuardConditionCollection guard_conditions; |
| 77 | + WaitableCollection waitables; |
| 78 | + |
| 79 | + void clear(); |
| 80 | + |
| 81 | + using TimerUpdatedFunc = std::function<void(rclcpp::TimerBase::SharedPtr)>; |
| 82 | + void update_timers(const ExecutorEntitiesCollection::TimerCollection & other, |
| 83 | + TimerUpdatedFunc timer_added, |
| 84 | + TimerUpdatedFunc timer_removed); |
| 85 | + |
| 86 | + using SubscriptionUpdatedFunc = std::function<void(rclcpp::SubscriptionBase::SharedPtr)>; |
| 87 | + void update_subscriptions(const ExecutorEntitiesCollection::SubscriptionCollection & other, |
| 88 | + SubscriptionUpdatedFunc subscription_added, |
| 89 | + SubscriptionUpdatedFunc subscription_removed); |
| 90 | + |
| 91 | + using ClientUpdatedFunc = std::function<void(rclcpp::ClientBase::SharedPtr)>; |
| 92 | + void update_clients(const ExecutorEntitiesCollection::ClientCollection & other, |
| 93 | + ClientUpdatedFunc client_added, |
| 94 | + ClientUpdatedFunc client_removed); |
| 95 | + |
| 96 | + using ServiceUpdatedFunc = std::function<void(rclcpp::ServiceBase::SharedPtr)>; |
| 97 | + void update_services(const ExecutorEntitiesCollection::ServiceCollection & other, |
| 98 | + ServiceUpdatedFunc service_added, |
| 99 | + ServiceUpdatedFunc service_removed); |
| 100 | + |
| 101 | + using GuardConditionUpdatedFunc = std::function<void(rclcpp::GuardCondition::SharedPtr)>; |
| 102 | + void update_guard_conditions(const ExecutorEntitiesCollection::GuardConditionCollection & other, |
| 103 | + GuardConditionUpdatedFunc guard_condition_added, |
| 104 | + GuardConditionUpdatedFunc guard_condition_removed); |
| 105 | + |
| 106 | + using WaitableUpdatedFunc = std::function<void(rclcpp::Waitable::SharedPtr)>; |
| 107 | + void update_waitables(const ExecutorEntitiesCollection::WaitableCollection & other, |
| 108 | + WaitableUpdatedFunc waitable_added, |
| 109 | + WaitableUpdatedFunc waitable_removed); |
| 110 | + }; |
| 111 | + |
| 112 | +void |
| 113 | +build_entities_collection( |
| 114 | + const std::vector<rclcpp::CallbackGroup::WeakPtr> & callback_groups, |
| 115 | + ExecutorEntitiesCollection & collection); |
| 116 | + |
| 117 | +std::deque<rclcpp::AnyExecutable> |
| 118 | +ready_executables( |
| 119 | + const ExecutorEntitiesCollection & collection, |
| 120 | + rclcpp::WaitResult<rclcpp::WaitSet> & wait_result |
| 121 | +); |
| 122 | + |
| 123 | +} // namespace executors |
| 124 | +} // namespace rclcpp |
| 125 | + |
| 126 | +#endif // RCLCPP__EXECUTORS__EXECUTOR_ENTITIES_COLLECTION_HPP_ |
0 commit comments