|
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: Data class to hold application root configuration info |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 |
|
21 // User includes |
|
22 #include "xnviewmanager.h" |
|
23 #include "xnviewdata.h" |
|
24 |
|
25 #include "xnappuiadapter.h" |
|
26 #include "xncontroladapter.h" |
|
27 #include "xnuiengine.h" |
|
28 #include "xnecomhandler.h" |
|
29 #include "xncomposer.h" |
|
30 #include "xnodtparser.h" |
|
31 |
|
32 #include "xndomdocument.h" |
|
33 #include "xndomnode.h" |
|
34 #include "xnodt.h" |
|
35 |
|
36 #include "xnnode.h" |
|
37 #include "xntype.h" |
|
38 |
|
39 #include "xnpanic.h" |
|
40 |
|
41 #include "xnplugindata.h" |
|
42 #include "xnrootdata.h" |
|
43 |
|
44 #include "debug.h" |
|
45 |
|
46 // Constants |
|
47 const TInt KScheduleInterval( 2000000 ); |
|
48 |
|
49 // ============================ LOCAL FUNCTIONS ================================ |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CXnRootData::NewL() |
|
54 // Two-phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CXnRootData* CXnRootData::NewL( CXnViewManager& aManager, |
|
58 TUid aApplicationUid ) |
|
59 { |
|
60 CXnRootData* self = CXnRootData::NewLC( aManager, aApplicationUid ); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CXnRootData::NewLC() |
|
67 // Two-phased constructor. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CXnRootData* CXnRootData::NewLC( CXnViewManager& aManager, |
|
71 TUid aApplicationUid ) |
|
72 { |
|
73 CXnRootData* self = new ( ELeave ) CXnRootData( aManager, aApplicationUid ); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CXnRootData::CXnRootData() |
|
81 // C++ default constructor |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CXnRootData::CXnRootData( CXnViewManager& aManager, TUid aApplicationUid ) |
|
85 : CXnPluginData( aManager ), iApplicationUid( aApplicationUid ) |
|
86 { |
|
87 iFlags.Clear( EIsRemovable ); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CXnRootData::~CXnRootData() |
|
92 // C++ default destructor. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CXnRootData::~CXnRootData() |
|
96 { |
|
97 if ( iLoadTimer ) |
|
98 { |
|
99 iLoadTimer->Cancel(); |
|
100 } |
|
101 |
|
102 delete iLoadTimer; |
|
103 |
|
104 if ( iDestroyTimer ) |
|
105 { |
|
106 iDestroyTimer->Cancel(); |
|
107 } |
|
108 |
|
109 delete iDestroyTimer; |
|
110 |
|
111 iViewsToDestroy.ResetAndDestroy(); |
|
112 |
|
113 iPluginsData.ResetAndDestroy(); |
|
114 |
|
115 delete iODT->DomDocument().RootNode()->LayoutNode(); |
|
116 |
|
117 delete iODT; |
|
118 |
|
119 delete iParser; |
|
120 delete iEcomHandler; |
|
121 |
|
122 User::Heap().Compress(); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CXnRootData::ConstructL() |
|
127 // 2nd phase constructor |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CXnRootData::ConstructL() |
|
131 { |
|
132 CXnPluginData::ConstructL(); |
|
133 |
|
134 iEcomHandler = CXnEcomHandler::NewL(); |
|
135 |
|
136 iParser = CXnODTParser::NewL( iManager, *iEcomHandler ); |
|
137 |
|
138 iLoadTimer = CPeriodic::NewL( CActive::EPriorityLow ); |
|
139 iDestroyTimer = CPeriodic::NewL( CActive::EPriorityLow ); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CXnRootData::Load() |
|
144 // |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 TInt CXnRootData::Load() |
|
148 { |
|
149 if ( Occupied() ) |
|
150 { |
|
151 return KErrInUse; |
|
152 } |
|
153 |
|
154 TInt err( KErrNone ); |
|
155 |
|
156 // Load application root configuration |
|
157 TRAP( err, iODT = iManager.Composer().ComposeRootL( *this ) ); |
|
158 |
|
159 if ( !iODT ) |
|
160 { |
|
161 // Can't recover |
|
162 return EXnInvalidConfiguration; |
|
163 } |
|
164 |
|
165 if ( !err ) |
|
166 { |
|
167 TRAP( err, iManager.Parser().LoadRootL( *this, iApplicationUid ) ); |
|
168 } |
|
169 |
|
170 if ( !err ) |
|
171 { |
|
172 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
173 { |
|
174 CXnViewData* plugin( |
|
175 static_cast< CXnViewData* >( iPluginsData[ i ] ) ); |
|
176 |
|
177 if ( plugin->Initial() ) |
|
178 { |
|
179 err = plugin->Load(); |
|
180 |
|
181 if ( plugin->Occupied() ) |
|
182 { |
|
183 // Initial view is succesfully composed. Some widget plugins |
|
184 // may have failed but it doesn't matter as those are removed. |
|
185 // Rest of the views will be loaded asynchronously by the RunLoadL() |
|
186 return err; |
|
187 } |
|
188 |
|
189 // Initial view failed |
|
190 iManager.RemoveFaultyView( plugin ); |
|
191 |
|
192 delete plugin; |
|
193 plugin = NULL; |
|
194 break; |
|
195 } |
|
196 } |
|
197 |
|
198 // Initial view loading failed, fallback to load any of the views |
|
199 while( iPluginsData.Count() ) |
|
200 { |
|
201 CXnViewData* plugin( |
|
202 static_cast< CXnViewData* >( iPluginsData[ 0 ] ) ); |
|
203 |
|
204 plugin->SetInitial(); |
|
205 |
|
206 // Ignore error |
|
207 plugin->Load(); |
|
208 |
|
209 if ( plugin->Occupied() ) |
|
210 { |
|
211 // Return error because of fallback condition |
|
212 return KXnErrViewPluginFailure; |
|
213 } |
|
214 |
|
215 // View failed, remove it |
|
216 iManager.RemoveFaultyView( plugin ); |
|
217 |
|
218 delete plugin; |
|
219 plugin = NULL; |
|
220 } |
|
221 } |
|
222 else if ( err == KErrNoMemory ) |
|
223 { |
|
224 return err; |
|
225 } |
|
226 |
|
227 // Configuration loading failed totally |
|
228 return EXnInvalidConfiguration; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CXnRootData::Destroy() |
|
233 // |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CXnRootData::Destroy() |
|
237 { |
|
238 iLoadTimer->Cancel(); |
|
239 iDestroyTimer->Cancel(); |
|
240 |
|
241 iFlags.Set( EIsDispose ); |
|
242 |
|
243 iDestroyTimer->Start( TTimeIntervalMicroSeconds32( 0 ), |
|
244 TTimeIntervalMicroSeconds32( 0 ), |
|
245 TCallBack( RunDestroyL, this ) ); |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CXnRootData::LoadRemainingViews() |
|
250 // |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CXnRootData::LoadRemainingViews() |
|
254 { |
|
255 if ( iFlags.IsClear( EIsDispose ) ) |
|
256 { |
|
257 if ( !AllViewsLoaded() ) |
|
258 { |
|
259 iLoadForward = ETrue; |
|
260 iLoadError = KErrNone; |
|
261 |
|
262 iLoadTimer->Cancel(); |
|
263 |
|
264 iLoadTimer->Start( TTimeIntervalMicroSeconds32( KScheduleInterval ), |
|
265 TTimeIntervalMicroSeconds32( KScheduleInterval ), |
|
266 TCallBack( RunLoadL, this ) ); |
|
267 } |
|
268 else |
|
269 { |
|
270 iManager.NotifyAllViewsLoadedL(); |
|
271 } |
|
272 } |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CXnRootData::CancelLoadRemainingViews() |
|
277 // |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 void CXnRootData::CancelLoadRemainingViews() |
|
281 { |
|
282 if ( iFlags.IsClear( EIsDispose ) && !AllViewsLoaded() ) |
|
283 { |
|
284 iLoadTimer->Cancel(); |
|
285 } |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CXnRootData::ODT() |
|
290 // |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 CXnODT* CXnRootData::ODT() const |
|
294 { |
|
295 return iODT; |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CXnRootData::RootNode() |
|
300 // |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 CXnNode* CXnRootData::RootNode() const |
|
304 { |
|
305 return iODT->DomDocument().RootNode()->LayoutNode(); |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CXnRootData::Parser() |
|
310 // |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 CXnODTParser& CXnRootData::Parser() const |
|
314 { |
|
315 return *iParser; |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CXnRootData::EcomHandler() |
|
320 // |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 CXnEcomHandler& CXnRootData::EcomHandler() const |
|
324 { |
|
325 return *iEcomHandler; |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CXnRootData::ActiveViewData() |
|
330 // Finds the active view data |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 CXnViewData& CXnRootData::ActiveViewData() const |
|
334 { |
|
335 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
336 { |
|
337 CXnViewData& plugin( static_cast< CXnViewData& >( *iPluginsData[i] ) ); |
|
338 |
|
339 if ( plugin.Active() ) |
|
340 { |
|
341 return plugin; |
|
342 } |
|
343 } |
|
344 |
|
345 // If active is not set, then try initial |
|
346 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
347 { |
|
348 CXnViewData& plugin( static_cast< CXnViewData& >( *iPluginsData[i] ) ); |
|
349 |
|
350 if ( plugin.Initial() ) |
|
351 { |
|
352 return plugin; |
|
353 } |
|
354 } |
|
355 |
|
356 Panic( EXnInvalidConfiguration ); |
|
357 |
|
358 // Remove compiler warning |
|
359 return static_cast< CXnViewData& > ( *iPluginsData[0] ); |
|
360 } |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // CXnRootData::PreviousViewData() |
|
364 // Finds the active view data |
|
365 // ----------------------------------------------------------------------------- |
|
366 // |
|
367 CXnViewData& CXnRootData::PreviousViewData() const |
|
368 { |
|
369 CXnViewData& active( ActiveViewData() ); |
|
370 |
|
371 TInt count( iPluginsData.Count() ); |
|
372 |
|
373 if ( count == 1 ) |
|
374 { |
|
375 // Only one view available |
|
376 return active; |
|
377 } |
|
378 |
|
379 TInt index( iPluginsData.Find( &active ) ); |
|
380 |
|
381 if ( index == 0 ) |
|
382 { |
|
383 // Return the last |
|
384 return static_cast< CXnViewData& >( *iPluginsData[ count - 1 ] ); |
|
385 } |
|
386 else |
|
387 { |
|
388 // Return the previous |
|
389 return static_cast< CXnViewData& >( *iPluginsData[ index - 1 ] ); |
|
390 } |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // CXnRootData::NextViewData() |
|
395 // Finds the active view data |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 CXnViewData& CXnRootData::NextViewData() const |
|
399 { |
|
400 CXnViewData& active( ActiveViewData() ); |
|
401 |
|
402 TInt count( iPluginsData.Count() ); |
|
403 |
|
404 if ( count == 1 ) |
|
405 { |
|
406 // Only one view available |
|
407 return active; |
|
408 } |
|
409 |
|
410 TInt index( iPluginsData.Find( &active ) ); |
|
411 |
|
412 if ( index + 1 < count ) |
|
413 { |
|
414 // Return the next |
|
415 return static_cast< CXnViewData& >( *iPluginsData[ index + 1 ] ); |
|
416 } |
|
417 else |
|
418 { |
|
419 // Return the first |
|
420 return static_cast< CXnViewData& >( *iPluginsData[ 0 ] ); |
|
421 } |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CXnRootData::DestroyViewData() |
|
426 // Sets view data to be destroyed |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CXnRootData::DestroyViewData( CXnViewData* aViewData ) |
|
430 { |
|
431 TInt index( iPluginsData.Find( aViewData ) ); |
|
432 |
|
433 if ( index != KErrNotFound ) |
|
434 { |
|
435 iPluginsData.Remove( index ); |
|
436 |
|
437 if ( iViewsToDestroy.Find( aViewData ) == KErrNotFound ) |
|
438 { |
|
439 iViewsToDestroy.Append( aViewData ); |
|
440 |
|
441 iDestroyTimer->Cancel(); |
|
442 |
|
443 iDestroyTimer->Start( TTimeIntervalMicroSeconds32( 0 ), |
|
444 TTimeIntervalMicroSeconds32( 0 ), |
|
445 TCallBack( RunDestroyL, this ) ); |
|
446 } |
|
447 } |
|
448 } |
|
449 |
|
450 // ----------------------------------------------------------------------------- |
|
451 // CXnRootData::AllViewsLoaded() |
|
452 // |
|
453 // ----------------------------------------------------------------------------- |
|
454 // |
|
455 TBool CXnRootData::AllViewsLoaded() const |
|
456 { |
|
457 for ( TInt i = 0; i < iPluginsData.Count(); i++ ) |
|
458 { |
|
459 if ( !iPluginsData[i]->Occupied() ) |
|
460 { |
|
461 return EFalse; |
|
462 } |
|
463 } |
|
464 |
|
465 return ETrue; |
|
466 } |
|
467 |
|
468 // ----------------------------------------------------------------------------- |
|
469 // CXnRootData::AllViewsDestroyed() |
|
470 // |
|
471 // ----------------------------------------------------------------------------- |
|
472 // |
|
473 TBool CXnRootData::AllViewsDestroyed() const |
|
474 { |
|
475 return ( iPluginsData.Count() == 0 ) && iFlags.IsSet( EIsDispose ); |
|
476 } |
|
477 |
|
478 // ----------------------------------------------------------------------------- |
|
479 // CXnRootData::RunLoadL() |
|
480 // |
|
481 // ----------------------------------------------------------------------------- |
|
482 // |
|
483 /* static */ TInt CXnRootData::RunLoadL( TAny* aAny ) |
|
484 { |
|
485 __PRINTS( "*** CXnRootData::RunLoadL" ); |
|
486 |
|
487 CXnRootData* self = static_cast< CXnRootData* >( aAny ); |
|
488 |
|
489 if ( self->iFlags.IsSet( EIsDispose ) ) |
|
490 { |
|
491 self->iLoadTimer->Cancel(); |
|
492 return KErrNone; |
|
493 } |
|
494 |
|
495 CXnPluginData& active( self->ActiveViewData() ); |
|
496 |
|
497 CXnPluginData* toLoad( NULL ); |
|
498 |
|
499 TInt index( self->iPluginsData.Find( &active ) ); |
|
500 TInt count( self->iPluginsData.Count() ); |
|
501 |
|
502 if ( self->iLoadForward ) |
|
503 { |
|
504 self->iLoadForward = EFalse; |
|
505 |
|
506 // Start from the next one |
|
507 index = index + 1; |
|
508 |
|
509 if ( index == count ) |
|
510 { |
|
511 index = 0; |
|
512 } |
|
513 |
|
514 for ( TInt i = index; i < self->iPluginsData.Count(); i++ ) |
|
515 { |
|
516 if ( !self->iPluginsData[i]->Occupied() ) |
|
517 { |
|
518 toLoad = self->iPluginsData[i]; |
|
519 break; |
|
520 } |
|
521 } |
|
522 } |
|
523 else |
|
524 { |
|
525 self->iLoadForward = ETrue; |
|
526 |
|
527 if ( index == 0 ) |
|
528 { |
|
529 index = count - 1; |
|
530 } |
|
531 else |
|
532 { |
|
533 index = index - 1; |
|
534 } |
|
535 |
|
536 for ( TInt i = index; i >= 0; i-- ) |
|
537 { |
|
538 if ( !self->iPluginsData[i]->Occupied() ) |
|
539 { |
|
540 toLoad = self->iPluginsData[i]; |
|
541 break; |
|
542 } |
|
543 } |
|
544 } |
|
545 |
|
546 TInt err( KErrNone ); |
|
547 |
|
548 if ( !self->AllViewsLoaded() && toLoad ) |
|
549 { |
|
550 err = toLoad->Load(); |
|
551 |
|
552 if ( err ) |
|
553 { |
|
554 self->iLoadError = err; |
|
555 } |
|
556 } |
|
557 |
|
558 if ( err == KXnErrViewPluginFailure ) |
|
559 { |
|
560 // Remove the view |
|
561 self->iManager.RemoveFaultyView( static_cast< CXnViewData* >( toLoad ) ); |
|
562 |
|
563 delete toLoad; |
|
564 toLoad = NULL; |
|
565 } |
|
566 |
|
567 if ( self->AllViewsLoaded() || err == KErrNoMemory ) |
|
568 { |
|
569 self->iLoadTimer->Cancel(); |
|
570 |
|
571 // Show the error note only once |
|
572 self->iManager.HandleErrorNotes( self->iLoadError ); |
|
573 |
|
574 self->iLoadError = KErrNone; |
|
575 self->iManager.NotifyAllViewsLoadedL(); |
|
576 } |
|
577 |
|
578 __PRINTS( "*** CXnRootData::RunLoadL - done" ); |
|
579 |
|
580 return KErrNone; |
|
581 } |
|
582 |
|
583 // ----------------------------------------------------------------------------- |
|
584 // CXnRootData::SetMaxPages( TInt32 aPages ) |
|
585 // |
|
586 // ----------------------------------------------------------------------------- |
|
587 // |
|
588 void CXnRootData::SetMaxPages( TInt32 aPages ) |
|
589 { |
|
590 iMaxPages = aPages; |
|
591 } |
|
592 |
|
593 // ----------------------------------------------------------------------------- |
|
594 // CXnRootData::MaxPages() |
|
595 // |
|
596 // ----------------------------------------------------------------------------- |
|
597 // |
|
598 TInt32 CXnRootData::MaxPages() |
|
599 { |
|
600 return iMaxPages; |
|
601 } |
|
602 |
|
603 // ----------------------------------------------------------------------------- |
|
604 // CXnRootData::RunDestroyL() |
|
605 // |
|
606 // ----------------------------------------------------------------------------- |
|
607 // |
|
608 /* static */ TInt CXnRootData::RunDestroyL( TAny* aAny ) |
|
609 { |
|
610 __PRINTS( "*** CXnRootData::RunDestroyL" ); |
|
611 |
|
612 CXnRootData* self = static_cast< CXnRootData* >( aAny ); |
|
613 |
|
614 if( self->iFlags.IsSet( EIsDispose ) ) |
|
615 { |
|
616 for ( TInt i = 0; i < self->iViewsToDestroy.Count(); i++ ) |
|
617 { |
|
618 if ( self->iPluginsData.Find( |
|
619 self->iViewsToDestroy[i] ) == KErrNotFound ) |
|
620 { |
|
621 // These must be deleted also |
|
622 self->iPluginsData.AppendL( self->iViewsToDestroy[i] ); |
|
623 } |
|
624 } |
|
625 |
|
626 self->iViewsToDestroy.Reset(); |
|
627 |
|
628 if ( self->iPluginsData.Count() > 0 ) |
|
629 { |
|
630 CXnPluginData* toDestroy( self->iPluginsData[0] ); |
|
631 |
|
632 delete toDestroy; |
|
633 toDestroy = NULL; |
|
634 |
|
635 self->iPluginsData.Remove( 0 ); |
|
636 |
|
637 User::Heap().Compress(); |
|
638 } |
|
639 |
|
640 if ( self->AllViewsDestroyed() ) |
|
641 { |
|
642 // All done |
|
643 delete self; |
|
644 } |
|
645 } |
|
646 else |
|
647 { |
|
648 if ( self->iViewsToDestroy.Count() > 0 ) |
|
649 { |
|
650 CXnPluginData* toDestroy( self->iViewsToDestroy[0] ); |
|
651 |
|
652 delete toDestroy; |
|
653 toDestroy = NULL; |
|
654 |
|
655 self->iViewsToDestroy.Remove( 0 ); |
|
656 |
|
657 User::Heap().Compress(); |
|
658 } |
|
659 |
|
660 if ( self->iViewsToDestroy.Count() == 0 ) |
|
661 { |
|
662 if ( self->iFlags.IsClear( EIsDispose ) ) |
|
663 { |
|
664 self->iDestroyTimer->Cancel(); |
|
665 } |
|
666 } |
|
667 } |
|
668 |
|
669 __PRINTS( "*** CXnRootData::RunDestroyL - done" ); |
|
670 |
|
671 return KErrNone; |
|
672 } |
|
673 |
|
674 // End of file |
|
675 |