timeout_node.h
Go to the documentation of this file.
1 /* Copyright (C) 2018-2023 Davide Faconti - All Rights Reserved
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #pragma once
14 
17 #include <atomic>
18 
19 namespace BT
20 {
35 class TimeoutNode : public DecoratorNode
36 {
37 public:
38  TimeoutNode(const std::string& name, unsigned milliseconds)
39  : DecoratorNode(name, {})
40  , child_halted_(false)
41  , timer_id_(0)
42  , msec_(milliseconds)
44  , timeout_started_(false)
45  {
46  setRegistrationID("Timeout");
47  }
48 
49  TimeoutNode(const std::string& name, const NodeConfig& config)
51  , child_halted_(false)
52  , timer_id_(0)
53  , msec_(0)
55  , timeout_started_(false)
56  {}
57 
58  ~TimeoutNode() override
59  {
60  timer_.cancelAll();
61  }
62 
64  {
65  return { InputPort<unsigned>("msec", "After a certain amount of time, "
66  "halt() the child if it is still running.") };
67  }
68 
69 private:
70  virtual BT::NodeStatus tick() override;
71 
72  void halt() override;
73 
75  std::atomic_bool child_halted_ = false;
76  uint64_t timer_id_;
77 
78  unsigned msec_;
80  std::atomic_bool timeout_started_ = false;
82 };
83 
84 } // namespace BT
BT
Definition: ex01_wrap_legacy.cpp:29
BT::TimerQueue
Definition: timer_queue.h:72
BT::TreeNode::config
const NodeConfig & config() const
Definition: tree_node.cpp:345
BT::TimeoutNode::read_parameter_from_ports_
bool read_parameter_from_ports_
Definition: timeout_node.h:79
BT::TimeoutNode::timer_id_
uint64_t timer_id_
Definition: timeout_node.h:76
BT::TimeoutNode::timer_
TimerQueue timer_
Definition: timeout_node.h:74
BT::DecoratorNode
Definition: decorator_node.h:8
timer_queue.h
BT::TimeoutNode::providedPorts
static PortsList providedPorts()
Definition: timeout_node.h:63
mutex
static pthread_mutex_t mutex
Definition: minitrace.cpp:77
BT::PortsList
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:585
BT::TimeoutNode::TimeoutNode
TimeoutNode(const std::string &name, const NodeConfig &config)
Definition: timeout_node.h:49
BT::TimeoutNode::~TimeoutNode
~TimeoutNode() override
Definition: timeout_node.h:58
BT::TimeoutNode::timeout_mutex_
std::mutex timeout_mutex_
Definition: timeout_node.h:81
BT::TreeNode::setRegistrationID
void setRegistrationID(StringView ID)
Definition: tree_node.cpp:433
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:296
BT::TimeoutNode::timeout_started_
std::atomic_bool timeout_started_
Definition: timeout_node.h:80
BT::TimeoutNode::msec_
unsigned msec_
Definition: timeout_node.h:78
BT::TimeoutNode::halt
void halt() override
The method used to interrupt the execution of this node.
Definition: timeout_node.cpp:77
BT::TimeoutNode::tick
virtual BT::NodeStatus tick() override
Method to be implemented by the user.
Definition: timeout_node.cpp:18
BT::TimeoutNode
The TimeoutNode will halt() a running child if the latter has been RUNNING longer than a given time....
Definition: timeout_node.h:35
BT::NodeConfig
Definition: tree_node.h:73
decorator_node.h
BT::TimeoutNode::child_halted_
std::atomic_bool child_halted_
Definition: timeout_node.h:75
BT::TimerQueue::cancelAll
size_t cancelAll()
Cancels all timers.
Definition: timer_queue.h:151
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
BT::TimeoutNode::TimeoutNode
TimeoutNode(const std::string &name, unsigned milliseconds)
Definition: timeout_node.h:38


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:08