MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / Groot2Publisher

Method Groot2Publisher

src/loggers/groot2_publisher.cpp:114–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112};
113
114Groot2Publisher::Groot2Publisher(const BT::Tree& tree, unsigned server_port)
115 : StatusChangeLogger(tree.rootNode()), _p(new PImpl())
116{
117 _p->server_port = server_port;
118 _p->tree_xml = WriteTreeToXML(tree, true, true);
119
120 //-------------------------------
121 // Prepare the status buffer
122 size_t node_count = 0;
123 for(const auto& subtree : tree.subtrees)
124 {
125 node_count += subtree->nodes.size();
126 }
127 _p->status_buffer.resize(3 * node_count);
128
129 unsigned ptr_offset = 0;
130 char* buffer_ptr = _p->status_buffer.data();
131
132 for(const auto& subtree : tree.subtrees)
133 {
134 auto name =
135 subtree->instance_name.empty() ? subtree->tree_ID : subtree->instance_name;
136 _p->subtrees.insert({ name, subtree });
137
138 for(const auto& node : subtree->nodes)
139 {
140 _p->nodes_by_uid.insert({ node->UID(), node });
141
142 ptr_offset += Monitor::Serialize(buffer_ptr, ptr_offset, node->UID());
143 _p->status_buffermap.insert({ node->UID(), buffer_ptr + ptr_offset });
144 ptr_offset += Monitor::Serialize(buffer_ptr, ptr_offset, uint8_t(NodeStatus::IDLE));
145 }
146 }
147 //-------------------------------
148 _p->server_address = StrCat("tcp://*:", std::to_string(server_port));
149 _p->publisher_address = StrCat("tcp://*:", std::to_string(server_port + 1));
150
151 _p->server.bind(_p->server_address.c_str());
152 _p->publisher.bind(_p->publisher_address.c_str());
153
154 _p->server_thread = std::thread(&Groot2Publisher::serverLoop, this);
155 _p->heartbeat_thread = std::thread(&Groot2Publisher::heartbeatLoop, this);
156}
157
158void Groot2Publisher::setMaxHeartbeatDelay(std::chrono::milliseconds delay)
159{

Callers

nothing calls this directly

Calls 9

WriteTreeToXMLFunction · 0.85
SerializeFunction · 0.85
StrCatFunction · 0.85
rootNodeMethod · 0.80
UIDMethod · 0.80
to_stringFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected