----------------------------------------------------------------------------- Thread for poll Z-Wave devices -----------------------------------------------------------------------------
| 4471 | // Thread for poll Z-Wave devices |
| 4472 | //----------------------------------------------------------------------------- |
| 4473 | void Driver::PollThreadProc |
| 4474 | ( |
| 4475 | Event* _exitEvent |
| 4476 | ) |
| 4477 | { |
| 4478 | while( 1 ) |
| 4479 | { |
| 4480 | int32 pollInterval = m_pollInterval; |
| 4481 | |
| 4482 | if( m_awakeNodesQueried && !m_pollList.empty() ) |
| 4483 | { |
| 4484 | // We only bother getting the lock if the pollList is not empty |
| 4485 | m_pollMutex->Lock(); |
| 4486 | |
| 4487 | // Get the next value to be polled |
| 4488 | PollEntry pe = m_pollList.front(); |
| 4489 | m_pollList.pop_front(); |
| 4490 | ValueID valueId = pe.m_id; |
| 4491 | |
| 4492 | // only execute this poll if pe.m_pollCounter == 1; otherwise decrement the counter and process the next polled value |
| 4493 | if( pe.m_pollCounter != 1) |
| 4494 | { |
| 4495 | pe.m_pollCounter--; |
| 4496 | m_pollList.push_back( pe ); |
| 4497 | m_pollMutex->Unlock(); |
| 4498 | continue; |
| 4499 | } |
| 4500 | |
| 4501 | // reset the poll counter to the full pollIntensity value and push it at the end of the list |
| 4502 | // release the value object referenced; call GetNode to ensure the node objects are locked during this period |
| 4503 | { |
| 4504 | LockGuard LG(m_nodeMutex); |
| 4505 | (void)GetNode( valueId.GetNodeId() ); |
| 4506 | Value* value = GetValue( valueId ); |
| 4507 | if (!value) |
| 4508 | continue; |
| 4509 | pe.m_pollCounter = value->GetPollIntensity(); |
| 4510 | m_pollList.push_back( pe ); |
| 4511 | value->Release(); |
| 4512 | } |
| 4513 | // If the polling interval is for the whole poll list, calculate the time before the next poll, |
| 4514 | // so that all polls can take place within the user-specified interval. |
| 4515 | if( !m_bIntervalBetweenPolls ) |
| 4516 | { |
| 4517 | if( pollInterval < 100 ) |
| 4518 | { |
| 4519 | Log::Write( LogLevel_Info, "The pollInterval setting is only %d, which appears to be a legacy setting. Multiplying by 1000 to convert to ms.", pollInterval ); |
| 4520 | pollInterval *= 1000; |
| 4521 | } |
| 4522 | pollInterval /= (int32) m_pollList.size(); |
| 4523 | } |
| 4524 | |
| 4525 | { |
| 4526 | LockGuard LG(m_nodeMutex); |
| 4527 | // Request the state of the value from the node to which it belongs |
| 4528 | if( Node* node = GetNode( valueId.GetNodeId() ) ) |
| 4529 | { |
| 4530 | bool requestState = true; |
no test coverage detected