taskswitcher/contextengine/hgctxutils/src/hgcenreplistener.cpp
changeset 4 4d54b72983ae
parent 3 fb3763350a08
child 5 c743ef5928ba
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
     1 /*
       
     2 * ===========================================================================
       
     3 *  Name        : HgCenrepListener.cpp
       
     4 *  Part of     : Hg
       
     5 *  Description : Active class to get notifications about changes to a cenrep key
       
     6 *
       
     7 *  Copyright © 2008 Nokia Corporation.
       
     8 *  This material, including documentation and any related 
       
     9 *  computer programs, is protected by copyright controlled by 
       
    10 *  Nokia Corporation. All rights are reserved. Copying, 
       
    11 *  including reproducing, storing, adapting or translating, any 
       
    12 *  or all of this material requires the prior written consent   of 
       
    13 *  Nokia Corporation. This material also contains confidential 
       
    14 *  information which may not be disclosed to others without the 
       
    15 *  prior written consent of Nokia Corporation.
       
    16 * ===========================================================================
       
    17 */
       
    18 
       
    19 #include <e32cmn.h>
       
    20 #include <centralrepository.h>
       
    21 #include "hgcenreplistener.h"
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // NewL
       
    25 // -----------------------------------------------------------------------------
       
    26 EXPORT_C CHgCenrepListener* CHgCenrepListener::NewL(const TUid& aRep, TUint32 aKey,
       
    27                                    MHgCenrepChangeObserver& aObserver)
       
    28     {
       
    29     CHgCenrepListener* self = CHgCenrepListener::NewLC(aRep, aKey, aObserver);
       
    30     CleanupStack::Pop(self);
       
    31     return self;
       
    32     }
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // NewLC
       
    36 // -----------------------------------------------------------------------------
       
    37 EXPORT_C CHgCenrepListener* CHgCenrepListener::NewLC(const TUid& aRep, TUint32 aKey,
       
    38                                        MHgCenrepChangeObserver& aObserver)
       
    39     {
       
    40     CHgCenrepListener *self = new(ELeave) CHgCenrepListener(aKey, aObserver);
       
    41     CleanupStack::PushL(self);
       
    42     self->ConstructL(aRep);
       
    43     return self;
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CHgCenrepListener
       
    48 // -----------------------------------------------------------------------------
       
    49 CHgCenrepListener::CHgCenrepListener(TUint32 aKey, 
       
    50                                      MHgCenrepChangeObserver& aObserver)
       
    51 : CActive( CActive::EPriorityStandard ), iObserver( aObserver ), iKey( aKey )
       
    52     {
       
    53     CActiveScheduler::Add(this);
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // ConstructL
       
    58 // -----------------------------------------------------------------------------
       
    59 void CHgCenrepListener::ConstructL(const TUid& aRep)
       
    60     {
       
    61     iRep = CRepository::NewL( aRep );
       
    62     iRep->NotifyRequest( iKey, iStatus );
       
    63     SetActive();
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // ~CHgCenrepListener
       
    68 // -----------------------------------------------------------------------------
       
    69 EXPORT_C CHgCenrepListener::~CHgCenrepListener()
       
    70     {
       
    71     Cancel();
       
    72     delete iRep;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // DoCancel
       
    77 // -----------------------------------------------------------------------------
       
    78 void CHgCenrepListener::DoCancel()
       
    79     {
       
    80     iRep->NotifyCancelAll();
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // RunL
       
    85 // -----------------------------------------------------------------------------
       
    86 void CHgCenrepListener::RunL()
       
    87     {
       
    88     if ( iStatus.Int() != KErrCancel )
       
    89         {
       
    90         iObserver.CenrepChanged( iKey, Value() );
       
    91         iRep->NotifyRequest( iKey, iStatus );
       
    92         SetActive();
       
    93         }
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // RunError
       
    98 // -----------------------------------------------------------------------------
       
    99 TInt CHgCenrepListener::RunError( TInt /*aError*/ )
       
   100     {
       
   101     return KErrNone;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // Value
       
   106 // -----------------------------------------------------------------------------
       
   107 EXPORT_C TInt CHgCenrepListener::Value()
       
   108     {
       
   109     TInt val = 0;
       
   110     iRep->Get( iKey, val );
       
   111     return val;
       
   112     }
       
   113 
       
   114 // end of file