|
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: State Manager |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 // User includes |
|
21 #include <hscontentpublisher.h> |
|
22 #include <aifwpublisherinfo.h> |
|
23 #include <debug.h> |
|
24 |
|
25 #include "caicpscommandbuffer.h" |
|
26 #include "aipluginfactory.h" |
|
27 |
|
28 #include "aistatemanager.h" |
|
29 |
|
30 // ======== LOCAL FUNCTIONS ======== |
|
31 // ---------------------------------------------------------------------------- |
|
32 // StartReason |
|
33 // |
|
34 // ---------------------------------------------------------------------------- |
|
35 // |
|
36 static CHsContentPublisher::TStartReason StartReason( TInt aReason ) |
|
37 { |
|
38 CHsContentPublisher::TStartReason reason; |
|
39 |
|
40 if ( aReason == EAiFwPageStartup ) |
|
41 { |
|
42 reason = CHsContentPublisher::EPageStartup; |
|
43 } |
|
44 else if ( aReason == EAiFwPluginStartup ) |
|
45 { |
|
46 reason = CHsContentPublisher::EPluginStartup; |
|
47 } |
|
48 else |
|
49 { |
|
50 reason = CHsContentPublisher::ESystemStartup; |
|
51 } |
|
52 |
|
53 return reason; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // StopReason |
|
58 // |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 static CHsContentPublisher::TStopReason StopReason( TInt aReason ) |
|
62 { |
|
63 CHsContentPublisher::TStopReason reason; |
|
64 |
|
65 if ( aReason == EAiFwPageShutdown ) |
|
66 { |
|
67 reason = CHsContentPublisher::EPageShutdown; |
|
68 } |
|
69 else if ( aReason == EAiFwPluginShutdown ) |
|
70 { |
|
71 reason = CHsContentPublisher::EPluginShutdown; |
|
72 } |
|
73 else |
|
74 { |
|
75 reason = CHsContentPublisher::ESystemShutdown; |
|
76 } |
|
77 |
|
78 return reason; |
|
79 } |
|
80 |
|
81 // ======== MEMBER FUNCTIONS ======== |
|
82 // ---------------------------------------------------------------------------- |
|
83 // CAiStateManager::NewL() |
|
84 // Two-phased constructor. |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 CAiStateManager* CAiStateManager::NewL( CAiPluginFactory& aFactory ) |
|
88 { |
|
89 CAiStateManager* self = CAiStateManager::NewLC( aFactory ); |
|
90 CleanupStack::Pop( self ); |
|
91 return self; |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // CAiStateManager::NewLC() |
|
96 // Two-phased constructor. |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 CAiStateManager* CAiStateManager::NewLC( CAiPluginFactory& aFactory ) |
|
100 { |
|
101 CAiStateManager* self = new ( ELeave ) CAiStateManager( aFactory ); |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL(); |
|
104 return self; |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // CAiStateManager::~CAiStateManager() |
|
109 // C++ default destructor. |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 CAiStateManager::~CAiStateManager() |
|
113 { |
|
114 iReloadPlugins.Reset(); |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // CAiStateManager::CAiStateManager() |
|
119 // C++ default constructor. |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 CAiStateManager::CAiStateManager( CAiPluginFactory& aFactory ) |
|
123 : iFactory( aFactory ) |
|
124 { |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // CAiStateManager::ConstructL() |
|
129 // 2nd phase constructor |
|
130 // ---------------------------------------------------------------------------- |
|
131 // |
|
132 void CAiStateManager::ConstructL() |
|
133 { |
|
134 iFactory.SetStateManager( this ); |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // CAiStateManager::NotifyStateChange() |
|
139 // |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 void CAiStateManager::NotifyStateChange( TAiFwState aState ) |
|
143 { |
|
144 if ( aState == EAiFwUiShutdown ) |
|
145 { |
|
146 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwUiShutdown" ); |
|
147 |
|
148 iFlags.Set( EShutdown ); |
|
149 |
|
150 iFactory.DestroyAllPlugins(); |
|
151 |
|
152 return; |
|
153 } |
|
154 else if ( aState == EAiFwUiStartup ) |
|
155 { |
|
156 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwUiStartup" ); |
|
157 |
|
158 iFlags.Clear( EShutdown ); |
|
159 |
|
160 return; |
|
161 } |
|
162 |
|
163 TBitFlags32 flags( iFlags ); |
|
164 |
|
165 if ( aState == EAiFwForeground ) |
|
166 { |
|
167 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwForeground" ); |
|
168 |
|
169 iFlags.Set( EIsForeground ); |
|
170 } |
|
171 else if ( aState == EAiFwBackground ) |
|
172 { |
|
173 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwBackground" ); |
|
174 |
|
175 iFlags.Clear( EIsForeground ); |
|
176 } |
|
177 else if ( aState == EAiFwBacklightOn ) |
|
178 { |
|
179 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwBacklightOn" ); |
|
180 |
|
181 iFlags.Set( EIsLightsOn ); |
|
182 } |
|
183 else if ( aState == EAiFwBacklightOff ) |
|
184 { |
|
185 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwBacklightOff" ); |
|
186 |
|
187 iFlags.Clear( EIsLightsOn ); |
|
188 } |
|
189 else if ( aState == EAiFwOnline ) |
|
190 { |
|
191 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwOnline" ); |
|
192 |
|
193 iFlags.Set( EIsOnline ); |
|
194 |
|
195 ProcessOnlineStateChange(); |
|
196 } |
|
197 else if ( aState == EAiFwOffline ) |
|
198 { |
|
199 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwOffline" ); |
|
200 |
|
201 iFlags.Clear( EIsOnline ); |
|
202 |
|
203 ProcessOnlineStateChange(); |
|
204 } |
|
205 else if ( aState == EAiFwGeneralThemeChange ) |
|
206 { |
|
207 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwGeneralThemeChange" ); |
|
208 |
|
209 ProcessGeneralThemeChange(); |
|
210 } |
|
211 else if ( aState == EAiFwBackupRestoreStart || |
|
212 aState == EAiFwBackupRestoreEnd ) |
|
213 { |
|
214 __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwBackupRestoreStart/End" ); |
|
215 |
|
216 ProcessBackupRestore( aState == EAiFwBackupRestoreStart ); |
|
217 } |
|
218 else |
|
219 { |
|
220 __PRINTS( "CAiStateManager::NotifyStateChange, aState: Unknown" ); |
|
221 } |
|
222 |
|
223 // State change evaluation and state change trial is done always here |
|
224 __PRINTS( "CAiStateManager::NotifyStateChange, Run state change" ); |
|
225 |
|
226 ProcessStateChange( EvaluateNextState() ); |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CAiStateManager::NotifyLoadPlugin() |
|
231 // |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 void CAiStateManager::NotifyLoadPlugin( const TAiFwPublisherInfo& aInfo ) |
|
235 { |
|
236 __PRINT( __DBG_FORMAT( |
|
237 "CAiStateManager::NotifyLoadPlugin: name: %S, reason: %d " ), |
|
238 &aInfo.Info().Name(), aInfo.Reason() ); |
|
239 |
|
240 __TIME_MARK( time ); |
|
241 |
|
242 iFactory.LoadPlugin( aInfo ); |
|
243 |
|
244 __TIME_ENDMARK( "CAiStateManager::NotifyLoadPlugin - done", time ); |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // CAiStateManager::NotifyDestroyPlugin() |
|
249 // |
|
250 // ---------------------------------------------------------------------------- |
|
251 // |
|
252 void CAiStateManager::NotifyDestroyPlugin( const TAiFwPublisherInfo& aInfo ) |
|
253 { |
|
254 __PRINT( __DBG_FORMAT( |
|
255 "CAiStateManager::NotifyDestroyPlugin: name: %S, reason: %d " ), |
|
256 &aInfo.Info().Name(), aInfo.Reason() ); |
|
257 |
|
258 __TIME_MARK( time ); |
|
259 |
|
260 iFactory.DestroyPlugin( aInfo ); |
|
261 |
|
262 __TIME_ENDMARK( "CAiStateManager::DestroyPlugin - done", time ); |
|
263 } |
|
264 |
|
265 // ---------------------------------------------------------------------------- |
|
266 // CAiStateManager::EvaluateNextState() |
|
267 // |
|
268 // ---------------------------------------------------------------------------- |
|
269 // |
|
270 CAiStateManager::TState CAiStateManager::EvaluateNextState() const |
|
271 { |
|
272 TState nextState( iCurrentState ); |
|
273 |
|
274 if ( iFlags.IsSet( EIsForeground ) && iFlags.IsSet( EIsLightsOn ) ) |
|
275 { |
|
276 nextState = EAlive; |
|
277 } |
|
278 else |
|
279 { |
|
280 nextState = ESuspended; |
|
281 } |
|
282 |
|
283 __PRINT( __DBG_FORMAT( |
|
284 "CAiStateManager::EvaluateNextState: current state: %d, next state: %d" ), |
|
285 (TInt)iCurrentState, (TInt)nextState ); |
|
286 |
|
287 return nextState; |
|
288 } |
|
289 |
|
290 // ---------------------------------------------------------------------------- |
|
291 // CAiStateManager::ProcessStateChange() |
|
292 // |
|
293 // ---------------------------------------------------------------------------- |
|
294 // |
|
295 void CAiStateManager::ProcessStateChange( TState aNextState ) |
|
296 { |
|
297 __PRINT( __DBG_FORMAT( |
|
298 "CAiStateManager::ProcessStateChange: current state: %d, next state: %d, halt: %d" ), |
|
299 (TInt)iCurrentState, (TInt)aNextState, iHalt ); |
|
300 |
|
301 __TIME_MARK( time ); |
|
302 |
|
303 if ( aNextState != iCurrentState ) |
|
304 { |
|
305 // Update state |
|
306 iCurrentState = aNextState; |
|
307 |
|
308 RPointerArray< CHsContentPublisher >& plugins( iFactory.Publishers() ); |
|
309 |
|
310 // Process state for all |
|
311 for( TInt i = 0; !iHalt && i < plugins.Count(); i++ ) |
|
312 { |
|
313 CHsContentPublisher* plugin( plugins[i] ); |
|
314 |
|
315 const THsPublisherInfo& info( plugin->PublisherInfo() ); |
|
316 |
|
317 __PRINT( __DBG_FORMAT( |
|
318 "CAiStateManager::ProcessStateChange: name: %S" ), &info.Name() ); |
|
319 |
|
320 if ( iCurrentState == EAlive ) |
|
321 { |
|
322 __TIME( "CAiStateManager::ProcessStateChange, EAlive", |
|
323 |
|
324 plugin->Resume( CHsContentPublisher::EForeground ) ); |
|
325 } |
|
326 else if ( iCurrentState == ESuspended ) |
|
327 { |
|
328 __TIME( "CAiStateManager::ProcessStateChange, ESuspended", |
|
329 |
|
330 plugin->Suspend( CHsContentPublisher::EBackground ) ); |
|
331 } |
|
332 } |
|
333 |
|
334 iFactory.FlushCommandBuffer(); |
|
335 } |
|
336 else |
|
337 { |
|
338 __PRINTS( "CAiStateManager::ProcessStateChange, no state change" ); |
|
339 } |
|
340 |
|
341 __TIME_ENDMARK( "CAiStateManager::ProcessStateChange - done", time ); |
|
342 } |
|
343 |
|
344 // ---------------------------------------------------------------------------- |
|
345 // CAiStateManager::ProcessGeneralThemeChange() |
|
346 // |
|
347 // ---------------------------------------------------------------------------- |
|
348 // |
|
349 void CAiStateManager::ProcessGeneralThemeChange() |
|
350 { |
|
351 __PRINTS( "CAiStateManager::ProcessGeneralThemeChange" ); |
|
352 __TIME_MARK( time ); |
|
353 |
|
354 RPointerArray< CHsContentPublisher >& plugins( iFactory.Publishers() ); |
|
355 |
|
356 for( TInt i = 0; i < plugins.Count(); i++ ) |
|
357 { |
|
358 CHsContentPublisher* plugin( plugins[i] ); |
|
359 |
|
360 plugin->Suspend( CHsContentPublisher::EGeneralThemeChange ); |
|
361 |
|
362 // Resume publisher immediately if in alive state |
|
363 if( !iHalt && iCurrentState == EAlive ) |
|
364 { |
|
365 plugin->Resume( CHsContentPublisher::EForeground ); |
|
366 } |
|
367 } |
|
368 |
|
369 iFactory.FlushCommandBuffer(); |
|
370 |
|
371 __TIME_ENDMARK( "CAiStateManager::ProcessGeneralThemeChange - done", time ); |
|
372 } |
|
373 |
|
374 // ---------------------------------------------------------------------------- |
|
375 // CAiStateManager::ProcessBackupRestore() |
|
376 // |
|
377 // ---------------------------------------------------------------------------- |
|
378 // |
|
379 void CAiStateManager::ProcessBackupRestore( TBool aStart ) |
|
380 { |
|
381 __PRINTS( "CAiStateManager::ProcessBackupRestore" ); |
|
382 __TIME_MARK( time ); |
|
383 |
|
384 iHalt = aStart; |
|
385 |
|
386 RPointerArray< CHsContentPublisher >& plugins( iFactory.Publishers() ); |
|
387 |
|
388 for( TInt i = 0; i < plugins.Count(); i++ ) |
|
389 { |
|
390 CHsContentPublisher* plugin( plugins[i] ); |
|
391 |
|
392 if ( aStart ) |
|
393 { |
|
394 plugin->Suspend( CHsContentPublisher::EBackupRestore ); |
|
395 } |
|
396 else |
|
397 { |
|
398 // Resume publisher immediately if in alive state |
|
399 if ( !iHalt && iCurrentState == EAlive ) |
|
400 { |
|
401 plugin->Resume( CHsContentPublisher::EForeground ); |
|
402 } |
|
403 } |
|
404 } |
|
405 |
|
406 iFactory.FlushCommandBuffer(); |
|
407 |
|
408 __TIME_ENDMARK( "CAiStateManager::ProcessBackupRestore - done", time ); |
|
409 } |
|
410 |
|
411 // ---------------------------------------------------------------------------- |
|
412 // CAiStateManager::ProcessOnlineStateChange() |
|
413 // |
|
414 // ---------------------------------------------------------------------------- |
|
415 // |
|
416 void CAiStateManager::ProcessOnlineStateChange() |
|
417 { |
|
418 __PRINTS( "CAiStateManager::ProcessOnlineStateChange" ); |
|
419 |
|
420 RPointerArray< CHsContentPublisher >& plugins( iFactory.Publishers() ); |
|
421 |
|
422 for( TInt i = 0; i < plugins.Count(); i++ ) |
|
423 { |
|
424 CHsContentPublisher* plugin( plugins[i] ); |
|
425 |
|
426 if ( iFlags.IsSet( EIsOnline ) ) |
|
427 { |
|
428 plugin->SetOnline(); |
|
429 } |
|
430 else |
|
431 { |
|
432 plugin->SetOffline(); |
|
433 } |
|
434 } |
|
435 |
|
436 iFactory.FlushCommandBuffer(); |
|
437 |
|
438 __PRINTS( "CAiStateManager::ProcessOnlineStateChange - done" ); |
|
439 } |
|
440 |
|
441 // ---------------------------------------------------------------------------- |
|
442 // CAiStateManager::StartPlugin() |
|
443 // |
|
444 // ---------------------------------------------------------------------------- |
|
445 // |
|
446 void CAiStateManager::StartPlugin( CHsContentPublisher& aPlugin, TInt aReason ) |
|
447 { |
|
448 const THsPublisherInfo& info( aPlugin.PublisherInfo() ); |
|
449 |
|
450 __PRINT( __DBG_FORMAT( |
|
451 "CAiStateManager::StartPlugin: name: %S, reason: %d" ), &info.Name(), (TInt)aReason ); |
|
452 |
|
453 aPlugin.Start( StartReason( aReason ) ); |
|
454 |
|
455 if ( iCurrentState == EAlive ) |
|
456 { |
|
457 __TIME( "CAiStateManager::StartPlugin, enter EAlive", |
|
458 |
|
459 aPlugin.Resume( CHsContentPublisher::EForeground ) ); |
|
460 } |
|
461 else if ( iCurrentState == ESuspended ) |
|
462 { |
|
463 __TIME( "CAiStateManager::StartPlugin, enter ESuspended", |
|
464 |
|
465 aPlugin.Suspend( CHsContentPublisher::EBackground ) ); |
|
466 } |
|
467 |
|
468 if ( iFlags.IsSet( EIsOnline ) ) |
|
469 { |
|
470 __TIME( "CAiStateManager::StartPlugin, Set Online", |
|
471 |
|
472 aPlugin.SetOnline() ); |
|
473 } |
|
474 else |
|
475 { |
|
476 __TIME( "CAiStateManager::StartPlugin, Set Offline", |
|
477 |
|
478 aPlugin.SetOffline() ); |
|
479 } |
|
480 |
|
481 __PRINTS( "CAiStateManager::StartPlugin - done" ); |
|
482 } |
|
483 |
|
484 // ---------------------------------------------------------------------------- |
|
485 // CAiStateManager::StopPlugin() |
|
486 // |
|
487 // ---------------------------------------------------------------------------- |
|
488 // |
|
489 void CAiStateManager::StopPlugin( CHsContentPublisher& aPlugin, TInt aReason ) |
|
490 { |
|
491 const THsPublisherInfo& info( aPlugin.PublisherInfo() ); |
|
492 |
|
493 __PRINT( __DBG_FORMAT( |
|
494 "CAiStateManager::StopPlugin: name: %S, reason: %d" ), &info.Name(), (TInt)aReason ); |
|
495 |
|
496 if ( iCurrentState == EAlive ) |
|
497 { |
|
498 __TIME( "CAiStateManager::StopPlugin, enter ESuspended", |
|
499 |
|
500 aPlugin.Suspend( CHsContentPublisher::EBackground ) ); |
|
501 } |
|
502 |
|
503 aPlugin.Stop( StopReason( aReason ) ); |
|
504 |
|
505 __PRINTS( "CAiStateManager::StopPlugin - done" ); |
|
506 } |
|
507 |
|
508 // ---------------------------------------------------------------------------- |
|
509 // CAiStateManager::NotifyReloadPlugins() |
|
510 // |
|
511 // ---------------------------------------------------------------------------- |
|
512 // |
|
513 void CAiStateManager::NotifyReloadPlugins() |
|
514 { |
|
515 __PRINTS( "CAiStateManager::NotifyReloadPlugins" ); |
|
516 |
|
517 // Factory needs to update its ecom plugins list |
|
518 TRAP_IGNORE( iFactory.ListImplementationsL() ); |
|
519 |
|
520 for ( TInt i = 0; i < iReloadPlugins.Count(); i++ ) |
|
521 { |
|
522 TAiFwPublisherInfo info( iReloadPlugins[i], |
|
523 TAiFwCallback(), EAiFwSystemStartup ); |
|
524 |
|
525 // Reload plugin |
|
526 NotifyLoadPlugin( info ); |
|
527 } |
|
528 |
|
529 iReloadPlugins.Reset(); |
|
530 |
|
531 __PRINTS( "CAiStateManager::NotifyReloadPlugins - done" ); |
|
532 } |
|
533 |
|
534 // ---------------------------------------------------------------------------- |
|
535 // CAiStateManager::NotifyReleasePlugins() |
|
536 // |
|
537 // ---------------------------------------------------------------------------- |
|
538 // |
|
539 void CAiStateManager::NotifyReleasePlugins( const RArray<TUid>& aUidList ) |
|
540 { |
|
541 __PRINTS( "CAiStateManager::NotifyReleasePlugins" ); |
|
542 |
|
543 iReloadPlugins.Reset(); |
|
544 |
|
545 TBool flush( EFalse ); |
|
546 |
|
547 for ( TInt i = 0; i < aUidList.Count(); i++ ) |
|
548 { |
|
549 const TUid& uid( aUidList[ i ] ); |
|
550 |
|
551 CHsContentPublisher* plugin( iFactory.PluginByUid( uid ) ); |
|
552 |
|
553 while ( plugin ) |
|
554 { |
|
555 StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown ); |
|
556 |
|
557 const THsPublisherInfo& info( plugin->PublisherInfo() ); |
|
558 iReloadPlugins.Append( info ); |
|
559 |
|
560 iFactory.DestroyPlugin( uid ); |
|
561 |
|
562 flush = ETrue; |
|
563 |
|
564 // Get next plugin with same uid |
|
565 plugin = iFactory.PluginByUid( uid ); |
|
566 } |
|
567 } |
|
568 |
|
569 if ( flush ) |
|
570 { |
|
571 iFactory.FlushCommandBuffer(); |
|
572 } |
|
573 |
|
574 __PRINTS( "CAiStateManager::NotifyReleasePlugins - done" ); |
|
575 } |
|
576 |
|
577 // End of file |