sensorservices/tiltcompensationssy/src/tcsendeventtimer.cpp
changeset 0 4e1aa6a622a0
child 17 0b0048910c20
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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:  CTCSendEventTimer class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tcsendeventtimer.h"
       
    20 #include "trace.h"
       
    21 #include "tcstatetiltlistendata.h"
       
    22 
       
    23 const TInt KOneSecondInMicroSeconds( 1000000 );
       
    24 
       
    25 // ----------------------------------------------------------------------------------
       
    26 // CTCSendEventTimer::CTCSendEventTimer
       
    27 // ----------------------------------------------------------------------------------
       
    28 //
       
    29 CTCSendEventTimer::CTCSendEventTimer( MSendDataCallBack& aPrtToCallback ) :
       
    30     CActive( CActive::EPriorityStandard ),
       
    31     iCallBack( aPrtToCallback )
       
    32 	{
       
    33 	CActiveScheduler::Add( this );
       
    34 	iIsCanceled = EFalse;
       
    35 	}
       
    36 
       
    37 // ----------------------------------------------------------------------------------
       
    38 // CTCSendEventTimer::~CTCSendEventTimer
       
    39 // ----------------------------------------------------------------------------------
       
    40 //
       
    41 CTCSendEventTimer::~CTCSendEventTimer() // destruct - virtual, so no export
       
    42 	{
       
    43 	iIsCanceled = ETrue;
       
    44 	Cancel();
       
    45 	iTimer.Cancel();
       
    46 	iTimer.Close();
       
    47 	}
       
    48 
       
    49 // ----------------------------------------------------------------------------------
       
    50 // CTCSendEventTimer::NewL
       
    51 // ----------------------------------------------------------------------------------
       
    52 //
       
    53 CTCSendEventTimer* CTCSendEventTimer::NewL( TInt aSetTimerToHzLevel,
       
    54      MSendDataCallBack& aPrtToCallback )
       
    55 	{
       
    56 	FUNC_LOG;
       
    57 	
       
    58 	CTCSendEventTimer* self = new ( ELeave ) CTCSendEventTimer( aPrtToCallback );
       
    59 	CleanupStack::PushL( self );
       
    60 	self->ConstructL( aSetTimerToHzLevel );
       
    61 	CleanupStack::Pop( self );
       
    62 	return self;
       
    63 	}
       
    64 
       
    65 // ----------------------------------------------------------------------------------
       
    66 // CTCSendEventTimer::ConstructL
       
    67 // ----------------------------------------------------------------------------------
       
    68 //
       
    69 void CTCSendEventTimer::ConstructL( TInt aSetTimerToHzLevel )
       
    70 	{
       
    71 	FUNC_LOG;
       
    72 	
       
    73     TInt ret( KErrNone );
       
    74 	ret = iTimer.CreateLocal();
       
    75 	User::LeaveIfError( ret );
       
    76 	iTimerToHzLevel = aSetTimerToHzLevel;
       
    77 	TTimeIntervalMicroSeconds32 interval( KOneSecondInMicroSeconds / aSetTimerToHzLevel );
       
    78 		
       
    79 	if( !IsActive() )
       
    80 		{
       
    81 		iTimer.After( iStatus, interval );
       
    82 		SetActive();
       
    83 		}
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------------
       
    87 // CTCSendEventTimer::RunL
       
    88 // ----------------------------------------------------------------------------------
       
    89 //
       
    90 void CTCSendEventTimer::RunL()
       
    91 	{
       
    92 	FUNC_LOG;
       
    93 	
       
    94     iCallBack.SendDataAfterTimer();
       
    95     TTimeIntervalMicroSeconds32 interval( KOneSecondInMicroSeconds / iTimerToHzLevel );
       
    96 	
       
    97     if( !IsActive() && !iIsCanceled )
       
    98 		{
       
    99 		iTimer.After( iStatus, interval );
       
   100 		SetActive();
       
   101 		}
       
   102 	}
       
   103 
       
   104 // ----------------------------------------------------------------------------------
       
   105 // CTCSendEventTimer::DoCancel
       
   106 // ----------------------------------------------------------------------------------
       
   107 //	
       
   108 void CTCSendEventTimer::DoCancel()
       
   109 	{
       
   110 	iIsCanceled = ETrue;
       
   111 	}
       
   112 
       
   113 // ----------------------------------------------------------------------------------
       
   114 // CTCSendEventTimer::RunError
       
   115 // ----------------------------------------------------------------------------------
       
   116 //
       
   117 TInt CTCSendEventTimer::RunError( TInt aError )
       
   118     {
       
   119     if( aError != KErrNone )
       
   120         {
       
   121         INFO_1( "Run error in send event timer: %d", aError );
       
   122         }
       
   123     return KErrNone;
       
   124     }
       
   125 
       
   126 // End of file