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