11#include " behaviortree_cpp/actions/test_node.h"
22
3- BT::TestNode::TestNode (const std::string& name, const NodeConfig& config,
4- TestNodeConfig test_config)
5- : StatefulActionNode(name, config), _test_config(std::move(test_config))
3+ namespace BT
4+ {
5+
6+ TestNode::TestNode (const std::string& name, const NodeConfig& config,
7+ TestNodeConfig test_config)
8+ : TestNode(name, config, std::make_shared<TestNodeConfig>(std::move(test_config)))
9+ {}
10+
11+ TestNode::TestNode (const std::string& name, const NodeConfig& config,
12+ std::shared_ptr<TestNodeConfig> test_config)
13+ : StatefulActionNode(name, config), _config(std::move(test_config))
614{
715 setRegistrationID (" TestNode" );
816
9- if (_test_config. return_status == NodeStatus::IDLE)
17+ if (_config-> return_status == NodeStatus::IDLE)
1018 {
1119 throw RuntimeError (" TestNode can not return IDLE" );
1220 }
@@ -22,21 +30,21 @@ BT::TestNode::TestNode(const std::string& name, const NodeConfig& config,
2230 executor = result.value ();
2331 }
2432 };
25- prepareScript (_test_config. success_script , _success_executor);
26- prepareScript (_test_config. failure_script , _failure_executor);
27- prepareScript (_test_config. post_script , _post_executor);
33+ prepareScript (_config-> success_script , _success_executor);
34+ prepareScript (_config-> failure_script , _failure_executor);
35+ prepareScript (_config-> post_script , _post_executor);
2836}
2937
30- BT:: NodeStatus BT:: TestNode::onStart ()
38+ NodeStatus TestNode::onStart ()
3139{
32- if (_test_config. async_delay <= std::chrono::milliseconds (0 ))
40+ if (_config-> async_delay <= std::chrono::milliseconds (0 ))
3341 {
3442 return onCompleted ();
3543 }
3644 // convert this in an asynchronous operation. Use another thread to count
3745 // a certain amount of time.
3846 _completed = false ;
39- _timer.add (std::chrono::milliseconds (_test_config. async_delay ), [this ](bool aborted) {
47+ _timer.add (std::chrono::milliseconds (_config-> async_delay ), [this ](bool aborted) {
4048 if (!aborted)
4149 {
4250 _completed.store (true );
@@ -50,7 +58,7 @@ BT::NodeStatus BT::TestNode::onStart()
5058 return NodeStatus::RUNNING;
5159}
5260
53- BT:: NodeStatus BT:: TestNode::onRunning ()
61+ NodeStatus TestNode::onRunning ()
5462{
5563 if (_completed)
5664 {
@@ -59,17 +67,18 @@ BT::NodeStatus BT::TestNode::onRunning()
5967 return NodeStatus::RUNNING;
6068}
6169
62- void BT:: TestNode::onHalted ()
70+ void TestNode::onHalted ()
6371{
6472 _timer.cancelAll ();
6573}
6674
67- BT:: NodeStatus BT:: TestNode::onCompleted ()
75+ NodeStatus TestNode::onCompleted ()
6876{
6977 Ast::Environment env = { config ().blackboard , config ().enums };
7078
71- auto status = (_test_config.complete_func ) ? _test_config.complete_func () :
72- _test_config.return_status ;
79+ auto status =
80+ (_config->complete_func ) ? _config->complete_func () : _config->return_status ;
81+
7382 if (status == NodeStatus::SUCCESS && _success_executor)
7483 {
7584 _success_executor (env);
@@ -84,3 +93,5 @@ BT::NodeStatus BT::TestNode::onCompleted()
8493 }
8594 return status;
8695}
96+
97+ } // namespace BT
0 commit comments