|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This file contains the implementations of the classes which parse the implementation data from resource |
|
15 // file version1, version2 and version3. |
|
16 // |
|
17 // |
|
18 |
|
19 #include "ParseImplementationData.h" |
|
20 #include <ecom/registryinfoconst.hrh> |
|
21 #include "EComDebug.h" |
|
22 #include "ecompanics.h" |
|
23 |
|
24 // |
|
25 // CParseImplementationData class |
|
26 /** |
|
27 Constructor for CParseImplementationData |
|
28 */ |
|
29 CParseImplementationData::CParseImplementationData() |
|
30 { |
|
31 // Do nothing here |
|
32 } |
|
33 /** |
|
34 Destructor for CParseImplementationData |
|
35 */ |
|
36 CParseImplementationData::~CParseImplementationData() |
|
37 { |
|
38 // Do nothing here |
|
39 } |
|
40 |
|
41 |
|
42 /** |
|
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. |
|
46 */ |
|
47 CParseImplementationData* CParseImplementationData::NewL(TInt aResourceFormatVersion) |
|
48 { |
|
49 CParseImplementationData* object = NULL; |
|
50 if (aResourceFormatVersion==1) |
|
51 { |
|
52 object = CParseImplementationDataFormatVersion1::NewL(); |
|
53 } |
|
54 else if (aResourceFormatVersion==2) |
|
55 { |
|
56 object = CParseImplementationDataFormatVersion2::NewL(); |
|
57 } |
|
58 else if (aResourceFormatVersion==3) |
|
59 { |
|
60 object = CParseImplementationDataFormatVersion3::NewL(); |
|
61 } |
|
62 else |
|
63 { |
|
64 User::Leave(KErrNotSupported); |
|
65 } |
|
66 return object; |
|
67 } |
|
68 |
|
69 /** |
|
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. |
|
73 */ |
|
74 CParseImplementationData* CParseImplementationData::NewLC(TInt aResourceFormatVersion) |
|
75 { |
|
76 CParseImplementationData* object = CParseImplementationData::NewL(aResourceFormatVersion); |
|
77 CleanupStack::PushL(object); |
|
78 return object; |
|
79 } |
|
80 |
|
81 /** |
|
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. |
|
86 @return None |
|
87 */ |
|
88 void CParseImplementationData::GetDataLC(RResourceReader& aReader, |
|
89 HBufC*& aData) |
|
90 { |
|
91 // Read in data from resource file to the buffer. |
|
92 aData = aReader.ReadHBufCL(); |
|
93 CleanupStack::PushL(aData); |
|
94 if (aData!=NULL) |
|
95 { |
|
96 if (aData->Length() > KRscStringMaxLength) |
|
97 { |
|
98 User::Leave(KErrNotSupported); |
|
99 } |
|
100 } |
|
101 } |
|
102 |
|
103 /** |
|
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. |
|
108 @return None |
|
109 */ |
|
110 void CParseImplementationData::GetDataLC(RResourceReader& aReader, |
|
111 HBufC8*& aData) |
|
112 { |
|
113 // Read in data from resource file to the buffer. |
|
114 aData = aReader.ReadHBufC8L(); |
|
115 CleanupStack::PushL(aData); |
|
116 if (aData!=NULL) |
|
117 { |
|
118 if (aData->Length() > KRscStringMaxLength) |
|
119 { |
|
120 User::Leave(KErrNotSupported); |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 // |
|
126 // CParseImplementationDataFormatVersion1 class |
|
127 /** |
|
128 Constructor for CParseImplementationDataFormatVersion1 |
|
129 */ |
|
130 CParseImplementationDataFormatVersion1::CParseImplementationDataFormatVersion1() |
|
131 { |
|
132 // Do nothing here |
|
133 } |
|
134 |
|
135 /** |
|
136 Standardized safe construction which leaves nothing on the cleanup stack. |
|
137 @return The newly created instance. |
|
138 */ |
|
139 CParseImplementationDataFormatVersion1* CParseImplementationDataFormatVersion1::NewL() |
|
140 { |
|
141 return new(ELeave) CParseImplementationDataFormatVersion1(); |
|
142 } |
|
143 |
|
144 /** |
|
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. |
|
155 */ |
|
156 void CParseImplementationDataFormatVersion1::ParseL(RResourceReader& aReader, |
|
157 TInt& /*aInfoFormat*/, |
|
158 TUid& aImplementationUid, |
|
159 TInt& aVersionNo, |
|
160 HBufC*& aName, |
|
161 HBufC8*& aDefaultData, |
|
162 HBufC8*& aOpaqueData, |
|
163 RExtendedInterfacesArray*& /*aExtendedInterfaces*/, |
|
164 TBool& aRomOnly) |
|
165 { |
|
166 //Read in implementation_uid |
|
167 aImplementationUid.iUid = aReader.ReadInt32L(); |
|
168 //Read in version_no |
|
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); |
|
176 aRomOnly = EFalse; |
|
177 CleanupStack::Pop(3); //Pop out opaqueData, defaultData and display name |
|
178 } |
|
179 |
|
180 |
|
181 // |
|
182 // CParseImplementationDataFormatVersion2 class |
|
183 /** |
|
184 Constructor for CParseImplementationDataFormatVersion2 |
|
185 */ |
|
186 CParseImplementationDataFormatVersion2::CParseImplementationDataFormatVersion2() |
|
187 { |
|
188 // Do nothing here |
|
189 } |
|
190 |
|
191 /** |
|
192 Standardized safe construction which leaves nothing on the cleanup stack. |
|
193 @return The newly created instance. |
|
194 */ |
|
195 CParseImplementationDataFormatVersion2* CParseImplementationDataFormatVersion2::NewL() |
|
196 { |
|
197 return new(ELeave) CParseImplementationDataFormatVersion2(); |
|
198 } |
|
199 |
|
200 /** |
|
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. |
|
211 */ |
|
212 void CParseImplementationDataFormatVersion2::ParseL(RResourceReader& aReader, |
|
213 TInt& /*aInfoFormat*/, |
|
214 TUid& aImplementationUid, |
|
215 TInt& aVersionNo, |
|
216 HBufC*& aName, |
|
217 HBufC8*& aDefaultData, |
|
218 HBufC8*& aOpaqueData, |
|
219 RExtendedInterfacesArray*& /*aExtendedInterfaces*/, |
|
220 TBool& aRomOnly) |
|
221 { |
|
222 //Read in implementation_uid |
|
223 aImplementationUid.iUid = aReader.ReadInt32L(); |
|
224 //Read in version_no |
|
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 |
|
235 } |
|
236 |
|
237 // |
|
238 // CParseImplementationDataFormatVersion3 class |
|
239 /** |
|
240 Constructor for CParseImplementationDataFormatVersion3 |
|
241 */ |
|
242 CParseImplementationDataFormatVersion3::CParseImplementationDataFormatVersion3() |
|
243 { |
|
244 // Do nothing here |
|
245 } |
|
246 |
|
247 /** |
|
248 Standardized safe construction which leaves nothing on the cleanup stack. |
|
249 @return The newly created instance. |
|
250 */ |
|
251 CParseImplementationDataFormatVersion3* CParseImplementationDataFormatVersion3::NewL() |
|
252 { |
|
253 return new(ELeave) CParseImplementationDataFormatVersion3(); |
|
254 } |
|
255 |
|
256 /** |
|
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. |
|
261 */ |
|
262 TInt CParseImplementationDataFormatVersion3::CompareUid(const TUid& aUid1, const TUid& aUid2) |
|
263 { |
|
264 return CompareTUidValues(aUid1.iUid,aUid2.iUid); |
|
265 } |
|
266 |
|
267 /** |
|
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. |
|
278 */ |
|
279 void CParseImplementationDataFormatVersion3::ParseL(RResourceReader& aReader, |
|
280 TInt& aInfoFormat, |
|
281 TUid& aImplementationUid, |
|
282 TInt& aVersionNo, |
|
283 HBufC*& aName, |
|
284 HBufC8*& aDefaultData, |
|
285 HBufC8*& aOpaqueData, |
|
286 RExtendedInterfacesArray*& aExtendedInterfaces, |
|
287 TBool& aRomOnly) |
|
288 { |
|
289 //Read in info_format |
|
290 aInfoFormat = aReader.ReadInt8L(); |
|
291 //Read in implementation_uid |
|
292 aImplementationUid.iUid = aReader.ReadInt32L(); |
|
293 //Read in version_no |
|
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) |
|
299 { |
|
300 GetDataType1LC(aReader,aDefaultData); |
|
301 GetDataType1LC(aReader,aOpaqueData); |
|
302 } |
|
303 else if (aInfoFormat == IMPLEMENTATION_INFO_RECORD_TYPE2) |
|
304 { |
|
305 GetDataType2LC(aReader,aDefaultData); |
|
306 GetDataType2LC(aReader,aOpaqueData); |
|
307 } |
|
308 else |
|
309 { |
|
310 User::Leave(KErrNotSupported); |
|
311 } |
|
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 |
|
318 } |
|
319 |
|
320 /** |
|
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 |
|
325 of the default data. |
|
326 @param aData The pointer point to the buffer for data to fill in. |
|
327 @return None |
|
328 */ |
|
329 void CParseImplementationDataFormatVersion3::GetDataType1LC(RResourceReader& aReader,HBufC8*& aData) |
|
330 { |
|
331 // Read default_data from resource file. |
|
332 TInt numberOfStrings = aReader.ReadUint8L(); |
|
333 if (numberOfStrings > KRscMaxNumberOfString) |
|
334 { |
|
335 User::Leave(KErrNotSupported); |
|
336 } |
|
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; |
|
341 TInt size = 0; |
|
342 for(TInt i = 0; i < numberOfStrings; i++) |
|
343 { |
|
344 arrayElementData = aReader.ReadHBufC8L(); |
|
345 if (arrayElementData!=NULL) |
|
346 { |
|
347 size = size + arrayElementData->Length(); |
|
348 dataPtr.Append(*arrayElementData); |
|
349 delete arrayElementData; |
|
350 } |
|
351 } |
|
352 // ReAlloc the buffer to exact size. |
|
353 aData->ReAllocL(size); |
|
354 } |
|
355 |
|
356 /** |
|
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 |
|
361 of the default data. |
|
362 @param aData The pointer point to the buffer for data to fill in. |
|
363 @return None |
|
364 */ |
|
365 void CParseImplementationDataFormatVersion3::GetDataType2LC(RResourceReader& aReader,HBufC8*& aData) |
|
366 { |
|
367 // read opaque_data from resource file |
|
368 TInt inputLength = aReader.ReadUint16L(); |
|
369 if (inputLength > KRscDataMaxLength) |
|
370 { |
|
371 User::Leave(KErrNotSupported); |
|
372 } |
|
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); |
|
379 } |
|
380 |
|
381 /** |
|
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. |
|
386 @return None |
|
387 */ |
|
388 void CParseImplementationDataFormatVersion3::GetExtendedInterfacesLC(RResourceReader& aReader, |
|
389 RExtendedInterfacesArray*& aExtendedInterfaces) |
|
390 { |
|
391 // Read in extended interface |
|
392 aExtendedInterfaces = new(ELeave) RExtendedInterfacesArray(KExtendedInterfaceGranularity); |
|
393 |
|
394 CleanupStack::PushL(TCleanupItem(CloseAndDeleteArray, aExtendedInterfaces)); |
|
395 |
|
396 TInt numExtendedInterfaces = aReader.ReadUint16L(); |
|
397 if (numExtendedInterfaces > KRscMaxExtendedInterfaces) |
|
398 { |
|
399 User::Leave(KErrNotSupported); |
|
400 } |
|
401 |
|
402 for(TInt index = 0; index < numExtendedInterfaces; index++) |
|
403 { |
|
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) |
|
410 { |
|
411 __ECOM_TRACE("ECOM: PANIC in CParseImplementationDataFormatVersion3::GetExtendedInterfacesLC(), duplicate extended interface"); |
|
412 __ASSERT_DEBUG(EFalse, User::Panic(KEComServerPanicCategory, EEComPanic_CParseImplementationDataFormatVersion3_DuplicateExIf)); |
|
413 } |
|
414 User::LeaveIfError(error); |
|
415 } |
|
416 } |
|
417 |