serialserver/packetloopbackcsy/src/LoopbackTimer.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Rudimentary timer class.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "LoopbackTimer.h"
       
    23 
       
    24 const TInt KOneMilliSecond=1000;	// < Constant multipler to map integer duration to millisecond timer.
       
    25 
       
    26 CLoopbackTimer* CLoopbackTimer::NewL(TInt aDuration, MTimerCallBack* aCallback)
       
    27 	{
       
    28 	return new(ELeave) CLoopbackTimer(aDuration, aCallback);
       
    29 	}
       
    30 
       
    31 CLoopbackTimer::CLoopbackTimer(TInt aDuration, MTimerCallBack* aCallback)
       
    32 	: CActive(EPriorityStandard), iDuration(aDuration), iCallback(aCallback)
       
    33 	{
       
    34 	CActiveScheduler::Add(this);
       
    35 	_LIT(KPanic,"CSimTimer::CSimTimer()");
       
    36 	__ASSERT_ALWAYS(iTimer.CreateLocal() == KErrNone, User::Panic(KPanic,KErrGeneral));
       
    37 	}
       
    38 
       
    39 CLoopbackTimer::~CLoopbackTimer()
       
    40 	{
       
    41 	Cancel();
       
    42 	iTimer.Close();
       
    43 	}
       
    44 
       
    45 void CLoopbackTimer::Start()
       
    46 	{
       
    47 	if (!iRunning)
       
    48 		{
       
    49 		iRunning = ETrue;
       
    50 		iTimer.After(iStatus, iDuration*KOneMilliSecond);
       
    51 		SetActive();
       
    52 		}
       
    53 	}
       
    54 
       
    55 void CLoopbackTimer::DoCancel()
       
    56 	{
       
    57 	iTimer.Cancel();
       
    58 	iRunning = EFalse;
       
    59 	}
       
    60 
       
    61 
       
    62 void CLoopbackTimer::RunL()
       
    63 	{
       
    64 	User::LeaveIfError(KErrNone);	// To prevent LeaveScan warning
       
    65 	iRunning = EFalse;
       
    66 	iCallback->TimerCallBack();
       
    67 	}
       
    68 	
       
    69 TBool CLoopbackTimer::Running() const
       
    70 	{
       
    71 	return iRunning;
       
    72 	}
       
    73