ROS 2 rclcpp + rcl - rolling  rolling-20536064
ROS 2 C++ Client Library with ROS Client Library
memory_strategy.hpp
1 // Copyright 2015 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__MEMORY_STRATEGY_HPP_
16 #define RCLCPP__MEMORY_STRATEGY_HPP_
17 
18 #include <map>
19 #include <memory>
20 
21 #include "rcl/allocator.h"
22 #include "rcl/wait.h"
23 
24 #include "rclcpp/any_executable.hpp"
25 #include "rclcpp/macros.hpp"
26 #include "rclcpp/node_interfaces/node_base_interface.hpp"
27 #include "rclcpp/visibility_control.hpp"
28 #include "rclcpp/waitable.hpp"
29 
30 namespace rclcpp
31 {
32 namespace memory_strategy
33 {
34 
36 
41 class RCLCPP_PUBLIC [[deprecated("The executor does not used this anymore")]] MemoryStrategy
42 {
43 public:
44  RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(MemoryStrategy)
45  using WeakCallbackGroupsToNodesMap = std::map<rclcpp::CallbackGroup::WeakPtr,
46  rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
47  std::owner_less<rclcpp::CallbackGroup::WeakPtr>>;
48 
49  virtual ~MemoryStrategy() = default;
50 
51  virtual bool collect_entities(const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
52 
53  virtual size_t number_of_ready_subscriptions() const = 0;
54  virtual size_t number_of_ready_services() const = 0;
55  virtual size_t number_of_ready_clients() const = 0;
56  virtual size_t number_of_ready_events() const = 0;
57  virtual size_t number_of_ready_timers() const = 0;
58  virtual size_t number_of_guard_conditions() const = 0;
59  virtual size_t number_of_waitables() const = 0;
60 
61  virtual void add_waitable_handle(const rclcpp::Waitable::SharedPtr & waitable) = 0;
62  virtual bool add_handles_to_wait_set(rcl_wait_set_t * wait_set) = 0;
63  virtual void clear_handles() = 0;
64  virtual void remove_null_handles(rcl_wait_set_t * wait_set) = 0;
65 
66  virtual void
67  add_guard_condition(const rclcpp::GuardCondition & guard_condition) = 0;
68 
69  virtual void
70  remove_guard_condition(const rclcpp::GuardCondition * guard_condition) = 0;
71 
72  virtual void
73  get_next_subscription(
74  rclcpp::AnyExecutable & any_exec,
75  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
76 
77  virtual void
78  get_next_service(
79  rclcpp::AnyExecutable & any_exec,
80  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
81 
82  virtual void
83  get_next_client(
84  rclcpp::AnyExecutable & any_exec,
85  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
86 
87  virtual void
88  get_next_timer(
89  rclcpp::AnyExecutable & any_exec,
90  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
91 
92  virtual void
93  get_next_waitable(
94  rclcpp::AnyExecutable & any_exec,
95  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
96 
97  virtual rcl_allocator_t
98  get_allocator() = 0;
99 
100  static rclcpp::SubscriptionBase::SharedPtr
101  get_subscription_by_handle(
102  const std::shared_ptr<const rcl_subscription_t> & subscriber_handle,
103  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
104 
105  static rclcpp::ServiceBase::SharedPtr
106  get_service_by_handle(
107  const std::shared_ptr<const rcl_service_t> & service_handle,
108  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
109 
110  static rclcpp::ClientBase::SharedPtr
111  get_client_by_handle(
112  const std::shared_ptr<const rcl_client_t> & client_handle,
113  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
114 
115  static rclcpp::TimerBase::SharedPtr
116  get_timer_by_handle(
117  const std::shared_ptr<const rcl_timer_t> & timer_handle,
118  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
119 
120  static rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
121  get_node_by_group(
122  const rclcpp::CallbackGroup::SharedPtr & group,
123  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
124 
125  static rclcpp::CallbackGroup::SharedPtr
126  get_group_by_subscription(
127  const rclcpp::SubscriptionBase::SharedPtr & subscription,
128  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
129 
130  static rclcpp::CallbackGroup::SharedPtr
131  get_group_by_service(
132  const rclcpp::ServiceBase::SharedPtr & service,
133  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
134 
135  static rclcpp::CallbackGroup::SharedPtr
136  get_group_by_client(
137  const rclcpp::ClientBase::SharedPtr & client,
138  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
139 
140  static rclcpp::CallbackGroup::SharedPtr
141  get_group_by_timer(
142  const rclcpp::TimerBase::SharedPtr & timer,
143  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
144 
145  static rclcpp::CallbackGroup::SharedPtr
146  get_group_by_waitable(
147  const rclcpp::Waitable::SharedPtr & waitable,
148  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
149 };
150 
151 } // namespace memory_strategy
152 } // namespace rclcpp
153 
154 #endif // RCLCPP__MEMORY_STRATEGY_HPP_
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
A condition that can be waited on in a single wait set and asynchronously triggered.
Delegate for handling memory allocations while the Executor is executing.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Container for subscription's, guard condition's, etc to be waited on.
Definition: wait.h:42