idlehomescreen/xmluirendering/uiengine/src/xnplugindata.cpp
branchRCL_3
changeset 9 f966699dea19
parent 2 08c6ee43b396
child 15 ff572dfe6d86
equal deleted inserted replaced
5:c743ef5928ba 9:f966699dea19
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <utf.h>
    19 #include <utf.h>
       
    20 #include <aifwdefs.h>
       
    21 #include <StringLoader.h>
       
    22 #include <aknnotewrappers.h>
    20 
    23 
    21 // User includes
    24 // User includes
       
    25 #include <xnuiengine.rsg>
    22 #include "xnappuiadapter.h"
    26 #include "xnappuiadapter.h"
    23 #include "xncomposer.h"
    27 #include "xncomposer.h"
    24 #include "xnodtparser.h"
    28 #include "xnodtparser.h"
    25 #include "xnresource.h"
    29 #include "xnresource.h"
    26 #include "xnodt.h"
    30 #include "xnodt.h"
    27 #include "xnnode.h"
    31 #include "xnnode.h"
    28 #include "xnplugindata.h"
    32 #include "xnplugindata.h"
    29 #include "xnviewdata.h"
    33 #include "xnviewdata.h"
    30 #include "xnviewmanager.h"
    34 #include "xnviewmanager.h"
    31 #include "xnoomsyshandler.h"
    35 #include "xnoomsyshandler.h"
       
    36 #include "xnpanic.h"
    32 
    37 
    33 // Constants
    38 // Constants
    34 _LIT8( KStateWaitConfirmation, "WaitForConfirmation" );
       
    35 _LIT8( KStateConfirmed, "Confirmed" );
       
    36 _LIT8( KStateError, "Error" );
       
    37 
    39 
    38 // ============================ LOCAL FUNCTIONS ================================
    40 // ============================ LOCAL FUNCTIONS ================================
    39 
    41 
    40 // ============================ MEMBER FUNCTIONS ===============================
    42 // ============================ MEMBER FUNCTIONS ===============================
    41 // -----------------------------------------------------------------------------
    43 // -----------------------------------------------------------------------------
    71 CXnPluginData::CXnPluginData( CXnPluginData& aParent )     
    73 CXnPluginData::CXnPluginData( CXnPluginData& aParent )     
    72     : iParent( &aParent ), iManager( iParent->ViewManager() )       
    74     : iParent( &aParent ), iManager( iParent->ViewManager() )       
    73     {
    75     {
    74     // Plugin data is removable by default    
    76     // Plugin data is removable by default    
    75     iFlags.Set( EIsRemovable );
    77     iFlags.Set( EIsRemovable );
    76     // Assume plugins ready
       
    77     iFlags.Set( EIsDataPluginsReady );
       
    78     }
    78     }
    79 
    79 
    80 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    81 // CXnPluginData::CXnPluginData()
    81 // CXnPluginData::CXnPluginData()
    82 // C++ constructor
    82 // C++ constructor
    84 //
    84 //
    85 CXnPluginData::CXnPluginData( CXnViewManager& aManager )     
    85 CXnPluginData::CXnPluginData( CXnViewManager& aManager )     
    86     : iParent( NULL ), iManager( aManager )
    86     : iParent( NULL ), iManager( aManager )
    87     {
    87     {
    88     // This constructor overload is used by CXnRootData
    88     // This constructor overload is used by CXnRootData
    89     // Assume plugins are ready
       
    90     iFlags.Set( EIsDataPluginsReady );    
       
    91     }
    89     }
    92 
    90 
    93 // -----------------------------------------------------------------------------
    91 // -----------------------------------------------------------------------------
    94 // CXnPluginData::~CXnPluginData()
    92 // CXnPluginData::~CXnPluginData()
    95 // C++ default destructor.
    93 // C++ default destructor.
    96 // -----------------------------------------------------------------------------
    94 // -----------------------------------------------------------------------------
    97 //
    95 //
    98 CXnPluginData::~CXnPluginData()
    96 CXnPluginData::~CXnPluginData()
    99     {
    97     {
   100     RevertPluginState();
       
   101         
       
   102     if ( iLoader )
    98     if ( iLoader )
   103         {
    99         {
   104         iLoader->Cancel();
   100         iLoader->Cancel();
   105         }
   101         }
   106 
   102 
   118     {    
   114     {    
   119     iLoader = CPeriodic::NewL( CActive::EPriorityStandard );    
   115     iLoader = CPeriodic::NewL( CActive::EPriorityStandard );    
   120     }
   116     }
   121 
   117 
   122 // -----------------------------------------------------------------------------
   118 // -----------------------------------------------------------------------------
   123 // CXnPluginData::LoadL()
   119 // CXnPluginData::Load()
   124 // -----------------------------------------------------------------------------
   120 // -----------------------------------------------------------------------------
   125 //
   121 //
   126 void CXnPluginData::LoadL()
   122 TInt CXnPluginData::Load()
   127     {        
   123     {        
   128     if ( Occupied() || PluginState().CompareF( KStateError ) == 0 )
   124     if ( Occupied() )
   129         {
   125         {
   130         return;
   126         return KErrInUse;
   131         }
   127         }
   132    
   128    
   133     if ( !CXnOomSysHandler::HeapAvailable( WIDGET_MIN_MEM ) )
   129     if ( !CXnOomSysHandler::HeapAvailable( WIDGET_MIN_MEM ) )
   134         {
   130         {                
   135         ViewManager().OomSysHandler().HandlePotentialOomL();        
   131         return KErrNoMemory;
   136         return;
       
   137         }
   132         }
   138 
   133 
   139     iFlags.Clear( EIsEmpty );
   134     iFlags.Clear( EIsEmpty );
   140     iFlags.Set( EIsRemovable );
   135     iFlags.Set( EIsRemovable );
   141     
   136            
   142     TRAPD( error,    
   137     TInt err( KErrNone );
   143             
   138     
   144         if ( iManager.Composer().ComposeWidgetL( *this ) == KErrNone )
   139     TRAP( err, err = iManager.Composer().ComposeWidgetL( *this ) );
   145             {
   140     
   146             iManager.Parser().LoadWidgetL( *this );
   141     if ( err == KErrNone )
   147             }                 
   142         {
   148         );
   143         TRAP( err, iManager.Parser().LoadWidgetL( *this ) );       
   149 
   144         }
   150     if ( Empty() )
   145     
   151         {
   146     if ( err == KErrNone )
   152         // All done
   147         {
   153         return;
   148         // Mark publishers as virgin
   154         }
   149         iVirginPublishers = ETrue;
   155     
   150         
   156     if ( error || !Occupied() )
   151         // Succesfully composed, try schedule publishers' loading
   157         {
   152         LoadPublishers();                  
   158         if( error == KErrNoMemory )
       
   159             {
       
   160             ViewManager().OomSysHandler().HandlePotentialOomL();
       
   161             }
       
   162         
       
   163         // Mark this plugin ready, View Manager will remove it
       
   164         DataPluginsLoadCompletedL( KErrGeneral );
       
   165         }    
   153         }    
   166     else
   154     else if ( err == KXnErrPluginFailure )
   167         {        
   155         {
   168         if ( Active() )
   156         // Widget's configuration is broken, remove it
   169             {
   157         TRAP_IGNORE( iManager.UnloadWidgetFromPluginL( *this, ETrue ) );                        
   170             // Load data plugins will set confirmation state to "wait"
   158         }      
   171             LoadDataPluginsL();  
   159         
   172             }
   160     return err;
   173         else
       
   174             {
       
   175             // Composed succesfully to inactive page. Set confirmed
       
   176             SetPluginStateL( KStateConfirmed );
       
   177             }        
       
   178         }
       
   179     }
   161     }
   180 
   162 
   181 // -----------------------------------------------------------------------------
   163 // -----------------------------------------------------------------------------
   182 // CXnPluginData::Destroy()
   164 // CXnPluginData::Destroy()
   183 // -----------------------------------------------------------------------------
   165 // -----------------------------------------------------------------------------
   184 //
   166 //
   185 void CXnPluginData::Destroy()
   167 void CXnPluginData::Destroy()
   186     {       
   168     {       
   187     if ( Occupied() )
   169     if ( Occupied() )
   188         {
   170         {
   189         TRAP_IGNORE( 
   171         DestroyPublishers();
   190                 DestroyDataPluginsL();
   172         
   191                 iManager.Parser().DestroyWidgetL( *this );
   173         TRAP_IGNORE( iManager.Parser().DestroyWidgetL( *this ) );                                       
   192                 );
       
   193         }
   174         }
   194     
   175     
   195     Flush();
   176     Flush();
   196     }
   177     }
   197 
   178 
   198 // -----------------------------------------------------------------------------
   179 // -----------------------------------------------------------------------------
   199 // CXnPluginData::LoadDataPluginsL
   180 // CXnPluginData::LoadPublishers
   200 // Loads data plugins associated to the plugin
   181 // Loads data plugins associated to the plugin
   201 // -----------------------------------------------------------------------------
   182 // -----------------------------------------------------------------------------
   202 //
   183 //
   203 void CXnPluginData::LoadDataPluginsL()
   184 void CXnPluginData::LoadPublishers()
   204     {                     
   185     {                     
   205     if ( !Active() || !Occupied() )
   186     if ( !Active() || !Occupied() || iContentSourceNodes.Count() == 0 )
   206         {
   187         {               
   207         iFlags.Set( EIsDataPluginsReady );
       
   208         
       
   209         return;
   188         return;
   210         }
   189         }
   211                          
   190                          
   212     if ( iContentSourceNodes.Count() == 0 )
   191     iLoader->Cancel();
   213         {        
   192                   
   214         DataPluginsLoadCompletedL( KErrNone );
   193     iLoader->Start( TTimeIntervalMicroSeconds32( 50 ),
   215         }
   194                     TTimeIntervalMicroSeconds32( 50 ),
   216     else
   195                     TCallBack( PeriodicEventL, this ) );
   217         {
   196     }
   218         iLoader->Cancel();
   197 
   219         
   198 // -----------------------------------------------------------------------------
   220         iFlags.Clear( EIsDataPluginsReady );
   199 // CXnPluginData::PeriodicEventL()
   221         
   200 // 
   222         iLoadIndex = 0;               
   201 // -----------------------------------------------------------------------------
   223                        
   202 //
   224         iLoader->Start( TTimeIntervalMicroSeconds32( 0 ),
   203 /* static */ TInt CXnPluginData::PeriodicEventL( TAny* aAny )
   225                         TTimeIntervalMicroSeconds32( 0 ),
   204     {
   226                         TCallBack( RunL, this ) );       
   205     CXnPluginData* self = static_cast< CXnPluginData* >( aAny );
   227         }        
   206     
   228     }
   207     self->iLoader->Cancel();
   229 
   208     
   230 // -----------------------------------------------------------------------------
   209     TInt reason( EAiFwPluginStartup );
   231 // CXnPluginData::DataPluginsLoadCompletedL
   210     
   232 // Indicates that all data plugins are loaded
   211     if ( self->LoadPublishers( reason ) != KErrNone )
   233 // -----------------------------------------------------------------------------
   212         {
   234 //
   213         self->iManager.UnloadWidgetFromPluginL( *self, ETrue );
   235 void CXnPluginData::DataPluginsLoadCompletedL( TInt aStatus )
   214         
   236     {
   215         self->ShowContentRemovedError();
   237     iFlags.Set( EIsDataPluginsReady );    
   216         }
   238 
   217     
   239     const TDesC8& state( aStatus == KErrNone 
   218     return KErrNone;
   240             ? KStateConfirmed() : KStateError() ); 
   219     }
   241     
   220 
   242     SetPluginStateL( state );
   221 // -----------------------------------------------------------------------------
   243             
   222 // CXnPluginData::LoadPublishers()
   244     iManager.SetDataPluginLoadCompleteL( *this );          
   223 // 
   245     }
   224 // -----------------------------------------------------------------------------
   246 
   225 //
   247 // -----------------------------------------------------------------------------
   226 TInt CXnPluginData::LoadPublishers( TInt aReason )
   248 // CXnPluginData::DataPluginsLoaded
   227     {                
   249 // Queries whether all data plugins are loaded
   228     TInt err( KErrNone );
   250 // -----------------------------------------------------------------------------
   229 
   251 //
   230     TRAP( err,
   252 TBool CXnPluginData::DataPluginsLoaded() const
   231         for ( TInt i = 0; i < iContentSourceNodes.Count(); i++ )
   253     {
   232             {            
   254     return ( iFlags.IsSet( EIsDataPluginsReady ) ? ETrue : EFalse );
   233             CXnNodeAppIf& plugin( iContentSourceNodes[i]->AppIfL() );
   255     }
   234                         
   256 
   235             TInt retval(
   257 // -----------------------------------------------------------------------------
   236                 iManager.AppUiAdapter().LoadPublisher( plugin, aReason ) );
   258 // CXnPluginData::DestroyDataPluginsL
   237                             
       
   238             if ( !err )
       
   239                 {
       
   240                 err = retval;
       
   241                 }
       
   242             }
       
   243         );
       
   244 
       
   245     iVirginPublishers = EFalse;
       
   246     
       
   247     if ( !Removable() )
       
   248         {
       
   249         // Not allowed to remove even it fails
       
   250         return KErrNone;
       
   251         }
       
   252     
       
   253     return err;        
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CXnPluginData::DestroyPublishers
   259 // Remove data plugins associated to the plugin
   258 // Remove data plugins associated to the plugin
   260 // -----------------------------------------------------------------------------
   259 // -----------------------------------------------------------------------------
   261 //
   260 //
   262 void CXnPluginData::DestroyDataPluginsL()
   261 void CXnPluginData::DestroyPublishers()
   263     {              
   262     {              
   264     if ( Occupied() )
   263     if ( Occupied() )
   265         {
   264         {
   266         iFlags.Set( EIsDataPluginsReady );
   265         // If not all plugins loaded yet               
   267         
   266         iLoader->Cancel();                                  
   268         if ( iLoader->IsActive() )
   267         
   269             {
   268         TRAP_IGNORE( DoDestroyPublishersL() );
   270             // Not all plugins loaded yet               
       
   271             iLoader->Cancel();
       
   272             
       
   273             RevertPluginState();            
       
   274             }
       
   275         
       
   276         // Create list of data plugins to be removed
       
   277         RPointerArray< CXnNodeAppIf > list;
       
   278         CleanupClosePushL( list );
       
   279         
       
   280         for ( TInt i = 0; i < iContentSourceNodes.Count(); i++ )
       
   281             {
       
   282             list.AppendL( &iContentSourceNodes[i]->AppIfL() );
       
   283             }
       
   284         
       
   285         // Destruction is synchronous
       
   286         iManager.AppUiAdapter().DestroyDataPluginsL( list );
       
   287         
       
   288         CleanupStack::PopAndDestroy( &list );
       
   289         
   269         
   290         User::Heap().Compress();
   270         User::Heap().Compress();
   291         }    
   271         }    
   292     }
   272     }
   293 
   273 
   294 // -----------------------------------------------------------------------------
   274 // -----------------------------------------------------------------------------
       
   275 // CXnPluginData::VirginPublishers
       
   276 // 
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 TBool CXnPluginData::VirginPublishers() const
       
   280     {
       
   281     return iVirginPublishers;
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CXnPluginData::DoDestroyPublishersL
       
   286 // Remove data plugins associated to the plugin
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CXnPluginData::DoDestroyPublishersL()
       
   290     {
       
   291     for ( TInt i = 0; i < iContentSourceNodes.Count(); i++ )
       
   292         {
       
   293         CXnNodeAppIf& plugin( iContentSourceNodes[i]->AppIfL() );
       
   294         
       
   295         // Destruction is synchronous
       
   296         iManager.AppUiAdapter().DestroyPublisher( 
       
   297             plugin, EAiFwPluginShutdown );        
       
   298         }
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
   295 // CXnPluginData::SetConfigurationIdL()
   302 // CXnPluginData::SetConfigurationIdL()
   296 // -----------------------------------------------------------------------------
   303 // -----------------------------------------------------------------------------
   297 //
   304 //
   298 void CXnPluginData::SetConfigurationIdL( const TDesC8& aConfigurationId )
   305 void CXnPluginData::SetConfigurationIdL( const TDesC8& aConfigurationId )
   299     {
   306     {
   374     {
   381     {
   375     delete iPluginType;
   382     delete iPluginType;
   376     iPluginType = NULL;
   383     iPluginType = NULL;
   377 
   384 
   378     iPluginType = aPluginType.AllocL();
   385     iPluginType = aPluginType.AllocL();
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CXnPluginData::SetPluginStateL()
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void CXnPluginData::SetPluginStateL( const TDesC8& aPluginState )     
       
   386     {    
       
   387     if ( PluginState().CompareF( aPluginState ) != 0 )
       
   388         {
       
   389         delete iPluginState;
       
   390         iPluginState = NULL;
       
   391 
       
   392         iPluginState = aPluginState.AllocL();
       
   393 
       
   394         // Tell new state to HSPS as well
       
   395         iManager.UpdatePluginStateL( *this );                           
       
   396         }
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CXnPluginData::RevertPluginState()
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void CXnPluginData::RevertPluginState()
       
   404     {
       
   405     // Need to change state if it is not error
       
   406     if ( Occupied() && PluginState().CompareF( KStateError ) != 0 )
       
   407         {
       
   408         // For now on it is confirmed
       
   409         TRAP_IGNORE( SetPluginStateL( KStateConfirmed ) );                
       
   410         }                
       
   411     }
   386     }
   412 
   387 
   413 // -----------------------------------------------------------------------------
   388 // -----------------------------------------------------------------------------
   414 // CXnPluginData::SetResources()
   389 // CXnPluginData::SetResources()
   415 // -----------------------------------------------------------------------------
   390 // -----------------------------------------------------------------------------
   538     // Don't touch to iOwner, because this plugin might be reused later
   513     // Don't touch to iOwner, because this plugin might be reused later
   539            
   514            
   540     iFlags.ClearAll();
   515     iFlags.ClearAll();
   541     
   516     
   542     // This is default
   517     // This is default
   543     iFlags.Set( EIsRemovable );
   518     iFlags.Set( EIsRemovable );    
   544     iFlags.Set( EIsDataPluginsReady );
       
   545            
   519            
   546     iNode = NULL;
   520     iNode = NULL;
   547 
       
   548     iLoadIndex = 0;
       
   549     
   521     
   550     delete iConfigurationId;
   522     delete iConfigurationId;
   551     iConfigurationId = NULL;
   523     iConfigurationId = NULL;
   552 
   524 
   553     delete iPluginId;
   525     delete iPluginId;
   559     delete iPluginName;
   531     delete iPluginName;
   560     iPluginName = NULL;
   532     iPluginName = NULL;
   561 
   533 
   562     delete iPluginType;
   534     delete iPluginType;
   563     iPluginType = NULL;
   535     iPluginType = NULL;
   564 
       
   565     delete iPluginState;
       
   566     iPluginState = NULL;
       
   567 
   536 
   568     delete iPublisherName;
   537     delete iPublisherName;
   569     iPublisherName = NULL;
   538     iPublisherName = NULL;
   570 
   539 
   571     if ( iResources )
   540     if ( iResources )
   622 // CXnPluginData::SetIsDisplayingPopup()
   591 // CXnPluginData::SetIsDisplayingPopup()
   623 // 
   592 // 
   624 // -----------------------------------------------------------------------------
   593 // -----------------------------------------------------------------------------
   625 //
   594 //
   626 void CXnPluginData::SetIsDisplayingPopup ( TBool aVisible, CXnNode* aNode )
   595 void CXnPluginData::SetIsDisplayingPopup ( TBool aVisible, CXnNode* aNode )
   627     {
   596     {    
   628     
       
   629     if ( aVisible )
   597     if ( aVisible )
   630         {
   598         {
   631         iPopupNodes.InsertInAddressOrder( aNode );
   599         iPopupNodes.InsertInAddressOrder( aNode );
   632         }
   600         }
   633     else
   601     else
   634         {
   602         {
   635         TInt index( iPopupNodes.Find( aNode ) );
   603         TInt index( iPopupNodes.Find( aNode ) );
       
   604 
   636         if ( index != KErrNotFound )
   605         if ( index != KErrNotFound )
   637             {
   606             {
   638             iPopupNodes.Remove( index );
   607             iPopupNodes.Remove( index );
   639             }
   608             }
   640         }
   609         }
   641     }
   610     }
   642 
   611 
   643 
       
   644 //------------------------------------------------------------------------------
   612 //------------------------------------------------------------------------------
   645 // CXnPluginData::IsDisplayingPopup()      
   613 // CXnPluginData::IsDisplayingPopup()      
   646 //
   614 //
   647 //------------------------------------------------------------------------------
   615 //------------------------------------------------------------------------------
   648 //    
   616 //    
   649 TBool CXnPluginData::IsDisplayingPopup() const
   617 TBool CXnPluginData::IsDisplayingPopup() const
   650     {
   618     {
   651     return ( iPopupNodes.Count() > 0 );
   619     return ( iPopupNodes.Count() > 0 );
   652     }
   620     }
   653 
   621 
   654 // -----------------------------------------------------------------------------
   622 //------------------------------------------------------------------------------
   655 // CXnPluginData::RunL()
   623 // CXnPluginData::ShowContentRemovedError()      
   656 // 
   624 //
   657 // -----------------------------------------------------------------------------
   625 //------------------------------------------------------------------------------
   658 //
   626 //    
   659 /* static */ TInt CXnPluginData::RunL( TAny* aAny )
   627 void CXnPluginData::ShowContentRemovedError()
   660     {
   628     {
   661     CXnPluginData* self = static_cast< CXnPluginData* >( aAny );
   629     TRAP_IGNORE( DoShowContentRemovedErrorL() );
   662     
   630     }
   663     self->iLoader->Cancel();
   631 
   664     
   632 //------------------------------------------------------------------------------
   665     RPointerArray< CXnNodeAppIf >list;
   633 // CXnPluginData::DoShowContentRemovedErrorL()      
   666     CleanupClosePushL( list );
   634 //
   667 
   635 //------------------------------------------------------------------------------
   668     for ( TInt i = 0; i < self->iContentSourceNodes.Count(); i++ )
   636 //    
   669         {
   637 void CXnPluginData::DoShowContentRemovedErrorL()
   670         list.AppendL( &self->iContentSourceNodes[i]->AppIfL() );
   638     {
   671         }
   639     HBufC* msg( StringLoader::LoadLC( R_QTN_HS_ERROR_WIDGETS_REMOVED ) );
   672         
   640         
   673     // State is "wait" until data plugins are loaded
   641     CAknErrorNote* note = new ( ELeave ) CAknErrorNote;
   674     self->SetPluginStateL( KStateWaitConfirmation );
   642     CleanupStack::PushL( note );
   675        
   643     
   676     TRAPD( err, self->iManager.AppUiAdapter().LoadDataPluginsL( list ) );
   644     note->ExecuteLD( *msg );
   677 
   645     
   678     if ( err && self->Removable() )
   646     CleanupStack::Pop( note );
   679         {               
   647     CleanupStack::PopAndDestroy( msg );                                       
   680         self->DataPluginsLoadCompletedL( err );            
   648     }
   681         }
   649 
   682     else
   650 //------------------------------------------------------------------------------
   683         {
   651 // CXnPluginData::ShowOutOfMemErrorL()      
   684         self->DataPluginsLoadCompletedL( KErrNone );                 
   652 //
   685         }
   653 //------------------------------------------------------------------------------
   686     
   654 //    
   687     CleanupStack::PopAndDestroy( &list );
   655 void CXnPluginData::ShowOutOfMemError()
   688         
   656     {
   689     return KErrNone;       
   657     TRAP_IGNORE( ViewManager().OomSysHandler().HandlePotentialOomL() );
   690     }
   658     }
   691 
   659 
   692 // End of file
   660 // End of file