srsf/vcommandhandler/src/intpropertywatcher.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Watches for the integer P&S property and notifies observer
       
    15 * 		 about the changes
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "rubydebug.h"
       
    21 #include "intpropertywatcher.h"
       
    22 
       
    23 CIntPropertyWatcher* CIntPropertyWatcher::NewL( const TUid aCategory, TUint aKey, 
       
    24                                     MIntChangeNotifiable& aObserver )
       
    25     {
       
    26     CIntPropertyWatcher* self = new (ELeave) CIntPropertyWatcher( aObserver );
       
    27     CleanupStack::PushL( self );
       
    28     self->ConstructL( aCategory, aKey );
       
    29     CleanupStack::Pop( self );
       
    30     return self;
       
    31     }
       
    32 
       
    33 CIntPropertyWatcher::CIntPropertyWatcher( MIntChangeNotifiable& aObserver )
       
    34     :CActive( CActive::EPriorityStandard ), iObserver( aObserver )
       
    35     {}
       
    36 
       
    37 void CIntPropertyWatcher::ConstructL( const TUid aCategory, TUint aKey )
       
    38     {
       
    39     User::LeaveIfError( iProperty.Attach( aCategory, aKey ) );
       
    40     CActiveScheduler::Add(this);
       
    41     // initial subscription
       
    42     iProperty.Subscribe(iStatus);
       
    43     SetActive();
       
    44     }
       
    45 
       
    46 CIntPropertyWatcher::~CIntPropertyWatcher()
       
    47     {
       
    48     Cancel();
       
    49     iProperty.Close();
       
    50     }
       
    51 
       
    52 void CIntPropertyWatcher::DoCancel()
       
    53     {
       
    54     iProperty.Cancel();
       
    55     }
       
    56 
       
    57 void CIntPropertyWatcher::RunL()
       
    58     {
       
    59     RUBY_DEBUG_BLOCKL( "" );
       
    60     // resubscribe before processing new value to prevent missing updates
       
    61     iProperty.Subscribe(iStatus);
       
    62     SetActive();    
       
    63     // property updated, get new value
       
    64     TInt newValue;
       
    65     if (iProperty.Get( newValue ) == KErrNotFound )
       
    66         {
       
    67         RUBY_DEBUG0( "Property deleted or was never defined, ignoring" );
       
    68         }
       
    69     else
       
    70         {
       
    71         iObserver.IntValueChanged( newValue );
       
    72         }
       
    73     }
       
    74     
       
    75 
       
    76     
       
    77 //End of file