|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Timers assemble for imps engine base function. |
|
15 * |
|
16 * CImpsIdleTimer |
|
17 * Idle timer to lauch Poll requests in CSP protocol. |
|
18 * CImpsPDPIdleTimer |
|
19 * Idle timer to close idle PDP-context (IAP). |
|
20 * CImpsPDPOpenTimer |
|
21 * Timer to open idle PDP-context. |
|
22 * CImpsShutdownTimer |
|
23 * Idle timer to lauch keep-alive and Poll requests in CSP protocol. |
|
24 * |
|
25 */ |
|
26 |
|
27 |
|
28 // INCLUDE FILES |
|
29 #include <e32std.h> |
|
30 #include <flogger.h> |
|
31 #include "impsutils.h" |
|
32 #include "impsTimer.h" |
|
33 #include "ImpsServer.h" |
|
34 |
|
35 // MACROS |
|
36 #ifndef _DEBUG |
|
37 #define _NO_IMPS_LOGGING_ |
|
38 #endif |
|
39 |
|
40 const TInt KImpsUseAfterLimit = 240; |
|
41 |
|
42 //********************************** |
|
43 // CImpsBaseTimer |
|
44 //********************************** |
|
45 CImpsBaseTimer::CImpsBaseTimer( |
|
46 TInt aPriority ) |
|
47 : CActive( aPriority ), |
|
48 iReset( EFalse ) |
|
49 { |
|
50 // Add this to the scheduler |
|
51 ( void ) iTimer.CreateLocal(); |
|
52 CActiveScheduler::Add( this ); |
|
53 } |
|
54 |
|
55 CImpsBaseTimer::~CImpsBaseTimer() |
|
56 { |
|
57 Cancel(); |
|
58 iTimer.Close(); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CImpsBaseTimer::Start |
|
63 // ----------------------------------------------------------------------------- |
|
64 void CImpsBaseTimer::Start( TInt aWaitSeconds ) |
|
65 { |
|
66 iReset = EFalse; |
|
67 |
|
68 // Cancel is needed because of the timer may be reset. |
|
69 Cancel(); |
|
70 |
|
71 if ( aWaitSeconds <= 0 ) |
|
72 { |
|
73 return; |
|
74 } |
|
75 |
|
76 iSeconds = aWaitSeconds; |
|
77 |
|
78 // The At function caused a CUserbase-Panic 46 in very small |
|
79 // time values. 1-4 seconds. Now if the KeepAlive time |
|
80 // is smaller than UseAfterLimit, then we use the After function |
|
81 // If it is larger then use the At function |
|
82 // The reason not to use the After function for every situation is |
|
83 // that the TInt overflows after 35 minutes. 1000000*60*36 > 2^31 |
|
84 if ( iSeconds <= KImpsUseAfterLimit ) |
|
85 { |
|
86 iTimer.After( iStatus, iSeconds * 1000000 ); |
|
87 } |
|
88 else |
|
89 { |
|
90 TTime myKeepAlive; |
|
91 myKeepAlive.HomeTime(); |
|
92 myKeepAlive += TTimeIntervalSeconds( iSeconds ); |
|
93 iTimer.At( iStatus, myKeepAlive ); |
|
94 } |
|
95 iStatus = KRequestPending; |
|
96 SetActive(); |
|
97 |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CImpsBaseTimer::Stop |
|
102 // ----------------------------------------------------------------------------- |
|
103 void CImpsBaseTimer::Stop( ) |
|
104 { |
|
105 iReset = ETrue; |
|
106 Cancel(); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CImpsBaseTimer::Reset |
|
111 // ----------------------------------------------------------------------------- |
|
112 void CImpsBaseTimer::Reset( ) |
|
113 { |
|
114 // Avoid continuos cancelling, therefore just set flag on |
|
115 iReset = ETrue; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CImpsBaseTimer::DoCancel |
|
120 // ----------------------------------------------------------------------------- |
|
121 void CImpsBaseTimer::DoCancel() |
|
122 { |
|
123 iTimer.Cancel(); |
|
124 } |
|
125 |
|
126 //********************************** |
|
127 // CImpsIdleTimer |
|
128 //********************************** |
|
129 |
|
130 CImpsIdleTimer::CImpsIdleTimer( |
|
131 MImpsCSPSession& aServer, |
|
132 TInt aPriority ) |
|
133 : CImpsBaseTimer( aPriority ), |
|
134 iServer( aServer ) |
|
135 { |
|
136 } |
|
137 |
|
138 CImpsIdleTimer::~CImpsIdleTimer() |
|
139 { |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CImpsIdleTimer::Start |
|
144 // ----------------------------------------------------------------------------- |
|
145 void CImpsIdleTimer::Start( TInt aWaitSeconds ) |
|
146 { |
|
147 #ifndef _NO_IMPS_LOGGING_ |
|
148 CImpsClientLogger::Log( _L( "CImpsIdleTimer: Start sec=%d" ), aWaitSeconds ); |
|
149 #endif |
|
150 CImpsBaseTimer::Start( aWaitSeconds ); |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CImpsIdleTimer::Stop |
|
155 // ----------------------------------------------------------------------------- |
|
156 void CImpsIdleTimer::Stop() |
|
157 { |
|
158 #ifndef _NO_IMPS_LOGGING_ |
|
159 CImpsClientLogger::Log( _L( "CImpsIdleTimer: Stop" ) ); |
|
160 #endif |
|
161 CImpsBaseTimer::Stop(); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CImpsIdleTimer::RunL |
|
166 // ----------------------------------------------------------------------------- |
|
167 void CImpsIdleTimer::RunL() |
|
168 { |
|
169 #ifndef _NO_IMPS_LOGGING_ |
|
170 CImpsClientLogger::Log( _L( "IdleTimer: RunL" ) ); |
|
171 #endif |
|
172 TInt err = KErrNone; |
|
173 TRAP( err, iServer.SendPollL() ); |
|
174 Start( iSeconds ); |
|
175 } |
|
176 |
|
177 |
|
178 //********************************** |
|
179 // CImpsPDPIdleTimer |
|
180 //********************************** |
|
181 |
|
182 CImpsPDPIdleTimer::CImpsPDPIdleTimer( |
|
183 MImpsCSPSession& aServer, |
|
184 TInt aPriority ) |
|
185 : CImpsBaseTimer( aPriority ), |
|
186 iServer( aServer ) |
|
187 { |
|
188 } |
|
189 |
|
190 CImpsPDPIdleTimer::~CImpsPDPIdleTimer() |
|
191 { |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CImpsPDPIdleTimer::Reset |
|
196 // ----------------------------------------------------------------------------- |
|
197 void CImpsPDPIdleTimer::Reset( ) |
|
198 { |
|
199 #ifndef _NO_IMPS_LOGGING_ |
|
200 CImpsClientLogger::Log( _L( "CImpsPDPIdleTimer: Reset" ) ); |
|
201 #endif |
|
202 // Reset re-starts this timer only if already runnig |
|
203 if ( IsActive() ) |
|
204 { |
|
205 CImpsBaseTimer::Start( iSeconds ); |
|
206 } |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CImpsPDPIdleTimer::Start |
|
211 // ----------------------------------------------------------------------------- |
|
212 void CImpsPDPIdleTimer::Start( TInt aWaitSeconds ) |
|
213 { |
|
214 #ifndef _NO_IMPS_LOGGING_ |
|
215 CImpsClientLogger::Log( _L( "CImpsPDPIdleTimer: Start sec =%d" ), aWaitSeconds ); |
|
216 #endif |
|
217 CImpsBaseTimer::Start( aWaitSeconds ); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CImpsPDPIdleTimer::Stop |
|
222 // ----------------------------------------------------------------------------- |
|
223 void CImpsPDPIdleTimer::Stop() |
|
224 { |
|
225 #ifndef _NO_IMPS_LOGGING_ |
|
226 CImpsClientLogger::Log( _L( "CImpsPDPIdleTimer: Stop" ) ); |
|
227 #endif |
|
228 CImpsBaseTimer::Stop(); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CImpsPDPIdleTimer::RunL |
|
233 // ----------------------------------------------------------------------------- |
|
234 void CImpsPDPIdleTimer::RunL() |
|
235 { |
|
236 #ifndef _NO_IMPS_LOGGING_ |
|
237 CImpsClientLogger::Log( _L( "PDPIdleTimer: RunL" ) ); |
|
238 #endif |
|
239 // This timer only calls ClosePDP() |
|
240 if ( iStatus.Int() != KErrCancel ) |
|
241 { |
|
242 iServer.ClosePDP(); |
|
243 } |
|
244 iReset = EFalse; |
|
245 Start( iSeconds ); |
|
246 } |
|
247 |
|
248 //********************************** |
|
249 // CImpsPDPOpenTimer |
|
250 //********************************** |
|
251 |
|
252 CImpsPDPOpenTimer::CImpsPDPOpenTimer( |
|
253 MImpsCSPSession& aServer, |
|
254 TInt aPriority ) |
|
255 : CImpsBaseTimer( aPriority ), |
|
256 iServer( aServer ) |
|
257 { |
|
258 } |
|
259 |
|
260 CImpsPDPOpenTimer::~CImpsPDPOpenTimer() |
|
261 { |
|
262 #ifndef _NO_IMPS_LOGGING_ |
|
263 CImpsClientLogger::Log( _L( "CImpsPDPOpenTimer: DELETE" ) ); |
|
264 #endif |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CImpsPDPOpenTimer::Start |
|
269 // ----------------------------------------------------------------------------- |
|
270 void CImpsPDPOpenTimer::Start( TInt aWaitSeconds ) |
|
271 { |
|
272 #ifndef _NO_IMPS_LOGGING_ |
|
273 CImpsClientLogger::Log( _L( "CImpsPDPOpenTimer: Start sec=%d" ), aWaitSeconds ); |
|
274 #endif |
|
275 CImpsBaseTimer::Start( aWaitSeconds ); |
|
276 } |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CImpsPDPOpenTimer::Stop |
|
279 // ----------------------------------------------------------------------------- |
|
280 void CImpsPDPOpenTimer::Stop() |
|
281 { |
|
282 #ifndef _NO_IMPS_LOGGING_ |
|
283 CImpsClientLogger::Log( _L( "CImpsPDPOpenTimer: Stop" ) ); |
|
284 #endif |
|
285 CImpsBaseTimer::Stop(); |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CImpsPDPOpenTimer::RunL |
|
290 // ----------------------------------------------------------------------------- |
|
291 void CImpsPDPOpenTimer::RunL() |
|
292 { |
|
293 #ifndef _NO_IMPS_LOGGING_ |
|
294 CImpsClientLogger::Log( _L( "CImpsPDPOpenTimer: RunL" ) ); |
|
295 #endif |
|
296 if ( iStatus.Int() != KErrCancel ) |
|
297 { |
|
298 TInt ret = iServer.OpenPDP(); |
|
299 // if already open then do not start |
|
300 if ( ret == KErrAlreadyExists ) |
|
301 { |
|
302 #ifndef _NO_IMPS_LOGGING_ |
|
303 CImpsClientLogger::Log( _L( "CImpsPDPOpenTimer: not started anymore ***" ) ); |
|
304 #endif |
|
305 return; |
|
306 } |
|
307 } |
|
308 Start( iSeconds ); |
|
309 } |
|
310 |
|
311 //********************************** |
|
312 // CImpsShutdownTimer |
|
313 //********************************** |
|
314 |
|
315 CImpsShutdownTimer::CImpsShutdownTimer( |
|
316 CImpsServer& aServer, |
|
317 TInt aPriority ) |
|
318 : CImpsBaseTimer( aPriority ), |
|
319 iServer( aServer ) |
|
320 { |
|
321 } |
|
322 |
|
323 CImpsShutdownTimer::~CImpsShutdownTimer() |
|
324 { |
|
325 iStatus = KErrNone; |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CImpsShutdownTimer::RunL |
|
330 // ----------------------------------------------------------------------------- |
|
331 void CImpsShutdownTimer::RunL() |
|
332 { |
|
333 #ifndef _NO_IMPS_LOGGING_ |
|
334 CImpsClientLogger::Log( _L( "ShutDownTimer: RunL" ) ); |
|
335 #endif |
|
336 if ( iStatus != KErrNone ) |
|
337 { |
|
338 #ifndef _NO_IMPS_LOGGING_ |
|
339 CImpsClientLogger::Log( _L( "ShutDownTimer: RunL ignored" ) ); |
|
340 #endif |
|
341 return; |
|
342 } |
|
343 if ( !iReset ) |
|
344 { |
|
345 iServer.DoShutDown(); |
|
346 } |
|
347 // It is extremely important that after the previous call this |
|
348 // method does nothing since DoShutDown actully deletes the |
|
349 // current entity if this class! |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CImpsShutdownTimer::Stop |
|
354 // ----------------------------------------------------------------------------- |
|
355 void CImpsShutdownTimer::Stop() |
|
356 { |
|
357 #ifndef _NO_IMPS_LOGGING_ |
|
358 CImpsClientLogger::Log( _L( "ShutDownTimer: Stop" ) ); |
|
359 #endif |
|
360 CImpsBaseTimer::Stop(); |
|
361 } |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CImpsShutdownTimer::Start |
|
365 // ----------------------------------------------------------------------------- |
|
366 void CImpsShutdownTimer::Start( TInt aWaitSeconds ) |
|
367 { |
|
368 #ifndef _NO_IMPS_LOGGING_ |
|
369 CImpsClientLogger::Log( _L( "ShutDownTimer: Start sec=%d" ), aWaitSeconds ); |
|
370 #endif |
|
371 |
|
372 Cancel(); |
|
373 |
|
374 if ( !aWaitSeconds ) |
|
375 { |
|
376 // Do the shut down ASAP |
|
377 iStatus = KRequestPending; |
|
378 SetActive(); |
|
379 iReset = EFalse; |
|
380 TRequestStatus* s = &iStatus; |
|
381 User::RequestComplete( s, KErrNone ); |
|
382 #ifndef _NO_IMPS_LOGGING_ |
|
383 CImpsClientLogger::Log( _L( "ShutDownTimer: RequestComplete" ) ); |
|
384 #endif |
|
385 } |
|
386 else |
|
387 { |
|
388 #ifndef _NO_IMPS_LOGGING_ |
|
389 CImpsClientLogger::Log( _L( "ShutDownTimer: BaseTimer:Start begins" ) ); |
|
390 #endif |
|
391 CImpsBaseTimer::Start( aWaitSeconds ); |
|
392 } |
|
393 #ifndef _NO_IMPS_LOGGING_ |
|
394 CImpsClientLogger::Log( _L( "ShutDownTimer: Start ends" ) ); |
|
395 #endif |
|
396 } |
|
397 |
|
398 //********************************** |
|
399 // CImpsExpiryTimer |
|
400 //********************************** |
|
401 |
|
402 CImpsExpiryTimer::CImpsExpiryTimer( |
|
403 CImpsServer& aServer, |
|
404 TImpsEventType aType, |
|
405 TInt aPriority ) |
|
406 : CImpsBaseTimer( aPriority ), |
|
407 iServer( aServer ), |
|
408 iType ( aType ) |
|
409 { |
|
410 } |
|
411 |
|
412 CImpsExpiryTimer::~CImpsExpiryTimer() |
|
413 { |
|
414 } |
|
415 |
|
416 // ----------------------------------------------------------------------------- |
|
417 // CImpsExpiryTimer::Start |
|
418 // ----------------------------------------------------------------------------- |
|
419 void CImpsExpiryTimer::Start( TInt aWaitSeconds ) |
|
420 { |
|
421 #ifndef _NO_IMPS_LOGGING_ |
|
422 CImpsClientLogger::Log( _L( "CImpsExpiryTimer: Start sec=%d" ), aWaitSeconds ); |
|
423 #endif |
|
424 CImpsBaseTimer::Start( aWaitSeconds ); |
|
425 } |
|
426 |
|
427 // ----------------------------------------------------------------------------- |
|
428 // CImpsExpiryTimer::Stop |
|
429 // ----------------------------------------------------------------------------- |
|
430 void CImpsExpiryTimer::Stop() |
|
431 { |
|
432 #ifndef _NO_IMPS_LOGGING_ |
|
433 CImpsClientLogger::Log( _L( "CImpsExpiryTimer: Stop" ) ); |
|
434 #endif |
|
435 CImpsBaseTimer::Stop(); |
|
436 } |
|
437 |
|
438 // ----------------------------------------------------------------------------- |
|
439 // CImpsExpiryTimer::RunL |
|
440 // ----------------------------------------------------------------------------- |
|
441 void CImpsExpiryTimer::RunL() |
|
442 { |
|
443 #ifndef _NO_IMPS_LOGGING_ |
|
444 CImpsClientLogger::Log( _L( "ExpiryTimer: RunL" ) ); |
|
445 #endif |
|
446 if ( iStatus == KErrNone ) |
|
447 { |
|
448 iServer.CheckExpiryL( iType ); |
|
449 iTimer.After( iStatus, iSeconds * 1000000 ); |
|
450 SetActive(); |
|
451 } |
|
452 else |
|
453 { |
|
454 #ifndef _NO_IMPS_LOGGING_ |
|
455 CImpsClientLogger::Log( _L( "ExpiryTimer: RunL ignored" ) ); |
|
456 #endif |
|
457 } |
|
458 } |
|
459 |
|
460 //********************************** |
|
461 // CImpsSendQueued |
|
462 //********************************** |
|
463 |
|
464 CImpsSendQueued::CImpsSendQueued( |
|
465 MImpsCSPSession& aServer, |
|
466 TInt aPriority ) |
|
467 : CActive( aPriority ), |
|
468 iServer( aServer ), |
|
469 iCanceled ( EFalse ) |
|
470 { |
|
471 // Add this to the scheduler |
|
472 CActiveScheduler::Add( this ); |
|
473 } |
|
474 |
|
475 CImpsSendQueued::~CImpsSendQueued() |
|
476 { |
|
477 Cancel(); |
|
478 } |
|
479 |
|
480 // ----------------------------------------------------------------------------- |
|
481 // CImpsSendQueued::Send |
|
482 // ----------------------------------------------------------------------------- |
|
483 void CImpsSendQueued::Send( ) |
|
484 { |
|
485 #ifndef _NO_IMPS_LOGGING_ |
|
486 CImpsClientLogger::Log( _L( "SendQueued: Send" ) ); |
|
487 #endif |
|
488 // This yields the control to the server thread active scheduler |
|
489 if ( !IsActive() ) |
|
490 { |
|
491 iStatus = KRequestPending; |
|
492 SetActive(); |
|
493 iCanceled = EFalse; |
|
494 TRequestStatus* s = &iStatus; |
|
495 User::RequestComplete( s, KErrNone ); |
|
496 } |
|
497 } |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // CImpsSendQueued::DoCancel |
|
501 // ----------------------------------------------------------------------------- |
|
502 void CImpsSendQueued::DoCancel() |
|
503 { |
|
504 iCanceled = ETrue; |
|
505 } |
|
506 |
|
507 // ----------------------------------------------------------------------------- |
|
508 // CImpsSendQueued::RunL |
|
509 // ----------------------------------------------------------------------------- |
|
510 void CImpsSendQueued::RunL() |
|
511 { |
|
512 #ifndef _NO_IMPS_LOGGING_ |
|
513 CImpsClientLogger::Log( _L( "SendQueued: RunL" ) ); |
|
514 #endif |
|
515 if ( iCanceled || iStatus.Int() != KErrNone ) |
|
516 { |
|
517 return; |
|
518 } |
|
519 // Trigger a server thread to send a queued message |
|
520 TInt errx = KErrNone; |
|
521 TRAP( errx, iServer.DoSendAllQueuedL() ); |
|
522 } |
|
523 |
|
524 |
|
525 // End of File |