|
1 // Copyright (c) 1997-2010 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 // |
|
15 |
|
16 #include <s32mem.h> |
|
17 #include "ImageResolverAPI.h" |
|
18 #include "../inc_pub/icl/ICL_PropertyUIDS.h" |
|
19 |
|
20 const TInt KMaxDescriptorLength = 128; // The biggest descriptor that will be |
|
21 // built when internalizing the object |
|
22 |
|
23 /* |
|
24 * |
|
25 * Default constructor |
|
26 * |
|
27 */ |
|
28 CCustomMatchData::CCustomMatchData() |
|
29 { |
|
30 } |
|
31 |
|
32 /* |
|
33 * |
|
34 * Default destructor |
|
35 * |
|
36 */ |
|
37 CCustomMatchData::~CCustomMatchData() |
|
38 { |
|
39 delete iMatchString; |
|
40 delete iFileSuffix; |
|
41 iMatchReqUidsArray.Close(); |
|
42 iOptionsUidsArray.Close(); |
|
43 } |
|
44 |
|
45 /* |
|
46 * |
|
47 * Standard, safe constructor that leaves nothing on the cleanup stack |
|
48 * |
|
49 * @return "CCustomMatchData*" |
|
50 * A pointer to the newly constructed match data object |
|
51 * |
|
52 */ |
|
53 CCustomMatchData* CCustomMatchData::NewL() |
|
54 { |
|
55 CCustomMatchData* self = CCustomMatchData::NewLC(); |
|
56 CleanupStack::Pop(self); |
|
57 return self; |
|
58 } |
|
59 /* |
|
60 * |
|
61 * Standard, safe constructor that leaves nothing on the cleanup stack |
|
62 * |
|
63 * @param "const TDesC8& aPackage" |
|
64 * A reference to a descriptor created using <code>PackL()</code> |
|
65 * used to initialize the object. |
|
66 * @return "CCustomMatchData*" |
|
67 * A pointer to the newly constructed match data object |
|
68 * |
|
69 */ |
|
70 CCustomMatchData* CCustomMatchData::NewL(const TDesC8& aPackage) |
|
71 { |
|
72 CCustomMatchData* self = CCustomMatchData::NewLC(aPackage); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 /* |
|
78 * |
|
79 * Standard, safe constructor that leaves the pointer to the newly constructed |
|
80 * match data object on the cleanup stack |
|
81 * |
|
82 * @return "CCustomMatchData*" |
|
83 * A pointer to the newly constructed match data object |
|
84 * |
|
85 */ |
|
86 CCustomMatchData* CCustomMatchData::NewLC() |
|
87 { |
|
88 CCustomMatchData* self = new(ELeave) CCustomMatchData; |
|
89 CleanupStack::PushL(self); |
|
90 return self; |
|
91 } |
|
92 |
|
93 /* |
|
94 * |
|
95 * Standard, safe constructor that leaves the pointer to the newly constructed |
|
96 * match data object on the cleanup stack |
|
97 * |
|
98 * @param "const TDesC8& aPackage" |
|
99 * A reference to a descriptor created using <code>PackL()</code> |
|
100 * used to initialize the object. |
|
101 * @return "CCustomMatchData*" |
|
102 * A pointer to the newly constructed match data object |
|
103 * |
|
104 */ |
|
105 CCustomMatchData* CCustomMatchData::NewLC(const TDesC8& aPackage) |
|
106 { |
|
107 CCustomMatchData* self = new(ELeave) CCustomMatchData; |
|
108 CleanupStack::PushL(self); |
|
109 self->ConstructL(aPackage); |
|
110 return self; |
|
111 } |
|
112 |
|
113 void CCustomMatchData::ConstructL(const TDesC8& aPackage) |
|
114 { |
|
115 UnPackL(aPackage); |
|
116 } |
|
117 |
|
118 /* |
|
119 * |
|
120 * Externalize the object to a stream. |
|
121 * All the member variables will be written to the stream, and if no MatchString |
|
122 * is provided a null descriptor is used. The stream must be able to accomodate |
|
123 * the streaming operation or it will leave with <code>KErrOverFlow</code>. |
|
124 * |
|
125 * @param "RWriteStream& aStream" |
|
126 * A reference to the stream to which the member variables will |
|
127 * be written. |
|
128 * |
|
129 */ |
|
130 void CCustomMatchData::ExternalizeL(RWriteStream& aStream) const |
|
131 { |
|
132 aStream.WriteInt32L(iMatchType); |
|
133 aStream.WriteInt32L(iBaseType.iUid); |
|
134 aStream.WriteInt32L(iSubType.iUid); |
|
135 aStream.WriteInt32L(iImplementationType.iUid); |
|
136 aStream.WriteInt32L(iMatchReqUidsArray.Count()); |
|
137 |
|
138 for (TInt index = 0; index < iMatchReqUidsArray.Count(); index++) |
|
139 { |
|
140 aStream.WriteInt32L((iMatchReqUidsArray[index]).iUid); |
|
141 } |
|
142 |
|
143 // if Match String is not used send empty descriptor |
|
144 if (iMatchString) |
|
145 aStream << *iMatchString; |
|
146 else |
|
147 aStream << KNullDesC8; |
|
148 |
|
149 // if File Suffix is not used send empty descriptor |
|
150 if (iFileSuffix) |
|
151 aStream << *iFileSuffix; |
|
152 else |
|
153 aStream << KNullDesC8; |
|
154 |
|
155 aStream.WriteInt32L(iExtensionOptions); |
|
156 |
|
157 aStream.WriteInt32L(iOptionsUidsArray.Count()); |
|
158 |
|
159 for (TInt index = 0; index < iOptionsUidsArray.Count(); index++) |
|
160 { |
|
161 aStream.WriteInt32L((iOptionsUidsArray[index]).iUid); |
|
162 } |
|
163 |
|
164 aStream.WriteInt32L(iOptions); |
|
165 } |
|
166 /* |
|
167 * |
|
168 * Internalize the object from a stream. |
|
169 * All the member variables will be read from the streamed. |
|
170 * If there is not enougth data in the stream or it will |
|
171 * leave with <code>KErrEof</code>. |
|
172 * |
|
173 * @param "RReadStream& aStream" |
|
174 * A reference to the stream from which data will be read to |
|
175 * setup the member variables. |
|
176 * |
|
177 */ |
|
178 void CCustomMatchData::InternalizeL(RReadStream& aStream) |
|
179 { |
|
180 iMatchType = STATIC_CAST(TResolverMatchType, aStream.ReadInt32L()); |
|
181 iBaseType.iUid = aStream.ReadInt32L(); |
|
182 iSubType.iUid = aStream.ReadInt32L(); |
|
183 iImplementationType.iUid = aStream.ReadInt32L(); |
|
184 |
|
185 TInt matchReqUidsCount = aStream.ReadInt32L(); |
|
186 if (matchReqUidsCount > 0) |
|
187 { |
|
188 iMatchReqUidsArray.Reset(); |
|
189 for (TInt index = 0; index < matchReqUidsCount; index++) |
|
190 { |
|
191 User::LeaveIfError(iMatchReqUidsArray.Append(TUid::Uid(aStream.ReadInt32L()))); |
|
192 } |
|
193 } |
|
194 |
|
195 delete iMatchString; iMatchString = NULL; |
|
196 iMatchString = HBufC8::NewL(aStream, KMaxDescriptorLength); //KErrOverflow |
|
197 |
|
198 delete iFileSuffix; iFileSuffix = NULL; |
|
199 iFileSuffix = HBufC::NewL(aStream, KMaxDescriptorLength); //KErrOverflow |
|
200 |
|
201 iExtensionOptions = aStream.ReadInt32L(); |
|
202 |
|
203 TInt optionsUidsCount = aStream.ReadInt32L(); |
|
204 if (optionsUidsCount > 0) |
|
205 { |
|
206 iOptionsUidsArray.Reset(); |
|
207 for (TInt index = 0; index < optionsUidsCount; index++) |
|
208 { |
|
209 User::LeaveIfError(iOptionsUidsArray.Append(TUid::Uid(aStream.ReadInt32L()))); |
|
210 } |
|
211 } |
|
212 |
|
213 iOptions = aStream.ReadInt32L(); |
|
214 } |
|
215 |
|
216 /* |
|
217 * |
|
218 * Set a string to match against. |
|
219 * |
|
220 * @param "const TDesC8& aMIMEType" |
|
221 * A reference to a descriptor to match against. |
|
222 * |
|
223 */ |
|
224 void CCustomMatchData::SetMatchStringL(const TDesC8& aMIMEType) |
|
225 { |
|
226 delete iMatchString; iMatchString = NULL; |
|
227 iMatchString = aMIMEType.AllocL(); |
|
228 } |
|
229 |
|
230 /* |
|
231 * |
|
232 * Sets the match type, base type and sub type to match against |
|
233 * |
|
234 * @param "const TResolverMatchType& aMatchType" |
|
235 * The type of match requested. |
|
236 * @param "const TUid& aBaseType" |
|
237 * The base type to match against |
|
238 * @param "const TUid& aSubType" |
|
239 * The sub type to match against |
|
240 * |
|
241 */ |
|
242 void CCustomMatchData::SetTypes(const TResolverMatchType& aMatchType, const TUid& aBaseType, const TUid& aSubType) |
|
243 { |
|
244 iMatchType = aMatchType; |
|
245 iBaseType = aBaseType; |
|
246 iSubType = aSubType; |
|
247 } |
|
248 |
|
249 /* |
|
250 * |
|
251 * Sets the match type to match against |
|
252 * |
|
253 * @param "const TResolverMatchType& aMatchType" |
|
254 * The type of match requested. |
|
255 * |
|
256 */ |
|
257 void CCustomMatchData::SetMatchType(const TResolverMatchType& aMatchType) |
|
258 { |
|
259 iMatchType = aMatchType; |
|
260 } |
|
261 |
|
262 /* |
|
263 * |
|
264 * Sets the base type to match against |
|
265 * |
|
266 * @param "const TUid& aBaseType" |
|
267 * The base type to match against |
|
268 * |
|
269 */ |
|
270 void CCustomMatchData::SetBaseType(const TUid& aBaseType) |
|
271 { |
|
272 iBaseType = aBaseType; |
|
273 } |
|
274 |
|
275 /* |
|
276 * |
|
277 * Sets the sub type to match against |
|
278 * |
|
279 * @param "const TUid& aSubType" |
|
280 * The sub type to match against |
|
281 * |
|
282 */ |
|
283 void CCustomMatchData::SetSubType(const TUid& aSubType) |
|
284 { |
|
285 iSubType = aSubType; |
|
286 } |
|
287 |
|
288 /* |
|
289 * |
|
290 * Sets the implementation type to match against |
|
291 * |
|
292 * @param "const TUid& aImplementationType" |
|
293 * The implementation uid of a specific codec to match against |
|
294 * |
|
295 */ |
|
296 void CCustomMatchData::SetImplementationType(const TUid& aImplementationType) |
|
297 { |
|
298 iImplementationType = aImplementationType; |
|
299 } |
|
300 /* |
|
301 * |
|
302 * Set a file extension to match against. |
|
303 * |
|
304 * @param "const TDesC8& aFileSuffix" |
|
305 * A reference to a file suffix to match against. |
|
306 * |
|
307 */ |
|
308 void CCustomMatchData::SetFileSuffixL(const TDesC& aFileSuffix) |
|
309 { |
|
310 delete iFileSuffix; iFileSuffix = NULL; |
|
311 iFileSuffix = aFileSuffix.AllocL(); |
|
312 } |
|
313 |
|
314 /* |
|
315 * |
|
316 * Retrieves the match type, base type and sub type to match against |
|
317 * |
|
318 * @param "TResolverMatchType& aMatchType" |
|
319 * The type of match requested. |
|
320 * @param "TUid& aBaseType" |
|
321 * The base type to match against |
|
322 * @param "TUid& aSubType" |
|
323 * The sub type to match against |
|
324 * |
|
325 */ |
|
326 void CCustomMatchData::GetTypes(TResolverMatchType& aMatchType, TUid& aBaseType, TUid& aSubType) const |
|
327 { |
|
328 aMatchType = iMatchType; |
|
329 aBaseType = iBaseType; |
|
330 aSubType = iSubType; |
|
331 } |
|
332 /* |
|
333 * |
|
334 * Retrieves the match type to match against |
|
335 * |
|
336 * @return "TResolverMatchType" |
|
337 * The type of match requested. |
|
338 * |
|
339 */ |
|
340 TResolverMatchType CCustomMatchData::MatchType() const |
|
341 { |
|
342 return iMatchType; |
|
343 } |
|
344 |
|
345 /* |
|
346 * |
|
347 * Retrieves the base type to match against |
|
348 * |
|
349 * @return "TUid" |
|
350 * The base type to match against |
|
351 * |
|
352 */ |
|
353 TUid CCustomMatchData::BaseType() const |
|
354 { |
|
355 return iBaseType; |
|
356 } |
|
357 |
|
358 /* |
|
359 * |
|
360 * Retrieves the sub type to match against |
|
361 * |
|
362 * @return "TUid" |
|
363 * The sub type to match against |
|
364 * |
|
365 */ |
|
366 TUid CCustomMatchData::SubType() const |
|
367 { |
|
368 return iSubType; |
|
369 } |
|
370 /* |
|
371 * |
|
372 * Retrieves the implementation type to match against |
|
373 * |
|
374 * @return "TUid" |
|
375 * The implementation of a specific codec to match against |
|
376 * |
|
377 */ |
|
378 |
|
379 TUid CCustomMatchData::ImplementationType() const |
|
380 { |
|
381 return iImplementationType; |
|
382 } |
|
383 |
|
384 /* |
|
385 * |
|
386 * Retrieves the string to match against. If no string is set |
|
387 * a null descriptor is returned. |
|
388 * |
|
389 * @return "TPtrC8" |
|
390 * The string to match against |
|
391 * |
|
392 */ |
|
393 const TPtrC8 CCustomMatchData::MatchString() const |
|
394 { |
|
395 TPtrC8 result; |
|
396 |
|
397 if(iMatchString) |
|
398 result.Set(*iMatchString); |
|
399 else |
|
400 result.Set(KNullDesC8); |
|
401 |
|
402 return result; |
|
403 } |
|
404 |
|
405 /* |
|
406 * |
|
407 * Retrieves the file extension to match against. If no suffix is set |
|
408 * a null descriptor is returned. |
|
409 * |
|
410 * @return "TPtrC8" |
|
411 * The file suffix to match against |
|
412 * |
|
413 */ |
|
414 const TPtrC CCustomMatchData::FileSuffix() const |
|
415 { |
|
416 TPtrC result; |
|
417 |
|
418 if(iFileSuffix) |
|
419 result.Set(*iFileSuffix); |
|
420 else |
|
421 result.Set(KNullDesC); |
|
422 |
|
423 return result; |
|
424 } |
|
425 |
|
426 /* Used to package up the object into a descriptor so |
|
427 * that it can be placed in the <code>DataType</code> descriptor of a |
|
428 * <code>TEComResolverParams</code> before being passed across the client |
|
429 * server boundary within ECom and handed to the custom resolver. |
|
430 * |
|
431 * @return "const HBufC8*" |
|
432 * A pointer to a desctriptor with the object packed in it. |
|
433 * The object does not take responsibility for the pointer |
|
434 * and the external code must ensure that the pointer is deleted. |
|
435 * The pointer is left on the cleanupstack. |
|
436 * |
|
437 */ |
|
438 HBufC8* CCustomMatchData::NewPackLC() const |
|
439 { |
|
440 //Calculate the size necessary size for the descriptor to pack the object |
|
441 TInt size = 0; |
|
442 if(iMatchString) |
|
443 size = iMatchString->Size(); |
|
444 if(iFileSuffix) |
|
445 size += iFileSuffix->Size(); |
|
446 |
|
447 size += iMatchReqUidsArray.Count() * sizeof(TUid); |
|
448 size += iOptionsUidsArray.Count() * sizeof(TUid); |
|
449 |
|
450 size += 9 * sizeof(TInt32); // The size necessary for |
|
451 // iMatchType |
|
452 // iBaseType |
|
453 // iSubType |
|
454 // iInterfaceUid |
|
455 // iMatchReqUidsArray.Count() |
|
456 // and the size of the descriptor (Max TInt32) |
|
457 // iExtensionOptions |
|
458 // iOptionsUidsArray.Count() |
|
459 // iOptions |
|
460 HBufC8* package = HBufC8::NewLC(size); |
|
461 TPtr8 packageDes = package->Des(); |
|
462 |
|
463 RDesWriteStream stream(packageDes); |
|
464 ExternalizeL(stream); |
|
465 stream.Close(); |
|
466 |
|
467 return package; |
|
468 } |
|
469 |
|
470 /* Used to unpack a descriptor packed using <code>PackL()</code> and set the |
|
471 * member variables to the data contained in the descriptor. The descriptor |
|
472 * is passed to the custom resolver by ECom and can be retrieved from the <code>DataType</code> |
|
473 * of <code>TEComResolverParams</code>. |
|
474 * |
|
475 * @param "const TDes8& aPackage" |
|
476 * A reference to a desctriptor created using <code>PackL()</code> to which |
|
477 * the member variables will be set. |
|
478 * |
|
479 */ |
|
480 void CCustomMatchData::UnPackL(const TDesC8& aPackage) |
|
481 { |
|
482 RDesReadStream stream(aPackage); |
|
483 InternalizeL(stream); |
|
484 stream.Close(); |
|
485 } |
|
486 |
|
487 /* Sets the array of required uids by copying all the elements of the array in parameter, |
|
488 * so the custom match data doesn't take ownership of the array specified. |
|
489 * |
|
490 * @param "const RUidDataArray& aMatchReqUidsArray" |
|
491 * The new required uids array. |
|
492 * |
|
493 */ |
|
494 void CCustomMatchData::SetMatchReqUidsL(const RUidDataArray& aMatchReqUidsArray) |
|
495 { |
|
496 iMatchReqUidsArray.Reset(); |
|
497 for(TInt index = 0 ; index < aMatchReqUidsArray.Count() ; index++) |
|
498 { |
|
499 User::LeaveIfError(iMatchReqUidsArray.Append(aMatchReqUidsArray[index])); |
|
500 } |
|
501 } |
|
502 |
|
503 /* Gets the array of required uids by copying all the elements of the member data array |
|
504 * in the array in parameter. |
|
505 * |
|
506 * @param "RUidDataArray& aMatchReqUidsArray" |
|
507 * The new required uids array to copy data to. |
|
508 * |
|
509 */ |
|
510 void CCustomMatchData::GetMatchReqUidsL(RUidDataArray& aMatchReqUidsArray) |
|
511 { |
|
512 aMatchReqUidsArray.Reset(); |
|
513 for(TInt index = 0 ; index < iMatchReqUidsArray.Count() ; index++) |
|
514 { |
|
515 User::LeaveIfError(aMatchReqUidsArray.Append(iMatchReqUidsArray[index])); |
|
516 } |
|
517 } |
|
518 |
|
519 /* Gets the array of required options uids by copying all the elements of the member data array |
|
520 * in the array in parameter. |
|
521 * |
|
522 * @param "RUidDataArray& aOptionsUidsArray" |
|
523 * The new required options uids array to copy data to. |
|
524 * |
|
525 */ |
|
526 void CCustomMatchData::GetOptionsUidsL(RUidDataArray& aOptionsUidsArray) |
|
527 { |
|
528 aOptionsUidsArray.Reset(); |
|
529 for(TInt index = 0 ; index < iOptionsUidsArray.Count() ; index++) |
|
530 { |
|
531 User::LeaveIfError(aOptionsUidsArray.Append(iOptionsUidsArray[index])); |
|
532 } |
|
533 } |
|
534 |
|
535 /* |
|
536 * Request that plugins support all extension interfaces interoperably. |
|
537 * |
|
538 * @param TInt aExtensionBits |
|
539 * Set of extensions (@see CImageDecoder::TOptions or @see CImageEncoder::TOptions) |
|
540 */ |
|
541 void CCustomMatchData::SetExtensionOptions(TUint aExtensionBits) |
|
542 { |
|
543 iExtensionOptions = (aExtensionBits & KIclExtensionOptionsMask); |
|
544 } |
|
545 |
|
546 /* |
|
547 * Request that plugins support specific options. |
|
548 * |
|
549 * @param TInt aOptions |
|
550 * Set of CImageDecoder options (@see CImageDecoder::TOptions) |
|
551 */ |
|
552 void CCustomMatchData::SetOptions(CImageDecoder::TOptions aOptions) |
|
553 { |
|
554 if ((aOptions & CImageDecoder::EOptionAutoRotate) != 0) |
|
555 { |
|
556 iOptionsUidsArray.Append(KUidJPGAutoRotateSupport); |
|
557 } |
|
558 if((aOptions & CImageDecoder::EOptionOptimisedPartialImageDecoding) != 0) |
|
559 { |
|
560 iOptionsUidsArray.Append(KUidJPGOptimisedPartialDecodingSupport); |
|
561 } |
|
562 iOptions = aOptions; |
|
563 } |
|
564 |
|
565 /* |
|
566 * Get list of all options required |
|
567 * |
|
568 * @return TUint |
|
569 * Set of options to match (@see CImagDecoder::TOptions) |
|
570 */ |
|
571 TUint CCustomMatchData::Options() |
|
572 { |
|
573 return iOptions; |
|
574 } |
|
575 |
|
576 /* |
|
577 * Get list of all extension interfaces required. |
|
578 * |
|
579 * @return TInt |
|
580 * Set of extensions to match (@see CImageDecoder::TOptions or @see CImageEncoder::TOptions) |
|
581 * |
|
582 */ |
|
583 TUint CCustomMatchData::ExtensionOptions() |
|
584 { |
|
585 return iExtensionOptions; |
|
586 } |