rclcpp  master
C++ ROS Client Library API
executors.hpp
Go to the documentation of this file.
1 // Copyright 2014 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_HPP_
16 #define RCLCPP__EXECUTORS_HPP_
17 
18 #include <future>
19 #include <memory>
20 
24 #include "rclcpp/node.hpp"
25 #include "rclcpp/utilities.hpp"
27 
28 namespace rclcpp
29 {
30 
32 
34 void
35 spin_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr);
36 
38 void
39 spin_some(rclcpp::Node::SharedPtr node_ptr);
40 
42 
44 void
45 spin(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr);
46 
48 void
49 spin(rclcpp::Node::SharedPtr node_ptr);
50 
51 namespace executors
52 {
53 
56 
58 
69 template<typename FutureT, typename TimeRepT = int64_t, typename TimeT = std::milli>
72  rclcpp::Executor & executor,
73  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
74  const FutureT & future,
76 {
77  // TODO(wjwwood): does not work recursively; can't call spin_node_until_future_complete
78  // inside a callback executed by an executor.
79  executor.add_node(node_ptr);
80  auto retcode = executor.spin_until_future_complete(future, timeout);
81  executor.remove_node(node_ptr);
82  return retcode;
83 }
84 
85 template<typename NodeT = rclcpp::Node, typename FutureT, typename TimeRepT = int64_t,
86  typename TimeT = std::milli>
89  rclcpp::Executor & executor,
90  std::shared_ptr<NodeT> node_ptr,
91  const FutureT & future,
93 {
95  executor,
96  node_ptr->get_node_base_interface(),
97  future,
98  timeout);
99 }
100 
101 } // namespace executors
102 
103 template<typename FutureT, typename TimeRepT = int64_t, typename TimeT = std::milli>
106  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
107  const FutureT & future,
109 {
111  return executors::spin_node_until_future_complete<FutureT>(executor, node_ptr, future, timeout);
112 }
113 
114 template<typename NodeT = rclcpp::Node, typename FutureT, typename TimeRepT = int64_t,
115  typename TimeT = std::milli>
118  std::shared_ptr<NodeT> node_ptr,
119  const FutureT & future,
121 {
122  return rclcpp::spin_until_future_complete(node_ptr->get_node_base_interface(), future, timeout);
123 }
124 
125 } // namespace rclcpp
126 
127 #endif // RCLCPP__EXECUTORS_HPP_
rclcpp::FutureReturnCode
FutureReturnCode
Return codes to be used with spin_until_future_complete.
Definition: future_return_code.hpp:33
std::shared_ptr
rclcpp::spin_until_future_complete
rclcpp::FutureReturnCode spin_until_future_complete(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, const FutureT &future, std::chrono::duration< TimeRepT, TimeT > timeout=std::chrono::duration< TimeRepT, TimeT >(-1))
Definition: executors.hpp:105
static_single_threaded_executor.hpp
node.hpp
std::chrono::duration
multi_threaded_executor.hpp
rclcpp::Executor
Coordinate the order and timing of available communication tasks.
Definition: executor.hpp:65
rclcpp::executors::spin_node_until_future_complete
rclcpp::FutureReturnCode spin_node_until_future_complete(rclcpp::Executor &executor, rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, 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.
Definition: executors.hpp:71
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
rclcpp::spin_some
void spin_some(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
Create a default single-threaded executor and execute any immediately available work.
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::Node
Node is the single point of entry for creating publishers and subscribers.
Definition: node.hpp:77
std::milli
rclcpp::executors::SingleThreadedExecutor
Single-threaded executor implementation.
Definition: single_threaded_executor.hpp:42
rclcpp::Executor::remove_node
virtual void remove_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Remove a node from the executor.
rclcpp::Executor::spin_until_future_complete
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.
Definition: executor.hpp:332
rclcpp::Executor::add_node
virtual void add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify=true)
Add a node to the executor.
single_threaded_executor.hpp
visibility_control.hpp
rclcpp::executors::MultiThreadedExecutor
Definition: multi_threaded_executor.hpp:36
rclcpp::spin
void spin(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
Create a default single-threaded executor and spin the specified node.
utilities.hpp