radioengine/utils/api/cradiorepositoryentity.inl
changeset 41 3a6b55c6390c
parent 33 11b6825f0862
child 48 e14766a36cdc
equal deleted inserted replaced
33:11b6825f0862 41:3a6b55c6390c
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <centralrepository.h>
       
    20 
       
    21 // -----------------------------------------------------------------------------
       
    22 //
       
    23 // -----------------------------------------------------------------------------
       
    24 //
       
    25 template <typename T>
       
    26 EXPORT_C CRadioRepositoryEntity<T>* CRadioRepositoryEntity<T>::NewL( const TUid& aUid,
       
    27                                                             TUint32 aKey,
       
    28                                                             MRadioRepositoryEntityObserver& aObserver,
       
    29                                                             CActive::TPriority aPriority )
       
    30     {
       
    31     LEVEL3( LOG_METHOD_AUTO );
       
    32     CRadioRepositoryEntity<T>* self = new ( ELeave ) CRadioRepositoryEntity<T>( aUid, aKey, aObserver, aPriority );
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 template <typename T>
       
    44 CRadioRepositoryEntity<T>::CRadioRepositoryEntity( const TUid& aUid,
       
    45                                                    TUint32 aKey,
       
    46                                                    MRadioRepositoryEntityObserver& aObserver,
       
    47                                                    CActive::TPriority aPriority )
       
    48     : CRadioRepositoryEntityBase( aUid, aKey, aObserver, aPriority )
       
    49     {
       
    50     LEVEL3( LOG_METHOD_AUTO );
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 template <typename T>
       
    58 void CRadioRepositoryEntity<T>::ConstructL()
       
    59     {
       
    60     LEVEL3( LOG_METHOD_AUTO );
       
    61     iRepository = CRepository::NewL( iUid );
       
    62 
       
    63     CActiveScheduler::Add( this );
       
    64     iRepository->Get( iKey, iValue );
       
    65     User::LeaveIfError( iRepository->NotifyRequest( iKey, iStatus ) );
       
    66     SetActive();
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 template <typename T>
       
    74 EXPORT_C CRadioRepositoryEntity<T>::~CRadioRepositoryEntity()
       
    75     {
       
    76     LEVEL3( LOG_METHOD_AUTO );
       
    77     Cancel();
       
    78     delete iRepository;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // Sets the value of the key.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 template <typename T>
       
    86 TInt CRadioRepositoryEntity<T>::SetValue( const T& aValue, TBool aSavingEnabled )
       
    87     {
       
    88     LEVEL3( LOG_METHOD_AUTO );
       
    89     iValue = aValue;
       
    90     if ( aSavingEnabled )
       
    91         {
       
    92         return iRepository->Set( iKey, aValue );
       
    93         }
       
    94     return KErrNone;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // Returns the cached copy of the key's value.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 template <typename T>
       
   102 const T& CRadioRepositoryEntity<T>::Value() const
       
   103     {
       
   104     LEVEL3( LOG_METHOD_AUTO );
       
   105     return iValue;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // Forcibly updates the cached value from the repository.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 template <typename T>
       
   113 void CRadioRepositoryEntity<T>::UpdateL()
       
   114     {
       
   115     LEVEL3( LOG_METHOD_AUTO );
       
   116     User::LeaveIfError( iRepository->Get( iKey, iValue ) );
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // Executed when the key's value is changed.
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 template <typename T>
       
   124 void CRadioRepositoryEntity<T>::RunL()
       
   125     {
       
   126     LEVEL3( LOG_METHOD_AUTO );
       
   127     User::LeaveIfError( iRepository->NotifyRequest( iKey, iStatus ) );
       
   128     SetActive();
       
   129 
       
   130     TInt err = iRepository->Get( iKey, iValue );
       
   131     iObserver.HandleRepositoryValueChangeL( iUid, iKey, iValue, err );
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // Cancels all pending notifications.
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 template <typename T>
       
   139 void CRadioRepositoryEntity<T>::DoCancel()
       
   140     {
       
   141     LEVEL3( LOG_METHOD_AUTO );
       
   142     iRepository->NotifyCancel( iKey );
       
   143     }