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