BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
abstract_logger.h
1#ifndef ABSTRACT_LOGGER_H
2#define ABSTRACT_LOGGER_H
3
4#include "behaviortree_cpp/behavior_tree.h"
5#include "behaviortree_cpp/bt_factory.h"
6
7#include <memory>
8
9namespace BT
10{
11enum class TimestampType
12{
13 absolute,
14 relative
15};
16
18{
19public:
20 /// Construct and immediately subscribe to status changes.
21 StatusChangeLogger(TreeNode* root_node);
22
23 virtual ~StatusChangeLogger();
24
25 StatusChangeLogger(const StatusChangeLogger& other) = delete;
26 StatusChangeLogger& operator=(const StatusChangeLogger& other) = delete;
27
28 StatusChangeLogger(StatusChangeLogger&& other) = delete;
29 StatusChangeLogger& operator=(StatusChangeLogger&& other) = delete;
30
31 virtual void callback(BT::Duration timestamp, const TreeNode& node,
32 NodeStatus prev_status, NodeStatus status) = 0;
33
34 virtual void flush() = 0;
35
36 void setEnabled(bool enabled);
37
38 void setTimestampType(TimestampType type);
39
40 bool enabled() const;
41
42 // false by default.
43 bool showsTransitionToIdle() const;
44
45 void enableTransitionToIdle(bool enable);
46
47protected:
48 /// Default constructor for deferred subscription. Call subscribeToTreeChanges() when ready.
50
51 /// Subscribe to status changes. Call at end of constructor for deferred subscription.
52 void subscribeToTreeChanges(TreeNode* root_node);
53
54 /// Stop new callbacks and wait until callbacks already in progress have completed.
55 /// Derived destructors must call this before destroying state used by callback().
57
58private:
59 /// Forward a status transition to callback(), unless disabled.
60 void handleStatusChange(TimePoint timestamp, const TreeNode& node, NodeStatus prev,
61 NodeStatus status);
62
63 // All state lives behind this pointer, so that changing it does not alter the
64 // layout that derived classes (including user-defined loggers) compile against.
65 struct PImpl;
66 std::unique_ptr<PImpl> _p;
67};
68} // namespace BT
69
70#endif // ABSTRACT_LOGGER_H
Definition: abstract_logger.h:18
void subscribeToTreeChanges(TreeNode *root_node)
Subscribe to status changes. Call at end of constructor for deferred subscription.
StatusChangeLogger(TreeNode *root_node)
Construct and immediately subscribe to status changes.
StatusChangeLogger()
Default constructor for deferred subscription. Call subscribeToTreeChanges() when ready.
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:154
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34