rclcpp  master
C++ ROS Client Library API
memory_strategy.hpp
Go to the documentation of this file.
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 
26 #include "rclcpp/macros.hpp"
29 #include "rclcpp/waitable.hpp"
30 
31 namespace rclcpp
32 {
33 namespace memory_strategy
34 {
35 
37 
43 {
44 public:
46  using WeakCallbackGroupsToNodesMap = std::map<rclcpp::CallbackGroup::WeakPtr,
47  rclcpp::node_interfaces::NodeBaseInterface::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 add_guard_condition(const rcl_guard_condition_t * guard_condition) = 0;
68 
69  virtual void remove_guard_condition(const rcl_guard_condition_t * guard_condition) = 0;
70 
71  virtual void
72  get_next_subscription(
73  rclcpp::AnyExecutable & any_exec,
74  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
75 
76  virtual void
77  get_next_service(
78  rclcpp::AnyExecutable & any_exec,
79  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
80 
81  virtual void
82  get_next_client(
83  rclcpp::AnyExecutable & any_exec,
84  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
85 
86  virtual void
87  get_next_timer(
88  rclcpp::AnyExecutable & any_exec,
89  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
90 
91  virtual void
92  get_next_waitable(
93  rclcpp::AnyExecutable & any_exec,
94  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
95 
96  virtual rcl_allocator_t
97  get_allocator() = 0;
98 
99  static rclcpp::SubscriptionBase::SharedPtr
100  get_subscription_by_handle(
102  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
103 
104  static rclcpp::ServiceBase::SharedPtr
105  get_service_by_handle(
107  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
108 
109  static rclcpp::ClientBase::SharedPtr
110  get_client_by_handle(
112  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
113 
114  static rclcpp::TimerBase::SharedPtr
115  get_timer_by_handle(
117  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
118 
119  static rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
120  get_node_by_group(
121  rclcpp::CallbackGroup::SharedPtr group,
122  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
123 
124  static rclcpp::CallbackGroup::SharedPtr
125  get_group_by_subscription(
126  rclcpp::SubscriptionBase::SharedPtr subscription,
127  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
128 
129  static rclcpp::CallbackGroup::SharedPtr
130  get_group_by_service(
131  rclcpp::ServiceBase::SharedPtr service,
132  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
133 
134  static rclcpp::CallbackGroup::SharedPtr
135  get_group_by_client(
136  rclcpp::ClientBase::SharedPtr client,
137  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
138 
139  static rclcpp::CallbackGroup::SharedPtr
140  get_group_by_timer(
141  rclcpp::TimerBase::SharedPtr timer,
142  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
143 
144  static rclcpp::CallbackGroup::SharedPtr
145  get_group_by_waitable(
146  rclcpp::Waitable::SharedPtr waitable,
147  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
148 };
149 
150 } // namespace memory_strategy
151 } // namespace rclcpp
152 
153 #endif // RCLCPP__MEMORY_STRATEGY_HPP_
rclcpp::memory_strategy::MemoryStrategy
Delegate for handling memory allocations while the Executor is executing.
Definition: memory_strategy.hpp:42
std::shared_ptr
wait.h
any_executable.hpp
std::owner_less
rcl_guard_condition_t
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
macros.hpp
node_base_interface.hpp
allocator.h
rcl_wait_set_t
rclcpp::AnyExecutable
Definition: any_executable.hpp:33
std::map< rclcpp::CallbackGroup::WeakPtr, rclcpp::node_interfaces::NodeBaseInterface::WeakPtr, std::owner_less< rclcpp::CallbackGroup::WeakPtr > >
rcutils_allocator_t
visibility_control.hpp
RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
waitable.hpp