Skip to content

Commit

Permalink
[TreeNode] add failed_ filed and has_failed()
Browse files Browse the repository at this point in the history
  • Loading branch information
umhan35 committed Nov 2, 2020
1 parent 2a7e30a commit fdf4ec9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/behaviortree_cpp_v3/tree_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -152,7 +154,7 @@ class TreeNode
parent_ = parent;
}

TreeNode* getParent() {
TreeNode* getParent() const {
return parent_;
}

Expand Down Expand Up @@ -185,6 +187,8 @@ class TreeNode

NodeStatus status_;

bool failed_ = false;

std::condition_variable state_condition_variable_;

mutable std::mutex state_mutex_;
Expand Down
8 changes: 8 additions & 0 deletions src/tree_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ void TreeNode::setStatus(NodeStatus new_status)
std::unique_lock<std::mutex> UniqueLock(state_mutex_);
prev_status = status_;
status_ = new_status;

if (status_ == NodeStatus::FAILURE) {
this->failed_ = true;
}
}
if (prev_status != new_status)
{
Expand All @@ -59,6 +63,10 @@ NodeStatus TreeNode::status() const
return status_;
}

bool TreeNode::has_failed() const {
return failed_;
}

NodeStatus TreeNode::waitValidStatus()
{
std::unique_lock<std::mutex> lock(state_mutex_);
Expand Down

0 comments on commit fdf4ec9

Please sign in to comment.