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 const rclcpp::CallbackGroup::SharedPtr & group_ptr,
106 const 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 const rclcpp::CallbackGroup::SharedPtr & group_ptr,
201 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr & node_ptr,
210 add_node(
const std::shared_ptr<rclcpp::Node> & node_ptr,
bool notify =
true);
231 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr & node_ptr,
240 remove_node(
const std::shared_ptr<rclcpp::Node> & node_ptr,
bool notify =
true);
249 template<
typename RepT =
int64_t,
typename T = std::milli>
252 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr & node,
253 std::chrono::duration<RepT, T> timeout = std::chrono::duration<RepT, T>(-1))
257 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
262 template<
typename NodeT = rclcpp::Node,
typename RepT =
int64_t,
typename T = std::milli>
265 const std::shared_ptr<NodeT> & node,
266 std::chrono::duration<RepT, T> timeout = std::chrono::duration<RepT, T>(-1))
269 node->get_node_base_interface(),
270 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
280 spin_node_some(
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr & node);
319 spin_some(std::chrono::nanoseconds max_duration = std::chrono::nanoseconds(0));
328 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr & node,
329 std::chrono::nanoseconds max_duration);
334 spin_node_all(
const std::shared_ptr<rclcpp::Node> & node, std::chrono::nanoseconds max_duration);
353 spin_all(std::chrono::nanoseconds max_duration);
367 spin_once(std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
382 template<
typename FutureT,
typename TimeRepT =
int64_t,
typename TimeT = std::milli>
385 const FutureT & future,
386 std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
389 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout),
390 [&future](std::chrono::nanoseconds wait_time) {
391 return future.wait_for(wait_time);
421 explicit Executor(
const std::shared_ptr<rclcpp::Context> & context);
434 const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr & node,
435 std::chrono::nanoseconds timeout);
451 std::chrono::nanoseconds timeout,
452 const std::function<std::future_status(std::chrono::nanoseconds wait_time)> & wait_for_future);
465 spin_some_impl(std::chrono::nanoseconds max_duration,
bool exhaustive);
485 const rclcpp::SubscriptionBase::SharedPtr & subscription);
494 execute_timer(
const rclcpp::TimerBase::SharedPtr & timer,
const std::shared_ptr<void> & data_ptr);
528 wait_for_work(std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
555 std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
576 mutable std::mutex mutex_;
585 spin_once_impl(std::chrono::nanoseconds timeout);
596 std::atomic_bool entities_need_rebuild_;
610 std::shared_ptr<rclcpp::executors::ExecutorNotifyWaitable> current_notify_waitable_
617 std::unique_ptr<ExecutorImplementation>
impl_;
Coordinate the order and timing of available communication tasks.
std::shared_ptr< rclcpp::GuardCondition > interrupt_guard_condition_
Guard condition for signaling the rmw layer to wake up for special events.
virtual RCLCPP_PUBLIC void spin_node_some(const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr &node)
Add a node, complete all immediately available work, and remove the node.
virtual RCLCPP_PUBLIC void spin_node_all(const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr &node, std::chrono::nanoseconds max_duration)
Add a node, complete all immediately available work exhaustively, 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.
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.
RCLCPP_PUBLIC void wait_for_work(std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))
Block until more work becomes avilable or timeout is reached.
RCLCPP_PUBLIC void spin_node_once_nanoseconds(const 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.
RCLCPP_PUBLIC Executor(const rclcpp::ExecutorOptions &options=rclcpp::ExecutorOptions())
Default constructor.
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.
static RCLCPP_PUBLIC void execute_timer(const rclcpp::TimerBase::SharedPtr &timer, const std::shared_ptr< void > &data_ptr)
Run timer executable.
RCLCPP_PUBLIC bool is_spinning()
Returns true if the executor is currently spinning.
virtual RCLCPP_PUBLIC void handle_updated_entities(bool notify)
This function triggers a recollect of all entities that are registered to the executor.
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.
virtual RCLCPP_PUBLIC void remove_node(const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr &node_ptr, bool notify=true)
Remove a node from the executor.
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.
void spin_node_once(const 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.
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.
void spin_node_once(const 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.
virtual RCLCPP_PUBLIC void remove_callback_group(const rclcpp::CallbackGroup::SharedPtr &group_ptr, bool notify=true)
Remove a callback group from the executor.
static RCLCPP_PUBLIC void execute_client(const rclcpp::ClientBase::SharedPtr &client)
Run service client executable.
rclcpp::OnShutdownCallbackHandle shutdown_callback_handle_
shutdown callback handle registered to Context
static RCLCPP_PUBLIC void execute_service(const rclcpp::ServiceBase::SharedPtr &service)
Run service server executable.
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.
virtual RCLCPP_PUBLIC void add_callback_group(const rclcpp::CallbackGroup::SharedPtr &group_ptr, const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr &node_ptr, bool notify=true)
Add a callback group to an executor.
virtual RCLCPP_PUBLIC void add_node(const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr &node_ptr, bool notify=true)
Add a node to the executor.
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.
RCLCPP_PUBLIC void spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive)
Collect work and execute available work, optionally within a duration.
static RCLCPP_PUBLIC void execute_subscription(const rclcpp::SubscriptionBase::SharedPtr &subscription)
Run subscription executable.
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.