idlefw/src/framework/aipluginfactory.cpp
branchRCL_3
changeset 74 edd621764147
parent 64 b276298d5729
equal deleted inserted replaced
64:b276298d5729 74:edd621764147
    19 #include <ecom/ecom.h>
    19 #include <ecom/ecom.h>
    20 #include <ecom/implementationinformation.h>
    20 #include <ecom/implementationinformation.h>
    21 
    21 
    22 // User includes
    22 // User includes
    23 #include <aisystemuids.hrh>
    23 #include <aisystemuids.hrh>
       
    24 #include <aifwpublisherinfo.h>
    24 #include <hscontentpublisher.h>
    25 #include <hscontentpublisher.h>
    25 #include <hspublisherinfo.h>
    26 #include <hspublisherinfo.h>
    26 #include <aicontentobserver.h>
    27 #include <aicontentobserver.h>
    27 #include <aiuicontroller.h>
    28 #include <aiuicontroller.h>
    28 #include "caicpscommandbuffer.h"
    29 #include "caicpscommandbuffer.h"
    29 #include "aiuicontrollermanager.h"
    30 #include "aiuicontrollermanager.h"
       
    31 #include "aistatemanager.h"
    30 #include "aipluginfactory.h"
    32 #include "aipluginfactory.h"
    31 #include "debug.h"
    33 #include "debug.h"
    32 
    34 
    33 // Constants
    35 // Constants
    34 const TUid KDeviceStatusPluginUid = 
    36 const TUid KDeviceStatusPluginUid = 
    35     { AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_DEVSTAPLUGIN };
    37     { AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_DEVSTAPLUGIN };
    36 
    38 
    37 const TUid KProfilePluginUid =
    39 const TUid KProfilePluginUid =
    38     { AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_PROFILEPLUGIN };
    40     { AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_PROFILEPLUGIN };
    39 
    41 
       
    42 const TUid KSapiPluginImplUid = { 0x20019594 };                
       
    43 const TUid KWrtPluginImplUid = { 0x200286DD };                          
       
    44 
    40 _LIT( KDeviceStatusPluginName, "DeviceStatus" );
    45 _LIT( KDeviceStatusPluginName, "DeviceStatus" );
    41 _LIT( KProfilePluginName, "Profile" );
    46 _LIT( KProfilePluginName, "Profile" );
    42 
    47 
       
    48 const TInt KQueueStartInterval( 500000 );
    43 
    49 
    44 // ======== LOCAL FUNCTIONS ========
    50 // ======== LOCAL FUNCTIONS ========
    45 // ----------------------------------------------------------------------------
    51 // ----------------------------------------------------------------------------
    46 // IsRecyclable()
    52 // IsRecyclable()
    47 //
    53 //
    59     
    65     
    60     return EFalse;
    66     return EFalse;
    61     }
    67     }
    62 
    68 
    63 // ----------------------------------------------------------------------------
    69 // ----------------------------------------------------------------------------
       
    70 // IsSapiOrWrt()
       
    71 //
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 TBool IsSapiOrWrt( const THsPublisherInfo& aInfo )
       
    75     {
       
    76     return ( aInfo.Uid() == KSapiPluginImplUid || 
       
    77              aInfo.Uid() == KWrtPluginImplUid );             
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------------------------
    64 // CleanupResetAndDestroy()
    81 // CleanupResetAndDestroy()
    65 //
    82 //
    66 // ----------------------------------------------------------------------------
    83 // ----------------------------------------------------------------------------
    67 //
    84 //
    68 template< class T >
    85 template< class T >
    89 // CAiPluginFactory::CAiPluginFactory()
   106 // CAiPluginFactory::CAiPluginFactory()
    90 //
   107 //
    91 // ----------------------------------------------------------------------------
   108 // ----------------------------------------------------------------------------
    92 //
   109 //
    93 CAiPluginFactory::CAiPluginFactory( CAiUiControllerManager& aManager )
   110 CAiPluginFactory::CAiPluginFactory( CAiUiControllerManager& aManager )
    94     : iUiControllerManager( aManager )
   111     : CTimer( CActive::EPriorityUserInput - 1 ), 
       
   112       iUiControllerManager( aManager ), iAllowFlush( ETrue )
    95     {
   113     {
    96     }
   114     }
    97 
   115 
    98 // ----------------------------------------------------------------------------
   116 // ----------------------------------------------------------------------------
    99 // CAiPluginFactory::~CAiPluginFactory()
   117 // CAiPluginFactory::~CAiPluginFactory()
   100 //
   118 //
   101 // ----------------------------------------------------------------------------
   119 // ----------------------------------------------------------------------------
   102 //
   120 //
   103 CAiPluginFactory::~CAiPluginFactory()
   121 CAiPluginFactory::~CAiPluginFactory()
   104     {
   122     {
       
   123     Cancel();
       
   124     
       
   125     delete iStarter;
       
   126     
       
   127     delete iCommandBuffer;
       
   128     
       
   129     iLoadQueue.Reset();
       
   130     iDestroyQueue.Reset();
       
   131     
   105     // All publishers should be already deleted from CAiFw::HandleUiShutdown       
   132     // All publishers should be already deleted from CAiFw::HandleUiShutdown       
   106     iPublishers.ResetAndDestroy();
   133     iPublishers.ResetAndDestroy();
   107     
   134     
   108     iEComPlugins.ResetAndDestroy();        
   135     iEComPlugins.ResetAndDestroy();        
   109     
   136     
   115 //
   142 //
   116 // ----------------------------------------------------------------------------
   143 // ----------------------------------------------------------------------------
   117 //
   144 //
   118 CAiPluginFactory* CAiPluginFactory::NewL( CAiUiControllerManager& aManager )
   145 CAiPluginFactory* CAiPluginFactory::NewL( CAiUiControllerManager& aManager )
   119     {
   146     {
   120     CAiPluginFactory* self = 
   147     return new ( ELeave ) CAiPluginFactory( aManager ); 
   121         new ( ELeave ) CAiPluginFactory( aManager );
       
   122                                                                       
       
   123     CleanupStack::PushL( self );
       
   124     self->ConstructL();
       
   125     CleanupStack::Pop( self );
       
   126     return self;
       
   127     }
   148     }
   128 
   149 
   129 // ----------------------------------------------------------------------------
   150 // ----------------------------------------------------------------------------
   130 // CAiPluginFactory::ConstructL()
   151 // CAiPluginFactory::ConstructL()
   131 //
   152 //
   132 // ----------------------------------------------------------------------------
   153 // ----------------------------------------------------------------------------
   133 //
   154 //
   134 void CAiPluginFactory::ConstructL()
   155 void CAiPluginFactory::ConstructL()
   135     {               
   156     {             
       
   157     ListImplementationsL();
       
   158     
       
   159     iCommandBuffer = CAiCpsCommandBuffer::NewL();
       
   160     
       
   161     // Ensure interface is available
       
   162     iCommandBuffer->GetCPSInterfaceL();
       
   163     
       
   164     CActiveScheduler::Add( this );
       
   165     
       
   166     CTimer::ConstructL();
       
   167     
       
   168     iStarter = CPeriodic::NewL( CActive::EPriorityIdle );
       
   169     }
       
   170 
       
   171 // ----------------------------------------------------------------------------
       
   172 // CAiPluginFactory::ListImplementationsL()
       
   173 //
       
   174 // ----------------------------------------------------------------------------
       
   175 //
       
   176 void CAiPluginFactory::ListImplementationsL()
       
   177     {
       
   178     iEComPlugins.ResetAndDestroy();
       
   179     
   136     REComSession::ListImplementationsL( 
   180     REComSession::ListImplementationsL( 
   137         KInterfaceUidHsContentPlugin, iEComPlugins );    
   181         KInterfaceUidHsContentPlugin, iEComPlugins );
   138     }
   182     }
   139         
   183 
   140 // ----------------------------------------------------------------------------
   184 // ----------------------------------------------------------------------------
   141 // CAiPluginFactory::CreatePluginL()
   185 // CAiPluginFactory::LoadPlugin()
   142 //
   186 //
   143 // ----------------------------------------------------------------------------
   187 // ----------------------------------------------------------------------------
   144 //
   188 //
   145 TInt CAiPluginFactory::CreatePlugin( 
   189 void CAiPluginFactory::LoadPlugin( const TAiFwPublisherInfo& aInfo )
   146     const THsPublisherInfo& aPublisherInfo )
   190     {    
   147     {
   191     const THsPublisherInfo& info( aInfo.Info() );
   148     __PRINTS( "*** CAiPluginFactory::CreatePlugin: Start ***" );
   192     
   149 
   193     for ( TInt i = 0; i < iDestroyQueue.Count(); i++ )
   150     if ( IsRecyclable( aPublisherInfo ) )
   194         {
   151         {
   195         if ( iDestroyQueue[i] == info )
   152         CHsContentPublisher* plugin( PluginByUid( aPublisherInfo.Uid() ) );
   196             {
       
   197             iDestroyQueue.Remove( i );
       
   198             break;
       
   199             }
       
   200         }
       
   201            
       
   202     if ( IsSapiOrWrt( info ) || IsRecyclable( info ) || !PluginByInfo( info ) )
       
   203         {
       
   204         TBool append( ETrue );
       
   205         
       
   206         for ( TInt i = 0; i < iLoadQueue.Count(); i++ )       
       
   207             {
       
   208             if ( iLoadQueue[i] == info )
       
   209                 {                
       
   210                 append = EFalse;
       
   211                 break;
       
   212                 }
       
   213             }    
       
   214                 
       
   215         // Plugin is not in load queue and is not currently loaded
       
   216         if( append )
       
   217             {                               
       
   218             iLoadQueue.Append( aInfo );
       
   219                         
       
   220             HandleQueueChanged();
       
   221             }    
       
   222         }    
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CAiPluginFactory::DestroyPlugin()
       
   227 //
       
   228 // ----------------------------------------------------------------------------
       
   229 //
       
   230 void CAiPluginFactory::DestroyPlugin( const TAiFwPublisherInfo& aInfo )
       
   231     {
       
   232     const THsPublisherInfo& info( aInfo.Info() );
       
   233            
       
   234     for ( TInt i = 0; i < iLoadQueue.Count(); i++ )
       
   235         {
       
   236         if ( iLoadQueue[i] == info )
       
   237             {
       
   238             iLoadQueue[i].Callback( KErrCancel );
       
   239             
       
   240             iLoadQueue.Remove( i );                       
       
   241             break;
       
   242             }
       
   243         }
       
   244         
       
   245     if ( PluginByInfo( info ) )
       
   246         {
       
   247         TBool append( ETrue );
       
   248         
       
   249         for ( TInt i = 0; i < iDestroyQueue.Count(); i++ )
       
   250             {
       
   251             if ( iDestroyQueue[i] == info )
       
   252                 {
       
   253                 append = EFalse;
       
   254                 break;
       
   255                 }        
       
   256             }
       
   257         
       
   258         // Plugin is not in destroy queue and is currently loaded
       
   259         if ( append )
       
   260             {                       
       
   261             iDestroyQueue.Append( aInfo );
       
   262             
       
   263             HandleQueueChanged();
       
   264             }    
       
   265         } 
       
   266     }
       
   267 
       
   268 // ----------------------------------------------------------------------------
       
   269 // CAiPluginFactory::HandleQueueChanged()
       
   270 // 
       
   271 // ----------------------------------------------------------------------------
       
   272 //
       
   273 void CAiPluginFactory::HandleQueueChanged()
       
   274     {
       
   275     __PRINTS( "CAiPluginFactory::HandleQueueChanged" );
       
   276 
       
   277     if ( iLoadQueue.Count() == 0 && iDestroyQueue.Count() == 0 )
       
   278         {
       
   279         __PRINTS( "CAiPluginFactory::HandleQueueChanged - done, queues empty" );
       
   280         
       
   281         return;
       
   282         }
       
   283             
       
   284     Cancel();
       
   285     iStarter->Cancel();
       
   286 
       
   287     __PRINTS( "CAiPluginFactory::HandleQueueChanged, iStarter->Start()" );
       
   288 
       
   289     if ( iLoadQueue.Count() == 1 && iDestroyQueue.Count() == 0 &&
       
   290         iLoadQueue[0].Reason() == EAiFwPluginStartup )
       
   291         {
       
   292         ProcessQueue( this );
       
   293         }
       
   294     else
       
   295         {
       
   296         iStarter->Start( KQueueStartInterval, 0, 
       
   297             TCallBack( ProcessQueue, this ) );        
       
   298         }               
       
   299 
       
   300     __PRINTS( "CAiPluginFactory::HandleQueueChanged - done" );
       
   301     }
       
   302 
       
   303 // ----------------------------------------------------------------------------
       
   304 // CAiPluginFactory::DoCreatePlugin()
       
   305 //
       
   306 // ----------------------------------------------------------------------------
       
   307 //
       
   308 TInt CAiPluginFactory::DoCreatePlugin( 
       
   309     const TAiFwPublisherInfo& aPublisherInfo )
       
   310     {
       
   311     __PRINTS( "*** CAiPluginFactory::DoCreatePlugin: Start ***" );
       
   312 
       
   313     const THsPublisherInfo& info( aPublisherInfo.Info() );
       
   314     
       
   315     if ( IsRecyclable( info ) )
       
   316         {
       
   317         CHsContentPublisher* plugin( PluginByUid( info.Uid() ) );
   153 
   318 
   154         if ( plugin )
   319         if ( plugin )
   155             {
   320             {
   156             if ( aPublisherInfo.Namespace() == KNullDesC8 )
   321             if ( info.Namespace() == KNullDesC8 )
   157                 {
   322                 {
   158                 // No namespace available
   323                 // No namespace available
   159                 __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
   324                 __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
   160                                Failed to Load Plug-in: KErrNotSupported ***" );
   325                                Failed to Load Plug-in: KErrNotSupported ***" );
   161                 return KErrNotSupported;
   326                 return KErrNotSupported;
   162                 }
   327                 }
   163 
   328 
   164             // Plugin already exists, update its namespace
   329             // Plugin already exists, update its namespace
   165             THsPublisherInfo& info( 
   330             THsPublisherInfo& pubinfo( 
   166                 const_cast< THsPublisherInfo& >( plugin->PublisherInfo() ) );
   331                 const_cast< THsPublisherInfo& >( plugin->PublisherInfo() ) );
   167 
   332 
   168             info.iNamespace.Copy( aPublisherInfo.Namespace() );
   333             pubinfo.iNamespace.Copy( info.Namespace() );
   169 
   334 
   170             __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
   335             __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
   171                            Plugin recycled ***" );
   336                            Plugin recycled ***" );
   172 
   337 
   173             return KErrNone;
   338             return KErrNone;
   178 
   343 
   179     for( TInt i = 0; i < iEComPlugins.Count(); i++ )
   344     for( TInt i = 0; i < iEComPlugins.Count(); i++ )
   180         {
   345         {
   181         CImplementationInformation* information( iEComPlugins[i] );
   346         CImplementationInformation* information( iEComPlugins[i] );
   182 
   347 
   183         if( information->ImplementationUid().iUid == aPublisherInfo.Uid().iUid )
   348         if( information->ImplementationUid() == info.Uid() )
   184             {
   349             {
   185             implFound = ETrue;
   350             implFound = ETrue;
   186             break;
   351             break;
   187             }
   352             }
   188         }
   353         }
   189     
   354     
   190     if( aPublisherInfo.Namespace() == KNullDesC8 || !implFound )
   355     if( info.Namespace() == KNullDesC8 || !implFound )
   191         {
   356         {
   192         // No namespace available or no ecom implementation available
   357         // No namespace available or no ecom implementation available
   193         __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
   358         __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
   194                        Failed to Load Plug-in: KErrNotSupported ***" );
   359                        Failed to Load Plug-in: KErrNotSupported ***" );
   195         
   360         
   196         return KErrNotSupported;
   361         return KErrNotSupported;
   197         }
   362         }
   198            
   363            
   199     CHsContentPublisher* plugin( PluginByInfo( aPublisherInfo ) );
   364     CHsContentPublisher* plugin( PluginByInfo( info ) );
   200 
   365 
   201     if( plugin )
   366     if( plugin )
   202         {
   367         {
   203         __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
   368         __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
   204                        Failed to Load Plug-in: KErrAlreadyExists ***" );
   369                        No need to Load Plug-in: KErrAlreadyExists ***" );
   205         
   370         
   206         return KErrAlreadyExists;
   371         return KErrAlreadyExists;
   207         }
   372         }
   208 
   373 
   209     TInt err( KErrNone );
   374     TInt err( KErrNone );
   210 
   375 
   211     TRAP( err, CreatePluginL( aPublisherInfo ) );
   376     TRAP( err, DoCreatePluginL( aPublisherInfo ) );
   212     
   377     
   213     __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done - Load Plug-in ***" );
   378     __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done - Load Plug-in ***" );
   214 
   379 
   215     return err;
   380     return err;
   216     }
   381     }
   217 
   382 
   218 // ----------------------------------------------------------------------------
   383 // ----------------------------------------------------------------------------
   219 // CAiPluginFactory::DestroyPlugin()
   384 // CAiPluginFactory::DoDestroyPlugin()
   220 //
   385 //
   221 // ----------------------------------------------------------------------------
   386 // ----------------------------------------------------------------------------
   222 //
   387 //
   223 void CAiPluginFactory::DestroyPlugin( const THsPublisherInfo& aPublisherInfo )                             
   388 void CAiPluginFactory::DoDestroyPlugin( 
   224     {
   389     const TAiFwPublisherInfo& aPublisherInfo )                             
   225     __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Start ***" );
   390     {
   226     
   391     __PRINTS( "*** CAiPluginFactory::DoDestroyPlugin: Start ***" );
   227     if ( IsRecyclable( aPublisherInfo ) )
   392     
       
   393     const THsPublisherInfo& info( aPublisherInfo.Info() );
       
   394       
       
   395     if ( IsRecyclable( info ) )
   228         {
   396         {
   229         // Don't destroy recyclable plugin
   397         // Don't destroy recyclable plugin
   230         __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Done - Keeping recyclable Plug-in ***" );
   398         __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Done - Keeping recyclable Plug-in ***" );
   231         
   399         
   232         return;
   400         return;
   233         }
   401         }
   234         
   402    
   235     CHsContentPublisher* plugin( PluginByInfo( aPublisherInfo ) );
   403     if ( IsSapiOrWrt( info ) )
       
   404         {
       
   405         if ( aPublisherInfo.Reason() == EAiFwPageShutdown )
       
   406             {
       
   407             // Don't destroy sapi or wrt plugin when page is changed        
       
   408             __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Done - Keeping SAPI/WRT plugin ***" );
       
   409             
       
   410             return;
       
   411             }
       
   412         }
       
   413                
       
   414     CHsContentPublisher* plugin( PluginByInfo( info ) );
   236     
   415     
   237     if ( plugin )
   416     if ( plugin )
   238         {
   417         {
   239         iPublishers.Remove( iPublishers.Find( plugin ) );
   418         iPublishers.Remove( iPublishers.Find( plugin ) );
   240         
   419         
   254     {
   433     {
   255     __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Start ***" );
   434     __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Start ***" );
   256     
   435     
   257     CHsContentPublisher* plugin( PluginByUid( aUid ) );
   436     CHsContentPublisher* plugin( PluginByUid( aUid ) );
   258     
   437     
   259     while ( plugin )
   438     if ( plugin )
   260         {
   439         {                
   261         iPublishers.Remove( iPublishers.Find( plugin ) );
   440         iPublishers.Remove( iPublishers.Find( plugin ) );
   262         
   441         
   263         __PRINT( __DBG_FORMAT( 
   442         __PRINT( __DBG_FORMAT( 
   264             "CAiPluginFactory::DestroyPlugin: name: %S" ), &plugin->PublisherInfo().Name() ); 
   443             "CAiPluginFactory::DestroyPlugin: name: %S" ), 
       
   444                 &plugin->PublisherInfo().Name() ); 
   265 
   445 
   266         delete plugin;
   446         delete plugin;
   267         plugin = NULL;            
   447         plugin = NULL;                
   268         }
   448         }
   269     
   449     
   270     __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Done ***" );
   450     __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Done ***" );
   271     }
   451     }
   272 
   452 
   273 // ----------------------------------------------------------------------------
   453 // ----------------------------------------------------------------------------
   274 // CAiPluginFactory::CreatePluginL()
   454 // CAiPluginFactory::DestroyAllPlugins()
   275 //
   455 //
   276 // ----------------------------------------------------------------------------
   456 // ----------------------------------------------------------------------------
   277 //
   457 //
   278 void CAiPluginFactory::CreatePluginL(
   458 void CAiPluginFactory::DestroyAllPlugins()
   279     const THsPublisherInfo& aPublisherInfo )
       
   280     {       
   459     {       
       
   460     Cancel();
       
   461     iStarter->Cancel();
       
   462     
       
   463     iLoadQueue.Reset();
       
   464     iDestroyQueue.Reset();
       
   465            
       
   466     for ( TInt i = 0; i < iPublishers.Count(); i++ )
       
   467         {
       
   468         CHsContentPublisher* plugin( iPublishers[i] );
       
   469     
       
   470         // Do shutdown state transition
       
   471         iStateManager->StopPlugin( *plugin, EAiFwSystemShutdown );        
       
   472         }    
       
   473     
       
   474     FlushCommandBuffer();
       
   475     
       
   476     // Finally get rid of all plugins
       
   477     iPublishers.ResetAndDestroy();
       
   478     }
       
   479 
       
   480 // ----------------------------------------------------------------------------
       
   481 // CAiPluginFactory::DoCreatePluginL()
       
   482 //
       
   483 // ----------------------------------------------------------------------------
       
   484 //
       
   485 void CAiPluginFactory::DoCreatePluginL(
       
   486     const TAiFwPublisherInfo& aPublisherInfo )
       
   487     {       
       
   488     const THsPublisherInfo& info( aPublisherInfo.Info() );
       
   489     
   281     __PRINT( __DBG_FORMAT( "\t[I]\t Loading plug-in uid=%x name=%S"), 
   490     __PRINT( __DBG_FORMAT( "\t[I]\t Loading plug-in uid=%x name=%S"), 
   282     aPublisherInfo.Uid(), &(aPublisherInfo.Name() ) );
   491     info.Uid(), &(info.Name() ) );
   283 
   492 
   284     iPublishers.ReserveL( iPublishers.Count() + 1 );
   493     iPublishers.ReserveL( iPublishers.Count() + 1 );
   285     
   494     
   286     CHsContentPublisher* plugin( NULL );
   495     CHsContentPublisher* plugin( NULL );
   287     
   496     
   288     __TIME( "CAiPluginFactory::CreatePluginL Create plug-in:",                                  
   497     __TIME( "CAiPluginFactory::CreatePluginL Create plug-in:",                                  
   289     plugin = CHsContentPublisher::NewL( aPublisherInfo ) );            
   498     plugin = CHsContentPublisher::NewL( info ) );            
   290     
   499     
   291     CleanupStack::PushL( plugin );
   500     CleanupStack::PushL( plugin );
   292     
   501     
   293     // Ensure interface is available
   502     if ( IsSapiOrWrt( info ) )
   294     iCommandBuffer->GetCPSInterfaceL();
   503         {
   295     
   504         plugin->SetProperty( CHsContentPublisher::ECpsCmdBuffer, 
   296     plugin->SetProperty( CHsContentPublisher::ECpsCmdBuffer, 
   505             static_cast< MAiCpsCommandBuffer* >( iCommandBuffer ) );    
   297         static_cast< MAiCpsCommandBuffer* >( iCommandBuffer ) );
   506         }
   298     
   507     
   299     __TIME( "FW: Subscribe content observers",    
   508     __TIME( "FW: Subscribe content observers",    
   300     SubscribeContentObserversL( *plugin, aPublisherInfo ) );             
   509     SubscribePluginL( *plugin, info ) );             
   301                                                       
   510                                                       
   302     __TIME( "FW: Configure Plugin",
   511     __TIME( "FW: Configure Plugin",
   303     ConfigurePluginL( *plugin, aPublisherInfo ) );
   512     ConfigurePluginL( *plugin, info ) );
   304     
   513     
   305     // Take plugin's ownership
   514     // Take plugin's ownership
   306     iPublishers.Append( plugin );
   515     iPublishers.Append( plugin );
   307     CleanupStack::Pop( plugin );
   516     CleanupStack::Pop( plugin );
   308     }
   517     }
   309 
   518 
   310 // ----------------------------------------------------------------------------
   519 // ----------------------------------------------------------------------------
   311 // CAiPluginFactory::SubscribeContentObserversL()
   520 // CAiPluginFactory::SubscribePluginL()
   312 //
   521 //
   313 // ----------------------------------------------------------------------------
   522 // ----------------------------------------------------------------------------
   314 //
   523 //
   315 void CAiPluginFactory::SubscribeContentObserversL(
   524 void CAiPluginFactory::SubscribePluginL(
   316     CHsContentPublisher& aContentPublisher,        
   525     CHsContentPublisher& aContentPublisher,        
   317     const THsPublisherInfo& aPublisherInfo )    
   526     const THsPublisherInfo& aPublisherInfo )    
   318     {
   527     {
   319     RPointerArray< CAiUiController >& 
   528     RPointerArray< CAiUiController >& 
   320         controllers( iUiControllerManager.UiControllers() );
   529         controllers( iUiControllerManager.UiControllers() );
   430     {
   639     {
   431     return iPublishers;
   640     return iPublishers;
   432     }
   641     }
   433 
   642 
   434 // ----------------------------------------------------------------------------
   643 // ----------------------------------------------------------------------------
   435 // CAiPluginFactory::SetCommandBuffer()
   644 // CAiPluginFactory::SetStateManager()
   436 //
   645 //
   437 // ----------------------------------------------------------------------------
   646 // ----------------------------------------------------------------------------
   438 //
   647 //
   439 void CAiPluginFactory::SetCommandBuffer( CAiCpsCommandBuffer* aCommandBuffer )
   648 void CAiPluginFactory::SetStateManager( CAiStateManager* aStateManager )
   440     {
   649     {
   441     iCommandBuffer = aCommandBuffer;
   650     iStateManager = aStateManager;
       
   651     }
       
   652 
       
   653 // ----------------------------------------------------------------------------
       
   654 // CAiPluginFactory::FlushCommandBuffer()
       
   655 //
       
   656 // ----------------------------------------------------------------------------
       
   657 //
       
   658 void CAiPluginFactory::FlushCommandBuffer()
       
   659     {
       
   660     __PRINTS( "CAiPluginFactory::FlushCommandBuffer" );
       
   661     
       
   662     if ( iCommandBuffer && iAllowFlush && !IsActive() )
       
   663         {
       
   664         iCommandBuffer->Flush();
       
   665         }
       
   666     
       
   667     __PRINTS( "CAiPluginFactory::FlushCommandBuffer - done" );
       
   668     }
       
   669 
       
   670 // ----------------------------------------------------------------------------
       
   671 // CAiPluginFactory::ProcessQueue()
       
   672 //
       
   673 // ----------------------------------------------------------------------------
       
   674 //
       
   675 /* static */ TInt CAiPluginFactory::ProcessQueue( TAny* aAny )
       
   676     {
       
   677     CAiPluginFactory* self = static_cast< CAiPluginFactory* >( aAny );
       
   678     
       
   679     self->iStarter->Cancel();
       
   680     
       
   681     if ( !self->IsActive() )
       
   682         {
       
   683         self->After( 0 );
       
   684         }
       
   685     
       
   686     return KErrNone;
       
   687     }
       
   688 
       
   689 // ----------------------------------------------------------------------------
       
   690 // CAiPluginFactory::RunL()
       
   691 //
       
   692 // ----------------------------------------------------------------------------
       
   693 //
       
   694 void CAiPluginFactory::RunL()
       
   695     {
       
   696     __PRINTS( "CAiPluginFactory::RunL" );
       
   697     
       
   698     if ( iStarter->IsActive() )
       
   699         {
       
   700         __PRINTS( "CAiPluginFactory::RunL - done, iStarter->IsActive()" );
       
   701         
       
   702         return;
       
   703         }
       
   704     
       
   705     iAllowFlush = EFalse;
       
   706            
       
   707     if ( iDestroyQueue.Count() > 0 )
       
   708         {        
       
   709         TAiFwPublisherInfo info( iDestroyQueue[ 0 ] );         
       
   710         iDestroyQueue.Remove( 0 );
       
   711                
       
   712         // Resolve plugin
       
   713         CHsContentPublisher* plugin( PluginByInfo( info.Info() ) ); 
       
   714 
       
   715         if ( plugin )
       
   716             {                  
       
   717             // Do shutdown state transition
       
   718             iStateManager->StopPlugin( *plugin, info.Reason() );
       
   719             
       
   720             // Destroy plugin
       
   721             DoDestroyPlugin( info );                        
       
   722             }        
       
   723         }
       
   724     else if ( iLoadQueue.Count() > 0 )
       
   725         {
       
   726         TAiFwPublisherInfo info( iLoadQueue[ 0 ] );            
       
   727         iLoadQueue.Remove( 0 );
       
   728     
       
   729         // Create plugin
       
   730         TInt retval( DoCreatePlugin( info ) );
       
   731         
       
   732         if ( retval == KErrNone || retval == KErrAlreadyExists )
       
   733             {
       
   734             CHsContentPublisher* plugin( PluginByInfo( info.Info() ) );
       
   735             
       
   736             if( plugin )
       
   737                 {
       
   738                 // Do startup state transition    
       
   739                 iStateManager->StartPlugin( *plugin, info.Reason() );                
       
   740                 }    
       
   741             else
       
   742                 {
       
   743                 retval = KErrNotFound;
       
   744                 }            
       
   745             }
       
   746         
       
   747         info.Callback( retval );
       
   748         }
       
   749 
       
   750     iAllowFlush = ETrue;
       
   751     
       
   752     After( 0 );
       
   753     
       
   754     if ( iLoadQueue.Count() == 0 && iDestroyQueue.Count() == 0 )
       
   755         {
       
   756         __PRINTS( "CAiPluginFactory::RunL - queues now empty" );
       
   757         
       
   758         Cancel();
       
   759         
       
   760         FlushCommandBuffer();                             
       
   761         }
       
   762     
       
   763     __PRINTS( "CAiPluginFactory::RunL - done" );    
       
   764     }
       
   765 
       
   766 // ----------------------------------------------------------------------------
       
   767 // CAiPluginFactory::DoCancel()
       
   768 //
       
   769 // ----------------------------------------------------------------------------
       
   770 //
       
   771 void CAiPluginFactory::DoCancel()
       
   772     {
       
   773     __PRINTS( "CAiPluginFactory::DoCancel" );       
   442     }
   774     }
   443 
   775 
   444 // End of file
   776 // End of file