Update contrib.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <mdf/codecapiresolverutils.h>
17 #include "codecapiresolverconsts.h"
21 Creates a new CCodecApiOpaqueData object.
23 A reference to the opaque data value.
24 @return A pointer to the newly constructed match data object.
26 EXPORT_C CCodecApiOpaqueData* CCodecApiOpaqueData::NewL(const TDesC8& aOpaqueData)
28 CCodecApiOpaqueData* result = CCodecApiOpaqueData::NewLC(aOpaqueData);
29 CleanupStack::Pop(result);
35 Creates a new CCodecApiOpaqueData object and leaves a pointer to it on the cleanup stack.
37 A reference to the opaque data value.
38 @return A pointer to the newly constructed match data object.
40 EXPORT_C CCodecApiOpaqueData* CCodecApiOpaqueData::NewLC(const TDesC8& aOpaqueData)
42 CCodecApiOpaqueData* result = new (ELeave) CCodecApiOpaqueData(aOpaqueData);
43 CleanupStack::PushL(result);
52 A reference to the opaque data value.
54 CCodecApiOpaqueData::CCodecApiOpaqueData(const TDesC8& aOpaqueData) :
55 iOpaqueData(aOpaqueData)
60 Sets up the data inside the class by calling <code>ParseTaggedDataL()</code>.
62 void CCodecApiOpaqueData::ConstructL()
71 CCodecApiOpaqueData::~CCodecApiOpaqueData()
73 delete iInputDataFormat;
74 delete iOutputDataFormat;
78 Parses the opaque data and calls <code>ProcessTaggedDataL()</code> to set the
79 data member of the class.
81 void CCodecApiOpaqueData::ParseTaggedDataL()
83 TInt readPosition = 0;
84 TBool moreData = (iOpaqueData.Length()>0) ? ETrue : EFalse;
87 // Assume that this segment will begin with a tag
88 TPtrC8 restOfData = iOpaqueData.Mid(readPosition);
89 TInt endPos = restOfData.MatchF(KTagMatch);
90 if (endPos == KErrNotFound)
92 User::Leave(KErrCorrupt);
95 TPtrC8 tag = restOfData.Left(KTagLength);
96 readPosition += KTagLength;
98 restOfData.Set(iOpaqueData.Mid(readPosition));
99 endPos = restOfData.MatchF(KTagMatch);
101 if (endPos == KErrNotFound)
103 // If we didn't find a tag, we must be at the end of the data
104 tagData.Set(restOfData);
105 readPosition = restOfData.Length();
110 tagData.Set(restOfData.Left(endPos));
111 readPosition += endPos;
113 ProcessTaggedDataL(tag, tagData);
120 Sets member data to the value of the given opaque data, based upon the tag value provided.
122 A constant reference to a tag from the opaque data. Can be \<i\>, \<s\> and \<d\>.
124 The data associated with a tag.
126 void CCodecApiOpaqueData::ProcessTaggedDataL(const TDesC8& aTag, const TDesC8& aData)
133 if (aTag==KInputPortFormat)
135 HBufC8* dataFormat = aData.AllocL();
136 delete iInputDataFormat;
137 iInputDataFormat = dataFormat;
140 if (aTag==KOutputPortFormat)
142 HBufC8* dataFormat = aData.AllocL();
143 delete iOutputDataFormat;
144 iOutputDataFormat = dataFormat;
147 User::Leave(KErrCorrupt);
152 Sets the value of the media UID data.
154 The value to set the media uid to.
156 void CCodecApiOpaqueData::SetMediaUidL(const TDesC8& aData)
158 ConvertTextToUidL(aData, iTypeUid);
163 Converts a given string to an integer.
165 The value to be converted.
166 @return The converted value
168 TUint CCodecApiOpaqueData::ConvertTextToTUintL(const TDesC8& aData)
170 // Determine whether hex or decimal then parse as such
172 TInt lenHexMarker = K0x().Length();
175 // simple white space left trim (only handles spaces)
177 while (aData[index]==' ')
181 TPtrC8 data = aData.Mid(index);
182 if (((data.Left(lenHexMarker).CompareF(K0x) == 0)) && (data.Length() >= 3))
184 // Only take the characters after "0x"
185 TLex8 lex(data.Mid(lenHexMarker));
186 User::LeaveIfError(lex.Val(value, EHex));
188 else if (data.Length() > 0)
191 User::LeaveIfError(lex.Val(value, EDecimal));
195 User::Leave(KErrCorrupt);
202 Converts a given string to a UID.
204 The value to be converted.
206 The value after conversion.
208 void CCodecApiOpaqueData::ConvertTextToUidL(const TDesC8& aData, TUid& aUid)
211 if ((aData.Length() == 10) && (aData.FindF(K0x) == 0))
213 // only take the right 8 characters (ie discard the "0x")
214 TLex8 lex(aData.Right(8));
216 User::LeaveIfError(lex.Val(value, EHex));
221 User::Leave(KErrCorrupt);
227 Returns the value of the type UID data member.
228 @return The value of the type UID data member.
230 EXPORT_C TUid CCodecApiOpaqueData::TypeUid() const
237 Returns the value of the input data type.
238 @return The value of the input data type.
240 EXPORT_C const TDesC8& CCodecApiOpaqueData::InputDataType() const
242 if (iInputDataFormat)
244 return *iInputDataFormat;
251 Returns the value of the output data type.
252 @return The value of the output data type.
254 EXPORT_C const TDesC8& CCodecApiOpaqueData::OutputDataType() const
256 if (iOutputDataFormat)
258 return *iOutputDataFormat;
265 Compares the input data type with the argument of the method.
267 The value to be compared to.
268 @return ETrue if the argument of the method and the input data
271 EXPORT_C TBool CCodecApiOpaqueData::CompareInputDataType(const TDesC8& aDataType)
275 const TDesC8& i = *iInputDataFormat;
276 if(aDataType.CompareF(i) == 0)
286 Compares the output data type with the argument of the method.
288 The value to be compared to.
289 @return ETrue if the argument of the method and the output data
292 EXPORT_C TBool CCodecApiOpaqueData::CompareOutputDataType(const TDesC8& aDataType)
294 if(iOutputDataFormat)
296 if(aDataType.CompareF(*iOutputDataFormat) == 0)