| 16 | { |
| 17 | |
| 18 | NodeStatus TimeoutNode::tick() |
| 19 | { |
| 20 | if(read_parameter_from_ports_) |
| 21 | { |
| 22 | if(!getInput("msec", msec_)) |
| 23 | { |
| 24 | throw RuntimeError("Missing parameter [msec] in TimeoutNode"); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | if(!timeout_started_) |
| 29 | { |
| 30 | timeout_started_ = true; |
| 31 | setStatus(NodeStatus::RUNNING); |
| 32 | child_halted_ = false; |
| 33 | |
| 34 | if(msec_ > 0) |
| 35 | { |
| 36 | timer_id_ = timer_.add(std::chrono::milliseconds(msec_), [this](bool aborted) { |
| 37 | // Return immediately if the timer was aborted. |
| 38 | // This function could be invoked during destruction of this object and |
| 39 | // we don't want to access member variables if not needed. |
| 40 | if(aborted) |
| 41 | { |
| 42 | return; |
| 43 | } |
| 44 | const std::unique_lock<std::mutex> lk(timeout_mutex_); |
| 45 | if(child()->status() == NodeStatus::RUNNING) |
| 46 | { |
| 47 | child_halted_ = true; |
| 48 | haltChild(); |
| 49 | emitWakeUpSignal(); |
| 50 | } |
| 51 | }); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | std::unique_lock<std::mutex> lk(timeout_mutex_); |
| 56 | |
| 57 | if(child_halted_) |
| 58 | { |
| 59 | timeout_started_ = false; |
| 60 | return NodeStatus::FAILURE; |
| 61 | } |
| 62 | const NodeStatus child_status = child()->executeTick(); |
| 63 | if(isStatusCompleted(child_status)) |
| 64 | { |
| 65 | timeout_started_ = false; |
| 66 | lk.unlock(); |
| 67 | timer_.cancel(timer_id_); |
| 68 | lk.lock(); |
| 69 | resetChild(); |
| 70 | } |
| 71 | return child_status; |
| 72 | } |
| 73 | |
| 74 | void TimeoutNode::halt() |
| 75 | { |
nothing calls this directly
no test coverage detected