MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / EnablePoll

Method EnablePoll

cpp/src/Driver.cpp:4230–4294  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Enable polling of a value -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

4228// Enable polling of a value
4229//-----------------------------------------------------------------------------
4230bool Driver::EnablePoll
4231(
4232 ValueID const &_valueId,
4233 uint8 const _intensity
4234)
4235{
4236 // make sure the polling thread doesn't lock the node while we're in this function
4237 m_pollMutex->Lock();
4238
4239 // confirm that this node exists
4240 uint8 nodeId = _valueId.GetNodeId();
4241 LockGuard LG(m_nodeMutex);
4242 Node* node = GetNode( nodeId );
4243 if( node != NULL )
4244 {
4245 // confirm that this value is in the node's value store
4246 if( Value* value = node->GetValue( _valueId ) )
4247 {
4248 // update the value's pollIntensity
4249 value->SetPollIntensity( _intensity );
4250
4251 // Add the valueid to the polling list
4252 // See if the node is already in the poll list.
4253 for( list<PollEntry>::iterator it = m_pollList.begin(); it != m_pollList.end(); ++it )
4254 {
4255 if( (*it).m_id == _valueId )
4256 {
4257 // It is already in the poll list, so we have nothing to do.
4258 Log::Write( LogLevel_Detail, "EnablePoll not required to do anything (value is already in the poll list)" );
4259 value->Release();
4260 m_pollMutex->Unlock();
4261 return true;
4262 }
4263 }
4264
4265 // Not in the list, so we add it
4266 PollEntry pe;
4267 pe.m_id = _valueId;
4268 pe.m_pollCounter = value->GetPollIntensity();
4269 m_pollList.push_back( pe );
4270 value->Release();
4271 m_pollMutex->Unlock();
4272
4273 // send notification to indicate polling is enabled
4274 Notification* notification = new Notification( Notification::Type_PollingEnabled );
4275 notification->SetHomeAndNodeIds( m_homeId, _valueId.GetNodeId() );
4276 QueueNotification( notification );
4277 Log::Write( LogLevel_Info, nodeId, "EnablePoll for HomeID 0x%.8x, value(cc=0x%02x,in=0x%02x,id=0x%02x)--poll list has %d items",
4278 _valueId.GetHomeId(), _valueId.GetCommandClassId(), _valueId.GetIndex(), _valueId.GetInstance(), m_pollList.size() );
4279 return true;
4280 }
4281
4282 // allow the poll thread to continue
4283 m_pollMutex->Unlock();
4284
4285 Log::Write( LogLevel_Info, nodeId, "EnablePoll failed - value not found for node %d", nodeId );
4286 return false;
4287 }

Callers 1

mainFunction · 0.45

Calls 13

WriteFunction · 0.85
GetNodeIdMethod · 0.80
GetPollIntensityMethod · 0.80
GetInstanceMethod · 0.80
LockMethod · 0.45
GetValueMethod · 0.45
SetPollIntensityMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
ReleaseMethod · 0.45
UnlockMethod · 0.45
GetCommandClassIdMethod · 0.45

Tested by

no test coverage detected