idlehomescreen/xmluicontroller/src/psobserver.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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:  Observer for changes in Publish & Subscribe keys
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "psobserver.h"
       
    20 #include "mpscallback.h"
       
    21 
       
    22 // ============================ MEMBER FUNCTIONS ===============================
       
    23 
       
    24 using namespace AiXmlUiController;
       
    25 
       
    26 CPSObserver::CPSObserver( MPSCallback& aCallback, TUid aCategory, TInt aKey ) :
       
    27     CActive( CActive::EPriorityStandard ),
       
    28 	iCallback( aCallback ),	
       
    29 	iCategory( aCategory ), 
       
    30 	iKey( aKey )
       
    31     {
       
    32     CActiveScheduler::Add( this );
       
    33     }
       
    34 
       
    35 CPSObserver* CPSObserver::NewL( MPSCallback& aCallback, TUid aCategory, TInt aKey )
       
    36     {
       
    37     CPSObserver* self = new( ELeave ) CPSObserver( aCallback, aCategory, aKey );
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();    
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43     
       
    44 CPSObserver::~CPSObserver()
       
    45     {
       
    46     Cancel();
       
    47     }
       
    48 
       
    49 void CPSObserver::ConstructL()
       
    50     {
       
    51     // subscribe for changes
       
    52     User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
    53     iProperty.Subscribe( iStatus );
       
    54     SetActive();
       
    55     }
       
    56 
       
    57 void CPSObserver::RunL()
       
    58 	{
       
    59     iProperty.Subscribe( iStatus );
       
    60     SetActive();
       
    61 
       
    62     TInt value;
       
    63     if( iProperty.Get( iCategory, iKey, value ) != KErrNotFound )
       
    64         {
       
    65 		iCallback.ValueUpdatedL( iKey, value );
       
    66         }
       
    67 	}
       
    68 
       
    69 TInt CPSObserver::RunError()
       
    70 	{
       
    71 	Cancel();
       
    72 	return KErrNone;		
       
    73 	}
       
    74 
       
    75 void CPSObserver::DoCancel()
       
    76 	{
       
    77     iProperty.Close();
       
    78 	}
       
    79 
       
    80 TInt CPSObserver::GetValue( TInt &aValue ) const
       
    81     {
       
    82     return iProperty.Get( iCategory, iKey, aValue );
       
    83     }
       
    84 
       
    85 
       
    86 //  End of File