idlefw/src/framework/aistatemanager.cpp
branchRCL_3
changeset 51 15e4dd19031c
parent 18 bd874ee5e5e2
child 59 a0713522ab97
equal deleted inserted replaced
19:502e5d91ad42 51:15e4dd19031c
    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 <aifwdefs.h>
    23 
    23 #include <AknWaitDialog.h> 
       
    24 #include <bautils.h>
       
    25 #include <ConeResLoader.h>
       
    26 #include <debug.h>
       
    27 
       
    28 #include "caicpscommandbuffer.h"
    24 #include "aipluginfactory.h"
    29 #include "aipluginfactory.h"
    25 
    30 
    26 #include "aistatemanager.h"
    31 #include "aistatemanager.h"
    27 
    32 
    28 #include "debug.h"
    33 #include <homescreen.rsg>
    29 
    34 
    30 // Constants
    35 _LIT( KResourceDrive, "Z:" );
    31 _LIT( KOnlineOffline, "online_offline" );
    36 _LIT( KResourceFile, "homescreen.rsc" );
       
    37 _LIT( KResourcePath, "\\resource\\apps\\" );
    32 
    38 
    33 // ======== LOCAL FUNCTIONS ========
    39 // ======== LOCAL FUNCTIONS ========
    34 // ----------------------------------------------------------------------------
    40 // ----------------------------------------------------------------------------
    35 // StartReason
    41 // StartReason
    36 // 
    42 // 
   112 // C++ default destructor.
   118 // C++ default destructor.
   113 // ----------------------------------------------------------------------------
   119 // ----------------------------------------------------------------------------
   114 //
   120 //
   115 CAiStateManager::~CAiStateManager()
   121 CAiStateManager::~CAiStateManager()
   116     {  
   122     {  
       
   123     if( iWaitDialog )
       
   124         {
       
   125         delete iWaitDialog;
       
   126         }
       
   127     delete iCommandBuffer;
       
   128 	iReloadPlugins.Close();
   117     }
   129     }
   118 
   130 
   119 // ----------------------------------------------------------------------------
   131 // ----------------------------------------------------------------------------
   120 // CAiStateManager::CAiStateManager()
   132 // CAiStateManager::CAiStateManager()
   121 // C++ default constructor.
   133 // C++ default constructor.
   131 // 2nd phase constructor
   143 // 2nd phase constructor
   132 // ----------------------------------------------------------------------------
   144 // ----------------------------------------------------------------------------
   133 //
   145 //
   134 void CAiStateManager::ConstructL()
   146 void CAiStateManager::ConstructL()
   135     {        
   147     {        
       
   148     iCommandBuffer = CAiCpsCommandBuffer::NewL();
       
   149     
       
   150     iFactory.SetCommandBuffer( iCommandBuffer );
   136     }
   151     }
   137 
   152 
   138 // ----------------------------------------------------------------------------
   153 // ----------------------------------------------------------------------------
   139 // CAiStateManager::NotifyStateChange()
   154 // CAiStateManager::NotifyStateChange()
   140 // 
   155 // 
   244     TInt retval( iFactory.CreatePlugin( aPublisherInfo ) );
   259     TInt retval( iFactory.CreatePlugin( aPublisherInfo ) );
   245     
   260     
   246     if ( retval == KErrNone )
   261     if ( retval == KErrNone )
   247         {
   262         {
   248         CHsContentPublisher* plugin( iFactory.PluginByInfo( aPublisherInfo ) );
   263         CHsContentPublisher* plugin( iFactory.PluginByInfo( aPublisherInfo ) );
   249 
   264         
   250         // Do startup state transition    
   265         if( plugin )
   251         StartPlugin( *plugin, StartReason( aReason ) );            
   266             {
       
   267             // Do startup state transition    
       
   268             StartPlugin( *plugin, StartReason( aReason ) );  
       
   269             }    
   252         }
   270         }
   253       
   271       
   254     __TIME_ENDMARK( "CAiStateManager::NotifyLoadPlugin, construction", time );
   272     __TIME_ENDMARK( "CAiStateManager::NotifyLoadPlugin, construction", time );
   255     
   273     
   256     return retval;
   274     return retval;
   284            
   302            
   285     __TIME_ENDMARK( "CAiStateManager::DestroyPlugin, done", time );
   303     __TIME_ENDMARK( "CAiStateManager::DestroyPlugin, done", time );
   286     }
   304     }
   287 
   305 
   288 // ----------------------------------------------------------------------------
   306 // ----------------------------------------------------------------------------
   289 // CAiStateManager::NotifyUpdatePlugins()
   307 // CAiStateManager::NotifyReloadPlugins()
   290 // 
   308 // 
   291 // ----------------------------------------------------------------------------
   309 // ----------------------------------------------------------------------------
   292 //
   310 //
   293 void CAiStateManager::NotifyUpdatePlugins()
   311 void CAiStateManager::NotifyReloadPlugins()
   294     {
   312     {
   295     __PRINTS( "CAiStateManager::NotifyUpdatePlugins" );
   313     __PRINTS( "CAiStateManager::NotifyReloadPlugins" );
   296     
   314 
   297     RArray< THsPublisherInfo > publishers;
   315     for ( TInt i = 0; i < iReloadPlugins.Count(); i++ )
   298         
   316         {
   299     // Get plugins which has upgrade available
   317         // Reload plugin
   300     TRAP_IGNORE( iFactory.ResolvePluginsToUpgradeL( publishers ) );
   318         NotifyLoadPlugin( iReloadPlugins[ i ], EAiFwSystemStartup );
   301     
   319         }
   302     for ( TInt i = 0; i < publishers.Count(); i++ )
   320     
   303         {        
   321     __PRINTS( "CAiStateManager::NotifyReloadPlugins, done" );
   304         THsPublisherInfo info( publishers[i] );
       
   305         
       
   306         // Update by destroy - load sequence 
       
   307         NotifyDestroyPlugin( info, EAiFwSystemShutdown );
       
   308         NotifyLoadPlugin( info, EAiFwSystemStartup );         
       
   309         }
       
   310     
       
   311     publishers.Reset();
       
   312     
       
   313     __PRINTS( "CAiStateManager::NotifyUpdatePlugins, done" );
       
   314     }
       
   315 
       
   316 // ----------------------------------------------------------------------------
       
   317 // CAiStateManager::OnlineStateInUse()
       
   318 // 
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 TBool CAiStateManager::OnlineStateInUse() const
       
   322     {
       
   323     __PRINTS( "CAiStateManager::OnlineStateInUse" );        
       
   324     
       
   325     RPointerArray< CHsContentPublisher >& plugins( iFactory.Publishers() );
       
   326     
       
   327     for( TInt i = 0; i < plugins.Count(); i++ )
       
   328         {
       
   329         CHsContentPublisher* plugin( plugins[i] );
       
   330         
       
   331         if ( plugin->HasMenuItem( KOnlineOffline() ) )
       
   332             {
       
   333             return ETrue;
       
   334             }
       
   335         }
       
   336     
       
   337     return EFalse;
       
   338     }
   322     }
   339 
   323 
   340 // ----------------------------------------------------------------------------
   324 // ----------------------------------------------------------------------------
   341 // CAiStateManager::EvaluateNextState()
   325 // CAiStateManager::EvaluateNextState()
   342 // 
   326 // 
   403                 __TIME( "CAiStateManager::ProcessStateChange, ESuspended",
   387                 __TIME( "CAiStateManager::ProcessStateChange, ESuspended",
   404                         
   388                         
   405                 plugin->Suspend( CHsContentPublisher::EBackground ) );
   389                 plugin->Suspend( CHsContentPublisher::EBackground ) );
   406                 }            
   390                 }            
   407             }
   391             }
       
   392         
       
   393         FlushCommandBuffer();
   408         }
   394         }
   409     else
   395     else
   410         {
   396         {
   411         __PRINTS( "CAiStateManager::ProcessStateChange, no state change" );
   397         __PRINTS( "CAiStateManager::ProcessStateChange, no state change" );
   412         }
   398         }
   437             {
   423             {
   438             plugin->Resume( CHsContentPublisher::EForeground );
   424             plugin->Resume( CHsContentPublisher::EForeground );
   439             }        
   425             }        
   440         } 
   426         } 
   441     
   427     
       
   428     FlushCommandBuffer();
       
   429     
   442     __TIME_ENDMARK( "CAiStateManager::ProcessGeneralThemeChange, done", time );
   430     __TIME_ENDMARK( "CAiStateManager::ProcessGeneralThemeChange, done", time );
   443     }
   431     }
   444 
   432 
   445 // ----------------------------------------------------------------------------
   433 // ----------------------------------------------------------------------------
   446 // CAiStateManager::ProcessBackupRestore()
   434 // CAiStateManager::ProcessBackupRestore()
   452     __PRINTS( "CAiStateManager::ProcessBackupRestore" );
   440     __PRINTS( "CAiStateManager::ProcessBackupRestore" );
   453     __TIME_MARK( time );
   441     __TIME_MARK( time );
   454     
   442     
   455     iHalt = aStart;
   443     iHalt = aStart;
   456 
   444 
       
   445     if ( aStart )
       
   446         {
       
   447         TRAP_IGNORE( StartWaitDialogL() );    
       
   448         }
       
   449     else
       
   450         {
       
   451         TRAP_IGNORE( StopWaitDialogL() );
       
   452         }
       
   453     
   457     RPointerArray< CHsContentPublisher >& plugins( iFactory.Publishers() );
   454     RPointerArray< CHsContentPublisher >& plugins( iFactory.Publishers() );
   458             
   455             
   459     for( TInt i = 0; i < plugins.Count(); i++ )
   456     for( TInt i = 0; i < plugins.Count(); i++ )
   460         {
   457         {
   461         CHsContentPublisher* plugin( plugins[i] );
   458         CHsContentPublisher* plugin( plugins[i] );
   471                 {
   468                 {
   472                 plugin->Resume( CHsContentPublisher::EForeground );
   469                 plugin->Resume( CHsContentPublisher::EForeground );
   473                 }
   470                 }
   474             }
   471             }
   475         }
   472         }
       
   473     
       
   474     FlushCommandBuffer();
   476             
   475             
   477     __TIME_ENDMARK( "CAiStateManager::ProcessBackupRestore, done", time );
   476     __TIME_ENDMARK( "CAiStateManager::ProcessBackupRestore, done", time );
   478     }
   477     }
   479 
   478 
   480 // ----------------------------------------------------------------------------
   479 // ----------------------------------------------------------------------------
   499         else
   498         else
   500             {
   499             {
   501             plugin->SetOffline();
   500             plugin->SetOffline();
   502             }
   501             }
   503         }               
   502         }               
       
   503     
       
   504     FlushCommandBuffer();
   504     }
   505     }
   505 
   506 
   506 // ----------------------------------------------------------------------------
   507 // ----------------------------------------------------------------------------
   507 // CAiStateManager::StartPlugin()
   508 // CAiStateManager::StartPlugin()
   508 // 
   509 // 
   542         __TIME( "CAiStateManager::StartPlugin, Set Offline",
   543         __TIME( "CAiStateManager::StartPlugin, Set Offline",
   543             
   544             
   544         aPlugin.SetOffline() );
   545         aPlugin.SetOffline() );
   545         }
   546         }
   546     
   547     
       
   548     FlushCommandBuffer();
       
   549     
   547     __PRINTS( "CAiStateManager::StartPlugin - done" );
   550     __PRINTS( "CAiStateManager::StartPlugin - done" );
   548     }
   551     }
   549 
   552 
   550 // ----------------------------------------------------------------------------
   553 // ----------------------------------------------------------------------------
   551 // CAiStateManager::StopPlugin()
   554 // CAiStateManager::StopPlugin()
   567         aPlugin.Suspend( CHsContentPublisher::EBackground ) );
   570         aPlugin.Suspend( CHsContentPublisher::EBackground ) );
   568         }
   571         }
   569     
   572     
   570     aPlugin.Stop( aReason );   
   573     aPlugin.Stop( aReason );   
   571     
   574     
       
   575     FlushCommandBuffer();
       
   576     
   572     __PRINTS( "CAiStateManager::StopPlugin - done" );
   577     __PRINTS( "CAiStateManager::StopPlugin - done" );
   573     }
   578     }
   574 
   579 
   575 // ----------------------------------------------------------------------------
   580 // ----------------------------------------------------------------------------
   576 // CAiStateManager::DestroyPlugins()
   581 // CAiStateManager::DestroyPlugins()
   590 
   595 
   591         // Do shutdown state transition
   596         // Do shutdown state transition
   592         StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );        
   597         StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );        
   593         }    
   598         }    
   594     
   599     
       
   600     FlushCommandBuffer();
       
   601     
   595     // Finally get rid of all plugins
   602     // Finally get rid of all plugins
   596     plugins.ResetAndDestroy();
   603     plugins.ResetAndDestroy();
   597     
   604     
   598     __TIME_ENDMARK( "CAiStateManager::DestroyPlugins, done", time );
   605     __TIME_ENDMARK( "CAiStateManager::DestroyPlugins, done", time );
   599     }
   606     }
   600 
   607 
       
   608 // ----------------------------------------------------------------------------
       
   609 // CAiStateManager::FlushCommandBuffer();()
       
   610 // 
       
   611 // ----------------------------------------------------------------------------
       
   612 //
       
   613 void CAiStateManager::FlushCommandBuffer()
       
   614     {
       
   615     __PRINTS( "CAiStateManager::FlushCommandBuffer, start" );    
       
   616         
       
   617     if ( iCommandBuffer )
       
   618         {
       
   619         __TIME( "CAiStateManager::FlushCommandBuffer, flush",
       
   620                 
       
   621         iCommandBuffer->Flush() );
       
   622         }
       
   623     
       
   624     __PRINTS( "CAiStateManager::FlushCommandBuffer - done" );
       
   625     }
       
   626 	
       
   627 // ----------------------------------------------------------------------------
       
   628 // CAiStateManager::NotifyReleasePlugins()
       
   629 // 
       
   630 // ----------------------------------------------------------------------------
       
   631 //
       
   632 void CAiStateManager::NotifyReleasePlugins( const RArray<TUid>& aUidList )
       
   633     {
       
   634     __PRINTS( "CAiStateManager::NotifyReleasePlugins" );    
       
   635 
       
   636     iReloadPlugins.Reset();
       
   637     
       
   638     for ( TInt i = 0; i < aUidList.Count(); i++ )
       
   639         {
       
   640         CHsContentPublisher* plugin = iFactory.PluginByUid( aUidList[ i ] );
       
   641         if ( plugin )
       
   642             {
       
   643             StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );
       
   644             THsPublisherInfo info = plugin->PublisherInfo();
       
   645             iReloadPlugins.Append( info );
       
   646             iFactory.DestroyPlugin( aUidList[ i ] );
       
   647             }
       
   648         }        
       
   649     __PRINTS( "CAiStateManager::NotifyReleasePlugins: return void" );    
       
   650     }
       
   651 
       
   652 // ----------------------------------------------------------------------------
       
   653 // CAiStateManager::StartWaitDialogL()
       
   654 // 
       
   655 // ----------------------------------------------------------------------------
       
   656 //
       
   657 void CAiStateManager::StartWaitDialogL()
       
   658     {
       
   659     RConeResourceLoader resourceLoader( *CCoeEnv::Static() );
       
   660     TFullName fileName( KResourceDrive );
       
   661     fileName.Append( KResourcePath );
       
   662     fileName.Append( KResourceFile );
       
   663         
       
   664     // Get language of resource file.
       
   665     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), fileName );
       
   666 
       
   667     // Open resource file.
       
   668     resourceLoader.OpenL( fileName );
       
   669     
       
   670     if( iWaitDialog )
       
   671         {
       
   672         delete iWaitDialog;
       
   673         iWaitDialog = NULL;
       
   674         }
       
   675      
       
   676     // For the wait dialog
       
   677     iWaitDialog = new (ELeave) CAknWaitDialog(
       
   678         REINTERPRET_CAST( CEikDialog**, &iWaitDialog ) );
       
   679     iWaitDialog->SetCallback( this );
       
   680     iWaitDialog->ExecuteLD( R_HOMESCREEN_WAIT_DIALOG );
       
   681     resourceLoader.Close();
       
   682     }
       
   683 
       
   684 // ----------------------------------------------------------------------------
       
   685 // CAiStateManager::StopWaitDialogL()
       
   686 // 
       
   687 // ----------------------------------------------------------------------------
       
   688 //
       
   689 void CAiStateManager::StopWaitDialogL()
       
   690     {
       
   691     if( iWaitDialog )
       
   692         {
       
   693         iWaitDialog->ProcessFinishedL(); 
       
   694         }
       
   695     }
       
   696 
       
   697 // ----------------------------------------------------------------------------
       
   698 // CAiStateManager::DialogDismissedL()
       
   699 // 
       
   700 // ----------------------------------------------------------------------------
       
   701 //
       
   702 void CAiStateManager::DialogDismissedL(TInt /*aButtonId*/)
       
   703     {
       
   704     // No implementation required.
       
   705     }
       
   706 
   601 // End of file
   707 // End of file