rclcpp  master
C++ ROS Client Library API
static_executor_entities_collector.hpp
Go to the documentation of this file.
1 // Copyright 2020 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__STATIC_EXECUTOR_ENTITIES_COLLECTOR_HPP_
16 #define RCLCPP__EXECUTORS__STATIC_EXECUTOR_ENTITIES_COLLECTOR_HPP_
17 
18 #include <chrono>
19 #include <list>
20 #include <map>
21 #include <memory>
22 #include <vector>
23 
24 #include "rcl/guard_condition.h"
25 #include "rcl/wait.h"
26 
28 #include "rclcpp/macros.hpp"
31 #include "rclcpp/waitable.hpp"
32 
33 namespace rclcpp
34 {
35 namespace executors
36 {
37 typedef std::map<rclcpp::CallbackGroup::WeakPtr,
38  rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
40 
42  : public rclcpp::Waitable,
43  public std::enable_shared_from_this<StaticExecutorEntitiesCollector>
44 {
45 public:
47 
48  // Constructor
51 
52  // Destructor
55 
57 
64  void
65  init(
66  rcl_wait_set_t * p_wait_set,
67  rclcpp::memory_strategy::MemoryStrategy::SharedPtr memory_strategy,
68  rcl_guard_condition_t * executor_guard_condition);
69 
72  bool
73  is_init() {return initialized_;}
74 
76  void
77  fini();
78 
81  void
82  execute(std::shared_ptr<void> & data) override;
83 
85 
91  take_data() override;
92 
94 
100  void
102 
107  bool
108  add_to_wait_set(rcl_wait_set_t * wait_set) override;
109 
111  size_t
113 
115 
119  bool
121  rclcpp::CallbackGroup::SharedPtr group_ptr,
122  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr);
123 
125 
130  bool
132  rclcpp::CallbackGroup::SharedPtr group_ptr,
133  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
134  WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
135 
137 
141  bool
143  rclcpp::CallbackGroup::SharedPtr group_ptr);
144 
146 
150  bool
152  rclcpp::CallbackGroup::SharedPtr group_ptr,
153  WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
154 
160  bool
161  add_node(
162  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr);
163 
169  bool
170  remove_node(
171  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr);
172 
176 
178 
184 
186 
192 
194 
200  bool
201  is_ready(rcl_wait_set_t * wait_set) override;
202 
204 
208  size_t
209  get_number_of_timers() {return exec_list_.number_of_timers;}
210 
212 
216  size_t
218 
220 
224  size_t
226 
228 
232  size_t
234 
236 
240  size_t
242 
249  rclcpp::SubscriptionBase::SharedPtr
250  get_subscription(size_t i) {return exec_list_.subscription[i];}
251 
258  rclcpp::TimerBase::SharedPtr
259  get_timer(size_t i) {return exec_list_.timer[i];}
260 
267  rclcpp::ServiceBase::SharedPtr
268  get_service(size_t i) {return exec_list_.service[i];}
269 
276  rclcpp::ClientBase::SharedPtr
277  get_client(size_t i) {return exec_list_.client[i];}
278 
285  rclcpp::Waitable::SharedPtr
286  get_waitable(size_t i) {return exec_list_.waitable[i];}
287 
288 private:
290 
293  void
294  prepare_wait_set();
295 
296  void
297  fill_executable_list();
298 
299  void
300  fill_memory_strategy();
301 
303 
307  bool
308  has_node(
309  const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
310  const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) const;
311 
315 
318  void
319  add_callback_groups_from_nodes_associated_to_executor();
320 
321  void
322  fill_executable_list_from_map(const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
323 
325  rclcpp::memory_strategy::MemoryStrategy::SharedPtr memory_strategy_;
326 
327  // maps callback groups to nodes.
328  WeakCallbackGroupsToNodesMap weak_groups_associated_with_executor_to_nodes_;
329  // maps callback groups to nodes.
330  WeakCallbackGroupsToNodesMap weak_groups_to_nodes_associated_with_executor_;
331 
332  typedef std::map<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
333  const rcl_guard_condition_t *,
335  WeakNodesToGuardConditionsMap;
336  WeakNodesToGuardConditionsMap weak_nodes_to_guard_conditions_;
337 
340 
342  rcl_wait_set_t * p_wait_set_ = nullptr;
343 
346 
348  bool initialized_ = false;
349 };
350 
351 } // namespace executors
352 } // namespace rclcpp
353 
354 #endif // RCLCPP__EXECUTORS__STATIC_EXECUTOR_ENTITIES_COLLECTOR_HPP_
rclcpp::executors::StaticExecutorEntitiesCollector::add_node
bool add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
rclcpp::executors::StaticExecutorEntitiesCollector::init
void init(rcl_wait_set_t *p_wait_set, rclcpp::memory_strategy::MemoryStrategy::SharedPtr memory_strategy, rcl_guard_condition_t *executor_guard_condition)
Initialize StaticExecutorEntitiesCollector.
rclcpp::executors::StaticExecutorEntitiesCollector::add_to_wait_set
bool add_to_wait_set(rcl_wait_set_t *wait_set) override
rclcpp::executors::StaticExecutorEntitiesCollector::get_number_of_clients
size_t get_number_of_clients()
Return number of clients.
Definition: static_executor_entities_collector.hpp:233
rclcpp::executors::StaticExecutorEntitiesCollector::~StaticExecutorEntitiesCollector
~StaticExecutorEntitiesCollector()
std::shared_ptr< void >
rclcpp::experimental::ExecutableList::waitable
std::vector< rclcpp::Waitable::SharedPtr > waitable
Definition: executable_list.hpp:84
rclcpp::executors::StaticExecutorEntitiesCollector::is_ready
bool is_ready(rcl_wait_set_t *wait_set) override
Complete all available queued work without blocking.
std::list< rclcpp::node_interfaces::NodeBaseInterface::WeakPtr >
guard_condition.h
std::vector< rclcpp::CallbackGroup::WeakPtr >
wait.h
std::chrono::nanoseconds
rclcpp::executors::StaticExecutorEntitiesCollector::take_data
std::shared_ptr< void > take_data() override
Take the data so that it can be consumed with execute.
std::owner_less
rclcpp::executors::StaticExecutorEntitiesCollector::get_waitable
rclcpp::Waitable::SharedPtr get_waitable(size_t i)
Definition: static_executor_entities_collector.hpp:286
rcl_guard_condition_t
executable_list.hpp
rclcpp::experimental::ExecutableList::number_of_clients
size_t number_of_clients
Definition: executable_list.hpp:82
rclcpp::executors::StaticExecutorEntitiesCollector::get_all_callback_groups
std::vector< rclcpp::CallbackGroup::WeakPtr > get_all_callback_groups()
rclcpp::executors::StaticExecutorEntitiesCollector::get_timer
rclcpp::TimerBase::SharedPtr get_timer(size_t i)
Definition: static_executor_entities_collector.hpp:259
rclcpp::Waitable
Definition: waitable.hpp:29
rclcpp::executors::StaticExecutorEntitiesCollector::refresh_wait_set
void refresh_wait_set(std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Function to add_handles_to_wait_set and wait for work and.
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
rclcpp::experimental::ExecutableList::service
std::vector< rclcpp::ServiceBase::SharedPtr > service
Definition: executable_list.hpp:76
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::executors::StaticExecutorEntitiesCollector::get_service
rclcpp::ServiceBase::SharedPtr get_service(size_t i)
Definition: static_executor_entities_collector.hpp:268
rclcpp::experimental::ExecutableList
This class contains subscriptionbase, timerbase, etc. which can be used to run callbacks.
Definition: executable_list.hpp:34
rclcpp::executors::StaticExecutorEntitiesCollector::get_manually_added_callback_groups
std::vector< rclcpp::CallbackGroup::WeakPtr > get_manually_added_callback_groups()
Get callback groups that belong to executor.
RCLCPP_SMART_PTR_DEFINITIONS
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
macros.hpp
rclcpp::executors::StaticExecutorEntitiesCollector::execute
void execute(std::shared_ptr< void > &data) override
Execute the waitable.
rclcpp::executors::StaticExecutorEntitiesCollector::remove_callback_group_from_map
bool remove_callback_group_from_map(rclcpp::CallbackGroup::SharedPtr group_ptr, WeakCallbackGroupsToNodesMap &weak_groups_to_nodes)
Remove a callback group from the executor.
rclcpp::executors::StaticExecutorEntitiesCollector::get_client
rclcpp::ClientBase::SharedPtr get_client(size_t i)
Definition: static_executor_entities_collector.hpp:277
rclcpp::executors::StaticExecutorEntitiesCollector::get_number_of_services
size_t get_number_of_services()
Return number of services.
Definition: static_executor_entities_collector.hpp:225
rclcpp::experimental::ExecutableList::client
std::vector< rclcpp::ClientBase::SharedPtr > client
Definition: executable_list.hpp:80
rclcpp::executors::StaticExecutorEntitiesCollector::get_automatically_added_callback_groups_from_nodes
std::vector< rclcpp::CallbackGroup::WeakPtr > get_automatically_added_callback_groups_from_nodes()
Get callback groups that belong to executor.
rclcpp::executors::StaticExecutorEntitiesCollector::add_callback_group
bool add_callback_group(rclcpp::CallbackGroup::SharedPtr group_ptr, rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
Add a callback group to an executor.
rclcpp::experimental::ExecutableList::subscription
std::vector< rclcpp::SubscriptionBase::SharedPtr > subscription
Definition: executable_list.hpp:68
std::enable_shared_from_this
rcl_wait_set_t
rclcpp::experimental::ExecutableList::number_of_waitables
size_t number_of_waitables
Definition: executable_list.hpp:86
rclcpp::executors::StaticExecutorEntitiesCollector::get_subscription
rclcpp::SubscriptionBase::SharedPtr get_subscription(size_t i)
Definition: static_executor_entities_collector.hpp:250
rclcpp::executors::StaticExecutorEntitiesCollector::is_init
bool is_init()
Finalize StaticExecutorEntitiesCollector to clear resources.
Definition: static_executor_entities_collector.hpp:73
rclcpp::executors::StaticExecutorEntitiesCollector::get_number_of_subscriptions
size_t get_number_of_subscriptions()
Return number of subscriptions.
Definition: static_executor_entities_collector.hpp:217
rclcpp::executors::WeakCallbackGroupsToNodesMap
std::map< rclcpp::CallbackGroup::WeakPtr, rclcpp::node_interfaces::NodeBaseInterface::WeakPtr, std::owner_less< rclcpp::CallbackGroup::WeakPtr > > WeakCallbackGroupsToNodesMap
Definition: static_executor_entities_collector.hpp:39
std::map
rclcpp::executors::StaticExecutorEntitiesCollector::get_number_of_ready_guard_conditions
size_t get_number_of_ready_guard_conditions() override
Get the number of ready guard_conditions.
rclcpp::executors::StaticExecutorEntitiesCollector::fini
void fini()
rclcpp::executors::StaticExecutorEntitiesCollector::get_number_of_waitables
size_t get_number_of_waitables()
Return number of waitables.
Definition: static_executor_entities_collector.hpp:241
rclcpp::executors::StaticExecutorEntitiesCollector
Definition: static_executor_entities_collector.hpp:41
rclcpp::executors::StaticExecutorEntitiesCollector::get_number_of_timers
size_t get_number_of_timers()
Return number of timers.
Definition: static_executor_entities_collector.hpp:209
visibility_control.hpp
rclcpp::executors::StaticExecutorEntitiesCollector::remove_callback_group
bool remove_callback_group(rclcpp::CallbackGroup::SharedPtr group_ptr)
Remove a callback group from the executor.
rclcpp::experimental::ExecutableList::number_of_timers
size_t number_of_timers
Definition: executable_list.hpp:74
rclcpp::experimental::ExecutableList::number_of_services
size_t number_of_services
Definition: executable_list.hpp:78
rclcpp::executors::StaticExecutorEntitiesCollector::remove_node
bool remove_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
waitable.hpp
rclcpp::experimental::ExecutableList::timer
std::vector< rclcpp::TimerBase::SharedPtr > timer
Definition: executable_list.hpp:72
memory_strategy.hpp
rclcpp::experimental::ExecutableList::number_of_subscriptions
size_t number_of_subscriptions
Definition: executable_list.hpp:70
rclcpp::executors::StaticExecutorEntitiesCollector::StaticExecutorEntitiesCollector
StaticExecutorEntitiesCollector()=default