piprofiler/engine/src/SamplerPluginLoader.cpp
author hgs
Fri, 27 Aug 2010 11:37:29 +0300
changeset 42 0ff24a8f6ca2
parent 20 a71a3e32a2ae
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
// INCLUDE FILES
hgs
parents:
diff changeset
    20
#include    "SamplerPluginLoader.h"
hgs
parents:
diff changeset
    21
//#include	<piprofiler/EngineUIDs.h>
hgs
parents:
diff changeset
    22
#include    <utf.h> // CnvUtfConverter
hgs
parents:
diff changeset
    23
#include  	<basched.h>
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
// CONSTANTS
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    28
// CSamplerPluginLoader::NewL
hgs
parents:
diff changeset
    29
//
hgs
parents:
diff changeset
    30
// EPOC two-phased constructor
hgs
parents:
diff changeset
    31
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    32
//
hgs
parents:
diff changeset
    33
CSamplerPluginLoader* CSamplerPluginLoader::NewL()
hgs
parents:
diff changeset
    34
    {
hgs
parents:
diff changeset
    35
    CSamplerPluginLoader* self = new( ELeave ) CSamplerPluginLoader;
hgs
parents:
diff changeset
    36
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    37
    self->ConstructL( );
hgs
parents:
diff changeset
    38
    CleanupStack::Pop( self );
hgs
parents:
diff changeset
    39
    return self;
hgs
parents:
diff changeset
    40
    }
hgs
parents:
diff changeset
    41
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    44
// CSamplerPluginLoader::CSamplerPluginLoader
hgs
parents:
diff changeset
    45
//
hgs
parents:
diff changeset
    46
// C++ default constructor can NOT contain any code, that
hgs
parents:
diff changeset
    47
// might leave.
hgs
parents:
diff changeset
    48
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    49
//
hgs
parents:
diff changeset
    50
CSamplerPluginLoader::CSamplerPluginLoader() : CActive( EPriorityStandard )
hgs
parents:
diff changeset
    51
    {
hgs
parents:
diff changeset
    52
    LOGSTRING( "CSamplerPluginLoader()::CSamplerPluginLoader()" );
hgs
parents:
diff changeset
    53
    }
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
hgs
parents:
diff changeset
    56
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    57
// CSamplerPluginLoader::ConstructL
hgs
parents:
diff changeset
    58
//
hgs
parents:
diff changeset
    59
// EPOC default constructor can leave.
hgs
parents:
diff changeset
    60
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    61
//
hgs
parents:
diff changeset
    62
void CSamplerPluginLoader::ConstructL( )
hgs
parents:
diff changeset
    63
    {
hgs
parents:
diff changeset
    64
    LOGSTRING( "CSamplerPluginLoader()::ConstructL()" );
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
    // get list of implementations
hgs
parents:
diff changeset
    67
    CSamplerPluginInterface::ListAllImplementationsL( iImplInfoArray );
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
    CActiveScheduler::Add( this );
hgs
parents:
diff changeset
    70
    }
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    73
// CSamplerPluginLoader::~CSamplerPluginLoader
hgs
parents:
diff changeset
    74
//
hgs
parents:
diff changeset
    75
// Destructor
hgs
parents:
diff changeset
    76
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    77
//
hgs
parents:
diff changeset
    78
CSamplerPluginLoader::~CSamplerPluginLoader()
hgs
parents:
diff changeset
    79
    {
hgs
parents:
diff changeset
    80
    LOGSTRING( "CSamplerPluginLoader()::~CSamplerPluginLoader()" );
hgs
parents:
diff changeset
    81
hgs
parents:
diff changeset
    82
    AbortAsyncLoad();
hgs
parents:
diff changeset
    83
hgs
parents:
diff changeset
    84
    Cancel();
hgs
parents:
diff changeset
    85
    
hgs
parents:
diff changeset
    86
    // reset ECOM implementation info array
hgs
parents:
diff changeset
    87
    iImplInfoArray.ResetAndDestroy();   // This is needed
hgs
parents:
diff changeset
    88
    iImplInfoArray.Close();
hgs
parents:
diff changeset
    89
    }
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    93
// CSamplerPluginLoader::LoadAsync
hgs
parents:
diff changeset
    94
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    95
//
hgs
parents:
diff changeset
    96
void CSamplerPluginLoader::LoadAsyncL(CArrayPtrFlat<CSamplerPluginInterface>* aPluginArray )
hgs
parents:
diff changeset
    97
    {
hgs
parents:
diff changeset
    98
    iPluginArray = aPluginArray;
hgs
parents:
diff changeset
    99
hgs
parents:
diff changeset
   100
    // Reset iterator
hgs
parents:
diff changeset
   101
    iImplInfoArrayIterator = 0;
hgs
parents:
diff changeset
   102
hgs
parents:
diff changeset
   103
    LOGSTRING2( "CSamplerPluginLoader()::Implementation info count: %d",
hgs
parents:
diff changeset
   104
        iImplInfoArray.Count() );
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
    NotifyProgress();
hgs
parents:
diff changeset
   107
hgs
parents:
diff changeset
   108
    //Begin CActive asynchronous loop.
hgs
parents:
diff changeset
   109
    CompleteOwnRequest();
hgs
parents:
diff changeset
   110
    }
hgs
parents:
diff changeset
   111
    
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   114
// CSamplerPluginLoader::LoadSyncL
hgs
parents:
diff changeset
   115
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   116
//
hgs
parents:
diff changeset
   117
void CSamplerPluginLoader::LoadSyncL(CArrayPtrFlat<CSamplerPluginInterface>* aPluginArray)
hgs
parents:
diff changeset
   118
    {
hgs
parents:
diff changeset
   119
    // cancel first active object from loading samplers dynamically
hgs
parents:
diff changeset
   120
    Cancel();
hgs
parents:
diff changeset
   121
    CSamplerPluginInterface* plugin = NULL;
hgs
parents:
diff changeset
   122
    
hgs
parents:
diff changeset
   123
    iPluginArray = aPluginArray;
hgs
parents:
diff changeset
   124
hgs
parents:
diff changeset
   125
    // Get a list of all implementations, even though we only want one specific
hgs
parents:
diff changeset
   126
    // one. There appears to be no way to otherwise extract a specific implementation
hgs
parents:
diff changeset
   127
    // info object :(
hgs
parents:
diff changeset
   128
    // Search for the implementation that matches aImplementationUid
hgs
parents:
diff changeset
   129
    const TInt impCount = iImplInfoArray.Count();
hgs
parents:
diff changeset
   130
    for( TInt i=0; i<impCount; i++ )
hgs
parents:
diff changeset
   131
        {
hgs
parents:
diff changeset
   132
        const CImplementationInformation* info = iImplInfoArray[ i ];
hgs
parents:
diff changeset
   133
            {
hgs
parents:
diff changeset
   134
            TRAPD(ret, plugin = &CreatePluginInstanceL( *info ); );
hgs
parents:
diff changeset
   135
            if( ret == KErrNone )
hgs
parents:
diff changeset
   136
                {
hgs
parents:
diff changeset
   137
                // Plugin ownership is transfered to iPluginArray
hgs
parents:
diff changeset
   138
                InsertPluginInOrderL( plugin, iPluginArray );
hgs
parents:
diff changeset
   139
                }
hgs
parents:
diff changeset
   140
            else
hgs
parents:
diff changeset
   141
                {
hgs
parents:
diff changeset
   142
                // Error note is displayed even if plugin is not loaded
hgs
parents:
diff changeset
   143
                LOGSTRING2("CSamplerPluginLoader::LoadSyncL() - plugin load failed, error %d", ret);
hgs
parents:
diff changeset
   144
                }
hgs
parents:
diff changeset
   145
            break;
hgs
parents:
diff changeset
   146
            }
hgs
parents:
diff changeset
   147
        }
hgs
parents:
diff changeset
   148
hgs
parents:
diff changeset
   149
    if  ( plugin == NULL )
hgs
parents:
diff changeset
   150
        {
hgs
parents:
diff changeset
   151
        User::Leave( KErrNotFound );
hgs
parents:
diff changeset
   152
        }
hgs
parents:
diff changeset
   153
    }
hgs
parents:
diff changeset
   154
hgs
parents:
diff changeset
   155
hgs
parents:
diff changeset
   156
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   157
// CSamplerPluginLoader::AbortAsyncLoad
hgs
parents:
diff changeset
   158
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   159
//
hgs
parents:
diff changeset
   160
void CSamplerPluginLoader::AbortAsyncLoad()
hgs
parents:
diff changeset
   161
    {
hgs
parents:
diff changeset
   162
    LOGSTRING( "CSamplerPluginLoader()::AbortAsyncLoad()" );
hgs
parents:
diff changeset
   163
    Cancel();
hgs
parents:
diff changeset
   164
    }
hgs
parents:
diff changeset
   165
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   168
// CSamplerPluginLoader::RunL
hgs
parents:
diff changeset
   169
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   170
//
hgs
parents:
diff changeset
   171
void CSamplerPluginLoader::RunL()
hgs
parents:
diff changeset
   172
    {
hgs
parents:
diff changeset
   173
    iRunLDebugCount++;
hgs
parents:
diff changeset
   174
    LoadNextPluginL();
hgs
parents:
diff changeset
   175
hgs
parents:
diff changeset
   176
    // Check if there are still more plugins to be loaded:
hgs
parents:
diff changeset
   177
    if ( iImplInfoArrayIterator < iImplInfoArray.Count() )
hgs
parents:
diff changeset
   178
        {
hgs
parents:
diff changeset
   179
        NotifyProgress();
hgs
parents:
diff changeset
   180
        // Continue CActive asynchronous loop.
hgs
parents:
diff changeset
   181
        CompleteOwnRequest();
hgs
parents:
diff changeset
   182
        }
hgs
parents:
diff changeset
   183
    else
hgs
parents:
diff changeset
   184
        {
hgs
parents:
diff changeset
   185
        // All plugins loaded:
hgs
parents:
diff changeset
   186
        LOGSTRING( "CSamplerPluginLoader()::Loading plugins finished." );
hgs
parents:
diff changeset
   187
        NotifyFinished();
hgs
parents:
diff changeset
   188
        }
hgs
parents:
diff changeset
   189
    }
hgs
parents:
diff changeset
   190
hgs
parents:
diff changeset
   191
hgs
parents:
diff changeset
   192
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   193
// CScGenreItemConstructionConductor::CompleteOwnRequest
hgs
parents:
diff changeset
   194
//
hgs
parents:
diff changeset
   195
// Issue request complete notification.
hgs
parents:
diff changeset
   196
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   197
void CSamplerPluginLoader::CompleteOwnRequest()
hgs
parents:
diff changeset
   198
    {
hgs
parents:
diff changeset
   199
    TRequestStatus* status = &iStatus;
hgs
parents:
diff changeset
   200
    User::RequestComplete( status, KErrNone );
hgs
parents:
diff changeset
   201
    SetActive();
hgs
parents:
diff changeset
   202
    }
hgs
parents:
diff changeset
   203
hgs
parents:
diff changeset
   204
hgs
parents:
diff changeset
   205
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   206
// CSamplerPluginLoader::RunError
hgs
parents:
diff changeset
   207
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   208
//
hgs
parents:
diff changeset
   209
TInt CSamplerPluginLoader::RunError( TInt aError )
hgs
parents:
diff changeset
   210
    {
hgs
parents:
diff changeset
   211
    // This method is called when a plugin loading fails.
hgs
parents:
diff changeset
   212
    // Always "fake" the return value so that ActiveSchedule
hgs
parents:
diff changeset
   213
    // keeps running and later plugins are continued to be loaded.
hgs
parents:
diff changeset
   214
    // Check if still plugins to be loaded:
hgs
parents:
diff changeset
   215
    LOGTEXT(_L("CSamplerPluginLoader::RunError() - error in loading plugin"));
hgs
parents:
diff changeset
   216
    if( iImplInfoArrayIterator < iImplInfoArray.Count() )
hgs
parents:
diff changeset
   217
        {
hgs
parents:
diff changeset
   218
        NotifyProgress();
hgs
parents:
diff changeset
   219
hgs
parents:
diff changeset
   220
        //Continue CActive asynchronous loop.
hgs
parents:
diff changeset
   221
        CompleteOwnRequest();
hgs
parents:
diff changeset
   222
        }
hgs
parents:
diff changeset
   223
    else // All plugins loaded:
hgs
parents:
diff changeset
   224
        {
hgs
parents:
diff changeset
   225
        NotifyFinished();
hgs
parents:
diff changeset
   226
        }
hgs
parents:
diff changeset
   227
hgs
parents:
diff changeset
   228
    if ( aError == KLeaveExit )
hgs
parents:
diff changeset
   229
        {
hgs
parents:
diff changeset
   230
        return KLeaveExit;
hgs
parents:
diff changeset
   231
        }
hgs
parents:
diff changeset
   232
hgs
parents:
diff changeset
   233
    return KErrNone;
hgs
parents:
diff changeset
   234
    }
hgs
parents:
diff changeset
   235
hgs
parents:
diff changeset
   236
hgs
parents:
diff changeset
   237
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   238
// CSamplerPluginLoader::DoCancel
hgs
parents:
diff changeset
   239
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   240
//
hgs
parents:
diff changeset
   241
void CSamplerPluginLoader::DoCancel()
hgs
parents:
diff changeset
   242
    {
hgs
parents:
diff changeset
   243
hgs
parents:
diff changeset
   244
    }
hgs
parents:
diff changeset
   245
hgs
parents:
diff changeset
   246
hgs
parents:
diff changeset
   247
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   248
// CSamplerPluginLoader::NotifyProgress
hgs
parents:
diff changeset
   249
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   250
//
hgs
parents:
diff changeset
   251
void CSamplerPluginLoader::NotifyProgress()
hgs
parents:
diff changeset
   252
    {
hgs
parents:
diff changeset
   253
    if( iObserver )
hgs
parents:
diff changeset
   254
        {
hgs
parents:
diff changeset
   255
        iObserver->HandlePluginLoaded( MSamplerPluginLoadObserver::ESamplerSuccess);
hgs
parents:
diff changeset
   256
        }
hgs
parents:
diff changeset
   257
    }
hgs
parents:
diff changeset
   258
hgs
parents:
diff changeset
   259
hgs
parents:
diff changeset
   260
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   261
// CSamplerPluginLoader::NotifyFinished
hgs
parents:
diff changeset
   262
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   263
//
hgs
parents:
diff changeset
   264
void CSamplerPluginLoader::NotifyFinished()
hgs
parents:
diff changeset
   265
    {
hgs
parents:
diff changeset
   266
    if( iObserver )
hgs
parents:
diff changeset
   267
        {
hgs
parents:
diff changeset
   268
        iObserver->HandlePluginLoaded( MSamplerPluginLoadObserver::ESamplerFinished );
hgs
parents:
diff changeset
   269
        }
hgs
parents:
diff changeset
   270
    }
hgs
parents:
diff changeset
   271
hgs
parents:
diff changeset
   272
hgs
parents:
diff changeset
   273
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   274
// CSamplerPluginLoader::SetObserver
hgs
parents:
diff changeset
   275
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   276
//
hgs
parents:
diff changeset
   277
void CSamplerPluginLoader::SetObserver(MSamplerPluginLoadObserver* aObserver)
hgs
parents:
diff changeset
   278
    {
hgs
parents:
diff changeset
   279
    LOGSTRING2("CSamplerPluginLoader()::Observer set:0x%X", aObserver);
hgs
parents:
diff changeset
   280
    iObserver = aObserver;
hgs
parents:
diff changeset
   281
    }
hgs
parents:
diff changeset
   282
hgs
parents:
diff changeset
   283
hgs
parents:
diff changeset
   284
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   285
// CSamplerPluginLoader::ParseToUid
hgs
parents:
diff changeset
   286
// Parses a UID from descriptor of form '0xNNNNNNNN' where N is hexadecimal.
hgs
parents:
diff changeset
   287
//
hgs
parents:
diff changeset
   288
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   289
//
hgs
parents:
diff changeset
   290
TInt CSamplerPluginLoader::ParseToUid( const TDesC8& aSource, TUid& aTarget )
hgs
parents:
diff changeset
   291
    {
hgs
parents:
diff changeset
   292
    // Remove "0x" from the descriptor if it exists
hgs
parents:
diff changeset
   293
    _LIT8(KHexPrefix, "0x");
hgs
parents:
diff changeset
   294
hgs
parents:
diff changeset
   295
    TPtrC8 pSource( aSource );
hgs
parents:
diff changeset
   296
    const TInt prefixPosition = pSource.Find( KHexPrefix );
hgs
parents:
diff changeset
   297
    if  ( prefixPosition != KErrNotFound )
hgs
parents:
diff changeset
   298
        {
hgs
parents:
diff changeset
   299
        pSource.Set( aSource.Mid( prefixPosition + KHexPrefix().Length() ) );
hgs
parents:
diff changeset
   300
        }
hgs
parents:
diff changeset
   301
hgs
parents:
diff changeset
   302
    // Parse to integer
hgs
parents:
diff changeset
   303
    TLex8 lex( pSource );
hgs
parents:
diff changeset
   304
    TUint integer = 0;
hgs
parents:
diff changeset
   305
hgs
parents:
diff changeset
   306
    // Parse using TRadix::EHex as radix:
hgs
parents:
diff changeset
   307
    const TInt err = lex.Val( integer, EHex );
hgs
parents:
diff changeset
   308
    aTarget.iUid = integer;
hgs
parents:
diff changeset
   309
hgs
parents:
diff changeset
   310
    if( err != KErrNone )
hgs
parents:
diff changeset
   311
        {
hgs
parents:
diff changeset
   312
        // If parsing parent UID failed, do not load plugin:
hgs
parents:
diff changeset
   313
        LOGSTRING2(
hgs
parents:
diff changeset
   314
            "CSamplerPluginLoader()::Parsing parent UID failed. Error code:%d",
hgs
parents:
diff changeset
   315
            err );
hgs
parents:
diff changeset
   316
        }
hgs
parents:
diff changeset
   317
    return err;
hgs
parents:
diff changeset
   318
    }
hgs
parents:
diff changeset
   319
hgs
parents:
diff changeset
   320
hgs
parents:
diff changeset
   321
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   322
// CSamplerPluginLoader::ParseOrderNumber
hgs
parents:
diff changeset
   323
//
hgs
parents:
diff changeset
   324
//
hgs
parents:
diff changeset
   325
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   326
//
hgs
parents:
diff changeset
   327
TInt CSamplerPluginLoader::ParseOrderNumber( const TDesC8& aSource, TInt& aOrderNumber )
hgs
parents:
diff changeset
   328
    {
hgs
parents:
diff changeset
   329
    // Parse plugin's order number from opaque_data:
hgs
parents:
diff changeset
   330
    TLex8 lex( aSource );
hgs
parents:
diff changeset
   331
    const TInt orderErr = lex.Val( aOrderNumber );
hgs
parents:
diff changeset
   332
    return orderErr;
hgs
parents:
diff changeset
   333
    }
hgs
parents:
diff changeset
   334
hgs
parents:
diff changeset
   335
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   336
// CSamplerPluginLoader::LoadNextPluginL
hgs
parents:
diff changeset
   337
// Iterate through iImplInfoArray. Load the plugin if it is eligible for
hgs
parents:
diff changeset
   338
// loading. Loaded plugin is added to iPluginArray. Each time a plugin is
hgs
parents:
diff changeset
   339
// loaded, iObserver is notified.
hgs
parents:
diff changeset
   340
//
hgs
parents:
diff changeset
   341
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   342
//
hgs
parents:
diff changeset
   343
void CSamplerPluginLoader::LoadNextPluginL()
hgs
parents:
diff changeset
   344
    {
hgs
parents:
diff changeset
   345
    // Iterate through iImplInfoArray. This loop continues between function
hgs
parents:
diff changeset
   346
    // calls. Therefore member variable iImplInfoArrayIterator is used as a
hgs
parents:
diff changeset
   347
    // counter. Loop will break when match is found and continues on next RunL.
hgs
parents:
diff changeset
   348
    for( ; iImplInfoArrayIterator < iImplInfoArray.Count();  )
hgs
parents:
diff changeset
   349
        {
hgs
parents:
diff changeset
   350
        const CImplementationInformation* info =
hgs
parents:
diff changeset
   351
            iImplInfoArray[ iImplInfoArrayIterator ];
hgs
parents:
diff changeset
   352
hgs
parents:
diff changeset
   353
        iImplInfoArrayIterator++;
hgs
parents:
diff changeset
   354
hgs
parents:
diff changeset
   355
//        PrintInfoDebug( *info, iImplInfoArrayIterator, iImplInfoArray.Count() );
hgs
parents:
diff changeset
   356
        LOGSTRING3("CSamplerPluginLoader() - iImplInfoArrayIterator %d, iImplInfoArray.Count() %d", 
hgs
parents:
diff changeset
   357
                iImplInfoArrayIterator, 
hgs
parents:
diff changeset
   358
                iImplInfoArray.Count() );
hgs
parents:
diff changeset
   359
        
hgs
parents:
diff changeset
   360
        // If this plugin is OK -> load it:
hgs
parents:
diff changeset
   361
        LOGSTRING2( "CSamplerPluginLoader() %S eligible for parent",
hgs
parents:
diff changeset
   362
                &info->DisplayName());
hgs
parents:
diff changeset
   363
        CSamplerPluginInterface* plugin = NULL;
hgs
parents:
diff changeset
   364
        TInt error(KErrNone);
hgs
parents:
diff changeset
   365
        // Create plugin. Trap leave for debugging purposes.
hgs
parents:
diff changeset
   366
        TRAP( error, plugin = &CreatePluginInstanceL( *info ); );
hgs
parents:
diff changeset
   367
hgs
parents:
diff changeset
   368
        if( error == KErrNone )
hgs
parents:
diff changeset
   369
            {
hgs
parents:
diff changeset
   370
            // Plugin ownership is transfered to iPluginArray
hgs
parents:
diff changeset
   371
            InsertPluginInOrderL( plugin, iPluginArray );
hgs
parents:
diff changeset
   372
            }
hgs
parents:
diff changeset
   373
        else
hgs
parents:
diff changeset
   374
            {
hgs
parents:
diff changeset
   375
            // Error note is displayed even if plugin is not loaded
hgs
parents:
diff changeset
   376
            LOGSTRING2("CSamplerPluginLoader::LoadNextPluginL() - plugin load failed, error %d", error);
hgs
parents:
diff changeset
   377
            }
hgs
parents:
diff changeset
   378
        // Wait for next round
hgs
parents:
diff changeset
   379
        break;
hgs
parents:
diff changeset
   380
        }
hgs
parents:
diff changeset
   381
    }
hgs
parents:
diff changeset
   382
 
hgs
parents:
diff changeset
   383
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   384
// CSamplerPluginLoader::CreatePluginInstanceL
hgs
parents:
diff changeset
   385
//
hgs
parents:
diff changeset
   386
//
hgs
parents:
diff changeset
   387
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   388
//
hgs
parents:
diff changeset
   389
hgs
parents:
diff changeset
   390
CSamplerPluginInterface& CSamplerPluginLoader::CreatePluginInstanceL(
hgs
parents:
diff changeset
   391
    const CImplementationInformation& aImpInfo )
hgs
parents:
diff changeset
   392
    {
hgs
parents:
diff changeset
   393
    // Now we can load the plugin
hgs
parents:
diff changeset
   394
    const TUid implUid = aImpInfo.ImplementationUid();
hgs
parents:
diff changeset
   395
hgs
parents:
diff changeset
   396
    CSamplerPluginInterface* plugin = CSamplerPluginInterface::NewL( implUid , (TAny*)&aImpInfo.DisplayName() );
hgs
parents:
diff changeset
   397
    CleanupStack::PushL ( plugin );
hgs
parents:
diff changeset
   398
hgs
parents:
diff changeset
   399
    // Parse plugin's order number from opaque_data:
hgs
parents:
diff changeset
   400
    TInt orderNumber(0);
hgs
parents:
diff changeset
   401
    const TInt orderErr = ParseOrderNumber( aImpInfo.OpaqueData(), orderNumber );
hgs
parents:
diff changeset
   402
hgs
parents:
diff changeset
   403
    if  ( orderErr == KErrNone && orderNumber >= 0 )
hgs
parents:
diff changeset
   404
        {
hgs
parents:
diff changeset
   405
        	plugin->iOrder = orderNumber;
hgs
parents:
diff changeset
   406
        }
hgs
parents:
diff changeset
   407
    CleanupStack::Pop( plugin ); // CSamplerController is now responsible for this memory.
hgs
parents:
diff changeset
   408
hgs
parents:
diff changeset
   409
    return *plugin;
hgs
parents:
diff changeset
   410
    }
hgs
parents:
diff changeset
   411
hgs
parents:
diff changeset
   412
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   413
// CSamplerPluginLoader::SortPluginsL
hgs
parents:
diff changeset
   414
//
hgs
parents:
diff changeset
   415
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   416
//
hgs
parents:
diff changeset
   417
void CSamplerPluginLoader::SortPluginsL(
hgs
parents:
diff changeset
   418
        CArrayPtrFlat<CSamplerPluginInterface>* aPlugins )
hgs
parents:
diff changeset
   419
    {
hgs
parents:
diff changeset
   420
    RPointerArray<CSamplerPluginInterface> plugins;
hgs
parents:
diff changeset
   421
    TLinearOrder<CSamplerPluginInterface> order( CSamplerPluginLoader::Compare );
hgs
parents:
diff changeset
   422
hgs
parents:
diff changeset
   423
    // Insertion will also order
hgs
parents:
diff changeset
   424
    for( TInt i = 0; i < aPlugins->Count(); i++ )
hgs
parents:
diff changeset
   425
        {
hgs
parents:
diff changeset
   426
        plugins.InsertInOrderL( (*aPlugins)[i], order );
hgs
parents:
diff changeset
   427
        }
hgs
parents:
diff changeset
   428
hgs
parents:
diff changeset
   429
    // Replace original array content with sorted items
hgs
parents:
diff changeset
   430
    aPlugins->Reset();
hgs
parents:
diff changeset
   431
    for( TInt i = 0; i < plugins.Count(); i++ )
hgs
parents:
diff changeset
   432
        {
hgs
parents:
diff changeset
   433
        aPlugins->AppendL( plugins[i] );
hgs
parents:
diff changeset
   434
        }
hgs
parents:
diff changeset
   435
    }
hgs
parents:
diff changeset
   436
hgs
parents:
diff changeset
   437
hgs
parents:
diff changeset
   438
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   439
// CSamplerPluginLoader::Compare
hgs
parents:
diff changeset
   440
//
hgs
parents:
diff changeset
   441
// Compare two plugins.
hgs
parents:
diff changeset
   442
// Precedence:
hgs
parents:
diff changeset
   443
// [1. plugin provider category]
hgs
parents:
diff changeset
   444
// 2. plugin order number
hgs
parents:
diff changeset
   445
// 3. plugin caption
hgs
parents:
diff changeset
   446
// Plugin provider gategory is currently disabled (not supported yet).
hgs
parents:
diff changeset
   447
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   448
//
hgs
parents:
diff changeset
   449
TInt CSamplerPluginLoader::Compare( const CSamplerPluginInterface& aFirst,
hgs
parents:
diff changeset
   450
                               const CSamplerPluginInterface& aSecond )
hgs
parents:
diff changeset
   451
    {
hgs
parents:
diff changeset
   452
    // compare indexes and sort
hgs
parents:
diff changeset
   453
    return CompareIndex( aFirst, aSecond );
hgs
parents:
diff changeset
   454
    }
hgs
parents:
diff changeset
   455
hgs
parents:
diff changeset
   456
hgs
parents:
diff changeset
   457
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   458
// CSamplerPluginLoader::InsertPluginInOrderL
hgs
parents:
diff changeset
   459
//
hgs
parents:
diff changeset
   460
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   461
//
hgs
parents:
diff changeset
   462
void CSamplerPluginLoader::InsertPluginInOrderL(
hgs
parents:
diff changeset
   463
    CSamplerPluginInterface* aPlugin,
hgs
parents:
diff changeset
   464
    CArrayPtrFlat<CSamplerPluginInterface>* aPlugins )
hgs
parents:
diff changeset
   465
    {
hgs
parents:
diff changeset
   466
    CSamplerPluginInterface* comparedPlugin;
hgs
parents:
diff changeset
   467
    TInt comparison = 0;
hgs
parents:
diff changeset
   468
    TBool inserted = EFalse;
hgs
parents:
diff changeset
   469
hgs
parents:
diff changeset
   470
    for( TInt i = 0; i < aPlugins->Count(); i++ )
hgs
parents:
diff changeset
   471
        {
hgs
parents:
diff changeset
   472
        comparedPlugin = (*aPlugins)[i];
hgs
parents:
diff changeset
   473
        // Optimization: do not call time consuming Compare() multiple times!
hgs
parents:
diff changeset
   474
        comparison = Compare( *aPlugin, *comparedPlugin );
hgs
parents:
diff changeset
   475
        if( comparison < 0 )
hgs
parents:
diff changeset
   476
            {
hgs
parents:
diff changeset
   477
            aPlugins->InsertL( i, aPlugin );
hgs
parents:
diff changeset
   478
            inserted = ETrue;
hgs
parents:
diff changeset
   479
            break;
hgs
parents:
diff changeset
   480
            }
hgs
parents:
diff changeset
   481
        else if( comparison == 0 )
hgs
parents:
diff changeset
   482
            {
hgs
parents:
diff changeset
   483
            aPlugins->InsertL( i+1, aPlugin );
hgs
parents:
diff changeset
   484
            inserted = ETrue;
hgs
parents:
diff changeset
   485
            break;
hgs
parents:
diff changeset
   486
            }
hgs
parents:
diff changeset
   487
        }
hgs
parents:
diff changeset
   488
    // Plugin was not before any other plugin - make sure it's appended
hgs
parents:
diff changeset
   489
    if( !inserted )
hgs
parents:
diff changeset
   490
        {
hgs
parents:
diff changeset
   491
        aPlugins->AppendL( aPlugin );
hgs
parents:
diff changeset
   492
        }
hgs
parents:
diff changeset
   493
hgs
parents:
diff changeset
   494
    #ifdef _GS_PLUGINLOADER_SORTING_TRACES
hgs
parents:
diff changeset
   495
        PrintOrderTraces( aPlugins );
hgs
parents:
diff changeset
   496
    #endif // _GS_PLUGINLOADER_SORTING_TRACES
hgs
parents:
diff changeset
   497
hgs
parents:
diff changeset
   498
    }
hgs
parents:
diff changeset
   499
hgs
parents:
diff changeset
   500
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   501
// CSamplerPluginLoader::CompareIndex
hgs
parents:
diff changeset
   502
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   503
//
hgs
parents:
diff changeset
   504
TInt CSamplerPluginLoader::CompareIndex( const CSamplerPluginInterface& aFirst,
hgs
parents:
diff changeset
   505
                                    const CSamplerPluginInterface& aSecond )
hgs
parents:
diff changeset
   506
    {
hgs
parents:
diff changeset
   507
    TInt comparison = KSamplerComparisonEqual;
hgs
parents:
diff changeset
   508
    // The plugin having index is before the one not having one
hgs
parents:
diff changeset
   509
hgs
parents:
diff changeset
   510
    if( aFirst.iOrder  == KSamplerPluginNotIndexed &&
hgs
parents:
diff changeset
   511
        aSecond.iOrder == KSamplerPluginNotIndexed )
hgs
parents:
diff changeset
   512
        {
hgs
parents:
diff changeset
   513
        // Neither have index -> equal
hgs
parents:
diff changeset
   514
        comparison = KSamplerComparisonEqual;
hgs
parents:
diff changeset
   515
        }
hgs
parents:
diff changeset
   516
    else if( aFirst.iOrder == KSamplerPluginNotIndexed )
hgs
parents:
diff changeset
   517
        {
hgs
parents:
diff changeset
   518
        // The plugin having index is before the one not having one
hgs
parents:
diff changeset
   519
        comparison = KSamplerComparisonAfter;
hgs
parents:
diff changeset
   520
        }
hgs
parents:
diff changeset
   521
    else if( aSecond.iOrder == KSamplerPluginNotIndexed )
hgs
parents:
diff changeset
   522
        {
hgs
parents:
diff changeset
   523
        // The plugin having index is before the one not having one
hgs
parents:
diff changeset
   524
        comparison = KSamplerComparisonBefore;
hgs
parents:
diff changeset
   525
        }
hgs
parents:
diff changeset
   526
    else if( aFirst.iOrder < aSecond.iOrder )
hgs
parents:
diff changeset
   527
        {
hgs
parents:
diff changeset
   528
        // Compare actual index values
hgs
parents:
diff changeset
   529
        comparison = KSamplerComparisonBefore;
hgs
parents:
diff changeset
   530
        }
hgs
parents:
diff changeset
   531
    else if( aFirst.iOrder > aSecond.iOrder )
hgs
parents:
diff changeset
   532
        {
hgs
parents:
diff changeset
   533
        // Compare actual index values
hgs
parents:
diff changeset
   534
        comparison = KSamplerComparisonAfter;
hgs
parents:
diff changeset
   535
        }
hgs
parents:
diff changeset
   536
    return comparison;
hgs
parents:
diff changeset
   537
    }
hgs
parents:
diff changeset
   538
hgs
parents:
diff changeset
   539
//  End of File