Skip to content

Commit e7d2e1a

Browse files
committed
fix style
1 parent 3fc7998 commit e7d2e1a

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

gtest/gtest_factory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ TEST(BehaviorTreeFactory, VerifyLargeTree)
100100

101101
BT::TreeNodePtr root_node = parser.instantiateTree(factory, nodes);
102102

103-
BT::PrintTreeRecursively(root_node.get());
103+
BT::printTreeRecursively(root_node.get());
104104

105105
ASSERT_EQ(root_node->name(), "root_selector");
106106

@@ -155,7 +155,7 @@ TEST(BehaviorTreeFactory, Subtree)
155155
CrossDoor cross_door(factory);
156156

157157
BT::TreeNodePtr root_node = parser.instantiateTree(factory, nodes);
158-
BT::PrintTreeRecursively(root_node.get());
158+
BT::printTreeRecursively(root_node.get());
159159

160160
ASSERT_EQ(root_node->name(), "root_selector");
161161

include/behavior_tree_core/behavior_tree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131

3232
namespace BT
3333
{
34-
void RecursiveVisitor(const TreeNode *node, const std::function<void(const TreeNode*)> visitor);
34+
void recursiveVisitor(const TreeNode *node, const std::function<void(const TreeNode*)> visitor);
3535

3636
/**
3737
* Debug function to print on a stream
3838
*/
39-
void PrintTreeRecursively(const TreeNode* root_node);
39+
void printTreeRecursively(const TreeNode* root_node);
4040
}
4141

4242
#endif // BEHAVIOR_TREE_H

include/behavior_tree_core/tree_node.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "behavior_tree_core/tick_engine.h"
3434
#include "behavior_tree_core/exceptions.h"
35+
#include "behavior_tree_core/signal.h"
3536

3637
namespace BT
3738
{
@@ -154,23 +155,23 @@ typedef std::map<std::string, std::string> NodeParameters;
154155
class TreeNode
155156
{
156157
private:
157-
// Node name
158158
std::string name_;
159159
NodeStatus status_;
160+
Signal<NodeStatus,NodeStatus> state_change_signal_;
161+
std::condition_variable state_condition_variable_;
162+
mutable std::mutex state_mutex_;
160163

161164
protected:
162-
mutable std::mutex state_mutex_;
163-
std::condition_variable state_condition_variable_;
164165

165166
// Method to be implemented by the user
166167
virtual BT::NodeStatus tick() = 0;
167168

168169
public:
169-
// The constructor and the distructor
170+
// The constructor and the destructor
170171
TreeNode(std::string name);
171172
virtual ~TreeNode() = default;
172173

173-
// The method that is going to be executed when the node receive a tick
174+
// The method that should be executed to invoke the tick()
174175
virtual BT::NodeStatus executeTick();
175176

176177
// The method used to interrupt the execution of the node
@@ -184,9 +185,24 @@ class TreeNode
184185
const std::string& name() const;
185186
void setName(const std::string& new_name);
186187

188+
// Will block until the status is either RUNNING, FAILURE or SUCCESS.
187189
BT::NodeStatus waitValidStatus();
188190

189191
virtual NodeType type() const = 0;
192+
193+
using StateChangeCallback = Signal<NodeStatus,NodeStatus>::CallableFuntion;
194+
using StateChangeSubscriber = Signal<NodeStatus,NodeStatus>::Subscriber;
195+
196+
/**
197+
* @brief subscribeToStateChange allows the user to have a callback invoked every time
198+
* the state of the this TreeNode changes.
199+
*
200+
* @param callback funtion, must have the signature [ void callback(BT::NodeStatus prev_status, BT::NodeStatus new_status) ]
201+
*
202+
* @return the returned StateChangeSubscriber objects will be automatically unsubscribed when it goes out of scope.
203+
*/
204+
StateChangeSubscriber subscribeToStateChange(StateChangeCallback callback);
205+
190206
};
191207

192208
typedef std::shared_ptr<TreeNode> TreeNodePtr;

src/behavior_tree.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BT
44
{
5-
void RecursiveVisitor(const TreeNode* node, const std::function<void(const TreeNode*)> visitor)
5+
void recursiveVisitor(const TreeNode* node, const std::function<void(const TreeNode*)> visitor)
66
{
77
if (!node)
88
{
@@ -16,17 +16,17 @@ void RecursiveVisitor(const TreeNode* node, const std::function<void(const TreeN
1616
{
1717
for (const auto& child : control->children())
1818
{
19-
RecursiveVisitor(child, visitor);
19+
recursiveVisitor(child, visitor);
2020
}
2121
}
2222
auto decorator = dynamic_cast<const BT::DecoratorNode*>(node);
2323
if (decorator)
2424
{
25-
RecursiveVisitor(decorator->child(), visitor);
25+
recursiveVisitor(decorator->child(), visitor);
2626
}
2727
}
2828

29-
void PrintTreeRecursively(const TreeNode* root_node)
29+
void printTreeRecursively(const TreeNode* root_node)
3030
{
3131
std::function<void(int, const BT::TreeNode*)> recursivePrint;
3232

0 commit comments

Comments
 (0)