wvuing/wvuistorage/src/CCARefreshTimer.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004-2005 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:  The CCARefreshTimer class handles the waiting functionality for
       
    15 *                the storage manager to wait before calling observer in case of
       
    16 *                multiple contacts adding.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CCARefreshTimer.h"
       
    23 #include "MCARefreshTimerObserver.h"
       
    24 
       
    25 #include "ChatDebugPrint.h"
       
    26 
       
    27 // CONSTANTS
       
    28 const TInt KTimeToWaitBeforeRefresh( 1000000 ); // 1 seconds in microseconds
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CCARefreshTimer::CCARefreshTimer
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CCARefreshTimer::CCARefreshTimer( MCARefreshTimerObserver* aObserver ) :
       
    39         CTimer( EPriorityIdle ),
       
    40         iObserver( aObserver )
       
    41     {
       
    42     CActiveScheduler::Add( this );
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CCARefreshTimer::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CCARefreshTimer::ConstructL()
       
    51     {
       
    52     // the base class must be constructed explicitely
       
    53     CTimer::ConstructL();
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CCARefreshTimer::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CCARefreshTimer* CCARefreshTimer::NewL( MCARefreshTimerObserver* aObserver )
       
    62     {
       
    63     CCARefreshTimer* self = new( ELeave ) CCARefreshTimer( aObserver );
       
    64 
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68 
       
    69     return self;
       
    70     }
       
    71 
       
    72 // Destructor
       
    73 CCARefreshTimer::~CCARefreshTimer()
       
    74     {
       
    75     Cancel();
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CCARefreshTimer::Start
       
    80 // -----------------------------------------------------------------------------
       
    81 
       
    82 void CCARefreshTimer::Start()
       
    83     {
       
    84     CHAT_DP_FUNC_ENTER( "Start" );
       
    85     if ( IsActive() )
       
    86         {
       
    87         Cancel();
       
    88         }
       
    89     TTimeIntervalMicroSeconds32 waittime( KTimeToWaitBeforeRefresh );
       
    90     CTimer::After( waittime );
       
    91     CHAT_DP_FUNC_DONE( "Start" );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CCARefreshTimer::RunL
       
    96 // Derived from CActive
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CCARefreshTimer::RunL()
       
   100     {
       
   101     CHAT_DP_FUNC_ENTER( "RunL" );
       
   102     if ( iObserver )
       
   103         {
       
   104         TInt status( iStatus.Int() );
       
   105         CHAT_DP( D_CHAT_LIT( "CCARefreshTimer::RunL status = %d" ), status );
       
   106         if ( status != KErrCancel )
       
   107             {
       
   108             iObserver->HandleTimeWaited( status );
       
   109             }
       
   110         }
       
   111     CHAT_DP_FUNC_DONE( "RunL" );
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CCARefreshTimer::RunError
       
   116 // Derived from CActive
       
   117 // ---------------------------------------------------------
       
   118 //
       
   119 TInt CCARefreshTimer::RunError( TInt aError )
       
   120     {
       
   121     CHAT_DP( D_CHAT_LIT( "CCARefreshTimer::RunError [%d]" ), aError );
       
   122 
       
   123     if ( iObserver )
       
   124         {
       
   125         iObserver->HandleTimeWaited( aError );
       
   126         }
       
   127 
       
   128     return aError;
       
   129     }
       
   130 
       
   131 //  End of File