perfsrv/piprofiler/engine/src/SamplerPluginLoader.cpp
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
    28 // CSamplerPluginLoader::NewL
    28 // CSamplerPluginLoader::NewL
    29 //
    29 //
    30 // EPOC two-phased constructor
    30 // EPOC two-phased constructor
    31 // ----------------------------------------------------------------------------
    31 // ----------------------------------------------------------------------------
    32 //
    32 //
    33 CSamplerPluginLoader* CSamplerPluginLoader::NewL()
    33 CSamplerPluginLoader* CSamplerPluginLoader::NewL(TBool aBootMode)
    34     {
    34     {
    35     CSamplerPluginLoader* self = new( ELeave ) CSamplerPluginLoader;
    35     CSamplerPluginLoader* self = new( ELeave ) CSamplerPluginLoader(aBootMode);
    36     CleanupStack::PushL( self );
    36     CleanupStack::PushL( self );
    37     self->ConstructL( );
    37     self->ConstructL( );
    38     CleanupStack::Pop( self );
    38     CleanupStack::Pop( self );
    39     return self;
    39     return self;
    40     }
    40     }
    45 //
    45 //
    46 // C++ default constructor can NOT contain any code, that
    46 // C++ default constructor can NOT contain any code, that
    47 // might leave.
    47 // might leave.
    48 // ----------------------------------------------------------------------------
    48 // ----------------------------------------------------------------------------
    49 //
    49 //
    50 CSamplerPluginLoader::CSamplerPluginLoader() : CActive( EPriorityStandard )
    50 CSamplerPluginLoader::CSamplerPluginLoader(TBool aBootMode) :
       
    51         CActive( EPriorityStandard )
    51     {
    52     {
    52     LOGSTRING( "CSamplerPluginLoader()::CSamplerPluginLoader()" );
    53     LOGSTRING( "CSamplerPluginLoader()::CSamplerPluginLoader()" );
       
    54     iBootMode = aBootMode;
    53     }
    55     }
    54 
    56 
    55 
    57 
    56 // ----------------------------------------------------------------------------
    58 // ----------------------------------------------------------------------------
    57 // CSamplerPluginLoader::ConstructL
    59 // CSamplerPluginLoader::ConstructL
    80     LOGSTRING( "CSamplerPluginLoader()::~CSamplerPluginLoader()" );
    82     LOGSTRING( "CSamplerPluginLoader()::~CSamplerPluginLoader()" );
    81 
    83 
    82     AbortAsyncLoad();
    84     AbortAsyncLoad();
    83 
    85 
    84     Cancel();
    86     Cancel();
       
    87     if ( iPluginArray )
       
    88         {
       
    89         iPluginArray = NULL;
       
    90         }
    85     
    91     
    86     // reset ECOM implementation info array
    92     // reset ECOM implementation info array
    87     iImplInfoArray.ResetAndDestroy();   // This is needed
    93     iImplInfoArray.ResetAndDestroy();   // This is needed
    88     iImplInfoArray.Close();
    94     iImplInfoArray.Close();
    89     }
    95     }
   107 
   113 
   108     //Begin CActive asynchronous loop.
   114     //Begin CActive asynchronous loop.
   109     CompleteOwnRequest();
   115     CompleteOwnRequest();
   110     }
   116     }
   111     
   117     
   112 
   118 // ----------------------------------------------------------------------------
       
   119 // CSamplerPluginLoader::LoadRlibraryL
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 void CSamplerPluginLoader::LoadRlibraryL(CArrayPtrFlat<CSamplerPluginInterface>* aPluginArray)
       
   123     {
       
   124     LOGSTRING("CSamplerPluginLoader rlibrary loading");
       
   125                 // Load dll
       
   126     iPluginArray = aPluginArray;
       
   127     RLibrary aLib;
       
   128     TInt ret = aLib.Load(_L("PIProfilerGenerals.dll"),_L("c:\\sys\\bin"));
       
   129 
       
   130     LOGSTRING2("RLibrary load returns %d", ret);
       
   131     User::LeaveIfError(ret);
       
   132     const TInt KNewLOrdinal = 2;
       
   133     TLibraryFunction NewL =aLib.Lookup(KNewLOrdinal);
       
   134 
       
   135     if(!NewL)
       
   136         {
       
   137         RDebug::Printf("library.lookup returns null");    
       
   138         }
       
   139     else
       
   140         {
       
   141         LOGSTRING2("library.lookup returns 0x%x", NewL);
       
   142         //CGeneralsPlugin* mydll=(CGeneralsPlugin*)NewL();
       
   143         CSamplerPluginInterface* mydll=(CSamplerPluginInterface*)NewL();
       
   144         //Generals plugin loaded, samplers enabled.
       
   145         CleanupStack::PushL( mydll );
       
   146         //InsertPluginInOrderL( mydll, aPluginArray);
       
   147         CleanupStack::Pop(mydll);
       
   148         // call engine to finalize the startup
       
   149         //TRAPD(result, iObserver->HandleSamplerControllerReadyL(););
       
   150         NotifyProgress();
       
   151 
       
   152         //Begin CActive asynchronous loop.
       
   153         CompleteOwnRequest();
       
   154         }
       
   155     LOGSTRING("RLibrary and plugins loaded");
       
   156     }
   113 // ----------------------------------------------------------------------------
   157 // ----------------------------------------------------------------------------
   114 // CSamplerPluginLoader::LoadSyncL
   158 // CSamplerPluginLoader::LoadSyncL
   115 // ----------------------------------------------------------------------------
   159 // ----------------------------------------------------------------------------
   116 //
   160 //
   117 void CSamplerPluginLoader::LoadSyncL(CArrayPtrFlat<CSamplerPluginInterface>* aPluginArray)
   161 void CSamplerPluginLoader::LoadSyncL(CArrayPtrFlat<CSamplerPluginInterface>* aPluginArray)
   168 // CSamplerPluginLoader::RunL
   212 // CSamplerPluginLoader::RunL
   169 // ----------------------------------------------------------------------------
   213 // ----------------------------------------------------------------------------
   170 //
   214 //
   171 void CSamplerPluginLoader::RunL()
   215 void CSamplerPluginLoader::RunL()
   172     {
   216     {
       
   217     LOGSTRING("CSamplerPluginLoader::RunL");
   173     iRunLDebugCount++;
   218     iRunLDebugCount++;
   174     LoadNextPluginL();
   219     LoadNextPluginL();
   175 
   220 
   176     // Check if there are still more plugins to be loaded:
   221     // Check if there are still more plugins to be loaded:
   177     if ( iImplInfoArrayIterator < iImplInfoArray.Count() )
   222     if ( iImplInfoArrayIterator < iImplInfoArray.Count() )
   362                 &info->DisplayName());
   407                 &info->DisplayName());
   363         CSamplerPluginInterface* plugin = NULL;
   408         CSamplerPluginInterface* plugin = NULL;
   364         TInt error(KErrNone);
   409         TInt error(KErrNone);
   365         // Create plugin. Trap leave for debugging purposes.
   410         // Create plugin. Trap leave for debugging purposes.
   366         TRAP( error, plugin = &CreatePluginInstanceL( *info ); );
   411         TRAP( error, plugin = &CreatePluginInstanceL( *info ); );
   367 
   412         if (plugin != NULL)
   368         if( error == KErrNone )
       
   369             {
   413             {
   370             // Plugin ownership is transfered to iPluginArray
   414             if( error == KErrNone )
   371             InsertPluginInOrderL( plugin, iPluginArray );
   415                 {
       
   416                 // Plugin ownership is transfered to iPluginArray
       
   417                 InsertPluginInOrderL( plugin, iPluginArray );
       
   418                 }
       
   419             else
       
   420                 {
       
   421                 // Error note is displayed even if plugin is not loaded
       
   422                 LOGSTRING2("CSamplerPluginLoader::LoadNextPluginL() - plugin load failed, error %d", error);
       
   423                 }
   372             }
   424             }
   373         else
   425         else
   374             {
   426             {
   375             // Error note is displayed even if plugin is not loaded
   427                 delete plugin;
   376             LOGSTRING2("CSamplerPluginLoader::LoadNextPluginL() - plugin load failed, error %d", error);
       
   377             }
   428             }
   378         // Wait for next round
   429         // Wait for next round
   379         break;
   430         break;
   380         }
   431         }
   381     }
   432     }
   392     {
   443     {
   393     // Now we can load the plugin
   444     // Now we can load the plugin
   394     const TUid implUid = aImpInfo.ImplementationUid();
   445     const TUid implUid = aImpInfo.ImplementationUid();
   395 
   446 
   396     CSamplerPluginInterface* plugin = CSamplerPluginInterface::NewL( implUid , (TAny*)&aImpInfo.DisplayName() );
   447     CSamplerPluginInterface* plugin = CSamplerPluginInterface::NewL( implUid , (TAny*)&aImpInfo.DisplayName() );
   397     CleanupStack::PushL ( plugin );
   448     if(plugin != NULL)
   398 
   449         {
   399     // Parse plugin's order number from opaque_data:
   450         CleanupStack::PushL ( plugin );
   400     TInt orderNumber(0);
   451 
   401     const TInt orderErr = ParseOrderNumber( aImpInfo.OpaqueData(), orderNumber );
   452         // Parse plugin's order number from opaque_data:
   402 
   453         TInt orderNumber(0);
   403     if  ( orderErr == KErrNone && orderNumber >= 0 )
   454         const TInt orderErr = ParseOrderNumber( aImpInfo.OpaqueData(), orderNumber );
   404         {
   455 
   405         	plugin->iOrder = orderNumber;
   456         if  ( orderErr == KErrNone && orderNumber >= 0 )
   406         }
   457             {
   407     CleanupStack::Pop( plugin ); // CSamplerController is now responsible for this memory.
   458                 plugin->iOrder = orderNumber;
   408 
   459             }
   409     return *plugin;
   460         CleanupStack::Pop( plugin ); // CSamplerController is now responsible for this memory.
       
   461         }
       
   462         return *plugin;
   410     }
   463     }
   411 
   464 
   412 // ----------------------------------------------------------------------------
   465 // ----------------------------------------------------------------------------
   413 // CSamplerPluginLoader::SortPluginsL
   466 // CSamplerPluginLoader::SortPluginsL
   414 //
   467 //
   430     aPlugins->Reset();
   483     aPlugins->Reset();
   431     for( TInt i = 0; i < plugins.Count(); i++ )
   484     for( TInt i = 0; i < plugins.Count(); i++ )
   432         {
   485         {
   433         aPlugins->AppendL( plugins[i] );
   486         aPlugins->AppendL( plugins[i] );
   434         }
   487         }
       
   488     plugins.Close();
   435     }
   489     }
   436 
   490 
   437 
   491 
   438 // ----------------------------------------------------------------------------
   492 // ----------------------------------------------------------------------------
   439 // CSamplerPluginLoader::Compare
   493 // CSamplerPluginLoader::Compare