|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Encapsulates media |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CMPXMEDIA_H |
|
21 #define CMPXMEDIA_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <s32strm.h> |
|
25 #include <mpxcmn.h> |
|
26 #include <mpxmediabase.h> |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 |
|
30 /** |
|
31 * Encapsulates arbitrary data. The ID is a unique identifier for the type |
|
32 * of content contained within this object: there may be several supported IDs. |
|
33 * Supported IDs provide a means whereby a client who receives a media object |
|
34 * can request additional media objects from the same source using another of |
|
35 * the supported IDs. Attributes are referenced by flags which are unique to |
|
36 * the type of content contained in the object (i.e ID). The media object may |
|
37 * contain the full range of attribute values or some subset, depending both |
|
38 * on the attributes requested by the client and the capabilities of the source |
|
39 * of the data. |
|
40 * |
|
41 * @lib mpxcommon.lib |
|
42 */ |
|
43 |
|
44 class CMPXMedia : public CMPXMediaBase |
|
45 { |
|
46 public: |
|
47 /** |
|
48 * Two-phased constructor. |
|
49 * |
|
50 * @since S60 3.2.3 |
|
51 * @param aSupportedIds, denotes all possible content that can be provided |
|
52 * by the source of this media object |
|
53 * @return new instance of object |
|
54 */ |
|
55 IMPORT_C static CMPXMedia* NewL(const TArray<TInt>& aSupportedIds); |
|
56 |
|
57 /** |
|
58 * Two-phased constructor. |
|
59 * @since S60 3.2.3 |
|
60 * @return new instance of object |
|
61 */ |
|
62 IMPORT_C static CMPXMedia* NewL(); |
|
63 |
|
64 /** |
|
65 * Two-phased constructor. |
|
66 * |
|
67 * @since S60 3.2.3 |
|
68 * @param aStream create object from stream |
|
69 * @return new instance of object |
|
70 */ |
|
71 IMPORT_C static CMPXMedia* NewL(RReadStream& aStream); |
|
72 |
|
73 /** |
|
74 * Two-phased constructor. Creates new instance of CMPXMedia |
|
75 * which shares underlying data from aMedia; lifetime of |
|
76 * data is reference counted, i.e. all CMPXMedia instances which |
|
77 * reference same data must be deleted before underlying data is deleted. |
|
78 * |
|
79 * @since S60 3.2.3 |
|
80 * @param aMedia create object from media |
|
81 * @return new instance of object |
|
82 */ |
|
83 IMPORT_C static CMPXMedia* NewL(const CMPXMedia& aMedia); |
|
84 |
|
85 /** |
|
86 * Two-phased constructor. Creates object from existing data handle. |
|
87 * The data handle is used to indentify the data in a media object. |
|
88 * |
|
89 * @since S60 3.2.3 |
|
90 * @param aDataHandle handle to the data |
|
91 * @return new instance of object |
|
92 */ |
|
93 IMPORT_C static CMPXMedia* NewL(TInt aDataHandle); |
|
94 |
|
95 /** |
|
96 * Two-phased constructor. Creates new instance of CMPXMedia |
|
97 * which duplicates underlying data from aMedia. |
|
98 * |
|
99 * @since S60 3.2.3 |
|
100 * @param aMedia create object from media |
|
101 * @return new instance of object |
|
102 */ |
|
103 IMPORT_C static CMPXMedia* CopyL(const CMPXMedia& aMedia); |
|
104 |
|
105 /** |
|
106 * Destructor. |
|
107 * |
|
108 * @since S60 3.2.3 |
|
109 */ |
|
110 IMPORT_C ~CMPXMedia(); |
|
111 |
|
112 /** |
|
113 * Assignment operator. |
|
114 * It copies data handle and increase the reference count of the aMedia only. |
|
115 * |
|
116 * @since S60 3.2.3 |
|
117 * @param aMedia source media |
|
118 * @return reference to updated object |
|
119 */ |
|
120 IMPORT_C CMPXMedia& operator=(const CMPXMedia& aMedia); |
|
121 |
|
122 /** |
|
123 * Gets the total size and the currently used size of the global heap. |
|
124 * |
|
125 * @since S60 3.2.3 |
|
126 * @param aTotal Total size of memory (out parameter) |
|
127 * @param aUsed Used size of memory (out parameter) |
|
128 */ |
|
129 IMPORT_C static void HeapMemoryInfoL( TInt& aTotal, TInt& aUsed ); |
|
130 |
|
131 public: |
|
132 /** |
|
133 * Possible content IDs that denote the type of content the source of this |
|
134 * object can supply. |
|
135 * |
|
136 * @since S60 3.2.3 |
|
137 * @return IDs indicating type of content that can be contained within |
|
138 * this object |
|
139 */ |
|
140 IMPORT_C const TArray<TInt> SupportedIds() const; |
|
141 |
|
142 /** |
|
143 * The attributes provided in this media object. |
|
144 * |
|
145 * @since S60 3.2.3 |
|
146 * @return array of attributes indicating the attributes for the values |
|
147 * contained in this object |
|
148 */ |
|
149 IMPORT_C const TArray<TMPXAttribute> Attributes() const; |
|
150 |
|
151 /** |
|
152 * Checks if this object contains the value for a given attribute. |
|
153 * |
|
154 * @since S60 3.2.3 |
|
155 * @param aAttribute the specified attribute |
|
156 * @return whether supported or not |
|
157 */ |
|
158 IMPORT_C TBool IsSupported(const TMPXAttribute& aAttribute) const; |
|
159 |
|
160 /** |
|
161 * The number of attribute values provided in this media object. |
|
162 * |
|
163 * @since S60 3.2.3 |
|
164 * @return count of attribute values in this object |
|
165 */ |
|
166 IMPORT_C TInt Count() const; |
|
167 |
|
168 /** |
|
169 * The attribute for a specific index. |
|
170 * |
|
171 * @since S60 3.2.3 |
|
172 * @param aIndex the index from 0 to Count()-1, covering all the values |
|
173 * provided in this object |
|
174 * @return the attribute corresponding to the value at the specified index |
|
175 */ |
|
176 IMPORT_C const TMPXAttribute& Attribute(TInt aIndex) const; |
|
177 |
|
178 /** |
|
179 * The attributes set for a specific content id. |
|
180 * |
|
181 * @since S60 3.2.3 |
|
182 * @param aContentId content Id |
|
183 * @return the attributes set corresponding to content id |
|
184 */ |
|
185 IMPORT_C TUint AttributesSet(TInt aContentId) const; |
|
186 |
|
187 /** |
|
188 * The index of a given attribute. |
|
189 * |
|
190 * @since S60 3.2.3 |
|
191 * @param aAttribute the specified attribute |
|
192 * @return the index, or KErrNotFound if not present in this object |
|
193 */ |
|
194 IMPORT_C TInt Index(const TMPXAttribute& aAttribute) const; |
|
195 |
|
196 /** |
|
197 * The type of data stored for the index. |
|
198 * |
|
199 * @since S60 3.2.3 |
|
200 * @param aIndex the index whose type of value is queried |
|
201 * @return the data type at that index |
|
202 */ |
|
203 IMPORT_C TMPXAttributeType Type(TInt aIndex) const; |
|
204 |
|
205 /** |
|
206 * The type of data stored for the attribute. |
|
207 * |
|
208 * @since S60 3.2.3 |
|
209 * @param aAttribute the attribute whose type of value is queried |
|
210 * @return the data type of the attribute, |
|
211 * EMPXTypeUnknown returned if the attribute does not exist |
|
212 */ |
|
213 IMPORT_C TMPXAttributeType Type(const TMPXAttribute& aAttribute) const; |
|
214 |
|
215 /** |
|
216 * Clears all the attributes and values. |
|
217 * |
|
218 * @since S60 3.2.3 |
|
219 */ |
|
220 IMPORT_C void Reset(); |
|
221 |
|
222 /** |
|
223 * Deletes a given attribute and its value; No effect |
|
224 * if attribute is not present. |
|
225 * |
|
226 * @since S60 3.2.3 |
|
227 * @param aAttribute the attribute to delete |
|
228 */ |
|
229 IMPORT_C void Delete(const TMPXAttribute& aAttribute); |
|
230 |
|
231 /** |
|
232 * Deletes a given attribute and its value; No effect |
|
233 * if attribute is not present. |
|
234 * |
|
235 * @since S60 3.2.3 |
|
236 * @param aIndex the index from 0 to Count()-1 |
|
237 */ |
|
238 IMPORT_C void Delete(TInt aIndex); |
|
239 |
|
240 /** |
|
241 * The value for a specific attribute. |
|
242 * |
|
243 * @since S60 3.2.3 |
|
244 * @param aAttribute the attribute whose value is queried |
|
245 * @return value of the attribute |
|
246 */ |
|
247 IMPORT_C const TDesC& ValueText(const TMPXAttribute& aAttribute) const; |
|
248 |
|
249 /** |
|
250 * Add a new attribute value to this object, or modifies existing |
|
251 * value if already present. |
|
252 * |
|
253 * @since S60 3.2.3 |
|
254 * @param aAttribute the attribute whose value is added/modified |
|
255 * @param aValue text value to be set |
|
256 */ |
|
257 IMPORT_C void SetTextValueL(const TMPXAttribute& aAttribute, |
|
258 const TDesC& aValue); |
|
259 |
|
260 /** |
|
261 * Merges in the attributes of the provided media. |
|
262 * |
|
263 * @since S60 3.2.3 |
|
264 * @param aMedia Media object with attributes to merge in |
|
265 */ |
|
266 IMPORT_C void MergeMediaL( const CMPXMedia& aMedia ); |
|
267 |
|
268 /** |
|
269 * Compares if the specified media's attribute matches this one. |
|
270 * |
|
271 * @since S60 3.2.3 |
|
272 * @param aMedia Media object to match |
|
273 * @param aAtt Attribute to match |
|
274 * @return ETrue if matches, else EFalse |
|
275 */ |
|
276 IMPORT_C TBool Match( |
|
277 const CMPXMedia& aMedia, |
|
278 const TMPXAttribute& aAtt ); |
|
279 |
|
280 public: |
|
281 |
|
282 /** |
|
283 * The value for a specific attribute. it may return NULL |
|
284 * |
|
285 * This method supports all T types and CMPXMediaBase classes like |
|
286 * CMPXMedia and CMPXMediaArray. |
|
287 * |
|
288 * This method returns NULL (ASSERT happens on UDEB image) for CBase |
|
289 * objects other than CMPXMedia, CMPXMediaArray. |
|
290 * |
|
291 * @since S60 3.2.3 |
|
292 * @param aAttribute the attribute whose value is queried |
|
293 * @return value of the attribute, or NULL if not present |
|
294 * Note: Ownership is not transferred to caller |
|
295 * @deprecated if an error code is set for the attribue, use method: |
|
296 * CMPXMedia::ValueTObjectL(const TMPXAttribute& aAttribute), |
|
297 * CMPXMedia::ValueNoNewLCObjectL(const TMPXAttribute& aAttribute), |
|
298 * CMPXMedia::ValueCObjectL(const TMPXAttribute& aAttribute). |
|
299 * |
|
300 * For CMPXCollectionPath, use method: |
|
301 * CMPXMedia::ValueCObjectL(const TMPXAttribute& aAttribute). |
|
302 */ |
|
303 template<typename T> |
|
304 inline T* Value(const TMPXAttribute& aAttribute) const; |
|
305 |
|
306 /** |
|
307 * A copy of the value for a specific attribute. |
|
308 * If the media attribute does not exist, the default T object will be returned. |
|
309 * |
|
310 * @since S60 3.2.3 |
|
311 * @param aAttribute the attribute whose value is queried |
|
312 * @return copy of the value of the attribute |
|
313 */ |
|
314 template<typename T> |
|
315 inline T ValueTObjectL(const TMPXAttribute& aAttribute) const; |
|
316 |
|
317 /** |
|
318 * Copy an object out of media object. |
|
319 * Note: C++ default contructor of class C must be public. |
|
320 * |
|
321 * @since S60 3.2.3 |
|
322 * @param aAttribute the attribute whose value is queried |
|
323 * @return new copy object of class C |
|
324 */ |
|
325 template<typename C> |
|
326 inline C* ValueNoNewLCObjectL(const TMPXAttribute& aAttribute) const; |
|
327 |
|
328 /** |
|
329 * Copy an object out of media object. |
|
330 * Note: class C must implement the function NewL() and streamable. |
|
331 * |
|
332 * @since S60 3.2.3 |
|
333 * @param aAttribute the attribute whose value is queried |
|
334 * @return new copy object of class C |
|
335 */ |
|
336 template<typename C> |
|
337 inline C* ValueCObjectL(const TMPXAttribute& aAttribute) const; |
|
338 |
|
339 /** |
|
340 * Add a new attribute value to this object, or modifies existing |
|
341 * value if already present. |
|
342 * |
|
343 * @since S60 3.2.3 |
|
344 * @param aAttribute the attribute whose value is added/modified |
|
345 * @param aValue attribute value of the T object. |
|
346 */ |
|
347 template<typename T> |
|
348 inline void SetTObjectValueL(const TMPXAttribute& aAttribute, T aValue); |
|
349 |
|
350 /** |
|
351 * Add a new attribute value to this object, or modifies existing |
|
352 * value if already present. |
|
353 * |
|
354 * @since S60 3.2.3 |
|
355 * @param aAttribute the attribute whose value is added/modified |
|
356 * @param aValue pointer to the C object |
|
357 */ |
|
358 template<typename C> |
|
359 inline void SetNoNewLCObjectL(const TMPXAttribute& aAttribute,C* aValue); |
|
360 |
|
361 /** |
|
362 * Add a new attribute value to this object, or modifies existing |
|
363 * value if already present. |
|
364 * Uses CTypeObject::NewL( RReadStream& aStream ). |
|
365 * |
|
366 * @since S60 3.2.3 |
|
367 * @param aAttribute the attribute whose value is added/modified |
|
368 * @param aValue pointer to the C object |
|
369 */ |
|
370 template<typename C> |
|
371 inline void SetCObjectValueL(const TMPXAttribute& aAttribute,C* aValue); |
|
372 |
|
373 /** |
|
374 * A representation (handle) of the data stored in this object. |
|
375 * |
|
376 * @since S60 3.2.3 |
|
377 * @return TInt handle to the data |
|
378 */ |
|
379 inline TInt Data() const; |
|
380 |
|
381 /** |
|
382 * Set an error code to an attribute. |
|
383 * |
|
384 * @since S60 3.2.3 |
|
385 * @param aAttribute the attribute whose error code is setted. |
|
386 * @param aError error code of the attribute. |
|
387 * Note: if error code is set for an attribute, call to Value<T> for |
|
388 * the attribute will return NULL. You MUST be careful to check the |
|
389 * return value of Value<T>. The Value<T> is deprecated for this reason |
|
390 * and you should use ValueTObject instead. |
|
391 */ |
|
392 IMPORT_C void SetErrorL(const TMPXAttribute& aAttribute, TInt aError); |
|
393 |
|
394 /** |
|
395 * Get the error code of an attribute. |
|
396 * |
|
397 * @since S60 3.2.3 |
|
398 * @param aAttribute the attribute whose error code is retrieved. |
|
399 * @return TInt error code of the attribute, or KErrNone if no error code is set. |
|
400 */ |
|
401 IMPORT_C TInt Error(const TMPXAttribute& aAttribute) const; |
|
402 |
|
403 public: |
|
404 |
|
405 /** |
|
406 * Externalize media object. |
|
407 * |
|
408 * @since S60 3.2.3 |
|
409 * @param aStream write stream |
|
410 */ |
|
411 IMPORT_C void ExternalizeL(RWriteStream& aStream) const; |
|
412 |
|
413 /** |
|
414 * Internalize media object. |
|
415 * |
|
416 * @since S60 3.2.3 |
|
417 * @param aStream read stream |
|
418 */ |
|
419 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
420 |
|
421 private: |
|
422 |
|
423 /** |
|
424 * 2nd phase contructor. |
|
425 * |
|
426 * @since S60 3.2.3 |
|
427 * @param aSupportedIds support content ids |
|
428 */ |
|
429 void ConstructL(const TArray<TInt>& aSupportedIds); |
|
430 |
|
431 /** |
|
432 * 2nd phase contructor. |
|
433 * |
|
434 * @since S60 3.2.3 |
|
435 * @param aStream read stream |
|
436 */ |
|
437 void ConstructL(RReadStream& aStream); |
|
438 |
|
439 private: |
|
440 /** |
|
441 * Set data. |
|
442 * |
|
443 * @since S60 3.2.3 |
|
444 * @param aAttribute the attribute whose value is queried |
|
445 * @param aValue the value of the media attribute |
|
446 * @param aType object type of the media attribute |
|
447 * |
|
448 */ |
|
449 IMPORT_C void SetValueL(const TMPXAttribute& aAttribute, |
|
450 const TDesC8& aValue, |
|
451 TMPXAttributeType aType); |
|
452 |
|
453 /** |
|
454 * The value for a specific attribute. |
|
455 * |
|
456 * @since S60 3.2.3 |
|
457 * @param aAttribute the attribute whose value is queried |
|
458 * @return value of the attribute, or NULL if not present |
|
459 * Note: ownerhip of returned pointer is not transferred. |
|
460 */ |
|
461 IMPORT_C TAny* ValuePtr(const TMPXAttribute& aAttribute) const; |
|
462 |
|
463 |
|
464 /** |
|
465 * Get the binary value for a specific attribute. |
|
466 * |
|
467 * @since S60 3.2.3 |
|
468 * @param aAttribute the attribute whose value is queried |
|
469 * @return type of the attribute or EMPXTypeUnknown |
|
470 * if not present |
|
471 */ |
|
472 IMPORT_C TMPXAttributeType GetValue(const TMPXAttribute& aAttribute, TDes8& aValue) const; |
|
473 |
|
474 private: |
|
475 /** |
|
476 * Reconstructs local attribute array. |
|
477 * |
|
478 * @since S60 3.2.3 |
|
479 */ |
|
480 void RefreshAttributes(); |
|
481 |
|
482 /** |
|
483 * Frees all local data. |
|
484 * |
|
485 * @since S60 3.2.3 |
|
486 */ |
|
487 void ResetLocal(); |
|
488 |
|
489 /** |
|
490 * Copy an object out of a descriptor buffer. |
|
491 * Note: Cbased class must implement the function NewL(). |
|
492 * |
|
493 * @since S60 3.2.3 |
|
494 * @return new copy object of class T |
|
495 */ |
|
496 template<typename T> |
|
497 inline T* ValueL(const TDesC8& aData) const; |
|
498 |
|
499 /** |
|
500 * Copy an object out of media object. |
|
501 * |
|
502 * @since S60 3.2.3 |
|
503 * @return pointer to new copy of object, ownership transferred |
|
504 */ |
|
505 TAny* ValueCObjectL(const TDesC8& aData) const; |
|
506 |
|
507 private: |
|
508 RArray<TMPXAttribute> iAttributes; |
|
509 }; |
|
510 |
|
511 #include "mpxmedia.inl" |
|
512 |
|
513 #endif // CMPXMEDIA_H |