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