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

Method serverLoop

src/loggers/groot2_publisher.cpp:233–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233void Groot2Publisher::serverLoop()
234{
235 auto const serialized_uuid = CreateRandomUUID();
236
237 auto& socket = _p->server;
238
239 auto sendErrorReply = [&socket](const std::string& msg) {
240 zmq::multipart_t error_msg;
241 error_msg.addstr("error");
242 error_msg.addstr(msg);
243 error_msg.send(socket);
244 };
245
246 // initialize _p->last_heartbeat
247 {
248 const std::unique_lock lk(_p->last_heartbeat_mutex);
249 _p->last_heartbeat = std::chrono::steady_clock::now();
250 }
251
252 while(_p->active_server)
253 {
254 zmq::multipart_t requestMsg;
255 try
256 {
257 if(!requestMsg.recv(socket) || requestMsg.size() == 0)
258 {
259 continue;
260 }
261 }
262 catch(const zmq::error_t&)
263 {
264 // Context was terminated or socket error - exit the loop
265 break;
266 }
267
268 // this heartbeat will help establishing if Groot is connected or not
269 {
270 const std::unique_lock lk(_p->last_heartbeat_mutex);
271 _p->last_heartbeat = std::chrono::steady_clock::now();
272 }
273
274 std::string const request_str = requestMsg[0].to_string();
275 if(request_str.size() != Monitor::RequestHeader::size())
276 {
277 sendErrorReply("wrong request header");
278 continue;
279 }
280
281 auto request_header = Monitor::DeserializeRequestHeader(request_str);
282
283 Monitor::ReplyHeader reply_header;
284 reply_header.request = request_header;
285 reply_header.request.protocol = Monitor::kProtocolID;
286 reply_header.tree_id = serialized_uuid;
287
288 zmq::multipart_t reply_msg;
289 reply_msg.addstr(Monitor::SerializeHeader(reply_header));
290

Callers

nothing calls this directly

Calls 15

CreateRandomUUIDFunction · 0.85
DeserializeRequestHeaderFunction · 0.85
SerializeHeaderFunction · 0.85
parseFunction · 0.85
addstrMethod · 0.80
sendMethod · 0.80
recvMethod · 0.80
addmemMethod · 0.80
unlockMethod · 0.80
push_backMethod · 0.80
dumpMethod · 0.80
sizeFunction · 0.50

Tested by

no test coverage detected