|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 #include "activetimer.h" |
|
18 |
|
19 CActiveTimer::CActiveTimer(CConsoleBase* aConsole) : |
|
20 CTimer(CActive::EPriorityStandard), |
|
21 iConsole(aConsole) |
|
22 { |
|
23 CActiveScheduler::Add(this); |
|
24 } |
|
25 |
|
26 void CActiveTimer::ConstructL() |
|
27 { |
|
28 CTimer::ConstructL(); |
|
29 iXPos = 0; |
|
30 iYPos = 1; |
|
31 } |
|
32 |
|
33 CActiveTimer* CActiveTimer::NewL(CConsoleBase* aConsole) |
|
34 { |
|
35 CActiveTimer* self = new(ELeave) CActiveTimer(aConsole); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CActiveTimer::~CActiveTimer() |
|
43 { |
|
44 Cancel(); |
|
45 } |
|
46 |
|
47 void CActiveTimer::StartL() |
|
48 { |
|
49 iStartTime.HomeTime(); |
|
50 CTimer::After(KPrintInterval); |
|
51 } |
|
52 |
|
53 void CActiveTimer::RunL() |
|
54 { |
|
55 TTimeIntervalSeconds seconds; |
|
56 TTime time; |
|
57 time.HomeTime(); |
|
58 time.SecondsFrom(iStartTime, seconds); |
|
59 |
|
60 TInt x = iConsole->WhereX(); |
|
61 TInt y = iConsole->WhereY(); |
|
62 |
|
63 iConsole->SetPos(iXPos, iYPos); |
|
64 iConsole->Printf(_L("\n")); |
|
65 iConsole->Printf(_L("[Time: %d] "), seconds.Int()); |
|
66 iConsole->SetPos(x, y); |
|
67 |
|
68 CTimer::After(KPrintInterval); |
|
69 } |
|
70 |
|
71 void CActiveTimer::DoCancel() |
|
72 { |
|
73 TTimeIntervalSeconds seconds; |
|
74 TTime time; |
|
75 time.HomeTime(); |
|
76 time.SecondsFrom(iStartTime, seconds); |
|
77 iConsole->Printf(_L("Total Time: [%d]"), seconds.Int()); |
|
78 CTimer::DoCancel(); |
|
79 } |
|
80 |
|
81 |
|
82 |