ROS 2 rclcpp + rcl - rolling  rolling-a919a6e5
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 <list>
19 #include <map>
20 #include <memory>
21 
22 #include "rcl/allocator.h"
23 #include "rcl/wait.h"
24 
25 #include "rclcpp/any_executable.hpp"
26 #include "rclcpp/macros.hpp"
27 #include "rclcpp/node_interfaces/node_base_interface.hpp"
28 #include "rclcpp/visibility_control.hpp"
29 #include "rclcpp/waitable.hpp"
30 
31 namespace rclcpp
32 {
33 namespace memory_strategy
34 {
35 
37 
42 class RCLCPP_PUBLIC MemoryStrategy
43 {
44 public:
45  RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(MemoryStrategy)
46  using WeakCallbackGroupsToNodesMap = std::map<rclcpp::CallbackGroup::WeakPtr,
47  rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
48  std::owner_less<rclcpp::CallbackGroup::WeakPtr>>;
49 
50  virtual ~MemoryStrategy() = default;
51 
52  virtual bool collect_entities(const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
53 
54  virtual size_t number_of_ready_subscriptions() const = 0;
55  virtual size_t number_of_ready_services() const = 0;
56  virtual size_t number_of_ready_clients() const = 0;
57  virtual size_t number_of_ready_events() const = 0;
58  virtual size_t number_of_ready_timers() const = 0;
59  virtual size_t number_of_guard_conditions() const = 0;
60  virtual size_t number_of_waitables() const = 0;
61 
62  virtual void add_waitable_handle(const rclcpp::Waitable::SharedPtr & waitable) = 0;
63  virtual bool add_handles_to_wait_set(rcl_wait_set_t * wait_set) = 0;
64  virtual void clear_handles() = 0;
65  virtual void remove_null_handles(rcl_wait_set_t * wait_set) = 0;
66 
67  virtual void
68  add_guard_condition(const rclcpp::GuardCondition & guard_condition) = 0;
69 
70  virtual void
71  remove_guard_condition(const rclcpp::GuardCondition * guard_condition) = 0;
72 
73  virtual void
74  get_next_subscription(
75  rclcpp::AnyExecutable & any_exec,
76  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
77 
78  virtual void
79  get_next_service(
80  rclcpp::AnyExecutable & any_exec,
81  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
82 
83  virtual void
84  get_next_client(
85  rclcpp::AnyExecutable & any_exec,
86  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
87 
88  virtual void
89  get_next_timer(
90  rclcpp::AnyExecutable & any_exec,
91  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
92 
93  virtual void
94  get_next_waitable(
95  rclcpp::AnyExecutable & any_exec,
96  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
97 
98  virtual rcl_allocator_t
99  get_allocator() = 0;
100 
101  static rclcpp::SubscriptionBase::SharedPtr
102  get_subscription_by_handle(
103  const std::shared_ptr<const rcl_subscription_t> & subscriber_handle,
104  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
105 
106  static rclcpp::ServiceBase::SharedPtr
107  get_service_by_handle(
108  const std::shared_ptr<const rcl_service_t> & service_handle,
109  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
110 
111  static rclcpp::ClientBase::SharedPtr
112  get_client_by_handle(
113  const std::shared_ptr<const rcl_client_t> & client_handle,
114  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
115 
116  static rclcpp::TimerBase::SharedPtr
117  get_timer_by_handle(
118  const std::shared_ptr<const rcl_timer_t> & timer_handle,
119  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
120 
121  static rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
122  get_node_by_group(
123  const rclcpp::CallbackGroup::SharedPtr & group,
124  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
125 
126  static rclcpp::CallbackGroup::SharedPtr
127  get_group_by_subscription(
128  const rclcpp::SubscriptionBase::SharedPtr & subscription,
129  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
130 
131  static rclcpp::CallbackGroup::SharedPtr
132  get_group_by_service(
133  const rclcpp::ServiceBase::SharedPtr & service,
134  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
135 
136  static rclcpp::CallbackGroup::SharedPtr
137  get_group_by_client(
138  const rclcpp::ClientBase::SharedPtr & client,
139  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
140 
141  static rclcpp::CallbackGroup::SharedPtr
142  get_group_by_timer(
143  const rclcpp::TimerBase::SharedPtr & timer,
144  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
145 
146  static rclcpp::CallbackGroup::SharedPtr
147  get_group_by_waitable(
148  const rclcpp::Waitable::SharedPtr & waitable,
149  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
150 };
151 
152 } // namespace memory_strategy
153 } // namespace rclcpp
154 
155 #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