mpx/commonframework/common/src/mpxcenrepwatcher.cpp
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     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:  Class for observing changes in central repository values
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <mpxcenrepobserver.h>
       
    22 #include <mpxcenrepwatcher.h>
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // Two-phased constructor.
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 EXPORT_C CMPXCenRepWatcher* CMPXCenRepWatcher::NewL(const TUid& aRepositoryUid,
       
    29                                           TUint32 aId,
       
    30                                        MMPXCenRepObserver* aObserver)
       
    31     {
       
    32     CMPXCenRepWatcher* self = new(ELeave) CMPXCenRepWatcher(
       
    33         aRepositoryUid, aId, aObserver);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(self);
       
    37     return self;
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CMPXCenRepWatcher::CMPXCenRepWatcher(const TUid& aRepositoryUid,
       
    46                                      TUint32 aId,
       
    47                                      MMPXCenRepObserver* aObserver)
       
    48 :   CActive(EPriorityStandard), 
       
    49     iRepository(NULL), 
       
    50     iRepositoryUid(aRepositoryUid), 
       
    51     iId(aId), 
       
    52     iObserver(aObserver)
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CMPXCenRepWatcher::ConstructL()
       
    61     {
       
    62     iRepository = CRepository::NewL(iRepositoryUid);
       
    63     CActiveScheduler::Add( this );
       
    64     User::LeaveIfError(iRepository->NotifyRequest(iId, iStatus));
       
    65     SetActive();
       
    66     }
       
    67 
       
    68 // Destructor
       
    69 EXPORT_C CMPXCenRepWatcher::~CMPXCenRepWatcher()
       
    70     {
       
    71     Cancel();
       
    72     delete iRepository;
       
    73     iObserver = NULL;
       
    74     }
       
    75     
       
    76 // -----------------------------------------------------------------------------
       
    77 // CMPXCenRepWatcher::CurrentValueL
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C TInt CMPXCenRepWatcher::CurrentValueL()
       
    81     {
       
    82     TInt res = 0;
       
    83     User::LeaveIfError(iRepository->Get(iId, res));
       
    84     return res;
       
    85     }    
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CMPXCenRepWatcher::SetValueL
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 EXPORT_C void CMPXCenRepWatcher::SetValueL(TInt aNewValue)
       
    92     {
       
    93     User::LeaveIfError(iRepository->Set(iId, aNewValue));
       
    94     }    
       
    95     
       
    96 // -----------------------------------------------------------------------------
       
    97 // CMPXCenRepWatcher::RunL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CMPXCenRepWatcher::RunL()
       
   101     {
       
   102     User::LeaveIfError(iRepository->NotifyRequest(iId, iStatus));
       
   103     SetActive();
       
   104 
       
   105     iObserver->HandleSettingChange(iRepositoryUid, iId);
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CMPXCenRepWatcher::DoCancel
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CMPXCenRepWatcher::DoCancel()
       
   113     {
       
   114     iRepository->NotifyCancel(iId);
       
   115     }
       
   116 
       
   117 
       
   118 // End of File