1 /* |
|
2 * Copyright (c) 2007 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: Recovery system class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "ctelerecoverysystem.h" |
|
21 #include <e32svr.h> |
|
22 #include <startupdomainpskeys.h> |
|
23 |
|
24 #include "phonelogger.h" |
|
25 #include "phoneui.pan" |
|
26 #include "cphonetimer.h" |
|
27 #include "ctelewaitingidle.h" |
|
28 |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KPhoneRecoveryItemsArrayGranularity = 8; |
|
32 const TInt KPhoneRecoveryTickInterval = 50000; // 0.05 second |
|
33 const TInt KPhoneRecoveryTicksForCritical = 2; |
|
34 const TInt KPhoneRecoveryTicksForHigh = 3; |
|
35 const TInt KPhoneRecoveryTicksForStandard = 5; |
|
36 const TInt KPhoneRecoveryTicksForLow = 23; |
|
37 const TInt KPhoneRecoveryTicksForDontCare = 37; |
|
38 const TInt KPhoneRecoveryTicksMaximum = 2048; //maximum about 1.5 minutes |
|
39 const TInt KPhoneRecoveryDontStartTimer = 10000; |
|
40 const TInt KPhoneRecoveryCounterStart = 0; |
|
41 const TInt KPhoneRecoveryCounterPause = -1; |
|
42 const TInt KPhoneRecoveryMainTimerPriority = CActive::EPriorityLow; |
|
43 const TInt KPhoneRecoveryAllStepsTimerPriority = CActive::EPriorityLow + 1; |
|
44 |
|
45 // Priority of active object; set it quite high. |
|
46 const TInt KTelePubSubPriority = CActive::EPriorityUserInput; |
|
47 |
|
48 // Flags for all priorities. |
|
49 enum |
|
50 { |
|
51 EPhoneFlagCritical = 1, |
|
52 EPhoneFlagHigh = 2, |
|
53 EPhoneFlagStandard = 4, |
|
54 EPhoneFlagLow = 8, |
|
55 EPhoneFlagDontCare = 16 |
|
56 }; |
|
57 |
|
58 // ============================ MEMBER FUNCTIONS =============================== |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CTeleRecoverySystem::CTeleRecoverySystem |
|
61 // C++ default constructor can NOT contain any code, that |
|
62 // might leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CTeleRecoverySystem::CTeleRecoverySystem() |
|
66 : CActive( KTelePubSubPriority ) |
|
67 { |
|
68 CActiveScheduler::Add( this ); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CTeleRecoverySystem::ConstructL |
|
73 // Symbian 2nd phase constructor can leave. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CTeleRecoverySystem::ConstructL() |
|
77 { |
|
78 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::ConstructL ()" ); |
|
79 iRequest = EPhoneNone; |
|
80 |
|
81 // Construct Recovery items array. |
|
82 iRecoveryItems = new ( ELeave ) CArrayFixFlat< TRecoveryItem >( |
|
83 KPhoneRecoveryItemsArrayGranularity ); |
|
84 |
|
85 // Construct CPhoneTimer. |
|
86 iTimer = CPhoneTimer::NewL( KPhoneRecoveryMainTimerPriority ); |
|
87 |
|
88 // Construct timer for recovery all steps. |
|
89 iAllStepsTimer = CPhoneTimer::NewL( KPhoneRecoveryAllStepsTimerPriority ); |
|
90 |
|
91 iWaitingIdle = CTeleWaitingIdle::NewL( CActive::EPriorityLow, *this ); |
|
92 iWaitingIdle->StartWaitingIdleL(); |
|
93 |
|
94 __PHONELOG( |
|
95 EBasic, |
|
96 EPhoneUIUtils, |
|
97 "CTeleRecoverySystem::ConstructL: timers" ); |
|
98 |
|
99 User::LeaveIfError( |
|
100 iSimStatusProperty.Attach( |
|
101 KPSUidStartup, |
|
102 KPSSimStatus ) ); |
|
103 |
|
104 __PHONELOG( |
|
105 EBasic, |
|
106 EPhoneUIUtils, |
|
107 "CTeleRecoverySystem::ConstructL: attach2" ); |
|
108 |
|
109 // Check current SIM status. |
|
110 User::LeaveIfError( CheckSIMAvailable() ); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CTeleRecoverySystem::NewL |
|
115 // Two-phased constructor. |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 CTeleRecoverySystem* CTeleRecoverySystem::NewL() |
|
119 { |
|
120 CTeleRecoverySystem* self = new( ELeave ) CTeleRecoverySystem; |
|
121 |
|
122 CleanupStack::PushL( self ); |
|
123 self->ConstructL(); |
|
124 CleanupStack::Pop(); |
|
125 |
|
126 return self; |
|
127 } |
|
128 |
|
129 // Destructor |
|
130 CTeleRecoverySystem::~CTeleRecoverySystem() |
|
131 { |
|
132 // Stop listening for SIM changes. |
|
133 Cancel(); |
|
134 |
|
135 iSimStatusProperty.Close(); |
|
136 iSimPresentProperty.Close(); |
|
137 |
|
138 if ( iWaitingIdle ) |
|
139 { |
|
140 delete iWaitingIdle; |
|
141 iWaitingIdle = NULL; |
|
142 } |
|
143 |
|
144 delete iRecoveryItems; |
|
145 delete iTimer; |
|
146 delete iAllStepsTimer; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CTeleRecoverySystem::AddL |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 TPhoneRecoveryId CTeleRecoverySystem::AddL( TCallBack aCallBack, |
|
154 TPhoneRecoveryPriority aPriority, TRecoveryState aState ) |
|
155 { |
|
156 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::AddL()" ); |
|
157 __ASSERT_DEBUG( !iIsCallBack, Panic( EPhoneUtilsNoCallBack ) ); |
|
158 |
|
159 CheckStateForPrecondition( aState ); |
|
160 |
|
161 iIdCounter++; |
|
162 TInt count = iRecoveryItems->Count(); |
|
163 TInt i = 0; |
|
164 for ( ; i < count; i++ ) |
|
165 { |
|
166 if ( iRecoveryItems->At( i ).iPriority <= aPriority ) |
|
167 { |
|
168 break; |
|
169 } |
|
170 } |
|
171 TRecoveryItem item; |
|
172 item.iCallBack = aCallBack; |
|
173 item.iId = iIdCounter; |
|
174 item.iPriority = aPriority; |
|
175 item.iState = aState; |
|
176 |
|
177 __PHONELOG1( |
|
178 EBasic, |
|
179 EPhoneUIUtils, |
|
180 "CTeleRecoverySystem::AddL itemIdx= %d:", i ); |
|
181 |
|
182 iRecoveryItems->InsertL( i, item ); |
|
183 |
|
184 StartTimerIfRequired( aState ); |
|
185 return iIdCounter; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CTeleRecoverySystem::Add |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 TPhoneRecoveryId CTeleRecoverySystem::Add( TCallBack aCallBack, |
|
193 TPhoneRecoveryPriority aPriority, TRecoveryState aState ) |
|
194 { |
|
195 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::AddL()" ); |
|
196 TPhoneRecoveryId id = KNullId; |
|
197 TRAP_IGNORE( id = AddL( aCallBack, aPriority, aState ) ); |
|
198 return id; |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CTeleRecoverySystem::Remove |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CTeleRecoverySystem::Remove( TPhoneRecoveryId aId ) |
|
206 { |
|
207 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::Remove()" ); |
|
208 __ASSERT_DEBUG( !iIsCallBack, Panic( EPhoneUtilsNoCallBack ) ); |
|
209 |
|
210 TInt count = iRecoveryItems->Count(); |
|
211 |
|
212 __PHONELOG1( |
|
213 EBasic, |
|
214 EPhoneUIUtils, |
|
215 "CTeleRecoverySystem::count = %d:", count ); |
|
216 |
|
217 for ( TInt i = 0; i < count; i++ ) |
|
218 { |
|
219 if( iRecoveryItems->At( i ).iId == aId ) |
|
220 { |
|
221 iRecoveryItems->Delete( i ); |
|
222 __PHONELOG1( |
|
223 EBasic, |
|
224 EPhoneUIUtils, |
|
225 "CTeleRecoverySystem::Delete itemIdx= %d:", i ); |
|
226 return; |
|
227 } |
|
228 } |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CTeleRecoverySystem::SetState |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CTeleRecoverySystem::SetState( |
|
236 TPhoneRecoveryId aId, TRecoveryState aState ) |
|
237 { |
|
238 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::SetState()" ); |
|
239 CheckStateForPrecondition( aState ); |
|
240 |
|
241 TInt count = iRecoveryItems->Count(); |
|
242 for ( TInt i = 0; i < count; i++ ) |
|
243 { |
|
244 TRecoveryItem& item = iRecoveryItems->At( i ); |
|
245 if( item.iId == aId ) |
|
246 { |
|
247 item.iState = aState; |
|
248 StartTimerIfRequired( aState ); |
|
249 __PHONELOG1( |
|
250 EBasic, |
|
251 EPhoneUIUtils, |
|
252 "CTeleRecoverySystem::SetState itemIdx= %d:", item.iId ); |
|
253 return; |
|
254 } |
|
255 } |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CTeleRecoverySystem::ResetPending |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 void CTeleRecoverySystem::ResetPending() |
|
263 { |
|
264 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::ResetPending()" ); |
|
265 TBool startTimer = EFalse; |
|
266 TInt count = iRecoveryItems->Count(); |
|
267 for ( TInt i = 0; i < count; i++ ) |
|
268 { |
|
269 TRecoveryItem& item = iRecoveryItems->At( i ); |
|
270 if( item.iState == EPhoneStatePending ) |
|
271 { |
|
272 item.iState = EPhoneStateWaiting; |
|
273 startTimer = ETrue; |
|
274 } |
|
275 } |
|
276 |
|
277 if ( startTimer ) |
|
278 { |
|
279 StartTimer(); |
|
280 } |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CTeleRecoverySystem::RecoverNow |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 TInt CTeleRecoverySystem::RecoverNow( TPhoneRecoveryId aId, |
|
288 TPhoneRecoveryPriority aPriority, TBool aAllSteps ) |
|
289 { |
|
290 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::RecoverNow()" ); |
|
291 TInt err = KErrNone; |
|
292 TInt pos = Find( aId ); |
|
293 |
|
294 if ( pos != KErrNotFound ) |
|
295 { |
|
296 TRecoveryItem& item = iRecoveryItems->At( pos ); |
|
297 item.iPriority = aPriority; |
|
298 err = DoItemCallBack( item ); |
|
299 if ( item.iState == EPhoneStateWaiting ) |
|
300 { |
|
301 if ( aAllSteps ) |
|
302 { |
|
303 item.iState = EPhoneStateStarting; |
|
304 } |
|
305 |
|
306 StartTimerIfRequired( item.iState ); |
|
307 } |
|
308 } |
|
309 __PHONELOG1( |
|
310 EBasic, |
|
311 EPhoneUIUtils, |
|
312 "CTeleRecoverySystem::RecoverNow error = %d:", err ); |
|
313 return err; |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CTeleRecoverySystem::RecoverAllNow |
|
318 // |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void CTeleRecoverySystem::RecoverAllNow() |
|
322 { |
|
323 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::RecoverAllNow()" ); |
|
324 StartTimerIfIdle(); |
|
325 StartAllStepsTimer(); |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CTeleRecoverySystem::EnablePrecondition |
|
330 // |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 void CTeleRecoverySystem::EnablePrecondition() |
|
334 { |
|
335 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::EnablePrecondition()" ); |
|
336 // If precondition has already been satisfied, then |
|
337 // there should not be anything left to do. |
|
338 if ( iPrecondOk ) |
|
339 { |
|
340 return; |
|
341 } |
|
342 |
|
343 // Store flag to indicate that precondition has been |
|
344 // satisfied. |
|
345 iPrecondOk = ETrue; |
|
346 |
|
347 // Go through all recovery items and update state so that |
|
348 // there won't be any items in EPhoneStatePrecond after the loop. |
|
349 // Timer must be started. |
|
350 TInt count = iRecoveryItems->Count(); |
|
351 |
|
352 for ( TInt index = 0; index < count; index++ ) |
|
353 { |
|
354 TRecoveryItem& item = iRecoveryItems->At( index ); |
|
355 |
|
356 CheckStateForPrecondition( item.iState ); |
|
357 } |
|
358 |
|
359 if ( IsIdle() ) |
|
360 { |
|
361 iTimer->Cancel(); |
|
362 StartTimer(); |
|
363 } |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CTeleRecoverySystem::Resume |
|
368 // |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 void CTeleRecoverySystem::Resume() |
|
372 { |
|
373 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::Resume()" ); |
|
374 if ( iTickCounter == KPhoneRecoveryCounterPause ) |
|
375 { |
|
376 StartTimer(); |
|
377 } |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CTeleRecoverySystem::RunL |
|
382 // |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void CTeleRecoverySystem::RunL() |
|
386 { |
|
387 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::RunL()" ); |
|
388 if ( iStatus != KErrNone ) |
|
389 { |
|
390 // If SIM is already available, just listen for SIM status. |
|
391 if ( iSimAvailable == ESimUsable ) |
|
392 { |
|
393 iRequest = EPhoneSIMStatus; |
|
394 } |
|
395 else |
|
396 { |
|
397 iRequest = EPhoneSIMPresent; |
|
398 } |
|
399 |
|
400 __PHONELOG1( |
|
401 EBasic, |
|
402 EPhoneUIUtils, |
|
403 "CTeleRecoverySystem::RunL NewRq = %d ", (TInt) iRequest ); |
|
404 |
|
405 IssueRequest(); |
|
406 return; |
|
407 } |
|
408 |
|
409 // If SIM present availability is still scrutinized, check status. |
|
410 if ( iRequest == EPhoneSIMPresent ) |
|
411 { |
|
412 if ( iSimPresentProperty.Handle() ) |
|
413 { |
|
414 iSimPresentProperty.Get( iSimAvailable ); |
|
415 } |
|
416 |
|
417 if ( iSimAvailable == ESimUsable ) |
|
418 { |
|
419 iRequest = EPhoneSIMStatus; |
|
420 |
|
421 __PHONELOG1( |
|
422 EBasic, |
|
423 EPhoneUIUtils, |
|
424 "CTeleRecoverySystem::RunL NewRq = %d ", (TInt) iRequest ); |
|
425 } |
|
426 else |
|
427 { |
|
428 // SIM is not yet available, start listening again. |
|
429 IssueRequest(); |
|
430 return; |
|
431 } |
|
432 } |
|
433 |
|
434 // If SIM is available and SIM status is ok and precondition has not been |
|
435 // set, set precondition. |
|
436 if ( IsSIMOk() && !iPrecondSimOk ) |
|
437 { |
|
438 EnablePrecondSimOk(); |
|
439 } |
|
440 |
|
441 // Start listening again. |
|
442 IssueRequest(); |
|
443 } |
|
444 |
|
445 // ----------------------------------------------------------------------------- |
|
446 // CTeleRecoverySystem::DoCancel |
|
447 // |
|
448 // ----------------------------------------------------------------------------- |
|
449 // |
|
450 void CTeleRecoverySystem::DoCancel() |
|
451 { |
|
452 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::DoCancel()"); |
|
453 |
|
454 if ( iSimStatusProperty.Handle() ) |
|
455 { |
|
456 iSimStatusProperty.Cancel(); |
|
457 } |
|
458 |
|
459 if ( iSimPresentProperty.Handle() ) |
|
460 { |
|
461 iSimPresentProperty.Cancel(); |
|
462 } |
|
463 } |
|
464 |
|
465 // ----------------------------------------------------------------------------- |
|
466 // CTeleRecoverySystem::EnablePrecondSimOk |
|
467 // ----------------------------------------------------------------------------- |
|
468 // |
|
469 void CTeleRecoverySystem::EnablePrecondSimOk() |
|
470 { |
|
471 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::EnablePreSIM()"); |
|
472 |
|
473 if ( iPrecondSimOk ) |
|
474 { |
|
475 return; |
|
476 } |
|
477 iPrecondSimOk = ETrue; |
|
478 |
|
479 // Go through all recovery items and update state so that |
|
480 // there won't be any items in EPhoneStatePrecondSim after the loop. |
|
481 // Timer must be started. |
|
482 TInt count = iRecoveryItems->Count(); |
|
483 |
|
484 for ( TInt index = 0; index < count; index++ ) |
|
485 { |
|
486 TRecoveryItem& item = iRecoveryItems->At( index ); |
|
487 |
|
488 CheckStateForPrecondition( item.iState ); |
|
489 } |
|
490 |
|
491 iTimer->Cancel(); |
|
492 StartTimer(); |
|
493 } |
|
494 |
|
495 // ----------------------------------------------------------------------------- |
|
496 // CTeleRecoverySystem::DoItemCallBack |
|
497 // ----------------------------------------------------------------------------- |
|
498 // |
|
499 TInt CTeleRecoverySystem::DoItemCallBack( TRecoveryItem& aItem ) |
|
500 { |
|
501 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::DoItemCallBack()"); |
|
502 |
|
503 #ifdef _DEBUG |
|
504 iIsCallBack = ETrue; |
|
505 #endif // _DEBUG |
|
506 |
|
507 TInt err = KErrNone; |
|
508 TRAPD( leaveErr, err = aItem.iCallBack.CallBack() ); |
|
509 |
|
510 __PHONELOG1( |
|
511 EBasic, |
|
512 EPhoneUIUtils, |
|
513 "CTeleRecoverySystem::DoItemCallBack Err = %d ", leaveErr ); |
|
514 |
|
515 #ifdef _DEBUG |
|
516 iIsCallBack = EFalse; |
|
517 #endif // _DEBUG |
|
518 |
|
519 if( leaveErr != KErrNone ) |
|
520 { |
|
521 err = leaveErr; |
|
522 } |
|
523 |
|
524 if ( err > KErrNone ) |
|
525 { |
|
526 aItem.iState = EPhoneStateWaiting; |
|
527 err = KErrNone; |
|
528 } |
|
529 else |
|
530 { |
|
531 switch ( err ) |
|
532 { |
|
533 case KErrNone: |
|
534 aItem.iState = EPhoneStateIdle; |
|
535 break; |
|
536 case KErrNoMemory: |
|
537 case KErrInUse: |
|
538 case KErrServerBusy: |
|
539 case KErrNotReady: |
|
540 case KErrLocked: |
|
541 case KErrTimedOut: |
|
542 case KErrDied: |
|
543 case KErrServerTerminated: |
|
544 aItem.iState = EPhoneStateWaiting; |
|
545 break; |
|
546 default: |
|
547 aItem.iState = EPhoneStatePending; |
|
548 break; |
|
549 } |
|
550 } |
|
551 |
|
552 return err; |
|
553 } |
|
554 |
|
555 // ----------------------------------------------------------------------------- |
|
556 // CTeleRecoverySystem::HandleTimer |
|
557 // |
|
558 // Callback function. |
|
559 // ----------------------------------------------------------------------------- |
|
560 // |
|
561 TInt CTeleRecoverySystem::HandleTimer( TAny* aAny ) |
|
562 { |
|
563 return static_cast< CTeleRecoverySystem* >( aAny )->DoHandleTimer(); |
|
564 } |
|
565 |
|
566 // ----------------------------------------------------------------------------- |
|
567 // CTeleRecoverySystem::DoHandleTimer |
|
568 // ----------------------------------------------------------------------------- |
|
569 // |
|
570 TInt CTeleRecoverySystem::DoHandleTimer() |
|
571 { |
|
572 // It will be sum of flags in which there are items in priority. |
|
573 TInt found = 0; |
|
574 |
|
575 // It contains flags which will be run at the current time. |
|
576 const TInt run = DetermineRun(); |
|
577 |
|
578 // Go through all items and for each item: |
|
579 // If item is in waiting state, |
|
580 // update variable found and |
|
581 // update priority and |
|
582 // perform action if required. |
|
583 |
|
584 const TInt count = iRecoveryItems->Count(); |
|
585 for ( TInt i = 0; i < count; i++ ) |
|
586 { |
|
587 TRecoveryItem& item = iRecoveryItems->At( i ); |
|
588 if( item.iState == EPhoneStateWaiting ) |
|
589 { |
|
590 TBool doCallBack = EFalse; |
|
591 |
|
592 if ( item.iPriority >= EPhonePriorityCritical ) |
|
593 { |
|
594 found |= EPhoneFlagCritical; |
|
595 doCallBack = ( run & EPhoneFlagCritical ); |
|
596 } |
|
597 else if ( item.iPriority > EPhonePriorityHigh ) |
|
598 { |
|
599 // For priority Critical. |
|
600 item.iPriority--; |
|
601 found |= EPhoneFlagHigh; |
|
602 doCallBack = ( run & EPhoneFlagHigh ); |
|
603 } |
|
604 else if ( item.iPriority > EPhonePriorityStandard ) |
|
605 { |
|
606 // For priority High. |
|
607 item.iPriority--; |
|
608 found |= EPhoneFlagStandard; |
|
609 doCallBack = ( run & EPhoneFlagHigh ); |
|
610 } |
|
611 else if ( item.iPriority > EPhonePriorityLow ) |
|
612 { |
|
613 // For priority Standard. |
|
614 item.iPriority--; |
|
615 found |= EPhoneFlagLow; |
|
616 doCallBack = ( run & EPhoneFlagStandard ); |
|
617 } |
|
618 else if ( item.iPriority > EPhonePriorityDontCare ) |
|
619 { |
|
620 // For priority Low. |
|
621 item.iPriority--; |
|
622 found |= EPhoneFlagDontCare; |
|
623 doCallBack = ( run & EPhoneFlagLow ); |
|
624 } |
|
625 else |
|
626 { |
|
627 // For priority DontCare. |
|
628 found |= EPhoneFlagDontCare; |
|
629 doCallBack = ( run & EPhoneFlagDontCare ); |
|
630 } |
|
631 |
|
632 if ( doCallBack ) |
|
633 { |
|
634 DoItemCallBack( item ); |
|
635 } |
|
636 } |
|
637 } |
|
638 |
|
639 // Start timer for the next time. |
|
640 StartNext( found ); |
|
641 return KErrNone; |
|
642 } |
|
643 |
|
644 // ----------------------------------------------------------------------------- |
|
645 // CTeleRecoverySystem::HandleAllStepsTimer |
|
646 // |
|
647 // Callback function. |
|
648 // ----------------------------------------------------------------------------- |
|
649 // |
|
650 TInt CTeleRecoverySystem::HandleAllStepsTimer( TAny* aAny ) |
|
651 { |
|
652 return |
|
653 static_cast< CTeleRecoverySystem* >( aAny )->DoHandleAllStepsTimer(); |
|
654 } |
|
655 |
|
656 // ----------------------------------------------------------------------------- |
|
657 // CTeleRecoverySystem::DoHandleAllStepsTimer |
|
658 // ----------------------------------------------------------------------------- |
|
659 // |
|
660 TInt CTeleRecoverySystem::DoHandleAllStepsTimer() |
|
661 { |
|
662 TInt count = iRecoveryItems->Count(); |
|
663 for ( TInt i = 0; i < count; i++ ) |
|
664 { |
|
665 TRecoveryItem& item = iRecoveryItems->At( i ); |
|
666 if( item.iState == EPhoneStateStarting ) |
|
667 { |
|
668 // Perform recovery step. |
|
669 // |
|
670 TInt err = DoItemCallBack( item ); |
|
671 |
|
672 if ( item.iState == EPhoneStateWaiting ) |
|
673 { |
|
674 // If step went ok, then we can perform next step soon. |
|
675 // If step didn't succeed, then there is no point to |
|
676 // start again immediately. |
|
677 if ( err == KErrNone ) |
|
678 { |
|
679 item.iState = EPhoneStateStarting; |
|
680 } |
|
681 |
|
682 // And start timer. |
|
683 StartTimerIfRequired( item.iState ); |
|
684 } |
|
685 } |
|
686 } |
|
687 return KErrNone; |
|
688 } |
|
689 |
|
690 // ----------------------------------------------------------------------------- |
|
691 // CTeleRecoverySystem::CheckStateForPrecondition |
|
692 // ----------------------------------------------------------------------------- |
|
693 // |
|
694 void CTeleRecoverySystem::CheckStateForPrecondition( TRecoveryState& aState ) |
|
695 { |
|
696 if ( iPrecondOk && aState == EPhoneStatePrecond ) |
|
697 { |
|
698 aState = EPhoneStateWaiting; |
|
699 } |
|
700 |
|
701 if ( iPrecondSimOk && aState == EPhoneStatePrecondSim ) |
|
702 { |
|
703 aState = EPhoneStateWaiting; |
|
704 } |
|
705 } |
|
706 |
|
707 // ----------------------------------------------------------------------------- |
|
708 // CTeleRecoverySystem::StartTimerIfRequired |
|
709 // ----------------------------------------------------------------------------- |
|
710 // |
|
711 void CTeleRecoverySystem::StartTimerIfRequired( TRecoveryState aNewState ) |
|
712 { |
|
713 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::StartTimerIfRequired()"); |
|
714 |
|
715 if ( IsIdle() ) |
|
716 { |
|
717 if ( aNewState == EPhoneStateWaiting ) |
|
718 { |
|
719 StartTimerIfIdle(); |
|
720 } |
|
721 else if ( aNewState == EPhoneStateStarting ) |
|
722 { |
|
723 StartAllStepsTimer(); |
|
724 } |
|
725 } |
|
726 } |
|
727 |
|
728 // ----------------------------------------------------------------------------- |
|
729 // CTeleRecoverySystem::IsIdle() |
|
730 // ----------------------------------------------------------------------------- |
|
731 // |
|
732 TBool CTeleRecoverySystem::IsIdle() |
|
733 { |
|
734 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::IsIdle()"); |
|
735 TBool retVal(EFalse); |
|
736 TInt error(0); |
|
737 TInt state(0); |
|
738 |
|
739 error = iIdleActive.Get( |
|
740 KPSUidStartup, |
|
741 KPSIdlePhase1Ok, |
|
742 state ); |
|
743 |
|
744 if ( ( state == EIdlePhase1Ok ) && |
|
745 ( error == KErrNone ) ) |
|
746 { |
|
747 if ( iWaitingIdle ) |
|
748 { |
|
749 delete iWaitingIdle; |
|
750 iWaitingIdle = NULL; |
|
751 } |
|
752 retVal = ETrue; |
|
753 } |
|
754 |
|
755 return retVal; |
|
756 } |
|
757 |
|
758 // ----------------------------------------------------------------------------- |
|
759 // CTeleRecoverySystem::StartTimerIfIdle |
|
760 // ----------------------------------------------------------------------------- |
|
761 // |
|
762 void CTeleRecoverySystem::StartTimerIfIdle() |
|
763 { |
|
764 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::StartTimerIfIdle()"); |
|
765 |
|
766 if ( !iTimer->IsActive() ) |
|
767 { |
|
768 iTimer->After( KPhoneRecoveryTickInterval, |
|
769 TCallBack( HandleTimer, this ) ); |
|
770 iTickCounter++; |
|
771 } |
|
772 } |
|
773 |
|
774 // ----------------------------------------------------------------------------- |
|
775 // CTeleRecoverySystem::StartTimer |
|
776 // ----------------------------------------------------------------------------- |
|
777 // |
|
778 void CTeleRecoverySystem::StartTimer() |
|
779 { |
|
780 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::StartTimer()"); |
|
781 |
|
782 if ( !iTimer->IsActive() ) |
|
783 { |
|
784 iTickCounter = KPhoneRecoveryCounterStart; |
|
785 iTimer->After( KPhoneRecoveryTickInterval, |
|
786 TCallBack( HandleTimer, this ) ); |
|
787 } |
|
788 } |
|
789 |
|
790 // ----------------------------------------------------------------------------- |
|
791 // CTeleRecoverySystem::StartAllStepsTimer |
|
792 // ----------------------------------------------------------------------------- |
|
793 // |
|
794 void CTeleRecoverySystem::StartAllStepsTimer() |
|
795 { |
|
796 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::StartAllStepsTimer()"); |
|
797 if ( !iAllStepsTimer->IsActive() ) |
|
798 { |
|
799 iAllStepsTimer->After( 1, TCallBack( HandleAllStepsTimer, this ) ); |
|
800 } |
|
801 } |
|
802 |
|
803 // ----------------------------------------------------------------------------- |
|
804 // CTeleRecoverySystem::StartNext |
|
805 // ----------------------------------------------------------------------------- |
|
806 // |
|
807 void CTeleRecoverySystem::StartNext( TInt aFound ) |
|
808 { |
|
809 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::StartNext()"); |
|
810 // Calculate time of next attempt. |
|
811 |
|
812 // This is performed as follows: |
|
813 // For each priority: |
|
814 // If there was item in waiting state, |
|
815 // then calculate next attempt time for that. |
|
816 // Use the minimum attempt time to determine next attempt. |
|
817 |
|
818 TInt nextTick = KPhoneRecoveryDontStartTimer; |
|
819 if ( aFound & EPhoneFlagCritical ) |
|
820 { |
|
821 nextTick = Min( nextTick, NextTick( KPhoneRecoveryTicksForCritical ) ); |
|
822 } |
|
823 if ( aFound & EPhoneFlagHigh ) |
|
824 { |
|
825 nextTick = Min( nextTick, NextTick( KPhoneRecoveryTicksForHigh ) ); |
|
826 } |
|
827 if ( aFound & EPhoneFlagStandard ) |
|
828 { |
|
829 nextTick = Min( nextTick, NextTick( KPhoneRecoveryTicksForStandard ) ); |
|
830 } |
|
831 if ( aFound & EPhoneFlagLow ) |
|
832 { |
|
833 nextTick = Min( nextTick, NextTick( KPhoneRecoveryTicksForLow ) ); |
|
834 } |
|
835 if ( aFound & EPhoneFlagDontCare ) |
|
836 { |
|
837 nextTick = Min( nextTick, NextTick( KPhoneRecoveryTicksForDontCare ) ); |
|
838 } |
|
839 |
|
840 if( nextTick < KPhoneRecoveryDontStartTimer ) |
|
841 { |
|
842 if ( nextTick <= KPhoneRecoveryTicksMaximum ) |
|
843 { |
|
844 iTimer->After( KPhoneRecoveryTickInterval*( nextTick-iTickCounter ), |
|
845 TCallBack( HandleTimer, this ) ); |
|
846 iTickCounter = nextTick; |
|
847 } |
|
848 else |
|
849 { |
|
850 //pause the recover to save memory |
|
851 iTickCounter = KPhoneRecoveryCounterPause; |
|
852 } |
|
853 } |
|
854 } |
|
855 |
|
856 // ----------------------------------------------------------------------------- |
|
857 // CTeleRecoverySystem::DetermineRun |
|
858 // ----------------------------------------------------------------------------- |
|
859 // |
|
860 TInt CTeleRecoverySystem::DetermineRun() const |
|
861 { |
|
862 TInt run = 0; |
|
863 |
|
864 // Check if critical tasks ought to be run. |
|
865 if ( !( iTickCounter % KPhoneRecoveryTicksForCritical ) ) |
|
866 { |
|
867 run |= EPhoneFlagCritical; |
|
868 } |
|
869 |
|
870 // Check if high tasks ought to be run. |
|
871 if ( !( iTickCounter % KPhoneRecoveryTicksForHigh ) ) |
|
872 { |
|
873 run |= EPhoneFlagHigh; |
|
874 } |
|
875 |
|
876 // Check if standard tasks ought to be run. |
|
877 if ( !( iTickCounter % KPhoneRecoveryTicksForStandard ) ) |
|
878 { |
|
879 run |= EPhoneFlagStandard; |
|
880 } |
|
881 |
|
882 // Check if low tasks ought to be run. |
|
883 if ( !( iTickCounter % KPhoneRecoveryTicksForLow ) ) |
|
884 { |
|
885 run |= EPhoneFlagLow; |
|
886 } |
|
887 |
|
888 // Check if 'dont care' tasks ought to be run. |
|
889 if ( !( iTickCounter % KPhoneRecoveryTicksForDontCare ) ) |
|
890 { |
|
891 run |= EPhoneFlagDontCare; |
|
892 } |
|
893 |
|
894 if ( !run ) |
|
895 { |
|
896 run |= EPhoneFlagCritical; |
|
897 } |
|
898 |
|
899 return run; |
|
900 } |
|
901 |
|
902 // ----------------------------------------------------------------------------- |
|
903 // CTeleRecoverySystem::NextTick |
|
904 // ----------------------------------------------------------------------------- |
|
905 // |
|
906 inline TInt CTeleRecoverySystem::NextTick( TInt aTicks ) const |
|
907 { |
|
908 // Find smallest such value k that satisfies the following conditions: |
|
909 // 1. It must be larger than iTickCounter |
|
910 // 2. It must be multiple of aTicks. |
|
911 |
|
912 return ( iTickCounter / aTicks + 1 ) * aTicks; |
|
913 } |
|
914 |
|
915 // ----------------------------------------------------------------------------- |
|
916 // CTeleRecoverySystem::Find |
|
917 // ----------------------------------------------------------------------------- |
|
918 // |
|
919 TInt CTeleRecoverySystem::Find( TPhoneRecoveryId aId ) const |
|
920 { |
|
921 const TInt count = iRecoveryItems->Count(); |
|
922 for ( TInt i = 0; i < count; i++ ) |
|
923 { |
|
924 const TRecoveryItem& item = iRecoveryItems->At( i ); |
|
925 if ( item.iId == aId ) |
|
926 { |
|
927 return i; |
|
928 } |
|
929 } |
|
930 |
|
931 return KErrNotFound; |
|
932 } |
|
933 |
|
934 // ----------------------------------------------------------------------------- |
|
935 // CTeleRecoverySystem::IssueRequest |
|
936 // |
|
937 // ----------------------------------------------------------------------------- |
|
938 // |
|
939 void CTeleRecoverySystem::IssueRequest() |
|
940 { |
|
941 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::IssueRequest()"); |
|
942 if ( !IsActive() ) |
|
943 { |
|
944 if ( iRequest == EPhoneSIMPresent ) |
|
945 { |
|
946 iSimPresentProperty.Subscribe( iStatus ); |
|
947 |
|
948 __PHONELOG( |
|
949 EBasic, |
|
950 EPhoneUIUtils, |
|
951 "CTeleRecoverySystem::DoItemCallBack IssueReq.2"); |
|
952 } |
|
953 else |
|
954 { |
|
955 __PHONELOG( |
|
956 EBasic, |
|
957 EPhoneUIUtils, |
|
958 "CTeleRecoverySystem::DoItemCallBack IssueReq.3"); |
|
959 |
|
960 __ASSERT_DEBUG( iRequest == EPhoneSIMStatus, Panic( EPhoneUtilsNoCallBack ) ); |
|
961 |
|
962 iSimStatusProperty.Subscribe( iStatus ); |
|
963 } |
|
964 |
|
965 SetActive(); |
|
966 } |
|
967 } |
|
968 |
|
969 |
|
970 // ----------------------------------------------------------------------------- |
|
971 // CTeleRecoverySystem::IsSIMOk |
|
972 // |
|
973 // ----------------------------------------------------------------------------- |
|
974 // |
|
975 TBool CTeleRecoverySystem::IsSIMOk() |
|
976 { |
|
977 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::IsSIMOk()"); |
|
978 |
|
979 TInt value = KErrNotFound; |
|
980 TBool simOk = EFalse; |
|
981 |
|
982 if ( iSimAvailable != ESimUsable ) |
|
983 { |
|
984 __PHONELOG( |
|
985 EBasic, |
|
986 EPhoneUIUtils, |
|
987 "CTeleRecoverySystem::IsSIMOk Ret 0"); |
|
988 // SIM is not yet available. |
|
989 return EFalse; |
|
990 } |
|
991 |
|
992 // Get current status. |
|
993 if ( iSimStatusProperty.Handle() ) |
|
994 { |
|
995 iSimStatusProperty.Get( value ); |
|
996 } |
|
997 |
|
998 simOk = ( value == ESimUsable ); |
|
999 |
|
1000 __PHONELOG1( |
|
1001 EBasic, |
|
1002 EPhoneUIUtils, |
|
1003 "CTeleRecoverySystem::IsSIMOk Ret: %d ", (TInt) simOk); |
|
1004 |
|
1005 return simOk; |
|
1006 } |
|
1007 |
|
1008 // ----------------------------------------------------------------------------- |
|
1009 // CTeleRecoverySystem::CheckSIMAvailable |
|
1010 // |
|
1011 // ----------------------------------------------------------------------------- |
|
1012 // |
|
1013 TInt CTeleRecoverySystem::CheckSIMAvailable() |
|
1014 { |
|
1015 __LOGMETHODSTARTEND( EPhoneUIUtils, "CTeleRecoverySystem::CheckSIMAvailable()"); |
|
1016 |
|
1017 // Check current SIM present state. |
|
1018 if ( iSimStatusProperty.Handle() ) |
|
1019 { |
|
1020 iSimStatusProperty.Get( iSimAvailable ); |
|
1021 |
|
1022 __PHONELOG1( |
|
1023 EBasic, |
|
1024 EPhoneUIUtils, |
|
1025 "CTeleRecoverySystem::CheckSIMAvailable %d ", iSimAvailable ); |
|
1026 |
|
1027 if ( iSimAvailable != ESimUsable ) |
|
1028 |
|
1029 { |
|
1030 // Since SIM is not yet present, wait for availability. |
|
1031 iRequest = EPhoneSIMStatus; |
|
1032 } |
|
1033 else |
|
1034 { |
|
1035 // SIM is now available, start listening for SIM status. |
|
1036 iRequest = EPhoneSIMStatus; |
|
1037 |
|
1038 __PHONELOG1( |
|
1039 EBasic, |
|
1040 EPhoneUIUtils, |
|
1041 "CTeleRecoverySystem::CheckSIMAvailable new rq %d ", (TInt) iRequest ); |
|
1042 |
|
1043 |
|
1044 if ( iSimStatusProperty.Handle() ) |
|
1045 { |
|
1046 TInt value = ESimStatusUninitialized; |
|
1047 iSimStatusProperty.Get( value ); |
|
1048 iPrecondSimOk = ( value == ESimUsable ); |
|
1049 } |
|
1050 else |
|
1051 { |
|
1052 return KErrBadHandle; |
|
1053 } |
|
1054 } |
|
1055 IssueRequest(); |
|
1056 } |
|
1057 else |
|
1058 { |
|
1059 return KErrBadHandle; |
|
1060 } |
|
1061 return KErrNone; |
|
1062 } |
|
1063 // End of File |
|