|
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 |
|
18 |
|
19 |
|
20 #include "openmaxaltestmodule.h" |
|
21 |
|
22 /* |
|
23 ------------------------------------------------------------------------------- |
|
24 |
|
25 Class: CSimpleTimeout |
|
26 |
|
27 Method: CSimpleTimeout |
|
28 |
|
29 Description: Default constructor |
|
30 |
|
31 C++ default constructor can NOT contain any code, that |
|
32 might leave. |
|
33 |
|
34 Parameters: None |
|
35 |
|
36 Return Values: None |
|
37 |
|
38 Errors/Exceptions: None |
|
39 |
|
40 Status: Approved |
|
41 |
|
42 ------------------------------------------------------------------------------- |
|
43 */ |
|
44 CSimpleTimeout::CSimpleTimeout() : CActive (CActive::EPriorityStandard) |
|
45 { |
|
46 iLog->Log(_L("CSimpleTimeout::CSimpleTimeout")); |
|
47 } |
|
48 |
|
49 /* |
|
50 ------------------------------------------------------------------------------- |
|
51 |
|
52 Class: CSimpleTimeout |
|
53 |
|
54 Method: ConstructL |
|
55 |
|
56 Description: Symbian OS second phase constructor |
|
57 |
|
58 Symbian OS default constructor can leave. |
|
59 |
|
60 Parameters: |
|
61 |
|
62 Return Values: None |
|
63 |
|
64 Errors/Exceptions: |
|
65 |
|
66 Status: Approved |
|
67 |
|
68 ------------------------------------------------------------------------------- |
|
69 */ |
|
70 void CSimpleTimeout::ConstructL( MTimeoutObserver* aObserver, |
|
71 CStifLogger* aLogger) |
|
72 { |
|
73 iLog->Log(_L("CSimpleTimeout::ConstructL")); |
|
74 iObserver = aObserver; |
|
75 iLog = aLogger; |
|
76 iTimer.CreateLocal(); |
|
77 iTestCaseTimeout = 0; // Initialize |
|
78 |
|
79 // Add to active scheduler |
|
80 CActiveScheduler::Add ( this ); |
|
81 } |
|
82 |
|
83 /* |
|
84 ------------------------------------------------------------------------------- |
|
85 |
|
86 Class: CSimpleTimeout |
|
87 |
|
88 Method: NewL |
|
89 |
|
90 Description: Two-phased constructor. |
|
91 |
|
92 Parameters: const TTestReportOutput aReportOutput: in: Report output type |
|
93 |
|
94 Return Values: CSimpleTimeout* : pointer to created object |
|
95 |
|
96 Errors/Exceptions: Leaves if memory allocation for object fails |
|
97 Leaves if ConstructL leaves |
|
98 |
|
99 Status: Approved |
|
100 |
|
101 ------------------------------------------------------------------------------- |
|
102 */ |
|
103 CSimpleTimeout* CSimpleTimeout::NewL( MTimeoutObserver* aTestClass, |
|
104 CStifLogger* aLogger) |
|
105 { |
|
106 CSimpleTimeout* self = new ( ELeave ) CSimpleTimeout(); |
|
107 CleanupStack::PushL( self ); |
|
108 self->ConstructL( aTestClass, aLogger); |
|
109 CleanupStack::Pop( self ); |
|
110 return self; |
|
111 |
|
112 } |
|
113 |
|
114 /* |
|
115 ------------------------------------------------------------------------------- |
|
116 |
|
117 Class: CSimpleTimeout |
|
118 |
|
119 Method: ~CSimpleTimeout |
|
120 |
|
121 Description: Destructor. |
|
122 |
|
123 Cancel request |
|
124 |
|
125 Parameters: None |
|
126 |
|
127 Return Values: None |
|
128 |
|
129 Errors/Exceptions: None |
|
130 |
|
131 Status: Approved |
|
132 |
|
133 ------------------------------------------------------------------------------- |
|
134 */ |
|
135 CSimpleTimeout::~CSimpleTimeout() |
|
136 { |
|
137 iLog->Log(_L("CSimpleTimeout::~CSimpleTimeout")); |
|
138 Cancel(); |
|
139 iTimer.Close(); |
|
140 } |
|
141 |
|
142 /* |
|
143 ------------------------------------------------------------------------------- |
|
144 |
|
145 Class: CSimpleTimeout |
|
146 |
|
147 Method: Start |
|
148 |
|
149 Description: Start timeout counting |
|
150 |
|
151 Parameters: None |
|
152 |
|
153 Return Values: None |
|
154 |
|
155 Errors/Exceptions: None |
|
156 |
|
157 Status: Approved |
|
158 |
|
159 ------------------------------------------------------------------------------- |
|
160 */ |
|
161 void CSimpleTimeout::Start(TTimeIntervalMicroSeconds aTimeout) |
|
162 { |
|
163 iLog->Log(_L("CSimpleTimeout::Start")); |
|
164 if (IsActive()) |
|
165 { |
|
166 Cancel(); |
|
167 } |
|
168 |
|
169 // Request timer |
|
170 TTime endTime; |
|
171 endTime.HomeTime(); |
|
172 endTime = endTime + aTimeout; |
|
173 |
|
174 TInt64 miliseconds = aTimeout.Int64(); |
|
175 miliseconds /= 1000; |
|
176 |
|
177 TBuf<30> dateString; |
|
178 endTime.FormatL(dateString, KFormatTimeStamp); |
|
179 iLog->Log(_L("Timer=%LD ms, EndTime=%S"), miliseconds, &dateString); |
|
180 |
|
181 // Store absolute timeout |
|
182 iTestCaseTimeout = endTime; |
|
183 |
|
184 // Taken from STIF engine |
|
185 // Note: iTimer.After() method cannot use because there needed |
|
186 // TTimeIntervalMicroSeconds32 and it is 32 bit. So then cannot create |
|
187 // timeout time that is long enough. At() uses 64 bit value=>Long enough. |
|
188 iTimer.At( iStatus, endTime ); |
|
189 SetActive(); |
|
190 } |
|
191 |
|
192 |
|
193 /* |
|
194 ------------------------------------------------------------------------------- |
|
195 |
|
196 Class: CSimpleTimeout |
|
197 |
|
198 Method: Start |
|
199 |
|
200 Description: Start timeout counting |
|
201 |
|
202 Parameters: None |
|
203 |
|
204 Return Values: None |
|
205 |
|
206 Errors/Exceptions: None |
|
207 |
|
208 Status: Approved |
|
209 |
|
210 ------------------------------------------------------------------------------- |
|
211 */ |
|
212 void CSimpleTimeout::Stop() |
|
213 { |
|
214 iLog->Log(_L("CSimpleTimeout::Stop")); |
|
215 if (IsActive()) |
|
216 { |
|
217 Cancel(); |
|
218 } |
|
219 } |
|
220 /* |
|
221 ------------------------------------------------------------------------------- |
|
222 |
|
223 Class: CSimpleTimeout |
|
224 |
|
225 Method: RunL |
|
226 |
|
227 Description: RunL handles completed timeouts. |
|
228 |
|
229 Parameters: None |
|
230 |
|
231 Return Values: None |
|
232 |
|
233 Errors/Exceptions: None |
|
234 |
|
235 Status: Approved |
|
236 |
|
237 ------------------------------------------------------------------------------- |
|
238 */ |
|
239 void CSimpleTimeout::RunL() |
|
240 { |
|
241 iLog->Log(_L("CSimpleTimeout::RunL")); |
|
242 iLog->Log(_L("CSimpleTimeout::RunL")); |
|
243 TTime timeout; |
|
244 timeout.HomeTime(); |
|
245 // Handle the abort case when system time gets changed, but timeout is |
|
246 // still valid. All other cases should timeout since they invalidate the |
|
247 // logic of the timers. |
|
248 if ( iStatus == KErrAbort) |
|
249 { |
|
250 if ( iTestCaseTimeout > timeout ) |
|
251 { |
|
252 RDebug::Print( _L( "Absolute timer still valid. Restaring timer. iStatus: %d" ), iStatus.Int() ); |
|
253 // Start new timer |
|
254 iStatus = KErrNone; // reset value |
|
255 iTimer.At ( iStatus, iTestCaseTimeout ); // restart timer |
|
256 SetActive(); |
|
257 } |
|
258 else |
|
259 { |
|
260 // Absolute timer no longer valid. Must timeout. |
|
261 iLog->Log(_L("Absolute timeout no longer valid")); |
|
262 iObserver->HandleTimeout(KErrNone); |
|
263 } |
|
264 |
|
265 } |
|
266 else |
|
267 { |
|
268 // Status was not KErrAbort. Timing out! |
|
269 // iLog->Log(_L("CSimpleTimeout::RunL - Timeout !!"), iTimeout); |
|
270 iLog->Log(_L("Timing out")); |
|
271 iObserver->HandleTimeout(KErrNone); |
|
272 } |
|
273 |
|
274 } |
|
275 |
|
276 /* |
|
277 ------------------------------------------------------------------------------- |
|
278 |
|
279 Class: CSimpleTimeout |
|
280 |
|
281 Method: DoCancel |
|
282 |
|
283 Description: Cancel active request |
|
284 |
|
285 Parameters: None |
|
286 |
|
287 Return Values: None |
|
288 |
|
289 Errors/Exceptions: None |
|
290 |
|
291 Status: Approved |
|
292 |
|
293 ------------------------------------------------------------------------------- |
|
294 */ |
|
295 void CSimpleTimeout::DoCancel() |
|
296 { |
|
297 iLog->Log(_L("CSimpleTimeout::DoCancel")); |
|
298 iTimer.Cancel(); |
|
299 } |
|
300 |
|
301 /* |
|
302 ------------------------------------------------------------------------------- |
|
303 |
|
304 Class: CSimpleTimeout |
|
305 |
|
306 Method: RunError |
|
307 |
|
308 Description: Handle errors. Just let framework handle errors because |
|
309 RunL does not leave. |
|
310 |
|
311 Parameters: TInt aError: in: Symbian OS error: Error code |
|
312 |
|
313 Return Values: TInt: Symbian OS error code |
|
314 |
|
315 Errors/Exceptions: None |
|
316 |
|
317 Status: Approved |
|
318 |
|
319 ------------------------------------------------------------------------------- |
|
320 */ |
|
321 TInt CSimpleTimeout::RunError( TInt aError ) |
|
322 { |
|
323 iLog->Log(_L("CSimpleTimeout::RunError")); |
|
324 iLog->Log(_L("Timeout error %d"), aError); |
|
325 iObserver->HandleTimeout(aError); |
|
326 return aError; |
|
327 } |
|
328 |