From fdf4ec9aeac9c2869fd18eaeb33a45f924860ade Mon Sep 17 00:00:00 2001 From: Zhao Han Date: Mon, 2 Nov 2020 16:29:00 -0500 Subject: [PATCH] [TreeNode] add failed_ filed and has_failed() --- include/behaviortree_cpp_v3/tree_node.h | 6 +++++- src/tree_node.cpp | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/behaviortree_cpp_v3/tree_node.h b/include/behaviortree_cpp_v3/tree_node.h index a1dfe3419..b6411520c 100644 --- a/include/behaviortree_cpp_v3/tree_node.h +++ b/include/behaviortree_cpp_v3/tree_node.h @@ -82,6 +82,8 @@ class TreeNode void setStatus(NodeStatus new_status); + bool has_failed() const; + /// Name of the instance, not the type const std::string& name() const; @@ -152,7 +154,7 @@ class TreeNode parent_ = parent; } - TreeNode* getParent() { + TreeNode* getParent() const { return parent_; } @@ -185,6 +187,8 @@ class TreeNode NodeStatus status_; + bool failed_ = false; + std::condition_variable state_condition_variable_; mutable std::mutex state_mutex_; diff --git a/src/tree_node.cpp b/src/tree_node.cpp index de36e20b5..1a6d74028 100644 --- a/src/tree_node.cpp +++ b/src/tree_node.cpp @@ -44,6 +44,10 @@ void TreeNode::setStatus(NodeStatus new_status) std::unique_lock UniqueLock(state_mutex_); prev_status = status_; status_ = new_status; + + if (status_ == NodeStatus::FAILURE) { + this->failed_ = true; + } } if (prev_status != new_status) { @@ -59,6 +63,10 @@ NodeStatus TreeNode::status() const return status_; } +bool TreeNode::has_failed() const { + return failed_; +} + NodeStatus TreeNode::waitValidStatus() { std::unique_lock lock(state_mutex_);