securitydialogs/lockapp/src/lockappcenrepobserver.cpp
branchRCL_3
changeset 50 03674e5abf46
equal deleted inserted replaced
49:09b1ac925e3f 50:03674e5abf46
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Central Repository key observer
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <centralrepository.h>
       
    20 #include "lockappcenrepobserver.h"
       
    21 #include "lockapputils.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // Two-phased constructor.
       
    25 // ---------------------------------------------------------------------------
       
    26 CLockAppCenRepObserver* CLockAppCenRepObserver::NewL( MLockAppObserverInterface* aObserver,
       
    27         TUid aCenRepUid, TUint32 aKeyId )
       
    28     {
       
    29     CLockAppCenRepObserver* self = new (ELeave) CLockAppCenRepObserver(aObserver, aCenRepUid, aKeyId);
       
    30     CleanupStack::PushL( self );
       
    31     self->ConstructL( );
       
    32     CleanupStack::Pop( self );
       
    33     return self;
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Destructor
       
    38 // ---------------------------------------------------------------------------
       
    39 CLockAppCenRepObserver::~CLockAppCenRepObserver( )
       
    40     {
       
    41     if ( iNotifyHandler )
       
    42         {
       
    43         iNotifyHandler->StopListening( );
       
    44         delete iNotifyHandler;
       
    45         iNotifyHandler = NULL;
       
    46         }
       
    47     if ( iRepository )
       
    48         {
       
    49         delete iRepository;
       
    50         iRepository = NULL;
       
    51         }
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // C++ default constructor
       
    56 // ---------------------------------------------------------------------------
       
    57 CLockAppCenRepObserver::CLockAppCenRepObserver( MLockAppObserverInterface* aObserver,
       
    58         TUid aCenRepUid, TUint32 aKeyId ) :
       
    59     iObserver(aObserver),
       
    60     iCenRepUid(aCenRepUid),
       
    61     iKeyId(aKeyId)
       
    62     {
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Symbian OS default constructor
       
    67 // ---------------------------------------------------------------------------
       
    68 void CLockAppCenRepObserver::ConstructL( )
       
    69     {
       
    70     // init cenrep connection
       
    71 INFO_4( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
    72     iRepository = CRepository::NewL( iCenRepUid );
       
    73     iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iRepository,
       
    74             CCenRepNotifyHandler::EIntKey, iKeyId );
       
    75     iNotifyHandler->StartListeningL( );
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // Gets value of the default key from CenRep.
       
    80 // ---------------------------------------------------------------------------
       
    81 TInt CLockAppCenRepObserver::GetValue(TInt& aValue )
       
    82     {
       
    83     return iRepository->Get( iKeyId, aValue );
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // Gets value of the key from CenRep.
       
    88 // ---------------------------------------------------------------------------
       
    89 TInt CLockAppCenRepObserver::GetKeyValue(TUint32 aKey, TInt& aValue )
       
    90     {
       
    91     	    INFO_4( "%s %s (%u) aKey=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKey );
       
    92 
       
    93     return iRepository->Get( aKey, aValue );
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Sets a value for the default key in CenRep.
       
    98 // ---------------------------------------------------------------------------
       
    99 TInt CLockAppCenRepObserver::SetValue(TInt aValue )
       
   100     {
       
   101     return iRepository->Set( iKeyId, aValue );
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // Sets a value for the key in CenRep.
       
   106 // ---------------------------------------------------------------------------
       
   107 TInt CLockAppCenRepObserver::SetKeyValue(TUint32 aKey, TInt aValue )
       
   108     {
       
   109     return iRepository->Set( aKey, aValue );
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // Handles changes. Called by CenRep.
       
   114 // ---------------------------------------------------------------------------
       
   115 void CLockAppCenRepObserver::HandleNotifyInt(TUint32 aKeyId, TInt aValue )
       
   116     {
       
   117 INFO_4( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   118     if ( aKeyId == iKeyId )
       
   119         {
       
   120         if ( iObserver )
       
   121             {
       
   122             iObserver->HandleCenRepNotify( iCenRepUid, iKeyId, aValue );
       
   123             }
       
   124         }
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Handles errors. Called by CenRep.
       
   129 // ---------------------------------------------------------------------------
       
   130 void CLockAppCenRepObserver::HandleNotifyError(TUint32 aId, TInt error, CCenRepNotifyHandler* /*aHandler*/)
       
   131     {
       
   132     ERROR_1(error, "CLockAppCenRepObserver::HandleNotifyError - %d", aId);
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // Handles Repository wide reset caused generic notifications. Called by CenRep.
       
   137 // ---------------------------------------------------------------------------
       
   138 void CLockAppCenRepObserver::HandleNotifyGeneric(TUint32 aId )
       
   139     {
       
   140     if ( aId == NCentralRepositoryConstants::KInvalidNotificationId )
       
   141         {
       
   142         // TODO implement what to do in this case
       
   143         }
       
   144     }
       
   145 
       
   146 // END OF FILE