srsf/vcommandhandler/src/intpropertywatcher.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 09:56:14 +0300
branchRCL_3
changeset 17 8ce15fced3a6
parent 0 bf1d17376201
permissions -rw-r--r--
Revision: 201031 Kit: 201033

/*
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Watches for the integer P&S property and notifies observer
* 		 about the changes
*
*/


#include "rubydebug.h"
#include "intpropertywatcher.h"

CIntPropertyWatcher* CIntPropertyWatcher::NewL( const TUid aCategory, TUint aKey, 
                                    MIntChangeNotifiable& aObserver )
    {
    CIntPropertyWatcher* self = new (ELeave) CIntPropertyWatcher( aObserver );
    CleanupStack::PushL( self );
    self->ConstructL( aCategory, aKey );
    CleanupStack::Pop( self );
    return self;
    }

CIntPropertyWatcher::CIntPropertyWatcher( MIntChangeNotifiable& aObserver )
    :CActive( CActive::EPriorityStandard ), iObserver( aObserver )
    {}

void CIntPropertyWatcher::ConstructL( const TUid aCategory, TUint aKey )
    {
    User::LeaveIfError( iProperty.Attach( aCategory, aKey ) );
    CActiveScheduler::Add(this);
    // initial subscription
    iProperty.Subscribe(iStatus);
    SetActive();
    }

CIntPropertyWatcher::~CIntPropertyWatcher()
    {
    Cancel();
    iProperty.Close();
    }

void CIntPropertyWatcher::DoCancel()
    {
    iProperty.Cancel();
    }

void CIntPropertyWatcher::RunL()
    {
    RUBY_DEBUG_BLOCKL( "" );
    // resubscribe before processing new value to prevent missing updates
    iProperty.Subscribe(iStatus);
    SetActive();    
    // property updated, get new value
    TInt newValue;
    if (iProperty.Get( newValue ) == KErrNotFound )
        {
        RUBY_DEBUG0( "Property deleted or was never defined, ignoring" );
        }
    else
        {
        iObserver.IntValueChanged( newValue );
        }
    }
    

    
//End of file