os/mm/mmdevicefw/mdf/src/codecapi/codecapiresolverutils.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) 2005-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 <mdf/codecapiresolverutils.h>
sl@0
    17
#include "codecapiresolverconsts.h"
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 Creates a new CCodecApiOpaqueData object.
sl@0
    22
 @param  aOpaqueData
sl@0
    23
 		 A reference to the opaque data value.
sl@0
    24
 @return A pointer to the newly constructed match data object.
sl@0
    25
 */
sl@0
    26
EXPORT_C CCodecApiOpaqueData* CCodecApiOpaqueData::NewL(const TDesC8& aOpaqueData)
sl@0
    27
	{
sl@0
    28
	CCodecApiOpaqueData* result = CCodecApiOpaqueData::NewLC(aOpaqueData);
sl@0
    29
	CleanupStack::Pop(result);
sl@0
    30
	return result;
sl@0
    31
	}
sl@0
    32
sl@0
    33
sl@0
    34
/**
sl@0
    35
 Creates a new CCodecApiOpaqueData object and leaves a pointer to it on the cleanup stack.
sl@0
    36
 @param  aOpaqueData
sl@0
    37
 		 A reference to the opaque data value.
sl@0
    38
 @return A pointer to the newly constructed match data object.
sl@0
    39
 */
sl@0
    40
EXPORT_C CCodecApiOpaqueData* CCodecApiOpaqueData::NewLC(const TDesC8& aOpaqueData)
sl@0
    41
	{
sl@0
    42
	CCodecApiOpaqueData* result = new (ELeave) CCodecApiOpaqueData(aOpaqueData);
sl@0
    43
	CleanupStack::PushL(result);
sl@0
    44
	result->ConstructL();
sl@0
    45
	return result;
sl@0
    46
	}
sl@0
    47
sl@0
    48
sl@0
    49
/**
sl@0
    50
 Constructor.
sl@0
    51
 @param  aOpaqueData
sl@0
    52
 		 A reference to the opaque data value.
sl@0
    53
 */
sl@0
    54
CCodecApiOpaqueData::CCodecApiOpaqueData(const TDesC8& aOpaqueData) :
sl@0
    55
	iOpaqueData(aOpaqueData)
sl@0
    56
	{
sl@0
    57
	}
sl@0
    58
sl@0
    59
/**
sl@0
    60
 Sets up the data inside the class by calling <code>ParseTaggedDataL()</code>. 
sl@0
    61
 */
sl@0
    62
void CCodecApiOpaqueData::ConstructL()
sl@0
    63
	{
sl@0
    64
	ParseTaggedDataL();
sl@0
    65
	}
sl@0
    66
sl@0
    67
sl@0
    68
/**
sl@0
    69
 Destructor.
sl@0
    70
 */
sl@0
    71
CCodecApiOpaqueData::~CCodecApiOpaqueData()
sl@0
    72
	{
sl@0
    73
	delete iInputDataFormat;
sl@0
    74
	delete iOutputDataFormat;
sl@0
    75
	}
sl@0
    76
sl@0
    77
/*
sl@0
    78
 Parses the opaque data and calls <code>ProcessTaggedDataL()</code> to set the
sl@0
    79
 data member of the class.
sl@0
    80
 */
sl@0
    81
void CCodecApiOpaqueData::ParseTaggedDataL()
sl@0
    82
	{
sl@0
    83
	TInt readPosition = 0;
sl@0
    84
	TBool moreData = (iOpaqueData.Length()>0) ? ETrue : EFalse;
sl@0
    85
	while (moreData)
sl@0
    86
		{
sl@0
    87
		// Assume that this segment will begin with a tag
sl@0
    88
		TPtrC8 restOfData = iOpaqueData.Mid(readPosition);
sl@0
    89
		TInt endPos = restOfData.MatchF(KTagMatch);
sl@0
    90
		if (endPos == KErrNotFound)
sl@0
    91
			{
sl@0
    92
			User::Leave(KErrCorrupt);
sl@0
    93
			}		
sl@0
    94
		// Extract the tag
sl@0
    95
		TPtrC8 tag = restOfData.Left(KTagLength);
sl@0
    96
		readPosition += KTagLength;
sl@0
    97
		// Find the next tag
sl@0
    98
		restOfData.Set(iOpaqueData.Mid(readPosition));
sl@0
    99
		endPos = restOfData.MatchF(KTagMatch);
sl@0
   100
		TPtrC8 tagData;
sl@0
   101
		if (endPos == KErrNotFound)
sl@0
   102
			{
sl@0
   103
			// If we didn't find a tag, we must be at the end of the data
sl@0
   104
			tagData.Set(restOfData);
sl@0
   105
			readPosition = restOfData.Length();
sl@0
   106
			moreData = EFalse;
sl@0
   107
			}
sl@0
   108
		else
sl@0
   109
			{
sl@0
   110
			tagData.Set(restOfData.Left(endPos));
sl@0
   111
			readPosition += endPos;
sl@0
   112
			}
sl@0
   113
		ProcessTaggedDataL(tag, tagData);		
sl@0
   114
		}
sl@0
   115
	}
sl@0
   116
sl@0
   117
sl@0
   118
sl@0
   119
/**
sl@0
   120
 Sets member data to the value of the given opaque data, based upon the tag value provided. 
sl@0
   121
 @param  aTag
sl@0
   122
 	   	 A constant reference to a tag from the opaque data. Can be \<i\>, \<s\> and \<d\>.
sl@0
   123
 @param  aData
sl@0
   124
 	   	 The data associated with a tag.
sl@0
   125
 */
sl@0
   126
void CCodecApiOpaqueData::ProcessTaggedDataL(const TDesC8& aTag, const TDesC8& aData)
sl@0
   127
	{
sl@0
   128
	if (aTag==KMediaUid)
sl@0
   129
		{
sl@0
   130
		SetMediaUidL(aData);
sl@0
   131
		return;
sl@0
   132
		}
sl@0
   133
	if (aTag==KInputPortFormat)
sl@0
   134
		{
sl@0
   135
		HBufC8* dataFormat = aData.AllocL();
sl@0
   136
		delete iInputDataFormat;
sl@0
   137
		iInputDataFormat = dataFormat;
sl@0
   138
		return;
sl@0
   139
		}
sl@0
   140
	if (aTag==KOutputPortFormat)
sl@0
   141
		{
sl@0
   142
		HBufC8* dataFormat = aData.AllocL();
sl@0
   143
		delete iOutputDataFormat;
sl@0
   144
		iOutputDataFormat = dataFormat;
sl@0
   145
		return;
sl@0
   146
		}
sl@0
   147
	User::Leave(KErrCorrupt);	
sl@0
   148
	}
sl@0
   149
sl@0
   150
sl@0
   151
/**
sl@0
   152
 Sets the value of the media UID data.
sl@0
   153
 @param  aData
sl@0
   154
 		 The value to set the media uid to.
sl@0
   155
 */
sl@0
   156
void CCodecApiOpaqueData::SetMediaUidL(const TDesC8& aData)
sl@0
   157
	{
sl@0
   158
	ConvertTextToUidL(aData, iTypeUid);
sl@0
   159
	}
sl@0
   160
sl@0
   161
sl@0
   162
/**
sl@0
   163
 Converts a given string to an integer.
sl@0
   164
 @param  aData
sl@0
   165
 		 The value to be converted.
sl@0
   166
 @return The converted value
sl@0
   167
 */
sl@0
   168
TUint CCodecApiOpaqueData::ConvertTextToTUintL(const TDesC8& aData)
sl@0
   169
	{
sl@0
   170
	// Determine whether hex or decimal then parse as such
sl@0
   171
	_LIT8(K0x, "0x");
sl@0
   172
	TInt lenHexMarker = K0x().Length();
sl@0
   173
	TUint value = 0;
sl@0
   174
sl@0
   175
	// simple white space left trim (only handles spaces)
sl@0
   176
	int index = 0;
sl@0
   177
	while (aData[index]==' ')
sl@0
   178
		{
sl@0
   179
		index++;
sl@0
   180
		}
sl@0
   181
	TPtrC8 data = aData.Mid(index);
sl@0
   182
	if (((data.Left(lenHexMarker).CompareF(K0x) == 0)) && (data.Length() >= 3))
sl@0
   183
		{
sl@0
   184
		// Only take the characters after "0x"
sl@0
   185
		TLex8 lex(data.Mid(lenHexMarker));
sl@0
   186
		User::LeaveIfError(lex.Val(value, EHex));
sl@0
   187
		}
sl@0
   188
	else if (data.Length() > 0)
sl@0
   189
		{
sl@0
   190
		TLex8 lex(data);
sl@0
   191
		User::LeaveIfError(lex.Val(value, EDecimal));
sl@0
   192
		}
sl@0
   193
	else
sl@0
   194
		{
sl@0
   195
		User::Leave(KErrCorrupt);
sl@0
   196
		}		
sl@0
   197
	return value;
sl@0
   198
	}
sl@0
   199
sl@0
   200
sl@0
   201
/**
sl@0
   202
 Converts a given string to a UID.
sl@0
   203
 @param  aData
sl@0
   204
 		 The value to be converted.
sl@0
   205
 @param  aData
sl@0
   206
 		 The value after conversion.
sl@0
   207
 */
sl@0
   208
void CCodecApiOpaqueData::ConvertTextToUidL(const TDesC8& aData, TUid& aUid)
sl@0
   209
	{
sl@0
   210
	_LIT8(K0x, "0x");	
sl@0
   211
	if ((aData.Length() == 10) && (aData.FindF(K0x) == 0))
sl@0
   212
		{
sl@0
   213
		// only take the right 8 characters (ie discard the "0x")
sl@0
   214
		TLex8 lex(aData.Right(8));
sl@0
   215
		TUint32 value = 0;
sl@0
   216
		User::LeaveIfError(lex.Val(value, EHex));
sl@0
   217
		aUid.iUid = value;
sl@0
   218
		}
sl@0
   219
	else
sl@0
   220
		{
sl@0
   221
		User::Leave(KErrCorrupt);
sl@0
   222
		}		
sl@0
   223
	}
sl@0
   224
sl@0
   225
sl@0
   226
/**
sl@0
   227
 Returns the value of the type UID data member.
sl@0
   228
 @return The value of the type UID data member.
sl@0
   229
 */
sl@0
   230
EXPORT_C TUid CCodecApiOpaqueData::TypeUid() const
sl@0
   231
	{
sl@0
   232
	return iTypeUid;
sl@0
   233
	}
sl@0
   234
	
sl@0
   235
sl@0
   236
/**
sl@0
   237
 Returns the value of the input data type.
sl@0
   238
 @return The value of the input data type.
sl@0
   239
 */	
sl@0
   240
EXPORT_C const TDesC8& CCodecApiOpaqueData::InputDataType() const
sl@0
   241
	{
sl@0
   242
	if (iInputDataFormat)
sl@0
   243
		{
sl@0
   244
		return *iInputDataFormat;
sl@0
   245
		}
sl@0
   246
	return KNullDesC8;
sl@0
   247
	}
sl@0
   248
sl@0
   249
sl@0
   250
/**
sl@0
   251
 Returns the value of the output data type.
sl@0
   252
 @return The value of the output data type.
sl@0
   253
 */	
sl@0
   254
EXPORT_C const TDesC8& CCodecApiOpaqueData::OutputDataType() const
sl@0
   255
	{
sl@0
   256
	if (iOutputDataFormat)
sl@0
   257
		{
sl@0
   258
		return *iOutputDataFormat;
sl@0
   259
		}
sl@0
   260
	return KNullDesC8;
sl@0
   261
	}
sl@0
   262
sl@0
   263
sl@0
   264
/**
sl@0
   265
 Compares the input data type with the argument of the method.
sl@0
   266
 @param  aDataType
sl@0
   267
 		 The value to be compared to.
sl@0
   268
 @return ETrue if the argument of the method and the input data 
sl@0
   269
 		 type are the same.
sl@0
   270
 */
sl@0
   271
EXPORT_C TBool CCodecApiOpaqueData::CompareInputDataType(const TDesC8& aDataType)
sl@0
   272
	{	
sl@0
   273
	if(iInputDataFormat)
sl@0
   274
		{
sl@0
   275
		const TDesC8& i = *iInputDataFormat;
sl@0
   276
		if(aDataType.CompareF(i) == 0)
sl@0
   277
			{
sl@0
   278
			return ETrue;
sl@0
   279
			}			
sl@0
   280
		}	
sl@0
   281
	return EFalse;
sl@0
   282
	}
sl@0
   283
	
sl@0
   284
	
sl@0
   285
/**
sl@0
   286
 Compares the output data type with the argument of the method.
sl@0
   287
 @param  aDataType
sl@0
   288
 		 The value to be compared to.
sl@0
   289
 @return ETrue if the argument of the method and the output data
sl@0
   290
 		 type are the same.
sl@0
   291
 */	
sl@0
   292
EXPORT_C TBool CCodecApiOpaqueData::CompareOutputDataType(const TDesC8& aDataType)
sl@0
   293
	{
sl@0
   294
	if(iOutputDataFormat)
sl@0
   295
		{
sl@0
   296
		if(aDataType.CompareF(*iOutputDataFormat) == 0)
sl@0
   297
			{
sl@0
   298
			return ETrue;
sl@0
   299
			}		
sl@0
   300
		}	
sl@0
   301
	return EFalse;
sl@0
   302
	}	
sl@0
   303
	
sl@0
   304