keepalive/flextimer/server/engine/src/flextimerwakeuptimer.cpp
changeset 32 5c4486441ae6
equal deleted inserted replaced
31:c16e04725da3 32:5c4486441ae6
       
     1 /*
       
     2  * Copyright (c) 2010 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  * Description:
       
    13  * This class contains implementation of CFlexTimerWakeUpTimer.
       
    14  *
       
    15  */
       
    16 
       
    17 // System include files
       
    18 // None
       
    19 
       
    20 // User include files go here:
       
    21 #include "flextimerwakeuptimer.h"
       
    22 #include "mflextimerwakeuptimercb.h"
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "flextimerwakeuptimerTraces.h"
       
    26 #endif
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // NewL
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CFlexTimerWakeUpTimer* CFlexTimerWakeUpTimer::NewL(
       
    33     MFlexTimerWakeUpTimerCB& aObserver )
       
    34     {
       
    35     CFlexTimerWakeUpTimer* self = new (ELeave) CFlexTimerWakeUpTimer(
       
    36         aObserver );
       
    37     
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 // ---------------------------------------------------------------------------
       
    44 // destructor, Cancel timer just in case it is still running.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CFlexTimerWakeUpTimer::~CFlexTimerWakeUpTimer()
       
    48     {
       
    49     // Super class CTimer destructor Cancels any pending requests.
       
    50     OstTrace0( TRACE_INTERNAL,
       
    51         DUP1_CFLEXTIMERWAKEUPTIMER_CFLEXTIMERWAKEUPTIMER,
       
    52         "CFlexTimerWakeUpTimer::~CFlexTimerWakeUpTimer" );
       
    53     }
       
    54 // ---------------------------------------------------------------------------
       
    55 // Start timer so that it will expire aInterval after this moment.
       
    56 // UTC is used to get indications about system time change.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CFlexTimerWakeUpTimer::StartTimer( TTimeIntervalMicroSeconds& aInterval )
       
    60     {
       
    61     CTimer::Cancel();
       
    62     TTime utcNow( 0 );
       
    63 
       
    64     utcNow.UniversalTime();
       
    65     utcNow = utcNow + aInterval;
       
    66     
       
    67     OstTraceExt1( TRACE_INTERNAL,
       
    68         CFLEXTIMERWAKEUPTIMER_STARTTIMER,
       
    69         "CFlexTimerWakeUpTimer::StartTimer;aInterval=%Ld",
       
    70         aInterval.Int64() );
       
    71 
       
    72     AtUTC( utcNow );
       
    73     }
       
    74 // ---------------------------------------------------------------------------
       
    75 // just call Cancel. If timer is alreay running it will be stopped.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CFlexTimerWakeUpTimer::StopTimer()
       
    79     {
       
    80     OstTrace0( TRACE_INTERNAL,
       
    81         CFLEXTIMERWAKEUPTIMER_STOPTIMER,
       
    82         "CFlexTimerWakeUpTimer::StopTimer" );
       
    83 
       
    84     Cancel();
       
    85     }
       
    86 // ---------------------------------------------------------------------------
       
    87 // KErrAbort comes if system time has changed. It is up to client to restart
       
    88 // timer
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CFlexTimerWakeUpTimer::RunL()
       
    92     {
       
    93     if ( KErrAbort == iStatus.Int() )
       
    94         {
       
    95         iObserver.SystemTimeChanged();
       
    96         }
       
    97     else
       
    98         {
       
    99         iObserver.WakeUp();
       
   100         }
       
   101     }
       
   102 // ---------------------------------------------------------------------------
       
   103 // Private constructor
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 CFlexTimerWakeUpTimer::CFlexTimerWakeUpTimer(
       
   107     MFlexTimerWakeUpTimerCB& aObserver ) :
       
   108         CTimer( EPriorityStandard ), iObserver( aObserver )
       
   109     {
       
   110     OstTrace0( TRACE_INTERNAL,
       
   111         CFLEXTIMERWAKEUPTIMER_CFLEXTIMERWAKEUPTIMER,
       
   112         "CFlexTimerWakeUpTimer::CFlexTimerWakeUpTimer" );
       
   113 
       
   114     //Nothing to do here
       
   115     }
       
   116 // ---------------------------------------------------------------------------
       
   117 // Private 2nd phase construction
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CFlexTimerWakeUpTimer::ConstructL()
       
   121     {
       
   122     CActiveScheduler::Add( this );
       
   123     CTimer::ConstructL();
       
   124     }