sysanadatacapture/piprofiler/piprofiler/engine/inc/SamplerPluginLoader.h
changeset 1 3ff3fecb12fe
equal deleted inserted replaced
0:f0f2b8682603 1:3ff3fecb12fe
       
     1 /*
       
     2 * Copyright (c) 2009 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef  SAMPLERPLUGINLOADER_H
       
    20 #define  SAMPLERPLUGINLOADER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include    <e32base.h>
       
    24 #include    <Ecom/ImplementationInformation.h>
       
    25 #include 	<piprofiler/ProfilerConfig.h>
       
    26 #include 	<piprofiler/SamplerPluginInterface.h>
       
    27 
       
    28 // CONSTANTS
       
    29 // Value for a to b comparison result when logically a == b.
       
    30 const TInt KSamplerComparisonEqual     = 0;
       
    31 
       
    32 // Value for a to b comparison result when logically a < b.
       
    33 const TInt KSamplerComparisonBefore    = -1;
       
    34 
       
    35 // Value for a to b comparison result when logically a > b.
       
    36 const TInt KSamplerComparisonAfter     = 1;
       
    37 
       
    38 // CLASS DEFINITIONS
       
    39 class CSamplerPluginInterface;
       
    40 class MSamplerPluginLoadObserver;
       
    41 class REComSession;
       
    42 
       
    43 /**
       
    44 * CSamplerPluginLoader. Mechanism used to load plugins asynchronously. Uses
       
    45 * MSamplerPluginLoadObserver as a callback.
       
    46 *
       
    47 * @lib ProfilerEngine.exe/.lib???????????
       
    48 * @since Series60_30.1
       
    49 */
       
    50 class CSamplerPluginLoader : public CActive
       
    51     {
       
    52     public:  // Constructor and destructor
       
    53 
       
    54         /**
       
    55         * Two-phased constructor.
       
    56         *
       
    57         * @param aAppUi Pointer to application UI. Does not take ownership.
       
    58         */
       
    59         static CSamplerPluginLoader* NewL();
       
    60 
       
    61         /**
       
    62         * Destructor
       
    63         */
       
    64         ~CSamplerPluginLoader();
       
    65 
       
    66     private: // Internal construction
       
    67 
       
    68         /**
       
    69         * Default C++ contructor
       
    70         */
       
    71         CSamplerPluginLoader();
       
    72 
       
    73         /**
       
    74         * Symbian OS default constructor
       
    75         * @return void
       
    76         */
       
    77         void ConstructL();
       
    78 
       
    79     public: // API
       
    80 
       
    81         /**
       
    82         * Starts loading GS plug-ins asynchronously. Will call
       
    83         * MSamplerPluginLoadObserver::HandlePluginLoaded() each time a plug-in is
       
    84         * loaded and when all plugins are loaded.
       
    85         *
       
    86         * CSamplerPluginLoader transfers the ownership of each loaded plugin view to
       
    87         * CAknViewAppUi. It is client's responsibility to remove the views from
       
    88         * CAknViewAppUi and delete the plugins if necessary.
       
    89         *
       
    90         * @param aInterfaceUid Uid ofthe interfaces to be loaded.
       
    91         * @param aParentUid Uid of the parent. Only children of this parent
       
    92         *        will be loaded.
       
    93         * @param aPluginArray An array for the loaded GS plug-ins.
       
    94         *        CSamplerPluginLoader does not take the ownership of this array.
       
    95         */
       
    96         void LoadAsyncL( CArrayPtrFlat<CSamplerPluginInterface>* aPluginArray );
       
    97 
       
    98         /**
       
    99         * Load a specific plugin instance synchronously.
       
   100         *
       
   101         * @param aInterfaceUid Uid ofthe interfaces to be loaded.
       
   102         * @param aImplementationUid Uid of the implementation to load
       
   103         */
       
   104         void LoadSyncL( CArrayPtrFlat<CSamplerPluginInterface>* aPluginArray );
       
   105 
       
   106         /**
       
   107         * Sets observer for this loader. Only one observer per loader in one
       
   108         * time is possible.
       
   109         */
       
   110         void SetObserver(MSamplerPluginLoadObserver* aObserver);
       
   111 
       
   112         /**
       
   113         * Aborts asynchronous loading of the GS plug-ins.
       
   114         */
       
   115         void AbortAsyncLoad();
       
   116 
       
   117 
       
   118         /**
       
   119         * Sorts the plugin array.
       
   120         *
       
   121         * Sorting criterias:
       
   122         *
       
   123         * 1. Order number if provider category is Internal.
       
   124         * 2. Provider category. Precedence as follows:
       
   125         *       1. KGSPluginProviderInternal
       
   126         *       2. EGSPluginProviderOEM
       
   127         *       3. EGSPluginProviderOperator
       
   128         *       4. EGSPluginProvider3rdParty
       
   129         * 3. Alphabetical
       
   130         *
       
   131         * @param aPlugins The array which will be sorted.
       
   132         */
       
   133         void SortPluginsL( CArrayPtrFlat<CSamplerPluginInterface>* aPlugins );
       
   134 
       
   135     private: // Internal methods
       
   136 
       
   137         /**
       
   138         * Starts loading next plugin.
       
   139         */
       
   140         void LoadNextPluginL();
       
   141 
       
   142         /**
       
   143         * Creates a plugin instance from given UID. Ownership is transferred.
       
   144         */
       
   145         CSamplerPluginInterface& CreatePluginInstanceL( 
       
   146                 const CImplementationInformation& aImpInfo );
       
   147 
       
   148         /**
       
   149         * Notifies MPluginLoadObserver.
       
   150         */
       
   151         void NotifyProgress();
       
   152 
       
   153         /**
       
   154         * Notifies MPluginLoadObserver.
       
   155         */
       
   156         void NotifyFinished();
       
   157 
       
   158         /**
       
   159         * Wait for the next round of CActive execution.
       
   160         */
       
   161         void CompleteOwnRequest();
       
   162 
       
   163         // Insertion function used by sorting:
       
   164 
       
   165         /**
       
   166         * Inserts plugin in the correct position in the array using sorting 
       
   167         * criterias. Assumes aPlugins is ordered.
       
   168         *
       
   169         * @param aPlugin The plugin to be inserted.
       
   170         * @param aPlugins Array in which the plugin is inserted into the
       
   171         *        corresponding location.
       
   172         */
       
   173         void InsertPluginInOrderL(
       
   174             CSamplerPluginInterface* aPlugin,
       
   175             CArrayPtrFlat<CSamplerPluginInterface>* aPlugins );
       
   176 
       
   177         // Comparison functions:
       
   178 
       
   179         /**
       
   180         * Compares plugins according to comparison criterias.
       
   181         * 
       
   182         * Note: GS internal comparison constants such as KGSComparisonEqual are 
       
   183         * different from the ones outputted by this function. This is because 
       
   184         * this function is also usable by RArray sort -functionality but BC 
       
   185         * cannot be broken in GS.
       
   186         * 
       
   187         * @return Negative value: If aFirst before aSecond.
       
   188         *                      0: If equal.
       
   189         *         Positive value: If aSecond before aFirst.
       
   190         */
       
   191         static TInt Compare( const CSamplerPluginInterface& aFirst,    
       
   192                              const CSamplerPluginInterface& aSecond );
       
   193 
       
   194         /**
       
   195         *
       
   196         * @return   KGSComparisonEqual  = equal indexes
       
   197         *           KGSComparisonBefore = aFirst is before aSecond
       
   198         *           KGSComparisonAfter  = aFirst is after aSecond
       
   199         */
       
   200 
       
   201         static TInt CompareIndex( 
       
   202                 const CSamplerPluginInterface& aFirst,
       
   203                 const CSamplerPluginInterface& aSecond );
       
   204 
       
   205     private: // Utility methods
       
   206 
       
   207         /**
       
   208         * Parses descriptor to UID.
       
   209         */
       
   210         static TInt ParseToUid( const TDesC8& aSource, TUid& aTarget );
       
   211 
       
   212         /**
       
   213         * Parsers plugin's order number
       
   214         */
       
   215         static TInt ParseOrderNumber( const TDesC8& aSource, TInt& aOrderNumber );
       
   216 
       
   217         /**
       
   218          * Print ordering debug data.
       
   219          */
       
   220         void CSamplerPluginLoader::PrintOrderTraces( 
       
   221                 CArrayPtrFlat<CSamplerPluginInterface>* aPlugins );
       
   222  
       
   223     private: // From CActive
       
   224 
       
   225         /**
       
   226         * See base class.
       
   227         */
       
   228         void RunL();
       
   229 
       
   230         /**
       
   231         * See base class.
       
   232         */
       
   233         TInt RunError( TInt aError );
       
   234 
       
   235         /**
       
   236         * See base class.
       
   237         */
       
   238         void DoCancel();
       
   239 
       
   240     private: // Data
       
   241         // Pluginloader goes through this array and loads the plugins into
       
   242         // iPluginArray if they fulfill the criterias.
       
   243         RImplInfoPtrArray iImplInfoArray;
       
   244 
       
   245         // Used as an iterator to maintain location in iImplInfoArray.
       
   246         TInt iImplInfoArrayIterator;
       
   247 
       
   248         // Array of loaded plugins.Plugins are owned by iAppUi. Only the array
       
   249         // pointers are owned by this class and therefore only reset array.
       
   250         CArrayPtrFlat<CSamplerPluginInterface>* iPluginArray;
       
   251 
       
   252         // Pointer to observer. Not owned.
       
   253         MSamplerPluginLoadObserver* iObserver;
       
   254 
       
   255         // Number of RunL calls.
       
   256         TInt iRunLDebugCount;
       
   257 
       
   258     };
       
   259 
       
   260 
       
   261 /**
       
   262 * Interface for SamplerPluginLoader observer. MSamplerPluginLoadObserver gets
       
   263 * notifications when plugins are loaded.
       
   264 *
       
   265 * @lib ProfilerEngine.exe/.lib???????????
       
   266 * @since Series60_30.1
       
   267 */
       
   268 
       
   269 class MSamplerPluginLoadObserver
       
   270     {
       
   271     public: // Enums
       
   272         enum KSamplerPluginLoaderStatus
       
   273             {
       
   274             // One plugin loaded successfully, continue to next.
       
   275             ESamplerSuccess,
       
   276             // Loading one plugin failed, contiue to next.
       
   277             ESamplerFail,
       
   278             // Client called AbortAsyncLoad(), finished loading.
       
   279             ESamplerAborted,
       
   280             // All plugins loaded successfully, finished loading.
       
   281             ESamplerFinished,
       
   282             // Severe error with loader, finished loading.
       
   283             ESamplerError
       
   284             };
       
   285 
       
   286     public: // New
       
   287 
       
   288         //CSamplerPluginLoader calls this function when each plug-in is loaded or
       
   289         //loading is finished..
       
   290         
       
   291         IMPORT_C virtual void HandlePluginLoaded(
       
   292             KSamplerPluginLoaderStatus aStatus ) = 0;
       
   293     };
       
   294 
       
   295 
       
   296 #endif // SAMPLERPLUGINLOADER_H
       
   297 // End of File