ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
executors.cpp
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 #include "rclcpp/executors.hpp"
16 
17 void
19  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
20  std::chrono::nanoseconds max_duration)
21 {
23  options.context = node_ptr->get_context();
25  exec.spin_node_all(node_ptr, max_duration);
26 }
27 
28 void
29 rclcpp::spin_all(rclcpp::Node::SharedPtr node_ptr, std::chrono::nanoseconds max_duration)
30 {
31  rclcpp::spin_all(node_ptr->get_node_base_interface(), max_duration);
32 }
33 
34 void
35 rclcpp::spin_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
36 {
38  options.context = node_ptr->get_context();
40  exec.spin_node_some(node_ptr);
41 }
42 
43 void
44 rclcpp::spin_some(rclcpp::Node::SharedPtr node_ptr)
45 {
46  rclcpp::spin_some(node_ptr->get_node_base_interface());
47 }
48 
49 void
50 rclcpp::spin(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
51 {
53  options.context = node_ptr->get_context();
55  exec.add_node(node_ptr);
56  exec.spin();
57  exec.remove_node(node_ptr);
58 }
59 
60 void
61 rclcpp::spin(rclcpp::Node::SharedPtr node_ptr)
62 {
63  rclcpp::spin(node_ptr->get_node_base_interface());
64 }
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.
Definition: executor.cpp:307
virtual RCLCPP_PUBLIC void remove_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Remove a node from the executor.
Definition: executor.cpp:223
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.
Definition: executor.cpp:326
virtual RCLCPP_PUBLIC void add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Add a node to the executor.
Definition: executor.cpp:187
Single-threaded executor implementation.
RCLCPP_PUBLIC void spin() override
Single-threaded implementation of spin.
RCLCPP_PUBLIC void spin(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
Create a default single-threaded executor and spin the specified node.
Definition: executors.cpp:50
RCLCPP_PUBLIC void spin_all(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, std::chrono::nanoseconds max_duration)
Create a default single-threaded executor and execute all available work exhaustively.
Definition: executors.cpp:18
RCLCPP_PUBLIC void spin_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
Create a default single-threaded executor and execute any immediately available work.
Definition: executors.cpp:35
Options to be passed to the executor constructor.