os/mm/mmlibs/mmfw/src/ControllerFramework/mmfcontrollerpluginresolver.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <badesca.h>
sl@0
    17
#include <utf.h>
sl@0
    18
#include <uri8.h>
sl@0
    19
#include <uriutils.h>
sl@0
    20
#include <mmf/plugin/mmfplugininterfaceuids.hrh>
sl@0
    21
#include <mmf/common/mmfcontrollerpluginresolver.h>
sl@0
    22
#include "mmfmatchdata.h"
sl@0
    23
#include <mmf/server/mmfdatasourcesink.hrh>
sl@0
    24
#include "MMFFormatImplementationInformationBody.h"
sl@0
    25
#include <mm/mmpluginutils.h>
sl@0
    26
sl@0
    27
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0
    28
#include <mmf/common/taggeddataparser.h>
sl@0
    29
#endif
sl@0
    30
sl@0
    31
_LIT8(KSupplier, "<s>");
sl@0
    32
_LIT8(KMediaId, "<i>");
sl@0
    33
_LIT8(KUriScheme,"<u>");
sl@0
    34
_LIT8(KNonNetwork,"<n>");
sl@0
    35
_LIT8(KPlayFormatCollectionUid, "<p>");
sl@0
    36
_LIT8(KRecordFormatCollectionUid, "<r>");
sl@0
    37
_LIT8(KFormatFileExtension, "<e>");
sl@0
    38
_LIT8(KFormatMimeType, "<m>");
sl@0
    39
_LIT8(KFormatHeaderData, "<h>");
sl@0
    40
_LIT8(KHeapSize, "<a>");
sl@0
    41
_LIT8(KCustomInterfaceSupport, "<c>");
sl@0
    42
_LIT8(KSecureDRMProcessMode, "<d>");
sl@0
    43
_LIT8(KStackSize, "<t>");
sl@0
    44
_LIT8(KTagMatch, "*<?>*");
sl@0
    45
_LIT8(KTagYes,"yes");
sl@0
    46
sl@0
    47
const TInt KTagLength = 3;
sl@0
    48
sl@0
    49
const TInt KMaxExtLen = 5 ;
sl@0
    50
const TInt KDesCArrayGranularity = 1;
sl@0
    51
sl@0
    52
const TInt KUriPriorityHigh = 3;
sl@0
    53
const TInt KUriPriorityMedium = 2;
sl@0
    54
const TInt KUriPriorityLow = 1;
sl@0
    55
const TInt KUriPriorityNone = 0;
sl@0
    56
sl@0
    57
static const TUid KUidInterfaceFormatDecode = {KMmfUidPluginInterfaceFormatDecode};
sl@0
    58
static const TUid KUidInterfaceFormatEncode = {KMmfUidPluginInterfaceFormatEncode};
sl@0
    59
static const TUid KUidInterfaceMMFController = {KMmfUidPluginInterfaceController};
sl@0
    60
sl@0
    61
sl@0
    62
EXPORT_C CMMFFormatSelectionParameters* CMMFFormatSelectionParameters::NewL()
sl@0
    63
	{
sl@0
    64
	CMMFFormatSelectionParameters* s = CMMFFormatSelectionParameters::NewLC();
sl@0
    65
	CleanupStack::Pop(s);
sl@0
    66
	return s;
sl@0
    67
	}
sl@0
    68
sl@0
    69
EXPORT_C CMMFFormatSelectionParameters* CMMFFormatSelectionParameters::NewLC()
sl@0
    70
	{
sl@0
    71
	CMMFFormatSelectionParameters* s = new(ELeave) CMMFFormatSelectionParameters;
sl@0
    72
	CleanupStack::PushL(s);
sl@0
    73
	return s;
sl@0
    74
	}
sl@0
    75
sl@0
    76
CMMFFormatSelectionParameters* CMMFFormatSelectionParameters::NewL(const CMMFFormatSelectionParameters& aParams)
sl@0
    77
	{
sl@0
    78
	CMMFFormatSelectionParameters* s = CMMFFormatSelectionParameters::NewLC();
sl@0
    79
	s->ConstructL(aParams);
sl@0
    80
	CleanupStack::Pop(s);
sl@0
    81
	return s;
sl@0
    82
	}
sl@0
    83
sl@0
    84
void CMMFFormatSelectionParameters::ConstructL(const CMMFFormatSelectionParameters& aParams)
sl@0
    85
	{
sl@0
    86
	iMatchReqData = CMatchData::CreateL();
sl@0
    87
	iMatchReqData->SetMatchDataL(aParams.MatchData());
sl@0
    88
	iMatchReqData->SetMatchUriSchemeL(aParams.MatchUriScheme());
sl@0
    89
	iMatchDataType = aParams.MatchDataType();
sl@0
    90
	}
sl@0
    91
sl@0
    92
CMMFFormatSelectionParameters::~CMMFFormatSelectionParameters()
sl@0
    93
	{
sl@0
    94
	delete iMatchReqData;
sl@0
    95
	iMatchReqData= NULL;
sl@0
    96
	}
sl@0
    97
sl@0
    98
CMMFFormatSelectionParameters::CMMFFormatSelectionParameters()
sl@0
    99
	{
sl@0
   100
	iMatchDataType = EMatchAny;
sl@0
   101
	}
sl@0
   102
	
sl@0
   103
EXPORT_C void CMMFFormatSelectionParameters::SetMatchToFileNameL(const TDesC& aFileName)
sl@0
   104
	{
sl@0
   105
	delete iMatchReqData;
sl@0
   106
	iMatchReqData = NULL;
sl@0
   107
	iMatchDataType = EMatchAny;	
sl@0
   108
	// Extract the extension from the data passed in
sl@0
   109
sl@0
   110
	// Parse the path and extract the extension
sl@0
   111
	_LIT( KDot, "." ) ;
sl@0
   112
	_LIT8( KDot8, "." );
sl@0
   113
sl@0
   114
	// If there is no dot "." in aFileName then assume that we have been passed the extension only (if KMaxExtLen or less)
sl@0
   115
	if ( (aFileName.Length() <= KMaxExtLen) && (aFileName.Find( KDot ) == KErrNotFound) )
sl@0
   116
		{
sl@0
   117
		RBuf8 temp;
sl@0
   118
		CleanupClosePushL(temp);
sl@0
   119
		temp.CreateL(aFileName.Length()+1);
sl@0
   120
		User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, aFileName));
sl@0
   121
		temp.Insert(0,KDot8);
sl@0
   122
		
sl@0
   123
		iMatchReqData = CMatchData::CreateL();
sl@0
   124
		iMatchReqData->SetMatchDataL(temp);
sl@0
   125
		
sl@0
   126
		CleanupStack::PopAndDestroy(&temp);
sl@0
   127
		
sl@0
   128
		}
sl@0
   129
	else if ( aFileName.Find( KDot ) == 0 )  // the first character is dot so assume extension only
sl@0
   130
		{
sl@0
   131
		RBuf8 temp;
sl@0
   132
		CleanupClosePushL(temp);
sl@0
   133
		temp.CreateL(aFileName.Length());
sl@0
   134
		User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, aFileName));
sl@0
   135
			
sl@0
   136
		iMatchReqData = CMatchData::CreateL();
sl@0
   137
		iMatchReqData->SetMatchDataL(temp);
sl@0
   138
		
sl@0
   139
		CleanupStack::PopAndDestroy(&temp);
sl@0
   140
		
sl@0
   141
		}
sl@0
   142
	else // We have been given the whole filename.  Use TParse to extract the extension.
sl@0
   143
		{
sl@0
   144
		TParse parser ;
sl@0
   145
		parser.Set( aFileName, NULL, NULL ) ;
sl@0
   146
		if ( !( parser.NamePresent() ) )
sl@0
   147
			User::Leave( KErrBadName ) ;
sl@0
   148
		if ( !( parser.PathPresent() ) )
sl@0
   149
			{
sl@0
   150
			RFs fsSession ;
sl@0
   151
			User::LeaveIfError(fsSession.Connect());
sl@0
   152
			TInt error = fsSession.Parse(aFileName, parser);
sl@0
   153
			fsSession.Close();
sl@0
   154
			User::LeaveIfError(error);
sl@0
   155
			}
sl@0
   156
		// Parser should now have the full filename and path
sl@0
   157
		TPtrC extension = parser.Ext();
sl@0
   158
		
sl@0
   159
		RBuf8 temp;
sl@0
   160
		CleanupClosePushL(temp);
sl@0
   161
		temp.CreateL(extension.Length());
sl@0
   162
		User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(temp, extension));
sl@0
   163
			
sl@0
   164
		iMatchReqData = CMatchData::CreateL();
sl@0
   165
		iMatchReqData->SetMatchDataL(temp);
sl@0
   166
		
sl@0
   167
		CleanupStack::PopAndDestroy(&temp);
sl@0
   168
		
sl@0
   169
		}
sl@0
   170
sl@0
   171
	// If we're here, we must now have the file extension
sl@0
   172
	iMatchDataType = EMatchFileExtension;
sl@0
   173
	}
sl@0
   174
	
sl@0
   175
EXPORT_C void CMMFFormatSelectionParameters::SetMatchToUriL(const TDesC& aUrl)
sl@0
   176
	{
sl@0
   177
	delete iMatchReqData;
sl@0
   178
	iMatchReqData = NULL;
sl@0
   179
	iMatchDataType = EMatchAny;	
sl@0
   180
	
sl@0
   181
	CUri8* uri = UriUtils::CreateUriL(aUrl); //Converts the TDesC16 aUrl to TDesC8 type
sl@0
   182
   	CleanupStack::PushL(uri);
sl@0
   183
  	const TDesC8& path = uri->Uri().Extract(EUriPath);
sl@0
   184
	
sl@0
   185
	// Now parse the file name 
sl@0
   186
   	TInt pos = path.LocateReverse('.');
sl@0
   187
   
sl@0
   188
   	if(pos != KErrNotFound) // if not found, then by default match data is NULL
sl@0
   189
   		{
sl@0
   190
   		TPtrC8 extension(path.Right(path.Length()-pos));
sl@0
   191
   		iMatchReqData = CMatchData::CreateL();
sl@0
   192
   		iMatchReqData->SetMatchDataL(extension);
sl@0
   193
  		}
sl@0
   194
   	CleanupStack::PopAndDestroy(uri);
sl@0
   195
   
sl@0
   196
   	// If we're here, we must now have the file extension
sl@0
   197
   	// Use match file extension, because we are matching to the file extension of the file specified by the URI
sl@0
   198
  	iMatchDataType = EMatchFileExtension;
sl@0
   199
	}
sl@0
   200
	
sl@0
   201
/**
sl@0
   202
	@publishedPartner
sl@0
   203
	@prototype
sl@0
   204
	
sl@0
   205
	Sets this object to match to uri scheme and file extension specified by a URI.
sl@0
   206
	
sl@0
   207
	The Uri scheme and extension are saved in iMatchReqData. Further,iMatchData contains uri extension, 
sl@0
   208
	iMatchUriScheme contains uri scheme.
sl@0
   209
sl@0
   210
	@param  aUri
sl@0
   211
	        The URI containing the scheme and uri extension to be matched. 
sl@0
   212
sl@0
   213
*/	
sl@0
   214
EXPORT_C void CMMFFormatSelectionParameters::SetMatchToUriSupportL(const TDesC& aUrl)
sl@0
   215
	{
sl@0
   216
	delete iMatchReqData;
sl@0
   217
	iMatchReqData = NULL;
sl@0
   218
	iMatchDataType = EMatchAny;	
sl@0
   219
	
sl@0
   220
	CUri8* uri = UriUtils::CreateUriL(aUrl); //Converts the TDesC16 aUrl to TDesC8 type
sl@0
   221
	CleanupStack::PushL(uri);
sl@0
   222
	
sl@0
   223
	const TDesC8& scheme = uri->Uri().Extract(EUriScheme);  //get the uri scheme
sl@0
   224
	iMatchReqData = CMatchData::CreateL();
sl@0
   225
	iMatchReqData->SetMatchUriSchemeL(scheme);
sl@0
   226
	
sl@0
   227
	const TDesC8& path = uri->Uri().Extract(EUriPath); 		
sl@0
   228
	// Now parse the file name 
sl@0
   229
	TInt pos = path.LocateReverse('.');
sl@0
   230
	
sl@0
   231
	if(pos != KErrNotFound) // if not found, by default match data is NULL
sl@0
   232
		{
sl@0
   233
		TPtrC8 extension(path.Right(path.Length()-pos));
sl@0
   234
		iMatchReqData->SetMatchDataL(extension);
sl@0
   235
 		}
sl@0
   236
		
sl@0
   237
	CleanupStack::PopAndDestroy(uri);
sl@0
   238
	// If we're here, we must now have the uri saved in iMatchData. Now, set match type 
sl@0
   239
	// to EMatchUri for checking schema and uri extension
sl@0
   240
	iMatchDataType = EMatchUri;
sl@0
   241
	}
sl@0
   242
	
sl@0
   243
sl@0
   244
sl@0
   245
EXPORT_C void CMMFFormatSelectionParameters::SetMatchToMimeTypeL(const TDesC8& aMimeType)
sl@0
   246
	{
sl@0
   247
	delete iMatchReqData;
sl@0
   248
	iMatchReqData = NULL;
sl@0
   249
	iMatchDataType = EMatchAny;	
sl@0
   250
	
sl@0
   251
	iMatchReqData = CMatchData::CreateL();
sl@0
   252
	iMatchReqData->SetMatchDataL(aMimeType);
sl@0
   253
	iMatchDataType = EMatchMimeType;
sl@0
   254
	}
sl@0
   255
sl@0
   256
EXPORT_C void CMMFFormatSelectionParameters::SetMatchToHeaderDataL(const TDesC8& aHeaderData)
sl@0
   257
	{
sl@0
   258
	delete iMatchReqData;
sl@0
   259
	iMatchReqData = NULL;
sl@0
   260
	iMatchDataType = EMatchAny;	
sl@0
   261
	
sl@0
   262
	iMatchReqData = CMatchData::CreateL();
sl@0
   263
	iMatchReqData->SetMatchDataL(aHeaderData);	
sl@0
   264
	iMatchDataType = EMatchHeaderData;
sl@0
   265
	}
sl@0
   266
sl@0
   267
EXPORT_C const TDesC8& CMMFFormatSelectionParameters::MatchData() const
sl@0
   268
	{
sl@0
   269
	if (iMatchReqData)
sl@0
   270
		{
sl@0
   271
		return iMatchReqData->MatchData();
sl@0
   272
		}
sl@0
   273
	else
sl@0
   274
		{
sl@0
   275
		return KNullDesC8;	
sl@0
   276
		}
sl@0
   277
	}
sl@0
   278
sl@0
   279
/**
sl@0
   280
	@publishedPartner
sl@0
   281
	@prototype
sl@0
   282
	
sl@0
   283
	Returns the uri scheme used to perform the plugin match.
sl@0
   284
	
sl@0
   285
	@return The uri scheme.
sl@0
   286
sl@0
   287
*/	
sl@0
   288
EXPORT_C const TDesC8& CMMFFormatSelectionParameters::MatchUriScheme() const
sl@0
   289
	{
sl@0
   290
	if (iMatchReqData)
sl@0
   291
		{
sl@0
   292
		return iMatchReqData->MatchUriScheme();
sl@0
   293
		}
sl@0
   294
	else
sl@0
   295
		{
sl@0
   296
		return KNullDesC8;
sl@0
   297
		}
sl@0
   298
	}
sl@0
   299
	
sl@0
   300
EXPORT_C CMMFFormatSelectionParameters::TMatchDataType CMMFFormatSelectionParameters::MatchDataType() const
sl@0
   301
	{
sl@0
   302
	return iMatchDataType;
sl@0
   303
	}
sl@0
   304
sl@0
   305
CMMFPluginSelectionParameters::CMMFPluginSelectionParameters(TUid aPluginInterfaceUid) :
sl@0
   306
	iPluginInterfaceUid(aPluginInterfaceUid)
sl@0
   307
	{
sl@0
   308
	iPreferredSupplierMatchType = ENoPreferredSupplierMatch;
sl@0
   309
	iMediaIdMatchType = ENoMediaIdMatch;
sl@0
   310
	}
sl@0
   311
sl@0
   312
CMMFPluginSelectionParameters::~CMMFPluginSelectionParameters()
sl@0
   313
	{
sl@0
   314
	delete iPreferredSupplier;
sl@0
   315
	iMediaIds.Reset();
sl@0
   316
	iMediaIds.Close();
sl@0
   317
	}
sl@0
   318
sl@0
   319
EXPORT_C void CMMFPluginSelectionParameters::SetPreferredSupplierL(const TDesC& aPreferredSupplier, TPreferredSupplierMatchType aMatchType)
sl@0
   320
	{
sl@0
   321
	delete iPreferredSupplier;
sl@0
   322
	iPreferredSupplier = NULL;
sl@0
   323
	iPreferredSupplier = aPreferredSupplier.AllocL();
sl@0
   324
	iPreferredSupplierMatchType = aMatchType;
sl@0
   325
	}
sl@0
   326
sl@0
   327
EXPORT_C void CMMFPluginSelectionParameters::SetMediaIdsL(const RArray<TUid>& aMediaIds, TMediaIdMatchType aMatchType)
sl@0
   328
	{
sl@0
   329
	iMediaIds.Reset();
sl@0
   330
	for (TInt i=0; i<aMediaIds.Count(); i++)
sl@0
   331
		{
sl@0
   332
		User::LeaveIfError(iMediaIds.Append(aMediaIds[i]));
sl@0
   333
		}
sl@0
   334
	iMediaIdMatchType = aMatchType;
sl@0
   335
	}
sl@0
   336
sl@0
   337
EXPORT_C const TDesC& CMMFPluginSelectionParameters::PreferredSupplier() const
sl@0
   338
	{
sl@0
   339
	if (iPreferredSupplier)
sl@0
   340
		return *iPreferredSupplier;
sl@0
   341
	else
sl@0
   342
		return KNullDesC;
sl@0
   343
	}
sl@0
   344
sl@0
   345
EXPORT_C CMMFPluginSelectionParameters::TPreferredSupplierMatchType CMMFPluginSelectionParameters::PreferredSupplierMatchType() const
sl@0
   346
	{
sl@0
   347
	return iPreferredSupplierMatchType;
sl@0
   348
	}
sl@0
   349
sl@0
   350
EXPORT_C const RArray<TUid>& CMMFPluginSelectionParameters::MediaIds() const
sl@0
   351
	{
sl@0
   352
	return iMediaIds;
sl@0
   353
	}
sl@0
   354
sl@0
   355
EXPORT_C CMMFPluginSelectionParameters::TMediaIdMatchType CMMFPluginSelectionParameters::MediaIdMatchType() const
sl@0
   356
	{
sl@0
   357
	return iMediaIdMatchType;
sl@0
   358
	}
sl@0
   359
sl@0
   360
EXPORT_C TUid CMMFPluginSelectionParameters::InterfaceUid() const
sl@0
   361
	{
sl@0
   362
	return iPluginInterfaceUid;
sl@0
   363
	}
sl@0
   364
sl@0
   365
sl@0
   366
TBool CMMFPluginSelectionParameters::CheckMediaIdSupportL(const CMMFPluginImplementationInformation& aPlugin) const
sl@0
   367
	{
sl@0
   368
	TBool ret = EFalse;
sl@0
   369
	switch (MediaIdMatchType())
sl@0
   370
		{
sl@0
   371
	case CMMFPluginSelectionParameters::ENoMediaIdMatch:
sl@0
   372
		// No match required so suitable
sl@0
   373
		ret = ETrue;
sl@0
   374
		break;
sl@0
   375
	case CMMFPluginSelectionParameters::EAllowOtherMediaIds:
sl@0
   376
		// Just check that the requested media id is supported by the plugin
sl@0
   377
		{
sl@0
   378
		for (TInt i=0; i<MediaIds().Count(); i++)
sl@0
   379
			{
sl@0
   380
			if (aPlugin.SupportsMediaId(MediaIds()[i]))
sl@0
   381
				{
sl@0
   382
				ret = ETrue;
sl@0
   383
				break;
sl@0
   384
				}
sl@0
   385
			}
sl@0
   386
		break;
sl@0
   387
		}
sl@0
   388
	case CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds:
sl@0
   389
		// Check the media id counts are the same, and that all requested ones are present
sl@0
   390
		{
sl@0
   391
		TInt found=0;
sl@0
   392
		for (TInt i=0; i<MediaIds().Count(); i++)
sl@0
   393
			{
sl@0
   394
			if (aPlugin.SupportsMediaId(MediaIds()[i]))
sl@0
   395
				found++;
sl@0
   396
			}
sl@0
   397
		// Check all request mediaIds are present
sl@0
   398
		if ((found == MediaIds().Count()) && (found == aPlugin.SupportedMediaIds().Count()))
sl@0
   399
			ret = ETrue;
sl@0
   400
		break;
sl@0
   401
		}
sl@0
   402
	default:
sl@0
   403
		User::Leave(KErrNotSupported);
sl@0
   404
		break;
sl@0
   405
		}
sl@0
   406
	return ret;
sl@0
   407
	}
sl@0
   408
sl@0
   409
sl@0
   410
sl@0
   411
EXPORT_C CMMFControllerPluginSelectionParameters* CMMFControllerPluginSelectionParameters::NewL()
sl@0
   412
	{
sl@0
   413
	CMMFControllerPluginSelectionParameters* s = CMMFControllerPluginSelectionParameters::NewLC();
sl@0
   414
	CleanupStack::Pop(s);
sl@0
   415
	return s;	
sl@0
   416
	}
sl@0
   417
sl@0
   418
EXPORT_C CMMFControllerPluginSelectionParameters* CMMFControllerPluginSelectionParameters::NewLC()
sl@0
   419
	{
sl@0
   420
	CMMFControllerPluginSelectionParameters* s = new(ELeave) CMMFControllerPluginSelectionParameters;
sl@0
   421
	CleanupStack::PushL(s);
sl@0
   422
	return s;
sl@0
   423
	}
sl@0
   424
sl@0
   425
CMMFControllerPluginSelectionParameters::CMMFControllerPluginSelectionParameters() :
sl@0
   426
	CMMFPluginSelectionParameters(KUidInterfaceMMFController)
sl@0
   427
	{
sl@0
   428
	}
sl@0
   429
sl@0
   430
CMMFControllerPluginSelectionParameters::~CMMFControllerPluginSelectionParameters()
sl@0
   431
	{
sl@0
   432
	delete iRequiredPlayFormatSupport;
sl@0
   433
	delete iRequiredRecordFormatSupport;
sl@0
   434
	}
sl@0
   435
sl@0
   436
EXPORT_C void CMMFControllerPluginSelectionParameters::SetRequiredPlayFormatSupportL(const CMMFFormatSelectionParameters& aRequiredSupport)
sl@0
   437
	{
sl@0
   438
	delete iRequiredPlayFormatSupport;
sl@0
   439
	iRequiredPlayFormatSupport = NULL;
sl@0
   440
	iRequiredPlayFormatSupport = CMMFFormatSelectionParameters::NewL(aRequiredSupport);
sl@0
   441
	}
sl@0
   442
sl@0
   443
EXPORT_C void CMMFControllerPluginSelectionParameters::SetRequiredRecordFormatSupportL(const CMMFFormatSelectionParameters& aRequiredSupport)
sl@0
   444
	{
sl@0
   445
	delete iRequiredRecordFormatSupport;
sl@0
   446
	iRequiredRecordFormatSupport = NULL;
sl@0
   447
	iRequiredRecordFormatSupport = CMMFFormatSelectionParameters::NewL(aRequiredSupport);
sl@0
   448
	}
sl@0
   449
sl@0
   450
EXPORT_C void CMMFControllerPluginSelectionParameters::ListImplementationsL(RMMFControllerImplInfoArray& aImplementations) const
sl@0
   451
	{
sl@0
   452
	aImplementations.ResetAndDestroy();
sl@0
   453
sl@0
   454
	RImplInfoPtrArray ecomArray;
sl@0
   455
	CleanupResetAndDestroyPushL(ecomArray);
sl@0
   456
sl@0
   457
	MmPluginUtils::FindImplementationsL(InterfaceUid(), ecomArray);
sl@0
   458
sl@0
   459
	TInt index;
sl@0
   460
	// Create Controller Implementation Information for each entry
sl@0
   461
	for (index=0; index<ecomArray.Count(); index++)
sl@0
   462
		{
sl@0
   463
		CMMFControllerImplementationInformation* c = NULL;
sl@0
   464
		if (ecomArray[index] == NULL)
sl@0
   465
			{
sl@0
   466
			User::Leave(KErrNoMemory);
sl@0
   467
			}
sl@0
   468
		TRAPD(error, c = CMMFControllerImplementationInformation::NewL(*(ecomArray[index])));
sl@0
   469
sl@0
   470
		if (error == KErrNone)
sl@0
   471
			{
sl@0
   472
			CleanupStack::PushL(c);
sl@0
   473
			
sl@0
   474
		// If required, get the play and record formats for the controller.
sl@0
   475
			if (iRequiredPlayFormatSupport)
sl@0
   476
				{
sl@0
   477
				c->GetPlayFormatsL();
sl@0
   478
				}
sl@0
   479
			if (iRequiredRecordFormatSupport)
sl@0
   480
				{
sl@0
   481
				c->GetRecordFormatsL();
sl@0
   482
				}
sl@0
   483
			
sl@0
   484
			// Find out whether this controller matches the client's requirements...
sl@0
   485
			TBool suitable = EFalse;
sl@0
   486
			TInt arrayPos; 
sl@0
   487
			suitable = CheckUriSupport(iRequiredPlayFormatSupport, c, c->PlayFormats());
sl@0
   488
			if(suitable)
sl@0
   489
				{
sl@0
   490
				suitable = CheckUriSupport(iRequiredRecordFormatSupport, c, c->RecordFormats());
sl@0
   491
				}
sl@0
   492
			if(suitable)
sl@0
   493
				{
sl@0
   494
				MatchImplementationToSelectParamsL(aImplementations, *c, arrayPos);
sl@0
   495
				}
sl@0
   496
			else
sl@0
   497
				{
sl@0
   498
				arrayPos = -1;	
sl@0
   499
				}
sl@0
   500
			
sl@0
   501
			if (arrayPos >=0)
sl@0
   502
				{
sl@0
   503
				// This plugin is suitable - insert it into the array at the suggested position
sl@0
   504
				User::LeaveIfError(aImplementations.Insert(c, arrayPos));
sl@0
   505
				CleanupStack::Pop(c);
sl@0
   506
				}
sl@0
   507
			else
sl@0
   508
				{
sl@0
   509
				// This plugin isn't suitable so just destroy it
sl@0
   510
				CleanupStack::PopAndDestroy(c);
sl@0
   511
				}
sl@0
   512
			}
sl@0
   513
		else if (error != KErrCorrupt)
sl@0
   514
			{
sl@0
   515
			// Ignore the plugin if it is corrupt.  Otherwise, leave.
sl@0
   516
			// if error !=KErrNone, c hasn't been constructed so it is safe to leave
sl@0
   517
			User::Leave(error);
sl@0
   518
			}
sl@0
   519
		}
sl@0
   520
sl@0
   521
	CleanupStack::PopAndDestroy();//ecomArray
sl@0
   522
	}
sl@0
   523
sl@0
   524
void CMMFControllerPluginSelectionParameters::MatchImplementationToSelectParamsL(RMMFControllerImplInfoArray& aImplementations, const CMMFControllerImplementationInformation& aPlugin, TInt& aArrayPos) const
sl@0
   525
	{
sl@0
   526
	TBool suitable = EFalse;
sl@0
   527
	
sl@0
   528
	// First, check whether the plugin supports the required play formats
sl@0
   529
	suitable = CheckFormatSupportL(iRequiredPlayFormatSupport, aPlugin.PlayFormats());
sl@0
   530
	
sl@0
   531
	// Next, check the record formats
sl@0
   532
	if (suitable)
sl@0
   533
		suitable = CheckFormatSupportL(iRequiredRecordFormatSupport, aPlugin.RecordFormats());
sl@0
   534
		
sl@0
   535
	// Next, check for correct media id support
sl@0
   536
	if (suitable)
sl@0
   537
		suitable = CheckMediaIdSupportL(aPlugin);
sl@0
   538
sl@0
   539
	// Finally, calculate the position the plugin should take in aImplementations depending on the preferred supplier and version number.
sl@0
   540
	if (suitable)
sl@0
   541
		aArrayPos = CheckPreferredSupplierL(aImplementations, aPlugin);
sl@0
   542
	else
sl@0
   543
		aArrayPos = -1;
sl@0
   544
	}
sl@0
   545
sl@0
   546
/**
sl@0
   547
	Checks the given Controller for uri support. Uri support may be there 
sl@0
   548
	if either requiredscheme or extension matches with that given controller
sl@0
   549
	
sl@0
   550
	@param  aSelectParams 
sl@0
   551
			Describes the selection parameter which a controller needs to 
sl@0
   552
			support in order to be selected
sl@0
   553
			
sl@0
   554
	@param	aPlugin
sl@0
   555
			The controller plugin which is checked for uri support 
sl@0
   556
			
sl@0
   557
	@param	aFormats
sl@0
   558
			The play or record formats looked for extension match
sl@0
   559
*/	
sl@0
   560
TBool CMMFControllerPluginSelectionParameters::CheckUriSupport(CMMFFormatSelectionParameters* aSelectParams, CMMFControllerImplementationInformation* aPlugin, const RMMFFormatImplInfoArray& aFormats) const
sl@0
   561
	{
sl@0
   562
	// If aSelectParams are NULL (ie none were set) then the plugin must be suitable!
sl@0
   563
	if (aSelectParams == NULL)
sl@0
   564
		return ETrue;
sl@0
   565
	
sl@0
   566
	//If EMatchUri not set then the plugin might be suitable!
sl@0
   567
	if(aSelectParams->MatchDataType() != CMMFFormatSelectionParameters::EMatchUri)
sl@0
   568
		{
sl@0
   569
		return ETrue;
sl@0
   570
		}
sl@0
   571
		
sl@0
   572
	TBool suitable = EFalse;
sl@0
   573
	TInt index;
sl@0
   574
	
sl@0
   575
	//If <n>yes is there in the aPlugin's opaque data, 
sl@0
   576
	//URI support not assumed. So, don't load the controller
sl@0
   577
	if(!aPlugin->SupportsNetworkCapability())
sl@0
   578
		{
sl@0
   579
		return EFalse;	
sl@0
   580
		}
sl@0
   581
sl@0
   582
    //the uri scheme to be matched for
sl@0
   583
	if (aPlugin->SupportsUriScheme(aSelectParams->MatchUriScheme()))
sl@0
   584
		{
sl@0
   585
		aPlugin->SetUriPriority(KUriPriorityMedium);
sl@0
   586
		suitable = ETrue;
sl@0
   587
		}
sl@0
   588
	else
sl@0
   589
		{
sl@0
   590
		//if other uri scheme support declared, but not the required one,
sl@0
   591
		// even then controller not supported
sl@0
   592
		if(aPlugin->SupportedUriSchemes().Count() > 0)
sl@0
   593
			{
sl@0
   594
			return EFalse;		
sl@0
   595
			}
sl@0
   596
		}
sl@0
   597
	
sl@0
   598
		
sl@0
   599
	//then match Uri extension. .
sl@0
   600
	
sl@0
   601
	//if ctrl has no network capability, then lowest priority given on matching file extension
sl@0
   602
	for (index=0;index<aFormats.Count();index++)
sl@0
   603
		{
sl@0
   604
		if (aFormats[index]-> SupportsFileExtension(aSelectParams->MatchData()))
sl@0
   605
			{
sl@0
   606
			if(!suitable)
sl@0
   607
				{
sl@0
   608
				aPlugin->SetUriPriority(KUriPriorityLow);	
sl@0
   609
				}
sl@0
   610
			else
sl@0
   611
				{
sl@0
   612
				aPlugin->SetUriPriority(KUriPriorityHigh);
sl@0
   613
				}
sl@0
   614
			
sl@0
   615
			suitable = ETrue;
sl@0
   616
			break;
sl@0
   617
			}
sl@0
   618
		}
sl@0
   619
	
sl@0
   620
	return suitable;
sl@0
   621
	}
sl@0
   622
sl@0
   623
TInt CMMFControllerPluginSelectionParameters::CheckPreferredSupplierL(RMMFControllerImplInfoArray& aImplementations, const CMMFControllerImplementationInformation& aPlugin) const
sl@0
   624
	{
sl@0
   625
	// Set the return value to indicated the plugin is not suitable.
sl@0
   626
	TBool pluginSuitable = EFalse;
sl@0
   627
	TBool needToPlaceInVersionOrder = EFalse;
sl@0
   628
	TBool needToPlaceInUriPriorityOrder = EFalse;
sl@0
   629
sl@0
   630
	if((iRequiredPlayFormatSupport && (iRequiredPlayFormatSupport->MatchDataType() == CMMFFormatSelectionParameters::EMatchUri))
sl@0
   631
	 || (iRequiredRecordFormatSupport && (iRequiredRecordFormatSupport->MatchDataType() == CMMFFormatSelectionParameters::EMatchUri)))
sl@0
   632
		{
sl@0
   633
		needToPlaceInUriPriorityOrder = ETrue;
sl@0
   634
		}
sl@0
   635
	
sl@0
   636
	switch (PreferredSupplierMatchType())
sl@0
   637
		{
sl@0
   638
	case ENoPreferredSupplierMatch:
sl@0
   639
		// No match, so suitable.
sl@0
   640
		pluginSuitable = ETrue;
sl@0
   641
	    break;
sl@0
   642
	case EPreferredSupplierPluginsFirstInList:
sl@0
   643
		pluginSuitable = ETrue;
sl@0
   644
		if (aPlugin.SupportsSupplier(PreferredSupplier()))
sl@0
   645
			needToPlaceInVersionOrder = ETrue;
sl@0
   646
		break;
sl@0
   647
	case EOnlyPreferredSupplierPluginsReturned:
sl@0
   648
		if (aPlugin.SupportsSupplier(PreferredSupplier()))
sl@0
   649
			{
sl@0
   650
			pluginSuitable = ETrue;
sl@0
   651
			needToPlaceInVersionOrder = ETrue;
sl@0
   652
			}
sl@0
   653
		break;
sl@0
   654
	default:
sl@0
   655
		User::Leave(KErrNotSupported);
sl@0
   656
		}
sl@0
   657
sl@0
   658
	TInt arrayPos;
sl@0
   659
			
sl@0
   660
	if (!pluginSuitable)
sl@0
   661
		{
sl@0
   662
		arrayPos = -1;
sl@0
   663
		}
sl@0
   664
		
sl@0
   665
	else
sl@0
   666
		{
sl@0
   667
		if(needToPlaceInUriPriorityOrder)
sl@0
   668
			{
sl@0
   669
			arrayPos = aImplementations.Count();
sl@0
   670
			// Cycle through aImplementations to find the first plugin with a uri priority LOWER than aPlugin's
sl@0
   671
			for (TInt i=0; i<aImplementations.Count(); i++)
sl@0
   672
				{
sl@0
   673
				CMMFControllerImplementationInformation* c = aImplementations[i];
sl@0
   674
				
sl@0
   675
				if(PreferredSupplierMatchType() == ENoPreferredSupplierMatch) //case 1
sl@0
   676
					{
sl@0
   677
					/**
sl@0
   678
					Place the plugin based on its Uri priority.
sl@0
   679
					Arrange the plugins in Decreasing order of their priority. In case if two or more plugins 
sl@0
   680
					have similar priority, append the next one at the end. 
sl@0
   681
					*/
sl@0
   682
					if (c->UriPriority() < aPlugin.UriPriority())
sl@0
   683
						{
sl@0
   684
						arrayPos = i;//plugin will be inserted before c in the array
sl@0
   685
						break;
sl@0
   686
						}
sl@0
   687
					}
sl@0
   688
				else
sl@0
   689
					{
sl@0
   690
					if(!needToPlaceInVersionOrder)  //case 2
sl@0
   691
						{
sl@0
   692
						/**
sl@0
   693
						This reflects the case EPreferredSupplierPluginsFirstInList and 
sl@0
   694
						aPlugin supplier not matching.
sl@0
   695
						Place the plugin based on its Uri Priority after the required suppliers plugin.
sl@0
   696
						If priority is equal, new plugin will be placed last.
sl@0
   697
						*/
sl@0
   698
						if( (c->Supplier() != PreferredSupplier()) && (c->UriPriority() < aPlugin.UriPriority()))
sl@0
   699
							{
sl@0
   700
							arrayPos = i;//plugin will be inserted before c in the array
sl@0
   701
							break;
sl@0
   702
							}
sl@0
   703
						}
sl@0
   704
					else  //case 3
sl@0
   705
						{
sl@0
   706
						/** 
sl@0
   707
						This reflects the case where 
sl@0
   708
						Supplier matches and EPreferredSupplierPluginsFirstInList is specified.
sl@0
   709
						OR
sl@0
   710
						Supplier matches and EOnlyPreferredSupplierPluginsReturned is specified.
sl@0
   711
						*/
sl@0
   712
						if(c->Supplier() == PreferredSupplier()) 
sl@0
   713
							{
sl@0
   714
							if(c->UriPriority() == aPlugin.UriPriority())
sl@0
   715
								{
sl@0
   716
								if(c->Version() <= aPlugin.Version())
sl@0
   717
									{
sl@0
   718
									arrayPos = i;//plugin will be inserted before c in the array
sl@0
   719
									break;
sl@0
   720
									}
sl@0
   721
								}
sl@0
   722
							else 
sl@0
   723
								{
sl@0
   724
								if(c->UriPriority() < aPlugin.UriPriority())
sl@0
   725
									{
sl@0
   726
									arrayPos = i;//plugin will be inserted before c in the array
sl@0
   727
									break;
sl@0
   728
									}
sl@0
   729
								}
sl@0
   730
							}
sl@0
   731
						else
sl@0
   732
							{
sl@0
   733
							/**
sl@0
   734
							This is a case of aImplementations now having unpreferred suppliers 
sl@0
   735
							when EPreferredSupplierPluginsFirstInList is specified and aPlugin is
sl@0
   736
							of preferred supplier but least priority.
sl@0
   737
							*/
sl@0
   738
							arrayPos = i;//plugin will be inserted before c in the array
sl@0
   739
							break;
sl@0
   740
							}
sl@0
   741
						}
sl@0
   742
					}
sl@0
   743
				}
sl@0
   744
			}
sl@0
   745
			
sl@0
   746
		else
sl@0
   747
			{
sl@0
   748
			if (!needToPlaceInVersionOrder)  
sl@0
   749
				{
sl@0
   750
				/**
sl@0
   751
				place it at the end.
sl@0
   752
				*/
sl@0
   753
				arrayPos = aImplementations.Count();
sl@0
   754
				}
sl@0
   755
			else
sl@0
   756
				{
sl@0
   757
				// Insert the plugin at the beginning of the array, in version order if possible.
sl@0
   758
				// Make an assumption: if we've been asked for format support, then only plugins 
sl@0
   759
				// that support the same format will be in the array - so ordering them by version
sl@0
   760
				// will be meaningful.  Otherwise, there's no point.
sl@0
   761
				if ((iRequiredPlayFormatSupport && (iRequiredPlayFormatSupport->MatchDataType() != CMMFFormatSelectionParameters::EMatchAny))
sl@0
   762
					|| (iRequiredRecordFormatSupport && (iRequiredRecordFormatSupport->MatchDataType() != CMMFFormatSelectionParameters::EMatchAny)))
sl@0
   763
					{
sl@0
   764
					// Put the plugin in version order at the beginning of the list
sl@0
   765
sl@0
   766
					// Set aArrayPos to the end of the array in case this plugin has the lowest version number
sl@0
   767
					arrayPos = aImplementations.Count();
sl@0
   768
					// Cycle through aImplementations to find the first plugin with a version number LOWER than aPlugin
sl@0
   769
					for (TInt i=0; i<aImplementations.Count(); i++)
sl@0
   770
						{
sl@0
   771
						CMMFControllerImplementationInformation* c = aImplementations[i];
sl@0
   772
						if (c->Supplier() == aPlugin.Supplier())
sl@0
   773
							{
sl@0
   774
							if (c->Version() <= aPlugin.Version())
sl@0
   775
								{
sl@0
   776
								arrayPos = i;//plugin will be inserted before c in the array
sl@0
   777
								break;
sl@0
   778
								}
sl@0
   779
							}
sl@0
   780
						else
sl@0
   781
							{
sl@0
   782
							arrayPos = i; //c has wrong supplier so this plugin must go before c
sl@0
   783
							break;
sl@0
   784
							}
sl@0
   785
						}
sl@0
   786
					}
sl@0
   787
				else
sl@0
   788
					{
sl@0
   789
					// We can't use the version numbers meaningfully, so just put this plugin
sl@0
   790
					// at the top of the list.
sl@0
   791
					arrayPos = 0;
sl@0
   792
					}
sl@0
   793
				}
sl@0
   794
			}
sl@0
   795
		}
sl@0
   796
	
sl@0
   797
	return arrayPos;
sl@0
   798
	}
sl@0
   799
sl@0
   800
TBool CMMFControllerPluginSelectionParameters::CheckFormatSupportL(CMMFFormatSelectionParameters* aSelectParams, const RMMFFormatImplInfoArray& aFormats) const
sl@0
   801
	{
sl@0
   802
	// If aSelectParams are NULL (ie none were set) then the plugin must be suitable!
sl@0
   803
	if (aSelectParams == NULL)
sl@0
   804
		return ETrue;
sl@0
   805
sl@0
   806
	TBool suitable = EFalse;
sl@0
   807
sl@0
   808
	// Check all the formats in aFormats.  If any support the required data type, return ETrue.
sl@0
   809
	TInt index;
sl@0
   810
	switch (aSelectParams->MatchDataType())
sl@0
   811
		{
sl@0
   812
	case CMMFFormatSelectionParameters::EMatchAny:
sl@0
   813
		// All plugins intrinsically match this!
sl@0
   814
		suitable = ETrue;
sl@0
   815
		break;
sl@0
   816
	case CMMFFormatSelectionParameters::EMatchFileExtension:
sl@0
   817
		for (index=0;index<aFormats.Count();index++)
sl@0
   818
			{
sl@0
   819
			if (aFormats[index]->SupportsFileExtension(aSelectParams->MatchData()))
sl@0
   820
				{
sl@0
   821
				suitable = ETrue;
sl@0
   822
				break;
sl@0
   823
				}
sl@0
   824
			}
sl@0
   825
		break;
sl@0
   826
	case CMMFFormatSelectionParameters::EMatchMimeType:
sl@0
   827
		for (index=0;index<aFormats.Count();index++)
sl@0
   828
			{
sl@0
   829
			if (aFormats[index]->SupportsMimeType(aSelectParams->MatchData()))
sl@0
   830
				{
sl@0
   831
				suitable = ETrue;
sl@0
   832
				break;
sl@0
   833
				}
sl@0
   834
			}
sl@0
   835
		break;
sl@0
   836
	case CMMFFormatSelectionParameters::EMatchHeaderData:
sl@0
   837
		for (index=0;index<aFormats.Count();index++)
sl@0
   838
			{
sl@0
   839
			if (aFormats[index]->SupportsHeaderDataL(aSelectParams->MatchData()))
sl@0
   840
				{
sl@0
   841
				suitable = ETrue;
sl@0
   842
				break;
sl@0
   843
				}
sl@0
   844
			}
sl@0
   845
		break;
sl@0
   846
		
sl@0
   847
	case CMMFFormatSelectionParameters::EMatchUri:
sl@0
   848
		{
sl@0
   849
		suitable = ETrue; //if uri match specifically looked , then that has been already matched in a CheckUriSupport()
sl@0
   850
		break;	
sl@0
   851
		}
sl@0
   852
		
sl@0
   853
sl@0
   854
	default:
sl@0
   855
		User::Leave(KErrNotSupported);
sl@0
   856
		};
sl@0
   857
sl@0
   858
	return suitable;
sl@0
   859
	}
sl@0
   860
sl@0
   861
sl@0
   862
sl@0
   863
EXPORT_C CMMFControllerSecureDrmPluginSelectionParameters* CMMFControllerSecureDrmPluginSelectionParameters::NewL()
sl@0
   864
	{
sl@0
   865
	CMMFControllerSecureDrmPluginSelectionParameters* s = CMMFControllerSecureDrmPluginSelectionParameters::NewLC();
sl@0
   866
	CleanupStack::Pop(s);
sl@0
   867
	return s;	
sl@0
   868
	}
sl@0
   869
sl@0
   870
EXPORT_C CMMFControllerSecureDrmPluginSelectionParameters* CMMFControllerSecureDrmPluginSelectionParameters::NewLC()
sl@0
   871
	{
sl@0
   872
	CMMFControllerSecureDrmPluginSelectionParameters* s = new(ELeave) CMMFControllerSecureDrmPluginSelectionParameters;
sl@0
   873
	CleanupStack::PushL(s);
sl@0
   874
	return s;
sl@0
   875
	}
sl@0
   876
sl@0
   877
CMMFControllerSecureDrmPluginSelectionParameters::CMMFControllerSecureDrmPluginSelectionParameters() :
sl@0
   878
	CMMFControllerPluginSelectionParameters()
sl@0
   879
	{
sl@0
   880
	}
sl@0
   881
sl@0
   882
EXPORT_C void CMMFControllerSecureDrmPluginSelectionParameters::ListImplementationsL(RMMFControllerImplInfoArray& aImplementations) const
sl@0
   883
	{
sl@0
   884
	CMMFControllerPluginSelectionParameters::ListImplementationsL(aImplementations);
sl@0
   885
	TInt pluginsCount = aImplementations.Count();
sl@0
   886
	for (TInt i = pluginsCount - 1; i >= 0; i--)
sl@0
   887
		{
sl@0
   888
		CMMFControllerImplementationInformation* c = aImplementations[i];
sl@0
   889
		if (!c->SupportsSecureDRMProcessMode())
sl@0
   890
			{
sl@0
   891
			aImplementations.Remove(i);
sl@0
   892
			delete c;
sl@0
   893
			}
sl@0
   894
		}
sl@0
   895
	aImplementations.Compress();
sl@0
   896
	}
sl@0
   897
sl@0
   898
sl@0
   899
sl@0
   900
CMMFFormatPluginSelectionParameters::CMMFFormatPluginSelectionParameters(TUid aInterfaceUid) :
sl@0
   901
	CMMFPluginSelectionParameters(aInterfaceUid)
sl@0
   902
	{
sl@0
   903
	}
sl@0
   904
sl@0
   905
CMMFFormatPluginSelectionParameters::~CMMFFormatPluginSelectionParameters()
sl@0
   906
	{
sl@0
   907
	delete iRequiredFormatSupport;
sl@0
   908
	}
sl@0
   909
sl@0
   910
EXPORT_C void CMMFFormatPluginSelectionParameters::SetRequiredFormatSupportL(const CMMFFormatSelectionParameters& aRequiredSupport)
sl@0
   911
	{
sl@0
   912
	delete iRequiredFormatSupport;
sl@0
   913
	iRequiredFormatSupport = NULL;
sl@0
   914
	iRequiredFormatSupport = CMMFFormatSelectionParameters::NewL(aRequiredSupport);
sl@0
   915
	}
sl@0
   916
sl@0
   917
EXPORT_C void CMMFFormatPluginSelectionParameters::ListImplementationsL(RMMFFormatImplInfoArray& aImplementations) const
sl@0
   918
	{
sl@0
   919
	aImplementations.ResetAndDestroy();
sl@0
   920
sl@0
   921
	RImplInfoPtrArray ecomArray;
sl@0
   922
	CleanupResetAndDestroyPushL(ecomArray);
sl@0
   923
sl@0
   924
	MmPluginUtils::FindImplementationsL(InterfaceUid(), ecomArray);
sl@0
   925
sl@0
   926
sl@0
   927
	TInt index;
sl@0
   928
	// Create Format Implementation Information for each entry
sl@0
   929
	for (index=0; index<ecomArray.Count(); index++)
sl@0
   930
		{
sl@0
   931
		CMMFFormatImplementationInformation* c = NULL;
sl@0
   932
		TRAPD(error, c = CMMFFormatImplementationInformation::NewL(*(ecomArray[index])));
sl@0
   933
sl@0
   934
		if (error == KErrNone)
sl@0
   935
			{
sl@0
   936
			CleanupStack::PushL(c);
sl@0
   937
			// Find out whether this format matches the client's requirements...
sl@0
   938
			TInt arrayPos;
sl@0
   939
			MatchImplementationToSelectParamsL(aImplementations, *c, arrayPos);
sl@0
   940
			if (arrayPos >=0)
sl@0
   941
				{
sl@0
   942
				// This plugin is suitable - insert it into the array at the suggested position
sl@0
   943
				User::LeaveIfError(aImplementations.Insert(c, arrayPos));
sl@0
   944
				CleanupStack::Pop(c);
sl@0
   945
				}
sl@0
   946
			else
sl@0
   947
				{
sl@0
   948
				// This plugin isn't suitable so just destroy it
sl@0
   949
				CleanupStack::PopAndDestroy(c);
sl@0
   950
				}
sl@0
   951
			}
sl@0
   952
		else if (error != KErrCorrupt)
sl@0
   953
			{
sl@0
   954
			// Ignore the plugin if it is corrupt.  Otherwise, leave.
sl@0
   955
			// if error !=KErrNone, c hasn't been constructed so it is safe to leave
sl@0
   956
			User::Leave(error);
sl@0
   957
			}
sl@0
   958
		}
sl@0
   959
sl@0
   960
	CleanupStack::PopAndDestroy();//ecomArray
sl@0
   961
	}
sl@0
   962
sl@0
   963
void CMMFFormatPluginSelectionParameters::MatchImplementationToSelectParamsL(RMMFFormatImplInfoArray& aImplementations, const CMMFFormatImplementationInformation& aPlugin, TInt& aArrayPos) const
sl@0
   964
	{
sl@0
   965
	TBool suitable = EFalse;
sl@0
   966
sl@0
   967
	// First, check whether the plugin supports the required play formats
sl@0
   968
	suitable = CheckFormatSupportL(aPlugin);
sl@0
   969
sl@0
   970
	// Next, check for correct media id support
sl@0
   971
	if (suitable)
sl@0
   972
		suitable = CheckMediaIdSupportL(aPlugin);
sl@0
   973
sl@0
   974
	// Finally, calculate the position the plugin should take in aImplementations depending on the preferred supplier and version number.
sl@0
   975
	if (suitable)
sl@0
   976
		aArrayPos = CheckPreferredSupplierL(aImplementations, aPlugin);
sl@0
   977
	else
sl@0
   978
		aArrayPos = -1;
sl@0
   979
	}
sl@0
   980
sl@0
   981
TInt CMMFFormatPluginSelectionParameters::CheckPreferredSupplierL(RMMFFormatImplInfoArray& aImplementations, const CMMFFormatImplementationInformation& aPlugin) const
sl@0
   982
	{
sl@0
   983
	// Set the return value to indicated the plugin is not suitable.
sl@0
   984
	TBool pluginSuitable = EFalse;
sl@0
   985
	TBool needToPlaceInVersionOrder = EFalse;
sl@0
   986
sl@0
   987
	switch (PreferredSupplierMatchType())
sl@0
   988
		{
sl@0
   989
	case ENoPreferredSupplierMatch:
sl@0
   990
		// No match, so suitable.
sl@0
   991
		pluginSuitable = ETrue;
sl@0
   992
		break;
sl@0
   993
	case EPreferredSupplierPluginsFirstInList:
sl@0
   994
		pluginSuitable = ETrue;
sl@0
   995
		if (aPlugin.SupportsSupplier(PreferredSupplier()))
sl@0
   996
			needToPlaceInVersionOrder = ETrue;
sl@0
   997
		break;
sl@0
   998
	case EOnlyPreferredSupplierPluginsReturned:
sl@0
   999
		if (aPlugin.SupportsSupplier(PreferredSupplier()))
sl@0
  1000
			{
sl@0
  1001
			pluginSuitable = ETrue;
sl@0
  1002
			needToPlaceInVersionOrder = ETrue;
sl@0
  1003
			}
sl@0
  1004
		break;
sl@0
  1005
	default:
sl@0
  1006
		User::Leave(KErrNotSupported);
sl@0
  1007
		}
sl@0
  1008
sl@0
  1009
sl@0
  1010
	TInt arrayPos;
sl@0
  1011
sl@0
  1012
	if (!pluginSuitable)
sl@0
  1013
		{
sl@0
  1014
		arrayPos = -1;
sl@0
  1015
		}
sl@0
  1016
	else
sl@0
  1017
		{
sl@0
  1018
		if (!needToPlaceInVersionOrder)
sl@0
  1019
			{
sl@0
  1020
			arrayPos = aImplementations.Count();
sl@0
  1021
			}
sl@0
  1022
		else
sl@0
  1023
			{
sl@0
  1024
			// Insert the plugin at the beginning of the array, in version order if possible.
sl@0
  1025
			// Make an assumption: if we've been asked for format support, then only plugins 
sl@0
  1026
			// that support the same format will be in the array - so ordering them by version
sl@0
  1027
			// will be meaningful.  Otherwise, there's no point.
sl@0
  1028
			if (iRequiredFormatSupport && (iRequiredFormatSupport->MatchDataType() != CMMFFormatSelectionParameters::EMatchAny))
sl@0
  1029
				{
sl@0
  1030
				// Put the plugin in version order at the beginning of the list
sl@0
  1031
sl@0
  1032
				// Set aArrayPos to the end of the array in case this plugin has the lowest version number
sl@0
  1033
				arrayPos = aImplementations.Count();
sl@0
  1034
				// Cycle through aImplementations to find the first plugin with a version number LOWER than aPlugin
sl@0
  1035
				for (TInt i=0; i<aImplementations.Count(); i++)
sl@0
  1036
					{
sl@0
  1037
					CMMFFormatImplementationInformation* c = aImplementations[i];
sl@0
  1038
					if ((c->Supplier() == aPlugin.Supplier())
sl@0
  1039
						&& (c->Version() <= aPlugin.Version()))
sl@0
  1040
						{
sl@0
  1041
						arrayPos = i;//plugin will be inserted before c in the array
sl@0
  1042
						break;
sl@0
  1043
						}
sl@0
  1044
					}
sl@0
  1045
				}
sl@0
  1046
			else
sl@0
  1047
				{
sl@0
  1048
				// We can't use the version numbers meaningfully, so just put this plugin
sl@0
  1049
				// at the top of the list.
sl@0
  1050
				arrayPos = 0;
sl@0
  1051
				}
sl@0
  1052
			}
sl@0
  1053
		}
sl@0
  1054
	return arrayPos;
sl@0
  1055
	}
sl@0
  1056
sl@0
  1057
TBool CMMFFormatPluginSelectionParameters::CheckFormatSupportL(const CMMFFormatImplementationInformation& aPlugin) const
sl@0
  1058
	{
sl@0
  1059
	// If iRequiredFormatSupport is NULL (ie no requirements set) then the plugin must be suitable!
sl@0
  1060
	if (iRequiredFormatSupport == NULL)
sl@0
  1061
		return ETrue;
sl@0
  1062
sl@0
  1063
	TBool suitable = EFalse;
sl@0
  1064
sl@0
  1065
	switch (iRequiredFormatSupport->MatchDataType())
sl@0
  1066
		{
sl@0
  1067
	case CMMFFormatSelectionParameters::EMatchAny:
sl@0
  1068
		suitable = ETrue;
sl@0
  1069
		break;
sl@0
  1070
	case CMMFFormatSelectionParameters::EMatchFileExtension:
sl@0
  1071
		if (aPlugin.SupportsFileExtension(iRequiredFormatSupport->MatchData()))
sl@0
  1072
			suitable = ETrue;
sl@0
  1073
		break;
sl@0
  1074
	case CMMFFormatSelectionParameters::EMatchMimeType:
sl@0
  1075
		if (aPlugin.SupportsMimeType(iRequiredFormatSupport->MatchData()))
sl@0
  1076
			suitable = ETrue;
sl@0
  1077
		break;
sl@0
  1078
	case CMMFFormatSelectionParameters::EMatchHeaderData:
sl@0
  1079
		if (aPlugin.SupportsHeaderDataL(iRequiredFormatSupport->MatchData()))
sl@0
  1080
			suitable = ETrue;
sl@0
  1081
		break;
sl@0
  1082
	default:
sl@0
  1083
		User::Leave(KErrNotSupported);
sl@0
  1084
		};
sl@0
  1085
sl@0
  1086
	return suitable;
sl@0
  1087
	}
sl@0
  1088
sl@0
  1089
sl@0
  1090
EXPORT_C CMMFFormatEncodePluginSelectionParameters* CMMFFormatEncodePluginSelectionParameters::NewL()
sl@0
  1091
	{
sl@0
  1092
	CMMFFormatEncodePluginSelectionParameters* s = CMMFFormatEncodePluginSelectionParameters::NewLC();
sl@0
  1093
	CleanupStack::Pop(s);
sl@0
  1094
	return s;
sl@0
  1095
	}
sl@0
  1096
sl@0
  1097
EXPORT_C CMMFFormatEncodePluginSelectionParameters* CMMFFormatEncodePluginSelectionParameters::NewLC()
sl@0
  1098
	{
sl@0
  1099
	CMMFFormatEncodePluginSelectionParameters* s = new(ELeave) CMMFFormatEncodePluginSelectionParameters;
sl@0
  1100
	CleanupStack::PushL(s);
sl@0
  1101
	return s;
sl@0
  1102
	}
sl@0
  1103
sl@0
  1104
CMMFFormatEncodePluginSelectionParameters::CMMFFormatEncodePluginSelectionParameters() :
sl@0
  1105
	CMMFFormatPluginSelectionParameters(KUidInterfaceFormatEncode)
sl@0
  1106
	{
sl@0
  1107
	}
sl@0
  1108
sl@0
  1109
sl@0
  1110
EXPORT_C CMMFFormatDecodePluginSelectionParameters* CMMFFormatDecodePluginSelectionParameters::NewL()
sl@0
  1111
	{
sl@0
  1112
	CMMFFormatDecodePluginSelectionParameters* s = CMMFFormatDecodePluginSelectionParameters::NewLC();
sl@0
  1113
	CleanupStack::Pop(s);
sl@0
  1114
	return s;
sl@0
  1115
	}
sl@0
  1116
sl@0
  1117
EXPORT_C CMMFFormatDecodePluginSelectionParameters* CMMFFormatDecodePluginSelectionParameters::NewLC()
sl@0
  1118
	{
sl@0
  1119
	CMMFFormatDecodePluginSelectionParameters* s = new(ELeave) CMMFFormatDecodePluginSelectionParameters;
sl@0
  1120
	CleanupStack::PushL(s);
sl@0
  1121
	return s;
sl@0
  1122
	}
sl@0
  1123
sl@0
  1124
CMMFFormatDecodePluginSelectionParameters::CMMFFormatDecodePluginSelectionParameters() :
sl@0
  1125
	CMMFFormatPluginSelectionParameters(KUidInterfaceFormatDecode)
sl@0
  1126
	{
sl@0
  1127
	}
sl@0
  1128
sl@0
  1129
sl@0
  1130
sl@0
  1131
sl@0
  1132
sl@0
  1133
void TaggedDataParser::ParseTaggedDataL(const TDesC8& aData, MTaggedDataParserClient& aClient)
sl@0
  1134
	{
sl@0
  1135
	TPtrC8 data(aData);
sl@0
  1136
	TInt readPosition = 0;
sl@0
  1137
	TBool moreData = data.Length() ? ETrue : EFalse;
sl@0
  1138
	while (moreData)
sl@0
  1139
		{
sl@0
  1140
		// Assumes that this segment will begin with a tag
sl@0
  1141
		TPtrC8 restOfData = data.Mid(readPosition);
sl@0
  1142
sl@0
  1143
		TInt endPos = restOfData.MatchF(KTagMatch);
sl@0
  1144
		if (endPos == KErrNotFound)
sl@0
  1145
			User::Leave(KErrCorrupt);
sl@0
  1146
sl@0
  1147
		// extract the tag
sl@0
  1148
		TPtrC8 tag = restOfData.Left(KTagLength);
sl@0
  1149
		
sl@0
  1150
	
sl@0
  1151
		readPosition += KTagLength;
sl@0
  1152
sl@0
  1153
		// Find the next tag
sl@0
  1154
		restOfData.Set(data.Mid(readPosition));
sl@0
  1155
		endPos = restOfData.MatchF(KTagMatch);
sl@0
  1156
sl@0
  1157
		TPtrC8 tagData;
sl@0
  1158
		if (endPos == KErrNotFound)
sl@0
  1159
			{
sl@0
  1160
			// If we didn't find a tag, we must be at the end of the data
sl@0
  1161
			tagData.Set(restOfData);
sl@0
  1162
			readPosition = restOfData.Length();
sl@0
  1163
			moreData = EFalse;
sl@0
  1164
			}
sl@0
  1165
		else
sl@0
  1166
			{
sl@0
  1167
			tagData.Set(restOfData.Left(endPos));
sl@0
  1168
			readPosition += endPos;
sl@0
  1169
			}
sl@0
  1170
sl@0
  1171
		aClient.ProcessTaggedDataL(tag, tagData);		
sl@0
  1172
		}
sl@0
  1173
	}
sl@0
  1174
sl@0
  1175
void TaggedDataParser::ConvertTextToUidL(const TDesC8& aData, TUid& aUid)
sl@0
  1176
	{
sl@0
  1177
	// Make sure aData is in the correct format - "0x12345678"
sl@0
  1178
	_LIT8(K0x, "0x");
sl@0
  1179
	_LIT8(K0X, "0X");
sl@0
  1180
	if ((aData.Length() == 10) && ((aData.FindF(K0x) == 0) || (aData.FindF(K0X) == 0)))
sl@0
  1181
		{
sl@0
  1182
		// only take the right 8 characters (ie discard the "0x")
sl@0
  1183
		TLex8 lex(aData.Right(8));
sl@0
  1184
		TUint32 value = 0;
sl@0
  1185
		User::LeaveIfError(lex.Val(value, EHex));
sl@0
  1186
		aUid.iUid = value;
sl@0
  1187
		}
sl@0
  1188
	else
sl@0
  1189
		User::Leave(KErrCorrupt);
sl@0
  1190
	}
sl@0
  1191
sl@0
  1192
sl@0
  1193
void TaggedDataParser::ConvertTextToTUintL(const TDesC8& aData, TUint& aUint)
sl@0
  1194
	{
sl@0
  1195
	// Determine whether hex or decimal then parse as such
sl@0
  1196
	_LIT8(K0x, "0x");
sl@0
  1197
	_LIT8(K0X, "0X");
sl@0
  1198
	if (((aData.FindF(K0x) == 0) || (aData.FindF(K0X) == 0)) && (aData.Length() >= 3))
sl@0
  1199
		{
sl@0
  1200
		// only take the characters after "0x"
sl@0
  1201
		TLex8 lex(aData.Right(aData.Length()-2));
sl@0
  1202
		TUint32 value = 0;
sl@0
  1203
		User::LeaveIfError(lex.Val(value, EHex));
sl@0
  1204
		aUint = value;
sl@0
  1205
		}
sl@0
  1206
	else if (aData.Length() > 0)
sl@0
  1207
		{
sl@0
  1208
		TLex8 lex(aData.Right(aData.Length()));
sl@0
  1209
		TUint32 value = 0;
sl@0
  1210
		User::LeaveIfError(lex.Val(value, EDecimal));
sl@0
  1211
		aUint = value;
sl@0
  1212
		}
sl@0
  1213
	else
sl@0
  1214
		User::Leave(KErrCorrupt);
sl@0
  1215
	}
sl@0
  1216
sl@0
  1217
sl@0
  1218
EXPORT_C TBool CMMFPluginImplementationInformation::SupportsSupplier(const TDesC& aSupplier) const
sl@0
  1219
	{
sl@0
  1220
	if (iSupplier)
sl@0
  1221
		{
sl@0
  1222
		if (aSupplier.CompareF(*iSupplier) == KErrNone)
sl@0
  1223
			return ETrue;
sl@0
  1224
		}
sl@0
  1225
	return EFalse;
sl@0
  1226
	}
sl@0
  1227
sl@0
  1228
EXPORT_C TBool CMMFPluginImplementationInformation::SupportsMediaId(TUid aMediaId) const
sl@0
  1229
	{
sl@0
  1230
	TInt location = iMediaIds.Find(aMediaId);
sl@0
  1231
	return (location != KErrNotFound);
sl@0
  1232
	}
sl@0
  1233
	
sl@0
  1234
EXPORT_C TUid CMMFPluginImplementationInformation::Uid() const
sl@0
  1235
	{
sl@0
  1236
	return iUid;
sl@0
  1237
	}
sl@0
  1238
sl@0
  1239
EXPORT_C const TDesC& CMMFPluginImplementationInformation::DisplayName() const
sl@0
  1240
	{
sl@0
  1241
	if (iDisplayName)
sl@0
  1242
		return *iDisplayName;
sl@0
  1243
	else
sl@0
  1244
		return KNullDesC;
sl@0
  1245
	}
sl@0
  1246
sl@0
  1247
EXPORT_C const TDesC& CMMFPluginImplementationInformation::Supplier() const
sl@0
  1248
	{
sl@0
  1249
	if (iSupplier)
sl@0
  1250
		return *iSupplier;
sl@0
  1251
	else
sl@0
  1252
		return KNullDesC;
sl@0
  1253
	}
sl@0
  1254
sl@0
  1255
EXPORT_C TInt CMMFPluginImplementationInformation::Version() const
sl@0
  1256
	{
sl@0
  1257
	return iVersion;
sl@0
  1258
	}
sl@0
  1259
	
sl@0
  1260
EXPORT_C const RArray<TUid>& CMMFPluginImplementationInformation::SupportedMediaIds() const
sl@0
  1261
	{
sl@0
  1262
	return iMediaIds;
sl@0
  1263
	}
sl@0
  1264
sl@0
  1265
CMMFPluginImplementationInformation::~CMMFPluginImplementationInformation()
sl@0
  1266
	{
sl@0
  1267
	delete iDisplayName;
sl@0
  1268
	delete iSupplier;
sl@0
  1269
	iMediaIds.Close();
sl@0
  1270
	}
sl@0
  1271
sl@0
  1272
sl@0
  1273
CMMFPluginImplementationInformation::CMMFPluginImplementationInformation()
sl@0
  1274
	{
sl@0
  1275
	}
sl@0
  1276
sl@0
  1277
void CMMFPluginImplementationInformation::SetSupplierL(const TDesC8& aData)
sl@0
  1278
	{
sl@0
  1279
	delete iSupplier;
sl@0
  1280
	iSupplier = NULL;
sl@0
  1281
	// Convert aData to unicode...
sl@0
  1282
	iSupplier = HBufC::NewL(aData.Length());
sl@0
  1283
	TPtr ptr = iSupplier->Des();
sl@0
  1284
	User::LeaveIfError(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr, aData));
sl@0
  1285
	}
sl@0
  1286
sl@0
  1287
void CMMFPluginImplementationInformation::AddMediaIdL(const TDesC8& aData)
sl@0
  1288
	{
sl@0
  1289
	TUid mediaId;
sl@0
  1290
	TaggedDataParser::ConvertTextToUidL(aData, mediaId);
sl@0
  1291
	User::LeaveIfError(iMediaIds.Append(mediaId));
sl@0
  1292
	}
sl@0
  1293
sl@0
  1294
CMMFControllerImplementationInformation* CMMFControllerImplementationInformation::NewL(const CImplementationInformation& aImplInfo)
sl@0
  1295
	{
sl@0
  1296
	CMMFControllerImplementationInformation* s = CMMFControllerImplementationInformation::NewLC(aImplInfo);
sl@0
  1297
	CleanupStack::Pop(s);
sl@0
  1298
	return s;
sl@0
  1299
	}
sl@0
  1300
sl@0
  1301
CMMFControllerImplementationInformation* CMMFControllerImplementationInformation::NewLC(const CImplementationInformation& aImplInfo)
sl@0
  1302
	{
sl@0
  1303
	CMMFControllerImplementationInformation* s = new(ELeave) CMMFControllerImplementationInformation;
sl@0
  1304
	CleanupStack::PushL(s);
sl@0
  1305
	s->ConstructL(aImplInfo);
sl@0
  1306
	return s;
sl@0
  1307
	}
sl@0
  1308
	
sl@0
  1309
EXPORT_C CMMFControllerImplementationInformation* CMMFControllerImplementationInformation::NewL(TUid aUid)
sl@0
  1310
	{
sl@0
  1311
	RImplInfoPtrArray ecomArray;
sl@0
  1312
	CleanupResetAndDestroyPushL(ecomArray);
sl@0
  1313
	
sl@0
  1314
	MmPluginUtils::FindImplementationsL(KUidInterfaceMMFController, ecomArray);
sl@0
  1315
sl@0
  1316
	TInt index;
sl@0
  1317
	CMMFControllerImplementationInformation* controller = NULL;
sl@0
  1318
	// Create Controller Implementation Information for the entry with the requested UID
sl@0
  1319
	for (index=0; index<ecomArray.Count() && (controller==NULL); index++)
sl@0
  1320
		{
sl@0
  1321
		if (ecomArray[index] == NULL)
sl@0
  1322
			{
sl@0
  1323
			User::Leave(KErrNoMemory);
sl@0
  1324
			}
sl@0
  1325
			
sl@0
  1326
		if (ecomArray[index]->ImplementationUid()==aUid)
sl@0
  1327
			{
sl@0
  1328
			// Create the impl info object, and get the play and record formats supported by the plugin
sl@0
  1329
			controller = CMMFControllerImplementationInformation::NewL(*(ecomArray[index]));
sl@0
  1330
sl@0
  1331
			CleanupStack::PushL(controller); // INC023207 - Placed controller on CleanupStack
sl@0
  1332
			controller->GetPlayFormatsL();
sl@0
  1333
			controller->GetRecordFormatsL(); // INC023207
sl@0
  1334
			CleanupStack::Pop();
sl@0
  1335
			}
sl@0
  1336
		}
sl@0
  1337
sl@0
  1338
	if (controller == NULL)
sl@0
  1339
		{
sl@0
  1340
		User::Leave(KErrNotFound);
sl@0
  1341
		}
sl@0
  1342
	
sl@0
  1343
	CleanupStack::PopAndDestroy(); // ecomArray
sl@0
  1344
	return controller;	
sl@0
  1345
	}
sl@0
  1346
sl@0
  1347
EXPORT_C const RMMFFormatImplInfoArray& CMMFControllerImplementationInformation::PlayFormats() const
sl@0
  1348
	{
sl@0
  1349
	return iPlayFormats;
sl@0
  1350
	}
sl@0
  1351
sl@0
  1352
EXPORT_C const RMMFFormatImplInfoArray& CMMFControllerImplementationInformation::RecordFormats() const
sl@0
  1353
	{
sl@0
  1354
	return iRecordFormats;
sl@0
  1355
	}
sl@0
  1356
sl@0
  1357
sl@0
  1358
EXPORT_C TUint CMMFControllerImplementationInformation::HeapSpaceRequired() const
sl@0
  1359
	{
sl@0
  1360
	return iHeapSpaceRequired;
sl@0
  1361
	}
sl@0
  1362
sl@0
  1363
EXPORT_C TUint CMMFControllerImplementationInformation::StackSize() const
sl@0
  1364
	{
sl@0
  1365
	return iStackSize;
sl@0
  1366
	}
sl@0
  1367
/**
sl@0
  1368
	@publishedPartner
sl@0
  1369
	@prototype
sl@0
  1370
	
sl@0
  1371
	Returns the uri schemes of this plugin.
sl@0
  1372
sl@0
  1373
	@return The array of uri schemes.
sl@0
  1374
*/
sl@0
  1375
EXPORT_C const CDesC8Array& CMMFControllerImplementationInformation::SupportedUriSchemes() const  
sl@0
  1376
	{
sl@0
  1377
	return *iUriSchemes;
sl@0
  1378
	}
sl@0
  1379
sl@0
  1380
/**
sl@0
  1381
	@publishedPartner
sl@0
  1382
	@prototype
sl@0
  1383
	
sl@0
  1384
	Tests whether the plugin supports aUriScheme.
sl@0
  1385
	
sl@0
  1386
	@param  aUriScheme
sl@0
  1387
	        The required Uri Scheme.
sl@0
  1388
sl@0
  1389
	@return A boolean indicating if the plugin supports aUriScheme. ETrue if this plugin supports aUriScheme, EFalse if not.
sl@0
  1390
*/
sl@0
  1391
EXPORT_C TBool CMMFControllerImplementationInformation::SupportsUriScheme(const TDesC8& aUriScheme) const
sl@0
  1392
  	{
sl@0
  1393
  	TInt position;
sl@0
  1394
  	TInt error = iUriSchemes->FindIsq(aUriScheme, position, ECmpFolded);
sl@0
  1395
  	return (error==KErrNone);
sl@0
  1396
  	}
sl@0
  1397
	
sl@0
  1398
/**
sl@0
  1399
	@publishedPartner
sl@0
  1400
	@prototype
sl@0
  1401
sl@0
  1402
	Sets the uri priority of this controller
sl@0
  1403
sl@0
  1404
	@param  aUriPriority
sl@0
  1405
	        The Uri priority to be assigned.
sl@0
  1406
*/
sl@0
  1407
EXPORT_C void CMMFControllerImplementationInformation::SetUriPriority(TInt aUriPriority)
sl@0
  1408
	{
sl@0
  1409
	iUriPriority = aUriPriority;
sl@0
  1410
	}
sl@0
  1411
sl@0
  1412
/**
sl@0
  1413
	@publishedPartner
sl@0
  1414
	@prototype
sl@0
  1415
	
sl@0
  1416
	Retrieves the uri priority of this controller
sl@0
  1417
	
sl@0
  1418
	@return  The assigned Uri priority.
sl@0
  1419
*/
sl@0
  1420
EXPORT_C TInt CMMFControllerImplementationInformation::UriPriority() const
sl@0
  1421
	{
sl@0
  1422
	return iUriPriority;
sl@0
  1423
	}
sl@0
  1424
sl@0
  1425
/**
sl@0
  1426
	@publishedPartner
sl@0
  1427
	@prototype
sl@0
  1428
	
sl@0
  1429
	Tests whether the controller plugin supports url
sl@0
  1430
		
sl@0
  1431
	@return A boolean indicating if the plugin supports url. ETrue for uri supporting controller, EFalse if not.
sl@0
  1432
*/
sl@0
  1433
EXPORT_C TBool CMMFControllerImplementationInformation::SupportsNetworkCapability() const
sl@0
  1434
	{
sl@0
  1435
	return iIsNetworkCtrl;
sl@0
  1436
	}
sl@0
  1437
sl@0
  1438
/**
sl@0
  1439
	@publishedPartner
sl@0
  1440
	@prototype
sl@0
  1441
	
sl@0
  1442
	Check whether the controller plugin supports secure DRM process mode
sl@0
  1443
	
sl@0
  1444
	@return  A boolean indicating if the plugin supports secure DRM process mode. 
sl@0
  1445
*/
sl@0
  1446
EXPORT_C TBool CMMFControllerImplementationInformation::SupportsSecureDRMProcessMode() const
sl@0
  1447
	{
sl@0
  1448
	return iSupportsSecureDRMProcessMode;
sl@0
  1449
	}
sl@0
  1450
sl@0
  1451
CMMFControllerImplementationInformation::CMMFControllerImplementationInformation()
sl@0
  1452
	{
sl@0
  1453
	iUriPriority = KUriPriorityNone;
sl@0
  1454
	iIsNetworkCtrl = ETrue;
sl@0
  1455
	iPlayFormatCollectionUid = KNullUid;
sl@0
  1456
	iRecordFormatCollectionUid = KNullUid;
sl@0
  1457
	iHeapSpaceRequired = KMMFDefaultControllerThreadHeapSize;
sl@0
  1458
	iSupportsSecureDRMProcessMode = EFalse;
sl@0
  1459
	iStackSize = KDefaultStackSize;
sl@0
  1460
	}
sl@0
  1461
sl@0
  1462
void CMMFControllerImplementationInformation::ConstructL(const CImplementationInformation& aImplInfo)
sl@0
  1463
	{
sl@0
  1464
	iUriSchemes = new(ELeave) CDesC8ArrayFlat(KDesCArrayGranularity);
sl@0
  1465
	iUid = aImplInfo.ImplementationUid();
sl@0
  1466
	iDisplayName = aImplInfo.DisplayName().AllocL();
sl@0
  1467
	iVersion = aImplInfo.Version();
sl@0
  1468
sl@0
  1469
	// Parse the opaque data...
sl@0
  1470
	TaggedDataParser::ParseTaggedDataL(aImplInfo.OpaqueData(), *this);
sl@0
  1471
	}
sl@0
  1472
sl@0
  1473
void CMMFControllerImplementationInformation::ProcessTaggedDataL(const TDesC8& aTag, const TDesC8& aData)
sl@0
  1474
	{
sl@0
  1475
	if (aTag==KSupplier)
sl@0
  1476
		{
sl@0
  1477
		SetSupplierL(aData);
sl@0
  1478
		}
sl@0
  1479
	else if (aTag==KMediaId)
sl@0
  1480
		{
sl@0
  1481
		AddMediaIdL(aData);
sl@0
  1482
		}
sl@0
  1483
	else if (aTag==KUriScheme)
sl@0
  1484
		{
sl@0
  1485
		SetUriSchemeL(aData);
sl@0
  1486
		}
sl@0
  1487
	else if (aTag==KNonNetwork)
sl@0
  1488
		{
sl@0
  1489
		SetNetworkCapabilityL(aData);
sl@0
  1490
		}
sl@0
  1491
	else if (aTag==KPlayFormatCollectionUid)
sl@0
  1492
		{
sl@0
  1493
		SetPlayFormatCollectionUidL(aData);
sl@0
  1494
		}
sl@0
  1495
	else if (aTag==KRecordFormatCollectionUid)
sl@0
  1496
		{
sl@0
  1497
		SetRecordFormatCollectionUidL(aData);
sl@0
  1498
		}
sl@0
  1499
	else if(aTag==KHeapSize)
sl@0
  1500
		{
sl@0
  1501
		SetHeapSizeL(aData);
sl@0
  1502
		}
sl@0
  1503
	else if (aTag==KSecureDRMProcessMode)
sl@0
  1504
		{
sl@0
  1505
		iSupportsSecureDRMProcessMode = ETrue;
sl@0
  1506
		}
sl@0
  1507
	else if (aTag==KStackSize)
sl@0
  1508
		{
sl@0
  1509
		SetStackSizeL(aData);
sl@0
  1510
		}
sl@0
  1511
	else
sl@0
  1512
		{
sl@0
  1513
		User::Leave(KErrCorrupt);
sl@0
  1514
		}
sl@0
  1515
	}
sl@0
  1516
sl@0
  1517
sl@0
  1518
CMMFControllerImplementationInformation::~CMMFControllerImplementationInformation()
sl@0
  1519
	{
sl@0
  1520
	iPlayFormats.ResetAndDestroy();
sl@0
  1521
	iRecordFormats.ResetAndDestroy();
sl@0
  1522
	delete iUriSchemes;
sl@0
  1523
	}
sl@0
  1524
sl@0
  1525
sl@0
  1526
void CMMFControllerImplementationInformation::SetPlayFormatCollectionUidL(const TDesC8& aData)
sl@0
  1527
	{
sl@0
  1528
	TaggedDataParser::ConvertTextToUidL(aData, iPlayFormatCollectionUid);
sl@0
  1529
	}
sl@0
  1530
sl@0
  1531
void CMMFControllerImplementationInformation::SetRecordFormatCollectionUidL(const TDesC8& aData)
sl@0
  1532
	{
sl@0
  1533
	TaggedDataParser::ConvertTextToUidL(aData, iRecordFormatCollectionUid);
sl@0
  1534
	}
sl@0
  1535
sl@0
  1536
void CMMFControllerImplementationInformation::SetHeapSizeL(const TDesC8& aData)
sl@0
  1537
	{
sl@0
  1538
	TaggedDataParser::ConvertTextToTUintL(aData, iHeapSpaceRequired);
sl@0
  1539
	}
sl@0
  1540
sl@0
  1541
void CMMFControllerImplementationInformation::SetStackSizeL(const TDesC8& aData)
sl@0
  1542
	{
sl@0
  1543
	TaggedDataParser::ConvertTextToTUintL(aData, iStackSize);
sl@0
  1544
	}
sl@0
  1545
sl@0
  1546
sl@0
  1547
void CMMFControllerImplementationInformation::AddFormatsSwallowCorruptL(RImplInfoPtrArray& aEcomArray, RMMFFormatImplInfoArray& aFormatArray)
sl@0
  1548
	{
sl@0
  1549
	for (TInt index=0; index<aEcomArray.Count(); index++)
sl@0
  1550
		{
sl@0
  1551
		CMMFFormatImplementationInformation* c = NULL;
sl@0
  1552
		TRAPD(error, c = CMMFFormatImplementationInformation::NewL(*(aEcomArray[index])));
sl@0
  1553
		if (error==KErrNone)
sl@0
  1554
			{
sl@0
  1555
			CleanupStack::PushL(c);
sl@0
  1556
			User::LeaveIfError(aFormatArray.Append(c));
sl@0
  1557
			CleanupStack::Pop(c);
sl@0
  1558
			}
sl@0
  1559
		else if (error != KErrCorrupt)// make sure we don't leave because of a corrupt resource file
sl@0
  1560
			User::Leave(error);
sl@0
  1561
		}
sl@0
  1562
	}
sl@0
  1563
sl@0
  1564
sl@0
  1565
void CMMFControllerImplementationInformation::GetFormatsL(TUid aFormatCollectionUid, TUid aFormatPluginCollectionUid, RMMFFormatImplInfoArray& aFormatArray)
sl@0
  1566
	{
sl@0
  1567
	RImplInfoPtrArray ecomArray;
sl@0
  1568
	CleanupResetAndDestroyPushL(ecomArray);
sl@0
  1569
	// If we have a valid play format collection uid, get the play formats defined by this plugin
sl@0
  1570
	if (aFormatCollectionUid != KNullUid)
sl@0
  1571
		{
sl@0
  1572
		MmPluginUtils::FindImplementationsL(aFormatCollectionUid, ecomArray);
sl@0
  1573
		// Create format implementation information for each entry
sl@0
  1574
		AddFormatsSwallowCorruptL(ecomArray, aFormatArray);
sl@0
  1575
		}
sl@0
  1576
sl@0
  1577
	// Now get all the format plugins attached to this controller
sl@0
  1578
sl@0
  1579
	// Create a descriptor and fill it with the uid of this controller plugin
sl@0
  1580
	TBuf8<10> controllerUid;
sl@0
  1581
	_LIT8(K0x, "0x");
sl@0
  1582
	controllerUid.Append(K0x);
sl@0
  1583
	controllerUid.AppendNumFixedWidth(iUid.iUid, EHex, 8);
sl@0
  1584
sl@0
  1585
	MmPluginUtils::FindImplementationsL(aFormatPluginCollectionUid, ecomArray, controllerUid);
sl@0
  1586
	// Create format implementation information for each entry
sl@0
  1587
	AddFormatsSwallowCorruptL(ecomArray, aFormatArray);
sl@0
  1588
sl@0
  1589
	CleanupStack::PopAndDestroy();//ecomArray
sl@0
  1590
	}
sl@0
  1591
sl@0
  1592
void CMMFControllerImplementationInformation::GetPlayFormatsL()
sl@0
  1593
	{
sl@0
  1594
	GetFormatsL(iPlayFormatCollectionUid, KUidInterfaceFormatDecode, iPlayFormats);
sl@0
  1595
	}
sl@0
  1596
sl@0
  1597
void CMMFControllerImplementationInformation::GetRecordFormatsL()
sl@0
  1598
	{
sl@0
  1599
	GetFormatsL(iRecordFormatCollectionUid, KUidInterfaceFormatEncode, iRecordFormats);
sl@0
  1600
	}
sl@0
  1601
sl@0
  1602
/**
sl@0
  1603
	Sets the Uri Scheme found in opaque data
sl@0
  1604
	
sl@0
  1605
	@param  aUriScheme
sl@0
  1606
			Gives the uri scheme supported by the controller
sl@0
  1607
*/
sl@0
  1608
void CMMFControllerImplementationInformation::SetUriSchemeL(const TDesC8& aUriScheme)
sl@0
  1609
	{
sl@0
  1610
	//If No uri support already declared in the resource file, 
sl@0
  1611
	//then mentioning a particular schema support is illegal
sl@0
  1612
	if(!iIsNetworkCtrl)
sl@0
  1613
		{
sl@0
  1614
		User::Leave(KErrArgument);
sl@0
  1615
		}
sl@0
  1616
	
sl@0
  1617
	// Insert the new uri scheme into the array	
sl@0
  1618
	iUriSchemes->InsertIsqL(aUriScheme, ECmpFolded);//ensures there are no repeated entries
sl@0
  1619
	}
sl@0
  1620
sl@0
  1621
/**
sl@0
  1622
	Sets the Network capability found in opaque data
sl@0
  1623
	
sl@0
  1624
	@param  aNetworkCapable
sl@0
  1625
			Declares the incapability to support uri if matches to 'yes'. 
sl@0
  1626
			If this is the case, iIsNetworkCtrl is set to EFalse
sl@0
  1627
*/
sl@0
  1628
void CMMFControllerImplementationInformation::SetNetworkCapabilityL(const TDesC8& aNetworkCapable)
sl@0
  1629
	{
sl@0
  1630
	//If a uri scheme is already declared in the resource file, 
sl@0
  1631
	//then mentioning no url support is illegal
sl@0
  1632
	if(iUriSchemes->Count() > 0)
sl@0
  1633
		{
sl@0
  1634
		User::Leave(KErrArgument);
sl@0
  1635
		}
sl@0
  1636
		
sl@0
  1637
	if (aNetworkCapable.CompareF(KTagYes) == KErrNone)
sl@0
  1638
		{
sl@0
  1639
		iIsNetworkCtrl = EFalse;
sl@0
  1640
		}
sl@0
  1641
	else
sl@0
  1642
		{
sl@0
  1643
		User::Leave(KErrBadName); // will leave if aNetworkCapable is anything other than 'yes'.
sl@0
  1644
		}
sl@0
  1645
	}
sl@0
  1646
sl@0
  1647
sl@0
  1648
sl@0
  1649
sl@0
  1650
CMMFFormatImplementationInformation* CMMFFormatImplementationInformation::NewL(const CImplementationInformation& aImplInfo)
sl@0
  1651
	{
sl@0
  1652
	CMMFFormatImplementationInformation* s = CMMFFormatImplementationInformation::NewLC(aImplInfo);
sl@0
  1653
	CleanupStack::Pop(s);
sl@0
  1654
	return s;
sl@0
  1655
	}
sl@0
  1656
sl@0
  1657
CMMFFormatImplementationInformation* CMMFFormatImplementationInformation::NewLC(const CImplementationInformation& aImplInfo)
sl@0
  1658
	{
sl@0
  1659
	CMMFFormatImplementationInformation* s = new(ELeave) CMMFFormatImplementationInformation();
sl@0
  1660
	CleanupStack::PushL(s);
sl@0
  1661
	s->ConstructL(aImplInfo);
sl@0
  1662
	return s;
sl@0
  1663
	}
sl@0
  1664
sl@0
  1665
CMMFFormatImplementationInformation::CMMFFormatImplementationInformation()
sl@0
  1666
	{
sl@0
  1667
	}
sl@0
  1668
sl@0
  1669
void CMMFFormatImplementationInformation::ConstructL(const CImplementationInformation& aImplInfo)
sl@0
  1670
	{
sl@0
  1671
	iUid = aImplInfo.ImplementationUid();
sl@0
  1672
	iDisplayName = aImplInfo.DisplayName().AllocL();
sl@0
  1673
sl@0
  1674
	iBody = CMMFFormatImplementationInformation::CBody::NewL();
sl@0
  1675
sl@0
  1676
	// Extract the rest of the data from the opaque data field of aImplInfo...
sl@0
  1677
	// Parse the opaque data...
sl@0
  1678
	TaggedDataParser::ParseTaggedDataL(aImplInfo.OpaqueData(), *this);
sl@0
  1679
	}
sl@0
  1680
sl@0
  1681
void CMMFFormatImplementationInformation::ProcessTaggedDataL(const TDesC8& aTag, const TDesC8& aTagData)
sl@0
  1682
	{
sl@0
  1683
	if (aTag == KSupplier)
sl@0
  1684
		SetSupplierL(aTagData);
sl@0
  1685
	else if (aTag == KMediaId)
sl@0
  1686
		AddMediaIdL(aTagData);
sl@0
  1687
	else if (aTag == KFormatFileExtension)
sl@0
  1688
		AddFileExtensionL(aTagData);
sl@0
  1689
	else if (aTag == KFormatMimeType)
sl@0
  1690
		AddMimeTypeL(aTagData);
sl@0
  1691
	else if (aTag == KFormatHeaderData)
sl@0
  1692
		AddHeaderDataL(aTagData);
sl@0
  1693
	else if ((aTag == KCustomInterfaceSupport) && (aTagData.CompareF(KTagYes) == 0))
sl@0
  1694
		iBody->SetSupportsCustomInterfaces(ETrue);
sl@0
  1695
	else
sl@0
  1696
		User::Leave(KErrCorrupt);
sl@0
  1697
	}
sl@0
  1698
sl@0
  1699
void CMMFFormatImplementationInformation::AddFileExtensionL(const TDesC8& aData)
sl@0
  1700
	{
sl@0
  1701
	iBody->AddFileExtensionL(aData);
sl@0
  1702
	}
sl@0
  1703
sl@0
  1704
void CMMFFormatImplementationInformation::AddMimeTypeL(const TDesC8& aData)
sl@0
  1705
	{
sl@0
  1706
	iBody->AddMimeTypeL(aData);
sl@0
  1707
	}
sl@0
  1708
sl@0
  1709
void CMMFFormatImplementationInformation::AddHeaderDataL(const TDesC8& aData)
sl@0
  1710
	{
sl@0
  1711
	iBody->AddHeaderDataL(aData);
sl@0
  1712
	}
sl@0
  1713
sl@0
  1714
CMMFFormatImplementationInformation::~CMMFFormatImplementationInformation()
sl@0
  1715
	{
sl@0
  1716
	delete iBody;
sl@0
  1717
	}
sl@0
  1718
sl@0
  1719
EXPORT_C const CDesC8Array& CMMFFormatImplementationInformation::SupportedFileExtensions() const
sl@0
  1720
	{
sl@0
  1721
	return iBody->SupportedFileExtensions();
sl@0
  1722
	}
sl@0
  1723
sl@0
  1724
EXPORT_C const CDesC8Array& CMMFFormatImplementationInformation::SupportedMimeTypes() const
sl@0
  1725
	{
sl@0
  1726
	return iBody->SupportedMimeTypes();
sl@0
  1727
	}
sl@0
  1728
sl@0
  1729
EXPORT_C const CDesC8Array& CMMFFormatImplementationInformation::SupportedHeaderData() const
sl@0
  1730
	{
sl@0
  1731
 	return iBody->SupportedHeaderData();
sl@0
  1732
	}
sl@0
  1733
sl@0
  1734
sl@0
  1735
EXPORT_C TBool CMMFFormatImplementationInformation::SupportsFileExtension(const TDesC8& aFileExtension) const
sl@0
  1736
	{
sl@0
  1737
	return iBody->SupportsFileExtension(aFileExtension);
sl@0
  1738
	}
sl@0
  1739
sl@0
  1740
EXPORT_C TBool CMMFFormatImplementationInformation::SupportsMimeType(const TDesC8& aMimeType) const
sl@0
  1741
	{
sl@0
  1742
	return iBody->SupportsMimeType(aMimeType);
sl@0
  1743
	}
sl@0
  1744
sl@0
  1745
EXPORT_C TBool CMMFFormatImplementationInformation::SupportsHeaderDataL(const TDesC8& aHeaderData) const
sl@0
  1746
	{
sl@0
  1747
	return iBody->SupportsHeaderDataL(aHeaderData);
sl@0
  1748
	}
sl@0
  1749
sl@0
  1750
EXPORT_C TBool CMMFFormatImplementationInformation::SupportsCustomInterfaces() const
sl@0
  1751
	{
sl@0
  1752
	return iBody->SupportsCustomInterfaces();
sl@0
  1753
	}
sl@0
  1754
sl@0
  1755
CMatchData* CMatchData::CreateL()
sl@0
  1756
	{
sl@0
  1757
	return new (ELeave) CMatchData();
sl@0
  1758
	}
sl@0
  1759
	
sl@0
  1760
void CMatchData::SetMatchDataL(const TDesC8& aMatchData)
sl@0
  1761
	{
sl@0
  1762
	delete iMatchData;
sl@0
  1763
	iMatchData = NULL;
sl@0
  1764
		
sl@0
  1765
	iMatchData = aMatchData.AllocL();	
sl@0
  1766
	}
sl@0
  1767
sl@0
  1768
void CMatchData::SetMatchUriSchemeL(const TDesC8& aMatchUriScheme)
sl@0
  1769
	{
sl@0
  1770
	delete iMatchUriScheme;
sl@0
  1771
	iMatchUriScheme = NULL;
sl@0
  1772
	
sl@0
  1773
	iMatchUriScheme = aMatchUriScheme.AllocL();	
sl@0
  1774
	}
sl@0
  1775
	
sl@0
  1776
const TDesC8& CMatchData::MatchData() const
sl@0
  1777
	{
sl@0
  1778
	if (iMatchData )
sl@0
  1779
		{
sl@0
  1780
		return *iMatchData;
sl@0
  1781
		}
sl@0
  1782
	else
sl@0
  1783
		{
sl@0
  1784
		return KNullDesC8;
sl@0
  1785
		}
sl@0
  1786
	}
sl@0
  1787
sl@0
  1788
const TDesC8& CMatchData::MatchUriScheme() const
sl@0
  1789
	{
sl@0
  1790
	if (iMatchUriScheme )
sl@0
  1791
		{
sl@0
  1792
		return *iMatchUriScheme;
sl@0
  1793
		}
sl@0
  1794
	else
sl@0
  1795
		{
sl@0
  1796
		return KNullDesC8;
sl@0
  1797
		}
sl@0
  1798
	}
sl@0
  1799
sl@0
  1800
CMatchData::~CMatchData()
sl@0
  1801
	{
sl@0
  1802
	delete iMatchData;
sl@0
  1803
	delete iMatchUriScheme;
sl@0
  1804
	}
sl@0
  1805