eventsui/eventsengine/src/evtdbnotifier.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2008 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:  Notifier class for any change in Storage API dtabase.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System Includes
       
    20 #include <centralrepository.h>
       
    21 
       
    22 // User Includes
       
    23 #include "evtdbnotifier.h"
       
    24 #include "evtdebug.h"
       
    25 
       
    26 // ================ Member funtions for CEvtDatabase class ==================
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // CEvtDbNotifier::CEvtDbNotifier
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CEvtDbNotifier::CEvtDbNotifier( MEvtDbObserver&    aObserver )
       
    33 						:CActive( EPriorityStandard ),
       
    34 						iDbObserver( aObserver )
       
    35     {
       
    36     }
       
    37     
       
    38 // ---------------------------------------------------------------------------
       
    39 // CEvtDbNotifier::~CEvtDbNotifier
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CEvtDbNotifier::~CEvtDbNotifier()
       
    43     {
       
    44 	Cancel();
       
    45     delete iRepository; 
       
    46     } 
       
    47     
       
    48 // ---------------------------------------------------------------------------
       
    49 // CEvtDbNotifier::NewL
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CEvtDbNotifier* CEvtDbNotifier::NewL( MEvtDbObserver&    aObserver )
       
    53     {
       
    54 	CEvtDbNotifier* self = NewLC( aObserver );
       
    55 	CleanupStack::Pop( self );
       
    56 	return self;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CEvtDbNotifier::NewLC
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CEvtDbNotifier* CEvtDbNotifier::NewLC( MEvtDbObserver&    aObserver )
       
    64     {
       
    65 	CEvtDbNotifier* self = new ( ELeave )CEvtDbNotifier( aObserver );
       
    66 	CleanupStack::PushL( self );
       
    67 	self->ConstructL( );
       
    68 	return self;
       
    69     } 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CEvtDbNotifier::ConstructL
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CEvtDbNotifier::ConstructL()
       
    76     {
       
    77 	EVTUIDEBUG( "+ CEvtDbNotifier::ConstructL()" );
       
    78     CActiveScheduler::Add(this);
       
    79     
       
    80 	EVTUIDEBUG( "Calling CRepository::NewL" );
       
    81     // Create the Central repository object notifying the Db change
       
    82     TRAPD(err, iRepository = CRepository::NewL( TUid::Uid( KCRUidEvtStorageDb ) ) );
       
    83 	EVTUIDEBUG1( "Calling CRepository::NewL Cenrep Error Code- %d", err );
       
    84 	User::LeaveIfError( err );
       
    85     // Request for notification
       
    86     StartNotification();
       
    87     
       
    88 	EVTUIDEBUG( "- CEvtDbNotifier::ConstructL()" );
       
    89     } 
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // void CEvtDbNotifier::RunL()
       
    93 // ---------------------------------------------------------------------------
       
    94 //                             
       
    95 void CEvtDbNotifier::RunL()
       
    96     {
       
    97 	EVTUIDEBUG( "+ CEvtDbNotifier::RunL()" );
       
    98     // resubscribe before processing new value to prevent missing updates
       
    99 	StartNotification();
       
   100 	
       
   101 	// processing new value
       
   102 	HandleDbChangedL();
       
   103 	
       
   104 	EVTUIDEBUG( "- CEvtDbNotifier::RunL()" );
       
   105     }
       
   106     
       
   107 // ---------------------------------------------------------------------------
       
   108 // void CEvtDbNotifier::DoCancel()
       
   109 // ---------------------------------------------------------------------------
       
   110 // 
       
   111 void CEvtDbNotifier::DoCancel()
       
   112     {
       
   113 	EVTUIDEBUG( "+ CEvtDbNotifier::DoCancel()" );
       
   114     // Cancel the outstanding CR notification request
       
   115     if( iRepository )
       
   116         {
       
   117         iRepository->NotifyCancel( KEvtDbChangeType );        
       
   118         }
       
   119 	EVTUIDEBUG( "- CEvtDbNotifier::DoCancel()" );
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // TInt CEvtDbNotifier::RunError()
       
   124 // ---------------------------------------------------------------------------
       
   125 //    
       
   126 TInt CEvtDbNotifier::RunError( TInt aError )
       
   127 	{    	
       
   128 	return CActive::RunError( aError );	
       
   129 	} 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // void CEvtDbNotifier::StartNotification()
       
   133 // ---------------------------------------------------------------------------
       
   134 //  
       
   135 void CEvtDbNotifier::StartNotification()
       
   136     {
       
   137 	EVTUIDEBUG( "+ CEvtDbNotifier::StartNotification()" );
       
   138     if( !IsActive() )
       
   139         {
       
   140         iStatus = KRequestPending;
       
   141         // Request for notification
       
   142     	iRepository->NotifyRequest( KEvtDbChangeType, iStatus );
       
   143         SetActive();          
       
   144         }  
       
   145 	EVTUIDEBUG( "- CEvtDbNotifier::StartNotification()" );
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CEvtDbNotifier::HandleDbChangedL
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CEvtDbNotifier::HandleDbChangedL( )
       
   153     {    
       
   154 	EVTUIDEBUG( "+ CEvtDbNotifier::HandleDbChangedL()" );
       
   155     // Notify the Observer for the database change type
       
   156     iDbObserver.HandleDbChangedL( );
       
   157 	EVTUIDEBUG( "- CEvtDbNotifier::HandleDbChangedL()" );
       
   158     }
       
   159     
       
   160 // ---------------------------------------------------------------------------
       
   161 // CEvtDbNotifier::DbChangedL
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CEvtDbNotifier::DbChangedL( )
       
   165     {
       
   166 	EVTUIDEBUG( "+ CEvtDbNotifier::DbChangedL()" );
       
   167     // Get the type of database change from Cenrep key
       
   168     TInt flag = 0;
       
   169     User::LeaveIfError( iRepository->Get( KEvtDbChangeType, flag ) );  
       
   170     
       
   171     EVTUIDEBUG1( "In DbChangedL Get %d", flag );
       
   172     flag = ( flag == 0 ) ? 1 : 0;
       
   173     EVTUIDEBUG1( "In DbChangedL Set %d", flag );
       
   174     
       
   175     // Set the KEvtDbChangeType key of the Cenrep, So that other database
       
   176     // connection can get the notifications
       
   177     User::LeaveIfError( iRepository->Set( KEvtDbChangeType, flag ) );
       
   178 	EVTUIDEBUG( "- CEvtDbNotifier::DbChangedL()" );
       
   179     }
       
   180     
       
   181 // End of File