idlefw/src/framework/aistatemanager.cpp
branchRCL_3
changeset 74 edd621764147
parent 59 a0713522ab97
equal deleted inserted replaced
64:b276298d5729 74:edd621764147
    17 
    17 
    18 // System includes
    18 // System includes
    19 
    19 
    20 // User includes
    20 // User includes
    21 #include <hscontentpublisher.h>
    21 #include <hscontentpublisher.h>
    22 #include <aifwdefs.h>
    22 #include <aifwpublisherinfo.h>
    23 #include <AknWaitDialog.h> 
       
    24 #include <bautils.h>
       
    25 #include <ConeResLoader.h>
       
    26 #include <debug.h>
    23 #include <debug.h>
    27 
    24 
    28 #include "caicpscommandbuffer.h"
    25 #include "caicpscommandbuffer.h"
    29 #include "aipluginfactory.h"
    26 #include "aipluginfactory.h"
    30 
    27 
    34 // ----------------------------------------------------------------------------
    31 // ----------------------------------------------------------------------------
    35 // StartReason
    32 // StartReason
    36 // 
    33 // 
    37 // ----------------------------------------------------------------------------
    34 // ----------------------------------------------------------------------------
    38 //
    35 //
    39 static CHsContentPublisher::TStartReason StartReason( TAiFwLoadReason aReason )
    36 static CHsContentPublisher::TStartReason StartReason( TInt aReason )
    40     {
    37     {
    41     CHsContentPublisher::TStartReason reason; 
    38     CHsContentPublisher::TStartReason reason; 
    42              
    39              
    43     if ( aReason == EAiFwPageStartup )
    40     if ( aReason == EAiFwPageStartup )
    44         {
    41         {
    59 // ----------------------------------------------------------------------------
    56 // ----------------------------------------------------------------------------
    60 // StopReason
    57 // StopReason
    61 // 
    58 // 
    62 // ----------------------------------------------------------------------------
    59 // ----------------------------------------------------------------------------
    63 //
    60 //
    64 static CHsContentPublisher::TStopReason StopReason( TAiFwDestroyReason aReason )
    61 static CHsContentPublisher::TStopReason StopReason( TInt aReason )
    65     {
    62     {
    66     CHsContentPublisher::TStopReason reason; 
    63     CHsContentPublisher::TStopReason reason; 
    67              
    64              
    68     if ( aReason == EAiFwPageShutdown )
    65     if ( aReason == EAiFwPageShutdown )
    69         {
    66         {
   111 // CAiStateManager::~CAiStateManager()
   108 // CAiStateManager::~CAiStateManager()
   112 // C++ default destructor.
   109 // C++ default destructor.
   113 // ----------------------------------------------------------------------------
   110 // ----------------------------------------------------------------------------
   114 //
   111 //
   115 CAiStateManager::~CAiStateManager()
   112 CAiStateManager::~CAiStateManager()
   116     {  
   113     {      
   117     delete iCommandBuffer;
   114     iReloadPlugins.Reset();
   118 	iReloadPlugins.Close();
       
   119     }
   115     }
   120 
   116 
   121 // ----------------------------------------------------------------------------
   117 // ----------------------------------------------------------------------------
   122 // CAiStateManager::CAiStateManager()
   118 // CAiStateManager::CAiStateManager()
   123 // C++ default constructor.
   119 // C++ default constructor.
   132 // CAiStateManager::ConstructL()
   128 // CAiStateManager::ConstructL()
   133 // 2nd phase constructor
   129 // 2nd phase constructor
   134 // ----------------------------------------------------------------------------
   130 // ----------------------------------------------------------------------------
   135 //
   131 //
   136 void CAiStateManager::ConstructL()
   132 void CAiStateManager::ConstructL()
   137     {        
   133     {               
   138     iCommandBuffer = CAiCpsCommandBuffer::NewL();
   134     iFactory.SetStateManager( this );    
   139     
       
   140     iFactory.SetCommandBuffer( iCommandBuffer );
       
   141     }
   135     }
   142 
   136 
   143 // ----------------------------------------------------------------------------
   137 // ----------------------------------------------------------------------------
   144 // CAiStateManager::NotifyStateChange()
   138 // CAiStateManager::NotifyStateChange()
   145 // 
   139 // 
   150     if ( aState == EAiFwUiShutdown )
   144     if ( aState == EAiFwUiShutdown )
   151         {     
   145         {     
   152         __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwUiShutdown" );
   146         __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwUiShutdown" );
   153         
   147         
   154         iFlags.Set( EShutdown );
   148         iFlags.Set( EShutdown );
   155         
   149                 
   156         DestroyPlugins();
   150         iFactory.DestroyAllPlugins();
   157         
   151         
   158         return;
   152         return;
   159         }    
   153         }    
   160     else if ( aState == EAiFwUiStartup )
   154     else if ( aState == EAiFwUiStartup )
   161         {
   155         {
   162         __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwUiStartup" );
   156         __PRINTS( "CAiStateManager::NotifyStateChange, aState: EAiFwUiStartup" );
   163         
   157                         
   164         iFlags.Clear( EShutdown );
   158         iFlags.Clear( EShutdown );
   165         
   159         
   166         return;
   160         return;
   167         }
   161         }
   168        
   162        
   226         __PRINTS( "CAiStateManager::NotifyStateChange, aState: Unknown" );
   220         __PRINTS( "CAiStateManager::NotifyStateChange, aState: Unknown" );
   227         }
   221         }
   228 
   222 
   229     // State change evaluation and state change trial is done always here
   223     // State change evaluation and state change trial is done always here
   230     __PRINTS( "CAiStateManager::NotifyStateChange, Run state change" );    
   224     __PRINTS( "CAiStateManager::NotifyStateChange, Run state change" );    
       
   225     
   231     ProcessStateChange( EvaluateNextState() );            
   226     ProcessStateChange( EvaluateNextState() );            
   232     }
   227     }
   233 
   228 
   234 // ----------------------------------------------------------------------------
   229 // ----------------------------------------------------------------------------
   235 // CAiStateManager::NotifyLoadPlugin()
   230 // CAiStateManager::NotifyLoadPlugin()
   236 // 
   231 // 
   237 // ----------------------------------------------------------------------------
   232 // ----------------------------------------------------------------------------
   238 //
   233 //
   239 TInt CAiStateManager::NotifyLoadPlugin( const THsPublisherInfo& aPublisherInfo,
   234 void CAiStateManager::NotifyLoadPlugin( const TAiFwPublisherInfo& aInfo )    
   240     TAiFwLoadReason aReason )
       
   241     {                
   235     {                
   242     __PRINT( __DBG_FORMAT( 
   236     __PRINT( __DBG_FORMAT( 
   243         "CAiStateManager::NotifyLoadPlugin: name: %S, reason: %d " ), 
   237         "CAiStateManager::NotifyLoadPlugin: name: %S, reason: %d " ), 
   244               &aPublisherInfo.Name(), (TInt) aReason );      
   238               &aInfo.Info().Name(), aInfo.Reason() );      
   245           
   239           
   246     __TIME_MARK( time );
   240     __TIME_MARK( time );
   247       
   241        
   248     // Create plugin
   242     iFactory.LoadPlugin( aInfo );
   249     TInt retval( iFactory.CreatePlugin( aPublisherInfo ) );
   243     
   250     
   244     __TIME_ENDMARK( "CAiStateManager::NotifyLoadPlugin - done", time );       
   251     if ( retval == KErrNone )
       
   252         {
       
   253         CHsContentPublisher* plugin( iFactory.PluginByInfo( aPublisherInfo ) );
       
   254         
       
   255         if( plugin )
       
   256             {
       
   257             // Do startup state transition    
       
   258             StartPlugin( *plugin, StartReason( aReason ) );  
       
   259             }    
       
   260         }
       
   261       
       
   262     __TIME_ENDMARK( "CAiStateManager::NotifyLoadPlugin, construction", time );
       
   263     
       
   264     return retval;
       
   265     }
   245     }
   266 
   246 
   267 // ----------------------------------------------------------------------------
   247 // ----------------------------------------------------------------------------
   268 // CAiStateManager::NotifyDestroyPlugin()
   248 // CAiStateManager::NotifyDestroyPlugin()
   269 // 
   249 // 
   270 // ----------------------------------------------------------------------------
   250 // ----------------------------------------------------------------------------
   271 //
   251 //
   272 void CAiStateManager::NotifyDestroyPlugin( 
   252 void CAiStateManager::NotifyDestroyPlugin( const TAiFwPublisherInfo& aInfo )           
   273     const THsPublisherInfo& aPublisherInfo, TAiFwDestroyReason aReason )    
       
   274     {
   253     {
   275     __PRINT( __DBG_FORMAT( 
   254     __PRINT( __DBG_FORMAT( 
   276         "CAiStateManager::NotifyDestroyPlugin: name: %S, reason: %d " ), 
   255         "CAiStateManager::NotifyDestroyPlugin: name: %S, reason: %d " ), 
   277             &aPublisherInfo.Name(), (TInt)aReason );              
   256             &aInfo.Info().Name(), aInfo.Reason() );              
   278     
   257     
   279     __TIME_MARK( time );
   258     __TIME_MARK( time );
   280     
   259     
   281     // Resolve plugin
   260     iFactory.DestroyPlugin( aInfo );
   282     CHsContentPublisher* plugin( iFactory.PluginByInfo( aPublisherInfo ) );
   261                                  
   283             
   262     __TIME_ENDMARK( "CAiStateManager::DestroyPlugin - done", time );
   284     if ( plugin )
       
   285         {                  
       
   286         // Do shutdown state transition
       
   287         StopPlugin( *plugin, StopReason( aReason ) );
       
   288         
       
   289         // Destroy plugin
       
   290         iFactory.DestroyPlugin( aPublisherInfo );                                    
       
   291         }
       
   292            
       
   293     __TIME_ENDMARK( "CAiStateManager::DestroyPlugin, done", time );
       
   294     }
       
   295 
       
   296 // ----------------------------------------------------------------------------
       
   297 // CAiStateManager::NotifyReloadPlugins()
       
   298 // 
       
   299 // ----------------------------------------------------------------------------
       
   300 //
       
   301 void CAiStateManager::NotifyReloadPlugins()
       
   302     {
       
   303     __PRINTS( "CAiStateManager::NotifyReloadPlugins" );
       
   304 
       
   305     for ( TInt i = 0; i < iReloadPlugins.Count(); i++ )
       
   306         {
       
   307         // Reload plugin
       
   308         NotifyLoadPlugin( iReloadPlugins[ i ], EAiFwSystemStartup );
       
   309         }
       
   310     
       
   311     __PRINTS( "CAiStateManager::NotifyReloadPlugins, done" );
       
   312     }
   263     }
   313 
   264 
   314 // ----------------------------------------------------------------------------
   265 // ----------------------------------------------------------------------------
   315 // CAiStateManager::EvaluateNextState()
   266 // CAiStateManager::EvaluateNextState()
   316 // 
   267 // 
   378                         
   329                         
   379                 plugin->Suspend( CHsContentPublisher::EBackground ) );
   330                 plugin->Suspend( CHsContentPublisher::EBackground ) );
   380                 }            
   331                 }            
   381             }
   332             }
   382         
   333         
   383         FlushCommandBuffer();
   334         iFactory.FlushCommandBuffer();
   384         }
   335         }
   385     else
   336     else
   386         {
   337         {
   387         __PRINTS( "CAiStateManager::ProcessStateChange, no state change" );
   338         __PRINTS( "CAiStateManager::ProcessStateChange, no state change" );
   388         }
   339         }
   389     
   340     
   390     __TIME_ENDMARK( "CAiStateManager::ProcessStateChange, done", time );
   341     __TIME_ENDMARK( "CAiStateManager::ProcessStateChange - done", time );
   391     }
   342     }
   392 
   343 
   393 // ----------------------------------------------------------------------------
   344 // ----------------------------------------------------------------------------
   394 // CAiStateManager::ProcessGeneralThemeChange()
   345 // CAiStateManager::ProcessGeneralThemeChange()
   395 // 
   346 // 
   413             {
   364             {
   414             plugin->Resume( CHsContentPublisher::EForeground );
   365             plugin->Resume( CHsContentPublisher::EForeground );
   415             }        
   366             }        
   416         } 
   367         } 
   417     
   368     
   418     FlushCommandBuffer();
   369     iFactory.FlushCommandBuffer();
   419     
   370     
   420     __TIME_ENDMARK( "CAiStateManager::ProcessGeneralThemeChange, done", time );
   371     __TIME_ENDMARK( "CAiStateManager::ProcessGeneralThemeChange - done", time );
   421     }
   372     }
   422 
   373 
   423 // ----------------------------------------------------------------------------
   374 // ----------------------------------------------------------------------------
   424 // CAiStateManager::ProcessBackupRestore()
   375 // CAiStateManager::ProcessBackupRestore()
   425 // 
   376 // 
   450                 plugin->Resume( CHsContentPublisher::EForeground );
   401                 plugin->Resume( CHsContentPublisher::EForeground );
   451                 }
   402                 }
   452             }
   403             }
   453         }
   404         }
   454     
   405     
   455     FlushCommandBuffer();
   406     iFactory.FlushCommandBuffer();
   456             
   407             
   457     __TIME_ENDMARK( "CAiStateManager::ProcessBackupRestore, done", time );
   408     __TIME_ENDMARK( "CAiStateManager::ProcessBackupRestore - done", time );
   458     }
   409     }
   459 
   410 
   460 // ----------------------------------------------------------------------------
   411 // ----------------------------------------------------------------------------
   461 // CAiStateManager::ProcessOnlineStateChange()
   412 // CAiStateManager::ProcessOnlineStateChange()
   462 // 
   413 // 
   480             {
   431             {
   481             plugin->SetOffline();
   432             plugin->SetOffline();
   482             }
   433             }
   483         }               
   434         }               
   484     
   435     
   485     FlushCommandBuffer();
   436     iFactory.FlushCommandBuffer();
       
   437     
       
   438     __PRINTS( "CAiStateManager::ProcessOnlineStateChange - done" );
   486     }
   439     }
   487 
   440 
   488 // ----------------------------------------------------------------------------
   441 // ----------------------------------------------------------------------------
   489 // CAiStateManager::StartPlugin()
   442 // CAiStateManager::StartPlugin()
   490 // 
   443 // 
   491 // ----------------------------------------------------------------------------
   444 // ----------------------------------------------------------------------------
   492 //
   445 //
   493 void CAiStateManager::StartPlugin( CHsContentPublisher& aPlugin,
   446 void CAiStateManager::StartPlugin( CHsContentPublisher& aPlugin, TInt aReason )    
   494     CHsContentPublisher::TStartReason aReason )
       
   495     {    
   447     {    
   496     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
   448     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
   497     
   449     
   498     __PRINT( __DBG_FORMAT( 
   450     __PRINT( __DBG_FORMAT( 
   499         "CAiStateManager::StartPlugin: name: %S, reason: %d" ), &info.Name(), (TInt)aReason ); 
   451         "CAiStateManager::StartPlugin: name: %S, reason: %d" ), &info.Name(), (TInt)aReason ); 
   500     
   452     
   501     aPlugin.Start( aReason );
   453     aPlugin.Start( StartReason( aReason ) );
   502     
   454     
   503     if ( iCurrentState == EAlive )
   455     if ( iCurrentState == EAlive )
   504         {
   456         {
   505         __TIME( "CAiStateManager::StartPlugin, enter EAlive",
   457         __TIME( "CAiStateManager::StartPlugin, enter EAlive",
   506                 
   458                 
   523         {
   475         {
   524         __TIME( "CAiStateManager::StartPlugin, Set Offline",
   476         __TIME( "CAiStateManager::StartPlugin, Set Offline",
   525             
   477             
   526         aPlugin.SetOffline() );
   478         aPlugin.SetOffline() );
   527         }
   479         }
   528     
   480            
   529     FlushCommandBuffer();
       
   530     
       
   531     __PRINTS( "CAiStateManager::StartPlugin - done" );
   481     __PRINTS( "CAiStateManager::StartPlugin - done" );
   532     }
   482     }
   533 
   483 
   534 // ----------------------------------------------------------------------------
   484 // ----------------------------------------------------------------------------
   535 // CAiStateManager::StopPlugin()
   485 // CAiStateManager::StopPlugin()
   536 // 
   486 // 
   537 // ----------------------------------------------------------------------------
   487 // ----------------------------------------------------------------------------
   538 //
   488 //
   539 void CAiStateManager::StopPlugin( CHsContentPublisher& aPlugin,
   489 void CAiStateManager::StopPlugin( CHsContentPublisher& aPlugin, TInt aReason )    
   540     CHsContentPublisher::TStopReason aReason )
       
   541     {
   490     {
   542     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
   491     const THsPublisherInfo& info( aPlugin.PublisherInfo() );
   543     
   492     
   544     __PRINT( __DBG_FORMAT( 
   493     __PRINT( __DBG_FORMAT( 
   545         "CAiStateManager::StopPlugin: name: %S, reason: %d" ), &info.Name(), (TInt)aReason ); 
   494         "CAiStateManager::StopPlugin: name: %S, reason: %d" ), &info.Name(), (TInt)aReason ); 
   549         __TIME( "CAiStateManager::StopPlugin, enter ESuspended", 
   498         __TIME( "CAiStateManager::StopPlugin, enter ESuspended", 
   550                 
   499                 
   551         aPlugin.Suspend( CHsContentPublisher::EBackground ) );
   500         aPlugin.Suspend( CHsContentPublisher::EBackground ) );
   552         }
   501         }
   553     
   502     
   554     aPlugin.Stop( aReason );   
   503     aPlugin.Stop( StopReason( aReason ) );   
   555     
   504            
   556     FlushCommandBuffer();
       
   557     
       
   558     __PRINTS( "CAiStateManager::StopPlugin - done" );
   505     __PRINTS( "CAiStateManager::StopPlugin - done" );
   559     }
   506     }
   560 
   507 
   561 // ----------------------------------------------------------------------------
   508 // ----------------------------------------------------------------------------
   562 // CAiStateManager::DestroyPlugins()
   509 // CAiStateManager::NotifyReloadPlugins()
   563 // 
   510 // 
   564 // ----------------------------------------------------------------------------
   511 // ----------------------------------------------------------------------------
   565 //
   512 //
   566 void CAiStateManager::DestroyPlugins()
   513 void CAiStateManager::NotifyReloadPlugins()
   567     {
   514     {
   568     __PRINTS( "CAiStateManager::DestroyPlugins, start" );    
   515     __PRINTS( "CAiStateManager::NotifyReloadPlugins" );
   569     __TIME_MARK( time );
   516 
   570     
   517     // Factory needs to update its ecom plugins list
   571     RPointerArray< CHsContentPublisher >& plugins( iFactory.Publishers() );
   518     TRAP_IGNORE( iFactory.ListImplementationsL() );
   572     
   519     
   573     for ( TInt i = 0; i < plugins.Count(); i++ )
   520     for ( TInt i = 0; i < iReloadPlugins.Count(); i++ )
   574         {
   521         {
   575         CHsContentPublisher* plugin( plugins[i] );
   522         TAiFwPublisherInfo info( iReloadPlugins[i], 
   576 
   523             TAiFwCallback(), EAiFwSystemStartup );
   577         // Do shutdown state transition
   524         
   578         StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );        
   525         // Reload plugin
   579         }    
   526         NotifyLoadPlugin( info );             
   580     
   527         }
   581     FlushCommandBuffer();
   528     
   582     
   529     iReloadPlugins.Reset();
   583     // Finally get rid of all plugins
   530     
   584     plugins.ResetAndDestroy();
   531     __PRINTS( "CAiStateManager::NotifyReloadPlugins - done" );
   585     
   532     }
   586     __TIME_ENDMARK( "CAiStateManager::DestroyPlugins, done", time );
   533 
   587     }
       
   588 
       
   589 // ----------------------------------------------------------------------------
       
   590 // CAiStateManager::FlushCommandBuffer();()
       
   591 // 
       
   592 // ----------------------------------------------------------------------------
       
   593 //
       
   594 void CAiStateManager::FlushCommandBuffer()
       
   595     {
       
   596     __PRINTS( "CAiStateManager::FlushCommandBuffer, start" );    
       
   597         
       
   598     if ( iCommandBuffer )
       
   599         {
       
   600         __TIME( "CAiStateManager::FlushCommandBuffer, flush",
       
   601                 
       
   602         iCommandBuffer->Flush() );
       
   603         }
       
   604     
       
   605     __PRINTS( "CAiStateManager::FlushCommandBuffer - done" );
       
   606     }
       
   607 	
       
   608 // ----------------------------------------------------------------------------
   534 // ----------------------------------------------------------------------------
   609 // CAiStateManager::NotifyReleasePlugins()
   535 // CAiStateManager::NotifyReleasePlugins()
   610 // 
   536 // 
   611 // ----------------------------------------------------------------------------
   537 // ----------------------------------------------------------------------------
   612 //
   538 //
   614     {
   540     {
   615     __PRINTS( "CAiStateManager::NotifyReleasePlugins" );    
   541     __PRINTS( "CAiStateManager::NotifyReleasePlugins" );    
   616 
   542 
   617     iReloadPlugins.Reset();
   543     iReloadPlugins.Reset();
   618     
   544     
       
   545     TBool flush( EFalse );
       
   546     
   619     for ( TInt i = 0; i < aUidList.Count(); i++ )
   547     for ( TInt i = 0; i < aUidList.Count(); i++ )
   620         {
   548         {
   621         CHsContentPublisher* plugin = iFactory.PluginByUid( aUidList[ i ] );
   549         const TUid& uid( aUidList[ i ] );
   622         if ( plugin )
   550         
       
   551         CHsContentPublisher* plugin( iFactory.PluginByUid( uid ) );
       
   552                 
       
   553         while ( plugin )               
   623             {
   554             {
   624             StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );
   555             StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );
   625             THsPublisherInfo info = plugin->PublisherInfo();
   556             
       
   557             const THsPublisherInfo& info( plugin->PublisherInfo() );            
   626             iReloadPlugins.Append( info );
   558             iReloadPlugins.Append( info );
   627             iFactory.DestroyPlugin( aUidList[ i ] );
   559             
       
   560             iFactory.DestroyPlugin( uid );
       
   561             
       
   562             flush = ETrue;
       
   563             
       
   564             // Get next plugin with same uid
       
   565             plugin = iFactory.PluginByUid( uid );                        
   628             }
   566             }
   629         }        
   567         }     
   630     __PRINTS( "CAiStateManager::NotifyReleasePlugins: return void" );    
   568     
   631     }
   569     if ( flush )
   632 
   570         {
       
   571         iFactory.FlushCommandBuffer();
       
   572         }
       
   573         
       
   574     __PRINTS( "CAiStateManager::NotifyReleasePlugins - done" );    
       
   575     }
       
   576     
   633 // End of file
   577 // End of file