idlefw/tsrc/framework/ut_aifw/stub/src/aipluginfactory_stub.cpp
branchRCL_3
changeset 27 2c7f27287390
equal deleted inserted replaced
25:9e077f9a342c 27:2c7f27287390
       
     1 /*
       
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Content publisher factory stub
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <ecom/ecom.h>
       
    20 #include <ecom/implementationinformation.h>
       
    21 
       
    22 // User includes
       
    23 #include <aisystemuids.hrh>
       
    24 #include <aifwpublisherinfo.h>
       
    25 #include <hscontentpublisher.h>
       
    26 #include <hspublisherinfo.h>
       
    27 #include <aicontentobserver.h>
       
    28 #include <aiuicontroller.h>
       
    29 #include "caicpscommandbuffer.h"
       
    30 #include "aiuicontrollermanager_stub.h"
       
    31 #include "aistatemanager.h"
       
    32 #include "aipluginfactory_stub.h"
       
    33 #include "debug.h"
       
    34 
       
    35 // Constants
       
    36 const TUid KDeviceStatusPluginUid = 
       
    37     { AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_DEVSTAPLUGIN };
       
    38 
       
    39 const TUid KProfilePluginUid =
       
    40     { AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_PROFILEPLUGIN };
       
    41 
       
    42 const TUid KSapiPluginImplUid = { 0x20019594 };                
       
    43 const TUid KWrtPluginImplUid = { 0x200286DD };                          
       
    44 
       
    45 _LIT( KDeviceStatusPluginName, "DeviceStatus" );
       
    46 _LIT( KProfilePluginName, "Profile" );
       
    47 
       
    48 const TInt KQueueStartInterval( 500000 );
       
    49 
       
    50 // ======== LOCAL FUNCTIONS ========
       
    51 // ----------------------------------------------------------------------------
       
    52 // IsRecyclable()
       
    53 //
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 TBool IsRecyclable( const THsPublisherInfo& aInfo )
       
    57     {
       
    58     if ( ( aInfo.Name() == KProfilePluginName && 
       
    59         aInfo.Uid() == KProfilePluginUid ) ||
       
    60         ( aInfo.Name() == KDeviceStatusPluginName &&
       
    61         aInfo.Uid() == KDeviceStatusPluginUid ) )
       
    62         {
       
    63         return ETrue;
       
    64         }
       
    65     
       
    66     return EFalse;
       
    67     }
       
    68 
       
    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 // ----------------------------------------------------------------------------
       
    81 // CleanupResetAndDestroy()
       
    82 //
       
    83 // ----------------------------------------------------------------------------
       
    84 //
       
    85 template< class T >
       
    86 static void CleanupResetAndDestroy( TAny* aObj )
       
    87     {        
       
    88     static_cast< T* >( aObj )->ResetAndDestroy();    
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // CleanupResetAndDestroyPushL()
       
    93 //
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 template< class T >
       
    97 static void CleanupResetAndDestroyPushL( T& aArray )
       
    98     {
       
    99     CleanupStack::PushL( 
       
   100         TCleanupItem( &CleanupResetAndDestroy< T >, &aArray ) );
       
   101     }
       
   102     
       
   103 // ======== MEMBER FUNCTIONS ========    
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CAiPluginFactory::CAiPluginFactory()
       
   107 //
       
   108 // ----------------------------------------------------------------------------
       
   109 //
       
   110 CAiPluginFactory::CAiPluginFactory( CAiUiControllerManager& aManager )
       
   111     : CTimer( CActive::EPriorityUserInput - 1 ), 
       
   112       iUiControllerManager( aManager ), iAllowFlush( ETrue )
       
   113     {
       
   114     }
       
   115 
       
   116 // ----------------------------------------------------------------------------
       
   117 // CAiPluginFactory::~CAiPluginFactory()
       
   118 //
       
   119 // ----------------------------------------------------------------------------
       
   120 //
       
   121 CAiPluginFactory::~CAiPluginFactory()
       
   122     {
       
   123     Cancel();
       
   124     
       
   125     delete iStarter;
       
   126     
       
   127     delete iCommandBuffer;
       
   128     
       
   129     iLoadQueue.Reset();
       
   130     iDestroyQueue.Reset();
       
   131     
       
   132     // All publishers should be already deleted from CAiFw::HandleUiShutdown       
       
   133     iPublishers.ResetAndDestroy();
       
   134     
       
   135     iEComPlugins.ResetAndDestroy();        
       
   136     
       
   137     REComSession::FinalClose();
       
   138     }
       
   139     
       
   140 // ----------------------------------------------------------------------------
       
   141 // CAiPluginFactory::NewL()
       
   142 //
       
   143 // ----------------------------------------------------------------------------
       
   144 //
       
   145 CAiPluginFactory* CAiPluginFactory::NewL( CAiUiControllerManager& aManager )
       
   146     {
       
   147     return new ( ELeave ) CAiPluginFactory( aManager ); 
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // CAiPluginFactory::ConstructL()
       
   152 //
       
   153 // ----------------------------------------------------------------------------
       
   154 //
       
   155 void CAiPluginFactory::ConstructL()
       
   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     
       
   180     REComSession::ListImplementationsL( 
       
   181         KInterfaceUidHsContentPlugin, iEComPlugins );
       
   182     }
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // CAiPluginFactory::LoadPlugin()
       
   186 //
       
   187 // ----------------------------------------------------------------------------
       
   188 //
       
   189 void CAiPluginFactory::LoadPlugin( const TAiFwPublisherInfo& aInfo )
       
   190     {    
       
   191     const THsPublisherInfo& info( aInfo.Info() );
       
   192     
       
   193     for ( TInt i = 0; i < iDestroyQueue.Count(); i++ )
       
   194         {
       
   195         if ( iDestroyQueue[i] == info )
       
   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() ) );
       
   318 
       
   319         if ( plugin )
       
   320             {
       
   321             if ( info.Namespace() == KNullDesC8 )
       
   322                 {
       
   323                 // No namespace available
       
   324                 __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
       
   325                                Failed to Load Plug-in: KErrNotSupported ***" );
       
   326                 return KErrNotSupported;
       
   327                 }
       
   328 
       
   329             // Plugin already exists, update its namespace
       
   330             THsPublisherInfo& pubinfo( 
       
   331                 const_cast< THsPublisherInfo& >( plugin->PublisherInfo() ) );
       
   332 
       
   333             pubinfo.iNamespace.Copy( info.Namespace() );
       
   334 
       
   335             __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
       
   336                            Plugin recycled ***" );
       
   337 
       
   338             return KErrNone;
       
   339             }
       
   340         }
       
   341 
       
   342     TBool implFound( EFalse );
       
   343 
       
   344     for( TInt i = 0; i < iEComPlugins.Count(); i++ )
       
   345         {
       
   346         CImplementationInformation* information( iEComPlugins[i] );
       
   347 
       
   348         if( information->ImplementationUid() == info.Uid() )
       
   349             {
       
   350             implFound = ETrue;
       
   351             break;
       
   352             }
       
   353         }
       
   354     
       
   355     if( info.Namespace() == KNullDesC8 || !implFound )
       
   356         {
       
   357         // No namespace available or no ecom implementation available
       
   358         __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
       
   359                        Failed to Load Plug-in: KErrNotSupported ***" );
       
   360         
       
   361         return KErrNotSupported;
       
   362         }
       
   363            
       
   364     CHsContentPublisher* plugin( PluginByInfo( info ) );
       
   365 
       
   366     if( plugin )
       
   367         {
       
   368         __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done -\
       
   369                        No need to Load Plug-in: KErrAlreadyExists ***" );
       
   370         
       
   371         return KErrAlreadyExists;
       
   372         }
       
   373 
       
   374     TInt err( KErrNone );
       
   375 
       
   376     TRAP( err, DoCreatePluginL( aPublisherInfo ) );
       
   377     
       
   378     __PRINTS( "*** CAiPluginFactory::CreatePlugin: Done - Load Plug-in ***" );
       
   379 
       
   380     return err;
       
   381     }
       
   382 
       
   383 // ----------------------------------------------------------------------------
       
   384 // CAiPluginFactory::DoDestroyPlugin()
       
   385 //
       
   386 // ----------------------------------------------------------------------------
       
   387 //
       
   388 void CAiPluginFactory::DoDestroyPlugin( 
       
   389     const TAiFwPublisherInfo& aPublisherInfo )                             
       
   390     {
       
   391     __PRINTS( "*** CAiPluginFactory::DoDestroyPlugin: Start ***" );
       
   392     
       
   393     const THsPublisherInfo& info( aPublisherInfo.Info() );
       
   394       
       
   395     if ( IsRecyclable( info ) )
       
   396         {
       
   397         // Don't destroy recyclable plugin
       
   398         __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Done - Keeping recyclable Plug-in ***" );
       
   399         
       
   400         return;
       
   401         }
       
   402    
       
   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 ) );
       
   415     
       
   416     if ( plugin )
       
   417         {
       
   418         iPublishers.Remove( iPublishers.Find( plugin ) );
       
   419         
       
   420         delete plugin;
       
   421         plugin = NULL;            
       
   422         }
       
   423     
       
   424     __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Done ***" );
       
   425     }
       
   426 
       
   427 // ----------------------------------------------------------------------------
       
   428 // CAiPluginFactory::DestroyPlugin()
       
   429 //
       
   430 // ----------------------------------------------------------------------------
       
   431 //
       
   432 void CAiPluginFactory::DestroyPlugin( const TUid& aUid )
       
   433     {
       
   434     __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Start ***" );
       
   435     
       
   436     CHsContentPublisher* plugin( PluginByUid( aUid ) );
       
   437     
       
   438     if ( plugin )
       
   439         {                
       
   440         iPublishers.Remove( iPublishers.Find( plugin ) );
       
   441         
       
   442         __PRINT( __DBG_FORMAT( 
       
   443             "CAiPluginFactory::DestroyPlugin: name: %S" ), 
       
   444                 &plugin->PublisherInfo().Name() ); 
       
   445 
       
   446         delete plugin;
       
   447         plugin = NULL;                
       
   448         }
       
   449     
       
   450     __PRINTS( "*** CAiPluginFactory::DestroyPlugin: Done ***" );
       
   451     }
       
   452 
       
   453 // ----------------------------------------------------------------------------
       
   454 // CAiPluginFactory::DestroyAllPlugins()
       
   455 //
       
   456 // ----------------------------------------------------------------------------
       
   457 //
       
   458 void CAiPluginFactory::DestroyAllPlugins()
       
   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     
       
   490     __PRINT( __DBG_FORMAT( "\t[I]\t Loading plug-in uid=%x name=%S"), 
       
   491     info.Uid(), &(info.Name() ) );
       
   492 
       
   493     iPublishers.ReserveL( iPublishers.Count() + 1 );
       
   494     
       
   495     CHsContentPublisher* plugin( NULL );
       
   496     
       
   497     __TIME( "CAiPluginFactory::CreatePluginL Create plug-in:",                                  
       
   498     plugin = CHsContentPublisher::NewL( info ) );            
       
   499     
       
   500     CleanupStack::PushL( plugin );
       
   501     
       
   502     if ( IsSapiOrWrt( info ) )
       
   503         {
       
   504         plugin->SetProperty( CHsContentPublisher::ECpsCmdBuffer, 
       
   505             static_cast< MAiCpsCommandBuffer* >( iCommandBuffer ) );    
       
   506         }
       
   507     
       
   508     __TIME( "FW: Subscribe content observers",    
       
   509     SubscribePluginL( *plugin, info ) );             
       
   510                                                       
       
   511     __TIME( "FW: Configure Plugin",
       
   512     ConfigurePluginL( *plugin, info ) );
       
   513     
       
   514     // Take plugin's ownership
       
   515     iPublishers.Append( plugin );
       
   516     CleanupStack::Pop( plugin );
       
   517     }
       
   518 
       
   519 // ----------------------------------------------------------------------------
       
   520 // CAiPluginFactory::SubscribePluginL()
       
   521 //
       
   522 // ----------------------------------------------------------------------------
       
   523 //
       
   524 void CAiPluginFactory::SubscribePluginL(
       
   525     CHsContentPublisher& aContentPublisher,        
       
   526     const THsPublisherInfo& aPublisherInfo )    
       
   527     {
       
   528     RPointerArray< CAiUiController >& 
       
   529         controllers( iUiControllerManager.UiControllers() );
       
   530             
       
   531     for( TInt i = 0; i < controllers.Count(); i++ )
       
   532         {
       
   533         MAiContentObserver& observer( 
       
   534             controllers[i]->GetContentObserver() );
       
   535         
       
   536         if ( observer.RequiresSubscription( aPublisherInfo ) )
       
   537             {
       
   538 			// Subscribe observer only if it understands the plugin
       
   539             aContentPublisher.SubscribeL( observer );
       
   540             }                   
       
   541         }
       
   542     }
       
   543 
       
   544 // ----------------------------------------------------------------------------
       
   545 // CAiPluginFactory::ConfigurePluginL()
       
   546 //
       
   547 // ----------------------------------------------------------------------------
       
   548 //
       
   549 void CAiPluginFactory::ConfigurePluginL(     
       
   550     CHsContentPublisher& aContentPublisher,
       
   551     const THsPublisherInfo& aPublisherInfo )
       
   552     {    
       
   553     RAiSettingsItemArray settings;
       
   554     CleanupResetAndDestroyPushL( settings );
       
   555     
       
   556     RPointerArray< CAiUiController >& 
       
   557         controllers( iUiControllerManager.UiControllers() );
       
   558     
       
   559     for( TInt i = 0; i < controllers.Count(); i++ )
       
   560         {
       
   561         // Get settings for plug-in        
       
   562         controllers[i]->GetSettingsL( aPublisherInfo, settings );
       
   563         }
       
   564     
       
   565     // Configure plug-in with its settings
       
   566     aContentPublisher.ConfigureL( settings );
       
   567     
       
   568     CleanupStack::PopAndDestroy( &settings );    
       
   569     }
       
   570         
       
   571 // ----------------------------------------------------------------------------
       
   572 // CAiPluginFactory::PluginByInfo()
       
   573 // Gets plugin by publisher info. Only this overload returns the exact match
       
   574 // ----------------------------------------------------------------------------
       
   575 //
       
   576 CHsContentPublisher* CAiPluginFactory::PluginByInfo( 
       
   577     const THsPublisherInfo& aPublisherInfo ) const
       
   578     {       
       
   579     for( TInt i = 0; i < iPublishers.Count(); i++ )
       
   580         {         
       
   581         const THsPublisherInfo& info( iPublishers[i]->PublisherInfo() ); 
       
   582                                                                              
       
   583         if( aPublisherInfo == info ) 
       
   584             {
       
   585             return iPublishers[i];
       
   586             }
       
   587         }
       
   588     
       
   589     return NULL;
       
   590     }
       
   591 
       
   592 // ----------------------------------------------------------------------------
       
   593 // CAiPluginFactory::PluginByUid()
       
   594 // Gets plugin by UID
       
   595 // ----------------------------------------------------------------------------
       
   596 //
       
   597 CHsContentPublisher* CAiPluginFactory::PluginByUid( const TUid& aUid ) const
       
   598     {
       
   599     for( TInt i = 0; i < iPublishers.Count(); i++ )
       
   600         {
       
   601         const THsPublisherInfo& info( iPublishers[i]->PublisherInfo() );
       
   602                                                                
       
   603         if( info.Uid() == aUid )
       
   604             {
       
   605             return iPublishers[i];            
       
   606             }
       
   607         }
       
   608     
       
   609     return NULL;        
       
   610     }
       
   611     
       
   612 // ----------------------------------------------------------------------------
       
   613 // CAiPluginFactory::PluginByName()
       
   614 // Gets plugin by name
       
   615 // ----------------------------------------------------------------------------
       
   616 //
       
   617 CHsContentPublisher* CAiPluginFactory::PluginByName( 
       
   618     const TDesC& aName ) const
       
   619     {
       
   620     for( TInt i = 0; i < iPublishers.Count(); i++ )
       
   621         {
       
   622         const THsPublisherInfo& info( iPublishers[i]->PublisherInfo() );
       
   623                                                                
       
   624         if( info.Name() == aName )
       
   625             {
       
   626             return iPublishers[i];            
       
   627             }
       
   628         }
       
   629     
       
   630     return NULL;    
       
   631     }
       
   632 
       
   633 // ----------------------------------------------------------------------------
       
   634 // CAiPluginFactory::Publishers()
       
   635 //
       
   636 // ----------------------------------------------------------------------------
       
   637 //
       
   638 RPointerArray< CHsContentPublisher >& CAiPluginFactory::Publishers() const
       
   639     {
       
   640     return iPublishers;
       
   641     }
       
   642 
       
   643 // ----------------------------------------------------------------------------
       
   644 // CAiPluginFactory::SetStateManager()
       
   645 //
       
   646 // ----------------------------------------------------------------------------
       
   647 //
       
   648 void CAiPluginFactory::SetStateManager( CAiStateManager* aStateManager )
       
   649     {
       
   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" );       
       
   774     }
       
   775 
       
   776 // End of file