----------------------------------------------------------------------------- The device is awake, so send all the pending messages -----------------------------------------------------------------------------
| 434 | // The device is awake, so send all the pending messages |
| 435 | //----------------------------------------------------------------------------- |
| 436 | void WakeUp::SendPending |
| 437 | ( |
| 438 | ) |
| 439 | { |
| 440 | m_awake = true; |
| 441 | bool reloading = false; |
| 442 | m_mutex->Lock(); |
| 443 | list<Driver::MsgQueueItem>::iterator it = m_pendingQueue.begin(); |
| 444 | while( it != m_pendingQueue.end() ) |
| 445 | { |
| 446 | Driver::MsgQueueItem const& item = *it; |
| 447 | if( Driver::MsgQueueCmd_SendMsg == item.m_command ) |
| 448 | { |
| 449 | GetDriver()->SendMsg( item.m_msg, Driver::MsgQueue_WakeUp ); |
| 450 | } |
| 451 | else if( Driver::MsgQueueCmd_QueryStageComplete == item.m_command ) |
| 452 | { |
| 453 | GetDriver()->SendQueryStageComplete( item.m_nodeId, item.m_queryStage ); |
| 454 | } |
| 455 | else if( Driver::MsgQueueCmd_Controller == item.m_command ) |
| 456 | { |
| 457 | GetDriver()->BeginControllerCommand( item.m_cci->m_controllerCommand, item.m_cci->m_controllerCallback, item.m_cci->m_controllerCallbackContext, item.m_cci->m_highPower, item.m_cci->m_controllerCommandNode, item.m_cci->m_controllerCommandArg ); |
| 458 | delete item.m_cci; |
| 459 | } |
| 460 | else if ( Driver::MsgQueueCmd_ReloadNode == item.m_command ) |
| 461 | { |
| 462 | GetDriver()->ReloadNode(item.m_nodeId); |
| 463 | reloading = true; |
| 464 | } |
| 465 | it = m_pendingQueue.erase( it ); |
| 466 | } |
| 467 | m_mutex->Unlock(); |
| 468 | |
| 469 | // Send the device back to sleep, unless we have outstanding queries. |
| 470 | bool sendToSleep = m_awake; |
| 471 | Node* node = GetNodeUnsafe(); |
| 472 | if( node != NULL ) |
| 473 | { |
| 474 | if( !node->AllQueriesCompleted() ) |
| 475 | { |
| 476 | sendToSleep = false; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | /* if we are reloading, the QueryStage_Complete will take care of sending the device back to sleep */ |
| 481 | if( sendToSleep && !reloading ) |
| 482 | { |
| 483 | if( m_com.GetFlagInt(COMPAT_FLAG_WAKEUP_DELAYNMI) == 0 ) { |
| 484 | SendNoMoreInfo(1); |
| 485 | |
| 486 | } else { |
| 487 | Log::Write( LogLevel_Info, GetNodeId(), " Node %d has delayed sleep of %dms", GetNodeId(), m_com.GetFlagInt(COMPAT_FLAG_WAKEUP_DELAYNMI) ); |
| 488 | TimerThread::TimerCallback callback = bind(&WakeUp::SendNoMoreInfo, this, 1); |
| 489 | TimerSetEvent(m_com.GetFlagInt(COMPAT_FLAG_WAKEUP_DELAYNMI), callback, 1); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 |
no test coverage detected