idlefw/src/framework/aistatemanager.cpp
branchRCL_3
changeset 17 cb506ec2d869
parent 15 a0713522ab97
child 19 edd621764147
equal deleted inserted replaced
13:c2817bb2a55c 17:cb506ec2d869
    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 
       
    28 #include "debug.h"
       
    29 
       
    30 // Constants
       
    31 _LIT( KOnlineOffline, "online_offline" );
       
    32 
    32 
    33 // ======== LOCAL FUNCTIONS ========
    33 // ======== LOCAL FUNCTIONS ========
    34 // ----------------------------------------------------------------------------
    34 // ----------------------------------------------------------------------------
    35 // StartReason
    35 // StartReason
    36 // 
    36 // 
   112 // C++ default destructor.
   112 // C++ default destructor.
   113 // ----------------------------------------------------------------------------
   113 // ----------------------------------------------------------------------------
   114 //
   114 //
   115 CAiStateManager::~CAiStateManager()
   115 CAiStateManager::~CAiStateManager()
   116     {  
   116     {  
       
   117     delete iCommandBuffer;
       
   118 	iReloadPlugins.Close();
   117     }
   119     }
   118 
   120 
   119 // ----------------------------------------------------------------------------
   121 // ----------------------------------------------------------------------------
   120 // CAiStateManager::CAiStateManager()
   122 // CAiStateManager::CAiStateManager()
   121 // C++ default constructor.
   123 // C++ default constructor.
   131 // 2nd phase constructor
   133 // 2nd phase constructor
   132 // ----------------------------------------------------------------------------
   134 // ----------------------------------------------------------------------------
   133 //
   135 //
   134 void CAiStateManager::ConstructL()
   136 void CAiStateManager::ConstructL()
   135     {        
   137     {        
       
   138     iCommandBuffer = CAiCpsCommandBuffer::NewL();
       
   139     
       
   140     iFactory.SetCommandBuffer( iCommandBuffer );
   136     }
   141     }
   137 
   142 
   138 // ----------------------------------------------------------------------------
   143 // ----------------------------------------------------------------------------
   139 // CAiStateManager::NotifyStateChange()
   144 // CAiStateManager::NotifyStateChange()
   140 // 
   145 // 
   244     TInt retval( iFactory.CreatePlugin( aPublisherInfo ) );
   249     TInt retval( iFactory.CreatePlugin( aPublisherInfo ) );
   245     
   250     
   246     if ( retval == KErrNone )
   251     if ( retval == KErrNone )
   247         {
   252         {
   248         CHsContentPublisher* plugin( iFactory.PluginByInfo( aPublisherInfo ) );
   253         CHsContentPublisher* plugin( iFactory.PluginByInfo( aPublisherInfo ) );
   249 
   254         
   250         // Do startup state transition    
   255         if( plugin )
   251         StartPlugin( *plugin, StartReason( aReason ) );            
   256             {
       
   257             // Do startup state transition    
       
   258             StartPlugin( *plugin, StartReason( aReason ) );  
       
   259             }    
   252         }
   260         }
   253       
   261       
   254     __TIME_ENDMARK( "CAiStateManager::NotifyLoadPlugin, construction", time );
   262     __TIME_ENDMARK( "CAiStateManager::NotifyLoadPlugin, construction", time );
   255     
   263     
   256     return retval;
   264     return retval;
   284            
   292            
   285     __TIME_ENDMARK( "CAiStateManager::DestroyPlugin, done", time );
   293     __TIME_ENDMARK( "CAiStateManager::DestroyPlugin, done", time );
   286     }
   294     }
   287 
   295 
   288 // ----------------------------------------------------------------------------
   296 // ----------------------------------------------------------------------------
   289 // CAiStateManager::NotifyUpdatePlugins()
   297 // CAiStateManager::NotifyReloadPlugins()
   290 // 
   298 // 
   291 // ----------------------------------------------------------------------------
   299 // ----------------------------------------------------------------------------
   292 //
   300 //
   293 void CAiStateManager::NotifyUpdatePlugins()
   301 void CAiStateManager::NotifyReloadPlugins()
   294     {
   302     {
   295     __PRINTS( "CAiStateManager::NotifyUpdatePlugins" );
   303     __PRINTS( "CAiStateManager::NotifyReloadPlugins" );
   296     
   304 
   297     RArray< THsPublisherInfo > publishers;
   305     for ( TInt i = 0; i < iReloadPlugins.Count(); i++ )
   298         
   306         {
   299     // Get plugins which has upgrade available
   307         // Reload plugin
   300     TRAP_IGNORE( iFactory.ResolvePluginsToUpgradeL( publishers ) );
   308         NotifyLoadPlugin( iReloadPlugins[ i ], EAiFwSystemStartup );
   301     
   309         }
   302     for ( TInt i = 0; i < publishers.Count(); i++ )
   310     
   303         {        
   311     __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     }
   312     }
   339 
   313 
   340 // ----------------------------------------------------------------------------
   314 // ----------------------------------------------------------------------------
   341 // CAiStateManager::EvaluateNextState()
   315 // CAiStateManager::EvaluateNextState()
   342 // 
   316 // 
   403                 __TIME( "CAiStateManager::ProcessStateChange, ESuspended",
   377                 __TIME( "CAiStateManager::ProcessStateChange, ESuspended",
   404                         
   378                         
   405                 plugin->Suspend( CHsContentPublisher::EBackground ) );
   379                 plugin->Suspend( CHsContentPublisher::EBackground ) );
   406                 }            
   380                 }            
   407             }
   381             }
       
   382         
       
   383         FlushCommandBuffer();
   408         }
   384         }
   409     else
   385     else
   410         {
   386         {
   411         __PRINTS( "CAiStateManager::ProcessStateChange, no state change" );
   387         __PRINTS( "CAiStateManager::ProcessStateChange, no state change" );
   412         }
   388         }
   436         if( !iHalt && iCurrentState == EAlive )
   412         if( !iHalt && iCurrentState == EAlive )
   437             {
   413             {
   438             plugin->Resume( CHsContentPublisher::EForeground );
   414             plugin->Resume( CHsContentPublisher::EForeground );
   439             }        
   415             }        
   440         } 
   416         } 
       
   417     
       
   418     FlushCommandBuffer();
   441     
   419     
   442     __TIME_ENDMARK( "CAiStateManager::ProcessGeneralThemeChange, done", time );
   420     __TIME_ENDMARK( "CAiStateManager::ProcessGeneralThemeChange, done", time );
   443     }
   421     }
   444 
   422 
   445 // ----------------------------------------------------------------------------
   423 // ----------------------------------------------------------------------------
   471                 {
   449                 {
   472                 plugin->Resume( CHsContentPublisher::EForeground );
   450                 plugin->Resume( CHsContentPublisher::EForeground );
   473                 }
   451                 }
   474             }
   452             }
   475         }
   453         }
       
   454     
       
   455     FlushCommandBuffer();
   476             
   456             
   477     __TIME_ENDMARK( "CAiStateManager::ProcessBackupRestore, done", time );
   457     __TIME_ENDMARK( "CAiStateManager::ProcessBackupRestore, done", time );
   478     }
   458     }
   479 
   459 
   480 // ----------------------------------------------------------------------------
   460 // ----------------------------------------------------------------------------
   499         else
   479         else
   500             {
   480             {
   501             plugin->SetOffline();
   481             plugin->SetOffline();
   502             }
   482             }
   503         }               
   483         }               
       
   484     
       
   485     FlushCommandBuffer();
   504     }
   486     }
   505 
   487 
   506 // ----------------------------------------------------------------------------
   488 // ----------------------------------------------------------------------------
   507 // CAiStateManager::StartPlugin()
   489 // CAiStateManager::StartPlugin()
   508 // 
   490 // 
   542         __TIME( "CAiStateManager::StartPlugin, Set Offline",
   524         __TIME( "CAiStateManager::StartPlugin, Set Offline",
   543             
   525             
   544         aPlugin.SetOffline() );
   526         aPlugin.SetOffline() );
   545         }
   527         }
   546     
   528     
       
   529     FlushCommandBuffer();
       
   530     
   547     __PRINTS( "CAiStateManager::StartPlugin - done" );
   531     __PRINTS( "CAiStateManager::StartPlugin - done" );
   548     }
   532     }
   549 
   533 
   550 // ----------------------------------------------------------------------------
   534 // ----------------------------------------------------------------------------
   551 // CAiStateManager::StopPlugin()
   535 // CAiStateManager::StopPlugin()
   567         aPlugin.Suspend( CHsContentPublisher::EBackground ) );
   551         aPlugin.Suspend( CHsContentPublisher::EBackground ) );
   568         }
   552         }
   569     
   553     
   570     aPlugin.Stop( aReason );   
   554     aPlugin.Stop( aReason );   
   571     
   555     
       
   556     FlushCommandBuffer();
       
   557     
   572     __PRINTS( "CAiStateManager::StopPlugin - done" );
   558     __PRINTS( "CAiStateManager::StopPlugin - done" );
   573     }
   559     }
   574 
   560 
   575 // ----------------------------------------------------------------------------
   561 // ----------------------------------------------------------------------------
   576 // CAiStateManager::DestroyPlugins()
   562 // CAiStateManager::DestroyPlugins()
   590 
   576 
   591         // Do shutdown state transition
   577         // Do shutdown state transition
   592         StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );        
   578         StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );        
   593         }    
   579         }    
   594     
   580     
       
   581     FlushCommandBuffer();
       
   582     
   595     // Finally get rid of all plugins
   583     // Finally get rid of all plugins
   596     plugins.ResetAndDestroy();
   584     plugins.ResetAndDestroy();
   597     
   585     
   598     __TIME_ENDMARK( "CAiStateManager::DestroyPlugins, done", time );
   586     __TIME_ENDMARK( "CAiStateManager::DestroyPlugins, done", time );
   599     }
   587     }
   600 
   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 // ----------------------------------------------------------------------------
       
   609 // CAiStateManager::NotifyReleasePlugins()
       
   610 // 
       
   611 // ----------------------------------------------------------------------------
       
   612 //
       
   613 void CAiStateManager::NotifyReleasePlugins( const RArray<TUid>& aUidList )
       
   614     {
       
   615     __PRINTS( "CAiStateManager::NotifyReleasePlugins" );    
       
   616 
       
   617     iReloadPlugins.Reset();
       
   618     
       
   619     for ( TInt i = 0; i < aUidList.Count(); i++ )
       
   620         {
       
   621         CHsContentPublisher* plugin = iFactory.PluginByUid( aUidList[ i ] );
       
   622         if ( plugin )
       
   623             {
       
   624             StopPlugin( *plugin, CHsContentPublisher::ESystemShutdown );
       
   625             THsPublisherInfo info = plugin->PublisherInfo();
       
   626             iReloadPlugins.Append( info );
       
   627             iFactory.DestroyPlugin( aUidList[ i ] );
       
   628             }
       
   629         }        
       
   630     __PRINTS( "CAiStateManager::NotifyReleasePlugins: return void" );    
       
   631     }
       
   632 
   601 // End of file
   633 // End of file