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