----------------------------------------------------------------------------- Create and manage the worker threads -----------------------------------------------------------------------------
| 426 | // Create and manage the worker threads |
| 427 | //----------------------------------------------------------------------------- |
| 428 | void Driver::DriverThreadProc |
| 429 | ( |
| 430 | Event* _exitEvent |
| 431 | ) |
| 432 | { |
| 433 | #define WAITOBJECTCOUNT 11 |
| 434 | |
| 435 | uint32 attempts = 0; |
| 436 | bool mfsisReady = false; |
| 437 | while( true ) |
| 438 | { |
| 439 | if( Init( attempts ) ) |
| 440 | { |
| 441 | // Driver has been initialised |
| 442 | Wait* waitObjects[WAITOBJECTCOUNT]; |
| 443 | waitObjects[0] = _exitEvent; // Thread must exit. |
| 444 | waitObjects[1] = m_notificationsEvent; // Notifications waiting to be sent. |
| 445 | waitObjects[2] = m_queueMsgEvent; ; // a DNS and HTTP Event |
| 446 | waitObjects[3] = m_controller; // Controller has received data. |
| 447 | waitObjects[4] = m_queueEvent[MsgQueue_Command]; // A controller command is in progress. |
| 448 | waitObjects[5] = m_queueEvent[MsgQueue_NoOp]; // Send device probes and diagnostics messages |
| 449 | waitObjects[6] = m_queueEvent[MsgQueue_Controller]; // A multi-part controller command is in progress |
| 450 | waitObjects[7] = m_queueEvent[MsgQueue_WakeUp]; // A node has woken. Pending messages should be sent. |
| 451 | waitObjects[8] = m_queueEvent[MsgQueue_Send]; // Ordinary requests to be sent. |
| 452 | waitObjects[9] = m_queueEvent[MsgQueue_Query]; // Node queries are pending. |
| 453 | waitObjects[10] = m_queueEvent[MsgQueue_Poll]; // Poll request is waiting. |
| 454 | |
| 455 | TimeStamp retryTimeStamp; |
| 456 | int retryTimeout = RETRY_TIMEOUT; |
| 457 | Options::Get()->GetOptionAsInt( "RetryTimeout", &retryTimeout ); |
| 458 | //retryTimeout = RETRY_TIMEOUT * 10; |
| 459 | while( true ) |
| 460 | { |
| 461 | Log::Write( LogLevel_StreamDetail, " Top of DriverThreadProc loop." ); |
| 462 | uint32 count = WAITOBJECTCOUNT; |
| 463 | int32 timeout = Wait::Timeout_Infinite; |
| 464 | |
| 465 | // if the ManufacturerDB class is setting up, we can't do anything yet |
| 466 | if (mfsisReady == false) { |
| 467 | count=3; |
| 468 | |
| 469 | // If we're waiting for a message to complete, we can only |
| 470 | // handle incoming data, notifications, DNS/HTTP and exit events. |
| 471 | } else if( m_waitingForAck || m_expectedCallbackId || m_expectedReply ) |
| 472 | { |
| 473 | count = 4; |
| 474 | timeout = m_waitingForAck ? ACK_TIMEOUT : retryTimeStamp.TimeRemaining(); |
| 475 | if( timeout < 0 ) |
| 476 | { |
| 477 | timeout = 0; |
| 478 | } |
| 479 | } |
| 480 | else if( m_currentControllerCommand != NULL ) |
| 481 | { |
| 482 | count = 7; |
| 483 | } |
| 484 | else |
| 485 | { |
no test coverage detected