void handleGetNodeInfoResponse(const ServiceCallResult<protocol::GetNodeInfo>& result) { Entry& entry = getEntry(result.getCallID().server_node_id); if (result.isSuccessful()) { /* * Updating the uptime here allows to properly handle a corner case where the service response arrives * after the device has restarted and published its new NodeStatus (although it's unlikely to happen). */ entry.uptime_sec = result.getResponse().status.uptime_sec; entry.request_needed = false; listeners_.forEach(NodeInfoRetrievedHandlerCaller(result.getCallID().server_node_id, result.getResponse())); } else { if (num_attempts_ != UnlimitedRequestAttempts) { entry.num_attempts_made++; if (entry.num_attempts_made >= num_attempts_) { entry.request_needed = false; listeners_.forEach(GenericHandlerCaller<NodeID>(&INodeInfoListener::handleNodeInfoUnavailable, result.getCallID().server_node_id)); } } } }
virtual void handleNodeStatusChange(const NodeStatusChangeEvent& event) { const bool was_offline = !event.old_status.known || (event.old_status.status_code == protocol::NodeStatus::STATUS_OFFLINE); const bool offline_now = !event.status.known || (event.status.status_code == protocol::NodeStatus::STATUS_OFFLINE); if (was_offline || offline_now) { Entry& entry = getEntry(event.node_id); entry.request_needed = !offline_now; entry.num_attempts_made = 0; UAVCAN_TRACE("NodeInfoRetriever", "Offline status change: node ID %d, request needed: %d", int(event.node_id.get()), int(entry.request_needed)); if (entry.request_needed) { startTimerIfNotRunning(); } } listeners_.forEach( GenericHandlerCaller<const NodeStatusChangeEvent&>(&INodeInfoListener::handleNodeStatusChange, event)); }
virtual void handleNodeStatusMessage(const ReceivedDataStructure<protocol::NodeStatus>& msg) { Entry& entry = getEntry(msg.getSrcNodeID()); if (msg.uptime_sec < entry.uptime_sec) { entry.request_needed = true; entry.num_attempts_made = 0; startTimerIfNotRunning(); } entry.uptime_sec = msg.uptime_sec; entry.updated_since_last_attempt = true; listeners_.forEach(GenericHandlerCaller<const ReceivedDataStructure<protocol::NodeStatus>&>( &INodeInfoListener::handleNodeStatusMessage, msg)); }