Update contrib.
1 // Copyright (c) 2008-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.
14 // This file contains the implementations of the classes which parse the implementation data from resource
15 // file version1, version2 and version3.
19 #include "ParseImplementationData.h"
20 #include <ecom/registryinfoconst.hrh>
21 #include "EComDebug.h"
22 #include "ecompanics.h"
25 // CParseImplementationData class
27 Constructor for CParseImplementationData
29 CParseImplementationData::CParseImplementationData()
34 Destructor for CParseImplementationData
36 CParseImplementationData::~CParseImplementationData()
43 Standardized safe construction which leaves nothing on the cleanup stack.
44 @param aResourceFormatVersion The resource file format version no.
45 @return The newly created instance.
47 CParseImplementationData* CParseImplementationData::NewL(TInt aResourceFormatVersion)
49 CParseImplementationData* object = NULL;
50 if (aResourceFormatVersion==1)
52 object = CParseImplementationDataFormatVersion1::NewL();
54 else if (aResourceFormatVersion==2)
56 object = CParseImplementationDataFormatVersion2::NewL();
58 else if (aResourceFormatVersion==3)
60 object = CParseImplementationDataFormatVersion3::NewL();
64 User::Leave(KErrNotSupported);
70 Standardized safe construction which leaves the returned object on the cleanup stack.
71 @param aResourceFormatVersion The resource file format version no.
72 @return The newly created instance.
74 CParseImplementationData* CParseImplementationData::NewLC(TInt aResourceFormatVersion)
76 CParseImplementationData* object = CParseImplementationData::NewL(aResourceFormatVersion);
77 CleanupStack::PushL(object);
82 Read out the data from the resource file. The created buffer is left in the cleanup stack.
83 This is a helper function to read out the display name.
84 @param aReader The resource file reader.
85 @param aData The pointer points to the buffer for data to be filled in.
88 void CParseImplementationData::GetDataLC(RResourceReader& aReader,
91 // Read in data from resource file to the buffer.
92 aData = aReader.ReadHBufCL();
93 CleanupStack::PushL(aData);
96 if (aData->Length() > KRscStringMaxLength)
98 User::Leave(KErrNotSupported);
104 Read out the data from the resource file. The created buffer left in the cleanup stack.
105 This is a helper function to read out the default data and opaque data for resource v1 and v2.
106 @param aReader The resource file reader.
107 @param aData The pointer points to the buffer for data to be filled in.
110 void CParseImplementationData::GetDataLC(RResourceReader& aReader,
113 // Read in data from resource file to the buffer.
114 aData = aReader.ReadHBufC8L();
115 CleanupStack::PushL(aData);
118 if (aData->Length() > KRscStringMaxLength)
120 User::Leave(KErrNotSupported);
126 // CParseImplementationDataFormatVersion1 class
128 Constructor for CParseImplementationDataFormatVersion1
130 CParseImplementationDataFormatVersion1::CParseImplementationDataFormatVersion1()
136 Standardized safe construction which leaves nothing on the cleanup stack.
137 @return The newly created instance.
139 CParseImplementationDataFormatVersion1* CParseImplementationDataFormatVersion1::NewL()
141 return new(ELeave) CParseImplementationDataFormatVersion1();
145 Parsing the implementation information structure for resource file with version 1.
146 @param aReader The resource file reader.
147 @param aInfoFormat The integer identifying Implementation Information record type to be filled.
148 @param aImplementationUid The implementation Uid to be filled.
149 @param aVersionNo The version no to be filled.
150 @param aName The pointer points to the buffer for display name to be filled in.
151 @param aDefaultData The pointer points to the buffer for default data to be filled in.
152 @param aOpaqueData The pointer points to the buffer for opaque data to be filled in.
153 @param aExtendedInterfaces The pointer points to the array for extended interfaces to be filled in.
154 @param aRomOnly The rom only flag to be filled in.
156 void CParseImplementationDataFormatVersion1::ParseL(RResourceReader& aReader,
157 TInt& /*aInfoFormat*/,
158 TUid& aImplementationUid,
161 HBufC8*& aDefaultData,
162 HBufC8*& aOpaqueData,
163 RExtendedInterfacesArray*& /*aExtendedInterfaces*/,
166 //Read in implementation_uid
167 aImplementationUid.iUid = aReader.ReadInt32L();
169 aVersionNo = aReader.ReadInt8L();
170 // Read in display name from resource file
171 GetDataLC(aReader,aName);
172 // Read in default_data from resource file
173 GetDataLC(aReader,aDefaultData);
174 // Read in opaque_data from resource file
175 GetDataLC(aReader,aOpaqueData);
177 CleanupStack::Pop(3); //Pop out opaqueData, defaultData and display name
182 // CParseImplementationDataFormatVersion2 class
184 Constructor for CParseImplementationDataFormatVersion2
186 CParseImplementationDataFormatVersion2::CParseImplementationDataFormatVersion2()
192 Standardized safe construction which leaves nothing on the cleanup stack.
193 @return The newly created instance.
195 CParseImplementationDataFormatVersion2* CParseImplementationDataFormatVersion2::NewL()
197 return new(ELeave) CParseImplementationDataFormatVersion2();
201 Parsing the implementation information structure for resource file with version 2.
202 @param aReader The resource file reader.
203 @param aInfoFormat The integer identifying Implementation Information record type to be filled.
204 @param aImplementationUid The implementation Uid to be filled.
205 @param aVersionNo The version no to be filled.
206 @param aName The pointer points to the buffer for display name to be filled in.
207 @param aDefaultData The pointer points to the buffer for default data to be filled in.
208 @param aOpaqueData The pointer points to the buffer for opaque data to be filled in.
209 @param aExtendedInterfaces The pointer points to the array for extended interfaces to be filled in.
210 @param aRomOnly The rom only flag to be filled in.
212 void CParseImplementationDataFormatVersion2::ParseL(RResourceReader& aReader,
213 TInt& /*aInfoFormat*/,
214 TUid& aImplementationUid,
217 HBufC8*& aDefaultData,
218 HBufC8*& aOpaqueData,
219 RExtendedInterfacesArray*& /*aExtendedInterfaces*/,
222 //Read in implementation_uid
223 aImplementationUid.iUid = aReader.ReadInt32L();
225 aVersionNo = aReader.ReadInt8L();
226 // Read in display name from resource file
227 GetDataLC(aReader,aName);
228 // Read in default_data from resource file
229 GetDataLC(aReader,aDefaultData);
230 // Read in opaque_data from resource file
231 GetDataLC(aReader,aOpaqueData);
232 //Read in RomOnly flag
233 aRomOnly = aReader.ReadInt8L();
234 CleanupStack::Pop(3); //Pop out opaqueData, defaultData and display name
238 // CParseImplementationDataFormatVersion3 class
240 Constructor for CParseImplementationDataFormatVersion3
242 CParseImplementationDataFormatVersion3::CParseImplementationDataFormatVersion3()
248 Standardized safe construction which leaves nothing on the cleanup stack.
249 @return The newly created instance.
251 CParseImplementationDataFormatVersion3* CParseImplementationDataFormatVersion3::NewL()
253 return new(ELeave) CParseImplementationDataFormatVersion3();
257 Determine the order of two extended interface.
258 @param aUid1 The first extended interface uid for compare.
259 @param aUid2 The second extended interface uid for compare.
260 @return integer indicating the order of the two.
262 TInt CParseImplementationDataFormatVersion3::CompareUid(const TUid& aUid1, const TUid& aUid2)
264 return CompareTUidValues(aUid1.iUid,aUid2.iUid);
268 Parsing the implementation information structure for resource file with version 3.
269 @param aReader The resource file reader.
270 @param aInfoFormat The integer identifying Implementation Information record type to be filled.
271 @param aImplementationUid The implementation Uid to be filled.
272 @param aVersionNo The version no to be filled.
273 @param aName The pointer points to the buffer for display name to be filled in.
274 @param aDefaultData The pointer points to the buffer for default data to be filled in.
275 @param aOpaqueData The pointer points to the buffer for opaque data to be filled in.
276 @param aExtendedInterfaces The pointer points to the array for extended interfaces to be filled in.
277 @param aRomOnly The rom only flag to be filled in.
279 void CParseImplementationDataFormatVersion3::ParseL(RResourceReader& aReader,
281 TUid& aImplementationUid,
284 HBufC8*& aDefaultData,
285 HBufC8*& aOpaqueData,
286 RExtendedInterfacesArray*& aExtendedInterfaces,
289 //Read in info_format
290 aInfoFormat = aReader.ReadInt8L();
291 //Read in implementation_uid
292 aImplementationUid.iUid = aReader.ReadInt32L();
294 aVersionNo = aReader.ReadInt8L();
295 // Read in display name from resource file
296 GetDataLC(aReader,aName);
297 // Read in default data and opaque data
298 if (aInfoFormat == IMPLEMENTATION_INFO_RECORD_TYPE1)
300 GetDataType1LC(aReader,aDefaultData);
301 GetDataType1LC(aReader,aOpaqueData);
303 else if (aInfoFormat == IMPLEMENTATION_INFO_RECORD_TYPE2)
305 GetDataType2LC(aReader,aDefaultData);
306 GetDataType2LC(aReader,aOpaqueData);
310 User::Leave(KErrNotSupported);
312 // Read in extended interfaces
313 GetExtendedInterfacesLC(aReader,aExtendedInterfaces);
314 //Read in RomOnly flag
315 const TUint8 flags = aReader.ReadInt8L();
316 aRomOnly = flags & IMPLEMENTATION_INFO_FLAG_ROM_ONLY;// extract ROM_ONLY flag
317 CleanupStack::Pop(4); //Pop out extended interface, opaqueData, defaultData and display name
321 Read out data from the resource file version 3 for implementation type 1.
322 The created buffer is left in the cleanup stack.
323 This is a helper function for read out default data and opaque data.
324 @param aReader The resource file reader. The current position of the reader is the entry
326 @param aData The pointer point to the buffer for data to fill in.
329 void CParseImplementationDataFormatVersion3::GetDataType1LC(RResourceReader& aReader,HBufC8*& aData)
331 // Read default_data from resource file.
332 TInt numberOfStrings = aReader.ReadUint8L();
333 if (numberOfStrings > KRscMaxNumberOfString)
335 User::Leave(KErrNotSupported);
337 // Each string of the data is limited to 255 characters max base on the definition.
338 aData = HBufC8::NewLC(numberOfStrings*KRscStringMaxLength);
339 TPtr8 dataPtr(aData->Des());
340 HBufC8* arrayElementData;
342 for(TInt i = 0; i < numberOfStrings; i++)
344 arrayElementData = aReader.ReadHBufC8L();
345 if (arrayElementData!=NULL)
347 size = size + arrayElementData->Length();
348 dataPtr.Append(*arrayElementData);
349 delete arrayElementData;
352 // ReAlloc the buffer to exact size.
353 aData->ReAllocL(size);
357 Read out data from the resource file version 3 for implementation type 2.
358 The created buffer is left in the cleanup stack.
359 This is a helper function for read out default data and opaque data
360 @param aReader The resource file reader. The current position of the reader is the entry
362 @param aData The pointer point to the buffer for data to fill in.
365 void CParseImplementationDataFormatVersion3::GetDataType2LC(RResourceReader& aReader,HBufC8*& aData)
367 // read opaque_data from resource file
368 TInt inputLength = aReader.ReadUint16L();
369 if (inputLength > KRscDataMaxLength)
371 User::Leave(KErrNotSupported);
373 aData = HBufC8::NewLC(inputLength);
374 TPtr8 dataPtr(aData->Des());
375 // Gets the pointer to the data represented by dataPtr and casts it to TAny*
376 TAny* ptr = reinterpret_cast<TAny*> (const_cast<TUint8*>(dataPtr.Ptr()));
377 aReader.ReadL(ptr,inputLength);
378 dataPtr.SetLength(inputLength);
382 Read out the extended interfaces from the resource file. The extended interfaces array is left in the cleanup stack.
383 @param aReader The resource file reader. The current position of the reader is the entry
384 of the extended interfaces.
385 @param aExtendedInterfaces The pointer points to the array for extended interfaces to be filled in.
388 void CParseImplementationDataFormatVersion3::GetExtendedInterfacesLC(RResourceReader& aReader,
389 RExtendedInterfacesArray*& aExtendedInterfaces)
391 // Read in extended interface
392 aExtendedInterfaces = new(ELeave) RExtendedInterfacesArray(KExtendedInterfaceGranularity);
394 CleanupStack::PushL(TCleanupItem(CloseAndDeleteArray, aExtendedInterfaces));
396 TInt numExtendedInterfaces = aReader.ReadUint16L();
397 if (numExtendedInterfaces > KRscMaxExtendedInterfaces)
399 User::Leave(KErrNotSupported);
402 for(TInt index = 0; index < numExtendedInterfaces; index++)
404 TUid extendedInterfaceUid = TUid::Uid(aReader.ReadInt32L());
405 // Ensure no duplicate extended interface is added.
406 // if there is duplicate extended interface, panic in debug mode and leave with KErrNotSupported.
407 TLinearOrder<TUid> uidComparator(CompareUid);
408 TInt error = aExtendedInterfaces->InsertInOrder(extendedInterfaceUid,uidComparator);
409 if (error == KErrAlreadyExists)
411 __ECOM_TRACE("ECOM: PANIC in CParseImplementationDataFormatVersion3::GetExtendedInterfacesLC(), duplicate extended interface");
412 __ASSERT_DEBUG(EFalse, User::Panic(KEComServerPanicCategory, EEComPanic_CParseImplementationDataFormatVersion3_DuplicateExIf));
414 User::LeaveIfError(error);