//----------------------------------------------------------------------------- // <ValueStore::AddValue> // Add a value to the store //----------------------------------------------------------------------------- bool ValueStore::AddValue ( Value* _value ) { if( !_value ) { return false; } uint32 key = _value->GetID().GetValueStoreKey(); map<uint32,Value*>::iterator it = m_values.find( key ); if( it != m_values.end() ) { // There is already a value in the store with this key, so we give up. return false; } m_values[key] = _value; _value->AddRef(); // Notify the watchers of the new value if( Driver* driver = Manager::Get()->GetDriver( _value->GetID().GetHomeId() ) ) { Notification* notification = new Notification( Notification::Type_ValueAdded ); notification->SetValueId( _value->GetID() ); driver->QueueNotification( notification ); } return true; }
//----------------------------------------------------------------------------- // <ValueStore::RemoveValue> // Remove a value from the store //----------------------------------------------------------------------------- bool ValueStore::RemoveValue ( uint32 const& _key ) { map<uint32,Value*>::iterator it = m_values.find( _key ); if( it != m_values.end() ) { Value* value = it->second; ValueID const& valueId = value->GetID(); // First notify the watchers if( Driver* driver = Manager::Get()->GetDriver( valueId.GetHomeId() ) ) { Notification* notification = new Notification( Notification::Type_ValueRemoved ); notification->SetValueId( valueId ); driver->QueueNotification( notification ); } // Now release and remove the value from the store value->Release(); m_values.erase( it ); return true; } // Value not found in the store return false; }
//----------------------------------------------------------------------------- // <ValueStore::RemoveCommandClassValues> // Remove all the values associated with a command class from the store //----------------------------------------------------------------------------- void ValueStore::RemoveCommandClassValues ( uint8 const _commandClassId ) { map<uint32,Value*>::iterator it = m_values.begin(); while( it != m_values.end() ) { Value* value = it->second; ValueID const& valueId = value->GetID(); if( _commandClassId == valueId.GetCommandClassId() ) { // The value belongs to the specified command class // First notify the watchers if( Driver* driver = Manager::Get()->GetDriver( valueId.GetHomeId() ) ) { Notification* notification = new Notification( Notification::Type_ValueRemoved ); notification->SetValueId( valueId ); driver->QueueNotification( notification ); } // Now release and remove the value from the store value->Release(); m_values.erase( it++ ); } else { ++it; } } }
//----------------------------------------------------------------------------- // <Value::OnValueChanged> // A value in a device has changed //----------------------------------------------------------------------------- void Value::OnValueChanged ( ) { if( IsWriteOnly() ) { return; } if( Driver* driver = Manager::Get()->GetDriver( m_id.GetHomeId() ) ) { m_isSet = true; // Notify the watchers Notification* notification = new Notification( Notification::Type_ValueChanged ); notification->SetValueId( m_id ); driver->QueueNotification( notification ); } /* Call Back to the Command Class that this Value has changed, so we can search the * TriggerRefreshValue vector to see if we should request any other values to be * refreshed. */ Node* node = NULL; if( Driver* driver = Manager::Get()->GetDriver( m_id.GetHomeId() ) ) { node = driver->GetNodeUnsafe( m_id.GetNodeId() ); if( node != NULL ) { if( CommandClass* cc = node->GetCommandClass( m_id.GetCommandClassId() ) ) { cc->CheckForRefreshValues(this); } } } }
//----------------------------------------------------------------------------- // <Value::OnValueRefreshed> // A value in a device has been refreshed //----------------------------------------------------------------------------- void Value::OnValueRefreshed ( ) { if( IsWriteOnly() ) { return; } if( Driver* driver = Manager::Get()->GetDriver( m_id.GetHomeId() ) ) { m_isSet = true; bool bSuppress; Options::Get()->GetOptionAsBool( "SuppressValueRefresh", &bSuppress ); if( !bSuppress ) { // Notify the watchers Notification* notification = new Notification( Notification::Type_ValueRefreshed ); notification->SetValueId( m_id ); driver->QueueNotification( notification ); } } }