| 565 | } |
| 566 | |
| 567 | bool Groot2Publisher::insertHook(std::shared_ptr<Monitor::Hook> hook) |
| 568 | { |
| 569 | auto const node_uid = hook->node_uid; |
| 570 | auto it = _p->nodes_by_uid.find(node_uid); |
| 571 | if(it == _p->nodes_by_uid.end()) |
| 572 | { |
| 573 | return false; |
| 574 | } |
| 575 | const TreeNode::Ptr node = it->second.lock(); |
| 576 | if(!node) |
| 577 | { |
| 578 | return false; |
| 579 | } |
| 580 | |
| 581 | auto injectedCallback = [hook, this](TreeNode& node) -> NodeStatus { |
| 582 | std::unique_lock<std::mutex> lk(hook->mutex); |
| 583 | if(!hook->enabled) |
| 584 | { |
| 585 | return NodeStatus::SKIPPED; |
| 586 | } |
| 587 | |
| 588 | // Notify that a breakpoint was reached, using the _p->publisher |
| 589 | const Monitor::RequestHeader breakpoint_request(Monitor::BREAKPOINT_REACHED); |
| 590 | zmq::multipart_t request_msg; |
| 591 | request_msg.addstr(Monitor::SerializeHeader(breakpoint_request)); |
| 592 | request_msg.addstr(std::to_string(hook->node_uid)); |
| 593 | request_msg.send(_p->publisher); |
| 594 | |
| 595 | // wait until someone wake us up |
| 596 | if(hook->mode == Monitor::Hook::Mode::BREAKPOINT) |
| 597 | { |
| 598 | hook->wakeup.wait(lk, [hook]() { return hook->ready || !hook->enabled; }); |
| 599 | |
| 600 | hook->ready = false; |
| 601 | // wait was unblocked but it could be the breakpoint becoming disabled. |
| 602 | // in this case, just skip |
| 603 | if(!hook->enabled) |
| 604 | { |
| 605 | return NodeStatus::SKIPPED; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | if(hook->remove_when_done) |
| 610 | { |
| 611 | // self-destruction at the end of this lambda function |
| 612 | const std::unique_lock<std::mutex> lk(_p->hooks_map_mutex); |
| 613 | _p->pre_hooks.erase(hook->node_uid); |
| 614 | node.setPreTickFunction({}); |
| 615 | } |
| 616 | return hook->desired_status; |
| 617 | }; |
| 618 | |
| 619 | const std::unique_lock<std::mutex> lk(_p->hooks_map_mutex); |
| 620 | _p->pre_hooks[node_uid] = hook; |
| 621 | node->setPreTickFunction(injectedCallback); |
| 622 | |
| 623 | return true; |
| 624 | } |
nothing calls this directly
no test coverage detected