|
1 // Copyright (c) 2005-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 // |
|
15 |
|
16 #include "CDummyAnswer.h" |
|
17 #include "CMainMenu.h" |
|
18 |
|
19 /** |
|
20 Factory constructor. |
|
21 |
|
22 @param aController Pointer to MExecAsync object that owns this object |
|
23 @return Instance of CDummyAnswer class |
|
24 */ |
|
25 CDummyAnswer* CDummyAnswer::NewL(MExecAsync* aController) |
|
26 { |
|
27 CDummyAnswer* self = new(ELeave) CDummyAnswer(aController); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 /** |
|
35 Constructor. |
|
36 |
|
37 @param aController Pointer to an MExecAsync object that owns this object. |
|
38 */ |
|
39 CDummyAnswer::CDummyAnswer(MExecAsync* aController) |
|
40 : CActive(EPriorityStandard), |
|
41 iController(aController) |
|
42 { |
|
43 iConsole = iController->GConsole(); |
|
44 CActiveScheduler::Add(this); |
|
45 } |
|
46 |
|
47 /** |
|
48 Notifies the menu object that it has completed its request. |
|
49 */ |
|
50 void CDummyAnswer::ExampleComplete() |
|
51 { |
|
52 iController->ExecComplete(KNotType); |
|
53 } |
|
54 |
|
55 /** |
|
56 Second phase constructor. |
|
57 */ |
|
58 void CDummyAnswer::ConstructL() |
|
59 { |
|
60 // Creates a thread-relative timer |
|
61 User::LeaveIfError(iTimer.CreateLocal()); |
|
62 iFirstTime = ETrue; |
|
63 } |
|
64 |
|
65 /** |
|
66 Sets iFirstTime to ETrue. |
|
67 */ |
|
68 void CDummyAnswer::ResetFirstTime() |
|
69 { |
|
70 iFirstTime = ETrue; |
|
71 } |
|
72 |
|
73 /** |
|
74 Destructor. |
|
75 Cancels outstanding requests and closes the iTimer object. |
|
76 */ |
|
77 CDummyAnswer::~CDummyAnswer() |
|
78 { |
|
79 Cancel(); |
|
80 iTimer.Close(); |
|
81 } |
|
82 |
|
83 /** |
|
84 Starts the timer for the duration specified in aDelay. |
|
85 */ |
|
86 void CDummyAnswer::StartCount(TTimeIntervalMicroSeconds32 aDelay) |
|
87 { |
|
88 _LIT(KDummyAnswerPanic, "CDummyAnswer"); |
|
89 __ASSERT_ALWAYS(!IsActive(), User::Panic(KDummyAnswerPanic, 1)); |
|
90 iTimer.After(iStatus, aDelay); |
|
91 SetActive(); |
|
92 } |
|
93 |
|
94 /** |
|
95 Checks the status of the active object and displays the current call duration |
|
96 if there is no error. |
|
97 */ |
|
98 void CDummyAnswer::RunL() |
|
99 { |
|
100 if (iStatus != KErrNone) |
|
101 { |
|
102 iConsole->Printf(KError); |
|
103 |
|
104 // Print the error status code |
|
105 iConsole->Printf(_L("%d\n"), iStatus.Int()); |
|
106 } |
|
107 else |
|
108 { |
|
109 // Print console output message if there is no error |
|
110 iConsole->ClearScreen(); |
|
111 iConsole->Printf(KMenuMsg); |
|
112 iConsole->Printf(KHangupMsg); |
|
113 iConsole->Printf(_L("Call Duration %d seconds\n"), iCount); |
|
114 iCount++; |
|
115 StartCount(1000000); |
|
116 } |
|
117 if (iFirstTime) |
|
118 { |
|
119 iFirstTime = EFalse; |
|
120 ExampleComplete(); |
|
121 } |
|
122 } |
|
123 |
|
124 /** |
|
125 Stops counting and resets the call duration. |
|
126 */ |
|
127 void CDummyAnswer::DoCancel() |
|
128 { |
|
129 ResetFirstTime(); |
|
130 iCount = 0; |
|
131 iTimer.Cancel(); |
|
132 } |