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