15 #ifndef RCLCPP__EXECUTOR_HPP_
16 #define RCLCPP__EXECUTOR_HPP_
32 #include "rclcpp/executors/executor_notify_waitable.hpp"
33 #include "rcpputils/scope_exit.hpp"
35 #include "rclcpp/context.hpp"
36 #include "rclcpp/contexts/default_context.hpp"
37 #include "rclcpp/guard_condition.hpp"
38 #include "rclcpp/executor_options.hpp"
39 #include "rclcpp/executors/executor_entities_collection.hpp"
40 #include "rclcpp/executors/executor_entities_collector.hpp"
41 #include "rclcpp/future_return_code.hpp"
42 #include "rclcpp/node_interfaces/node_base_interface.hpp"
43 #include "rclcpp/utilities.hpp"
44 #include "rclcpp/visibility_control.hpp"
45 #include "rclcpp/wait_set.hpp"
52 class ExecutorImplementation;
67 RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(
Executor)
105 rclcpp::CallbackGroup::SharedPtr group_ptr,
106 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
122 virtual std::vector<rclcpp::CallbackGroup::WeakPtr>
136 virtual std::vector<rclcpp::CallbackGroup::WeakPtr>
151 virtual std::vector<rclcpp::CallbackGroup::WeakPtr>
176 rclcpp::CallbackGroup::SharedPtr group_ptr,
200 add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
bool notify =
true);
208 add_node(std::shared_ptr<rclcpp::Node> node_ptr,
bool notify =
true);
228 remove_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
bool notify =
true);
236 remove_node(std::shared_ptr<rclcpp::Node> node_ptr,
bool notify =
true);
245 template<
typename RepT =
int64_t,
typename T = std::milli>
248 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node,
249 std::chrono::duration<RepT, T> timeout = std::chrono::duration<RepT, T>(-1))
253 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
258 template<
typename NodeT = rclcpp::Node,
typename RepT =
int64_t,
typename T = std::milli>
261 std::shared_ptr<NodeT> node,
262 std::chrono::duration<RepT, T> timeout = std::chrono::duration<RepT, T>(-1))
265 node->get_node_base_interface(),
266 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
276 spin_node_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node);
303 spin_some(std::chrono::nanoseconds max_duration = std::chrono::nanoseconds(0));
312 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node,
313 std::chrono::nanoseconds max_duration);
318 spin_node_all(std::shared_ptr<rclcpp::Node> node, std::chrono::nanoseconds max_duration);
337 spin_all(std::chrono::nanoseconds max_duration);
351 spin_once(std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
363 template<
typename FutureT,
typename TimeRepT =
int64_t,
typename TimeT = std::milli>
366 const FutureT & future,
367 std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
370 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout),
371 [&future](std::chrono::nanoseconds wait_time) {
372 return future.wait_for(wait_time);
402 explicit Executor(
const std::shared_ptr<rclcpp::Context> & context);
415 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node,
416 std::chrono::nanoseconds timeout);
432 std::chrono::nanoseconds timeout,
433 const std::function<std::future_status(std::chrono::nanoseconds wait_time)> & wait_for_future);
446 spin_some_impl(std::chrono::nanoseconds max_duration,
bool exhaustive);
466 rclcpp::SubscriptionBase::SharedPtr subscription);
475 execute_timer(rclcpp::TimerBase::SharedPtr timer,
const std::shared_ptr<void> & data_ptr);
509 wait_for_work(std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
536 std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
556 mutable std::mutex mutex_;
565 spin_once_impl(std::chrono::nanoseconds timeout);
576 std::atomic_bool entities_need_rebuild_;
590 std::shared_ptr<rclcpp::executors::ExecutorNotifyWaitable> current_notify_waitable_
597 std::unique_ptr<ExecutorImplementation>
impl_;
Coordinate the order and timing of available communication tasks.
virtual RCLCPP_PUBLIC void spin_node_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node)
Add a node, complete all immediately available work, and remove the node.
std::shared_ptr< rclcpp::GuardCondition > interrupt_guard_condition_
Guard condition for signaling the rmw layer to wake up for special events.
RCLCPP_PUBLIC void spin_node_once_nanoseconds(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node, std::chrono::nanoseconds timeout)
Add a node to executor, execute the next available unit of work, and remove the node.
virtual RCLCPP_PUBLIC ~Executor()
Default destructor.
virtual RCLCPP_PUBLIC std::vector< rclcpp::CallbackGroup::WeakPtr > get_manually_added_callback_groups()
Get callback groups that belong to executor.
virtual RCLCPP_PUBLIC void remove_callback_group(rclcpp::CallbackGroup::SharedPtr group_ptr, bool notify=true)
Remove a callback group from the executor.
FutureReturnCode spin_until_future_complete(const FutureT &future, std::chrono::duration< TimeRepT, TimeT > timeout=std::chrono::duration< TimeRepT, TimeT >(-1))
Spin (blocking) until the future is complete, it times out waiting, or rclcpp is interrupted.
rclcpp::WaitSet wait_set_ RCPPUTILS_TSA_GUARDED_BY(mutex_)
WaitSet to be waited on.
virtual RCLCPP_PUBLIC void add_callback_group(rclcpp::CallbackGroup::SharedPtr group_ptr, rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Add a callback group to an executor.
RCLCPP_PUBLIC void wait_for_work(std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Block until more work becomes avilable or timeout is reached.
static RCLCPP_PUBLIC void execute_service(rclcpp::ServiceBase::SharedPtr service)
Run service server executable.
virtual RCLCPP_PUBLIC void remove_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Remove a node from the executor.
RCLCPP_PUBLIC Executor(const rclcpp::ExecutorOptions &options=rclcpp::ExecutorOptions())
Default constructor.
virtual RCLCPP_PUBLIC void spin_node_all(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node, std::chrono::nanoseconds max_duration)
Add a node, complete all immediately available work exhaustively, and remove the node.
RCLCPP_PUBLIC bool get_next_executable(AnyExecutable &any_executable, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Wait for executable in ready state and populate union structure.
virtual RCLCPP_PUBLIC void spin_once(std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Collect work once and execute the next available work, optionally within a duration.
virtual RCLCPP_PUBLIC void spin_some(std::chrono::nanoseconds max_duration=std::chrono::nanoseconds(0))
Collect work once and execute all available work, optionally within a max duration.
rclcpp::executors::ExecutorEntitiesCollection current_collection_ RCPPUTILS_TSA_GUARDED_BY(mutex_)
Hold the current state of the collection being waited on by the waitset.
virtual RCLCPP_PUBLIC void cancel()
Cancel any running spin* function, causing it to return.
RCLCPP_PUBLIC bool is_spinning()
Returns true if the executor is currently spinning.
void spin_node_once(std::shared_ptr< NodeT > node, std::chrono::duration< RepT, T > timeout=std::chrono::duration< RepT, T >(-1))
Convenience function which takes Node and forwards NodeBaseInterface.
RCLCPP_PUBLIC bool get_next_ready_executable(AnyExecutable &any_executable)
Check for executable in ready state and populate union structure.
std::shared_ptr< rclcpp::Context > context_
The context associated with this executor.
std::shared_ptr< rclcpp::executors::ExecutorNotifyWaitable > current_notify_waitable_ RCPPUTILS_TSA_GUARDED_BY(mutex_)
Hold the current state of the notify waitable being waited on by the waitset.
static RCLCPP_PUBLIC void execute_timer(rclcpp::TimerBase::SharedPtr timer, const std::shared_ptr< void > &data_ptr)
Run timer executable.
void trigger_entity_recollect(bool notify)
This function triggers a recollect of all entities that are registered to the executor.
static RCLCPP_PUBLIC void execute_subscription(rclcpp::SubscriptionBase::SharedPtr subscription)
Run subscription executable.
RCLCPP_PUBLIC void collect_entities()
Gather all of the waitable entities from associated nodes and callback groups.
virtual RCLCPP_PUBLIC std::vector< rclcpp::CallbackGroup::WeakPtr > get_automatically_added_callback_groups_from_nodes()
Get callback groups that belong to executor.
virtual RCLCPP_PUBLIC FutureReturnCode spin_until_future_complete_impl(std::chrono::nanoseconds timeout, const std::function< std::future_status(std::chrono::nanoseconds wait_time)> &wait_for_future)
Spin (blocking) until the future is complete, it times out waiting, or rclcpp is interrupted.
rclcpp::OnShutdownCallbackHandle shutdown_callback_handle_
shutdown callback handle registered to Context
virtual RCLCPP_PUBLIC void add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Add a node to the executor.
RCLCPP_PUBLIC void execute_any_executable(AnyExecutable &any_exec)
Find the next available executable and do the work associated with it.
virtual void spin()=0
Do work periodically as it becomes available to us. Blocking call, may block indefinitely.
std::shared_ptr< rclcpp::executors::ExecutorNotifyWaitable > notify_waitable_
Waitable containing guard conditions controlling the executor flow.
virtual RCLCPP_PUBLIC std::vector< rclcpp::CallbackGroup::WeakPtr > get_all_callback_groups()
Get callback groups that belong to executor.
static RCLCPP_PUBLIC void execute_client(rclcpp::ClientBase::SharedPtr client)
Run service client executable.
rclcpp::executors::ExecutorEntitiesCollector collector_
Collector used to associate executable entities from nodes and guard conditions.
virtual RCLCPP_PUBLIC void spin_all(std::chrono::nanoseconds max_duration)
Collect and execute work repeatedly within a duration or until no more work is available.
std::unique_ptr< ExecutorImplementation > impl_
Pointer to implementation.
void spin_node_once(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node, std::chrono::duration< RepT, T > timeout=std::chrono::duration< RepT, T >(-1))
Add a node to executor, execute the next available unit of work, and remove the node.
RCLCPP_PUBLIC void spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive)
Collect work and execute available work, optionally within a duration.
std::shared_ptr< rclcpp::GuardCondition > shutdown_guard_condition_
Guard condition for signaling the rmw layer to wake up for system shutdown.
std::atomic_bool spinning
Spinning state, used to prevent multi threaded calls to spin and to cancel blocking spins.
Encapsulates sets of waitable items which can be waited on as a group.
Class to monitor a set of nodes and callback groups for changes in entity membership.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
FutureReturnCode
Return codes to be used with spin_until_future_complete.
Options to be passed to the executor constructor.
Represent the total set of entities for a single executor.