|
1 /* |
|
2 * Copyright (c) 2003-2005 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 the License "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: A generic parameter class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 #ifndef LIW_GENERIC_PARAM_H |
|
25 #define LIW_GENERIC_PARAM_H |
|
26 |
|
27 // INCLUDES |
|
28 #include <e32base.h> |
|
29 #include "liwgenericparam.hrh" |
|
30 #include "liwvariant.h" |
|
31 |
|
32 namespace LIW |
|
33 { |
|
34 /* |
|
35 * LIW generic parameter id. This data type should always be used when dealing |
|
36 * with LIW generic parameters. UIDs can be used as LIW generic parameter IDs. |
|
37 * However, values from 0 to 131071 are reserved. |
|
38 * @see TLiwGenericParam |
|
39 * @see TGenericParamIdValue |
|
40 */ |
|
41 typedef TInt TGenericParamId; |
|
42 } |
|
43 // CLASS DECLARATION |
|
44 |
|
45 /** |
|
46 * Generic parameter class for passing data between applications. |
|
47 * A generic parameter is a pair of semantic ID and |
|
48 * variant value. The semantic ID tells the purpose of the parameter, |
|
49 * for example a file name, URL or phone number. The variant value contains |
|
50 * the data format and actual value. This class does not implement any |
|
51 * consistency checks between the semantic ID and value's data format. |
|
52 * So one semantic ID can be expressed as alternative data formats. |
|
53 * |
|
54 * @lib ServiceHandler.lib |
|
55 * @since Series 60 2.6 |
|
56 * @see TLiwVariant |
|
57 * @see CLiwGenericParamList |
|
58 */ |
|
59 class TLiwGenericParam |
|
60 { |
|
61 public: // Constructors and destructor |
|
62 /** |
|
63 * Constructs a generic parameter. |
|
64 */ |
|
65 inline TLiwGenericParam(); |
|
66 |
|
67 /** |
|
68 * Constructs a generic parameter. |
|
69 * |
|
70 * @param aSemanticId The semantic ID of the parameter, one of TGenericParamId values. |
|
71 */ |
|
72 inline TLiwGenericParam(LIW::TGenericParamId aSemanticId); |
|
73 |
|
74 /** |
|
75 * Constructs a generic parameter. |
|
76 * |
|
77 * @param aSemanticId The semantic ID of the parameter, one of TGenericParamId values. |
|
78 * @param aValue The parameter value. |
|
79 */ |
|
80 inline TLiwGenericParam(LIW::TGenericParamId aSemanticId, const TLiwVariant& aValue); |
|
81 |
|
82 /** |
|
83 * Constructs a generic parameter. |
|
84 * |
|
85 * @param aName Name of the generic parameter |
|
86 * @param aValue The parameter value. |
|
87 */ |
|
88 inline TLiwGenericParam(const TDesC8& aName, const TLiwVariant& aValue); |
|
89 |
|
90 public: // Interface |
|
91 /** |
|
92 * Sets the semantic ID. Possibly set previous ID is overwritten. |
|
93 * |
|
94 * @param aSemanticId The semantic ID of the parameter. |
|
95 */ |
|
96 inline void SetSemanticId(LIW::TGenericParamId aSemanticId); |
|
97 |
|
98 /** |
|
99 * Set name. Possibly set previous name is overwritten. |
|
100 * |
|
101 * @param aName Parameter name. |
|
102 */ |
|
103 inline void SetNameL(const TDesC8& aName); |
|
104 |
|
105 /** |
|
106 * Set name and value. Possibly set previous name and value is overwritten. |
|
107 * |
|
108 * @param aName the parameter name. |
|
109 * |
|
110 * @param aValue the parameter value |
|
111 */ |
|
112 inline void SetNameAndValueL(const TDesC8& aName, const TLiwVariant& aValue); |
|
113 |
|
114 /** |
|
115 * Returns the semantic ID of this parameter. |
|
116 * |
|
117 * @return The semantic ID. |
|
118 */ |
|
119 inline LIW::TGenericParamId SemanticId() const; |
|
120 |
|
121 /** |
|
122 * Returns the name of this parameter. |
|
123 * |
|
124 * @return The name of the parameter. |
|
125 */ |
|
126 inline const TDesC8& Name() const; |
|
127 |
|
128 /** |
|
129 * Returns the value of this parameter. |
|
130 * |
|
131 * @return The value of the parameter. |
|
132 */ |
|
133 inline TLiwVariant& Value(); |
|
134 |
|
135 /** |
|
136 * Returns the const value of this parameter. |
|
137 * |
|
138 * @return The const value of the parameter. |
|
139 */ |
|
140 inline const TLiwVariant& Value() const; |
|
141 |
|
142 /** |
|
143 * Resets the semantic ID and the value of this parameter. |
|
144 */ |
|
145 inline void Reset(); |
|
146 |
|
147 /** |
|
148 * TLiwGenericParam cleanup method |
|
149 * |
|
150 * !!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|
151 * |
|
152 * Parameters can be pushed into the CleanupStack using this method |
|
153 * along with TCleanupItem |
|
154 * |
|
155 * @ param aObj - TLiwGenericParam Object but of type TAny* for usage with TCleanupItem |
|
156 * |
|
157 * Example 1: Here the client explicitly pushes the parameter into the CleanupStack using TCleanupItem |
|
158 * |
|
159 * @code |
|
160 * TLiwGenericParam param; |
|
161 * CleanupStack::PushL( TCleanupItem( TLiwGenericParam::ParamCleanup , ¶m ) ); |
|
162 * User::Leave(KErrGeneral); //This calls the ParamCleanup method which cleans up TLiwGenericParam |
|
163 * CleanupStack::Pop(¶m); |
|
164 * param.Reset(); |
|
165 * @endcode |
|
166 * |
|
167 * Example 2: Here the client calls the PushL method of TLiwGenericParam which pushes the object into |
|
168 * the CleanupStack using TCleanupItem |
|
169 * |
|
170 * @code |
|
171 * TLiwGenericParam param; |
|
172 * param.PushL(); |
|
173 * User::Leave(KErrGeneral); //This calls the ParamCleanup method which cleans up TLiwGenericParam |
|
174 * CleanupStack::Pop(¶m); |
|
175 * param.Reset(); |
|
176 * @endcode |
|
177 * |
|
178 * The clients can use the convenient PushL method which is recommended (as shown in e.g 2) rather than |
|
179 * explicitly pushing the parameter object into the CleanupStack using TCleanupItem and ParamCleanup. |
|
180 * |
|
181 * @ see PushL() method |
|
182 */ |
|
183 IMPORT_C static void ParamCleanup(TAny* aObj); |
|
184 |
|
185 /** |
|
186 * A friendly and convenient method to push the TLiwGenericParam Object into the CleanupStack |
|
187 * |
|
188 * !!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|
189 * |
|
190 * This method informs the CleanupStack that ParamCleanup method should be called incase of any Leave |
|
191 * |
|
192 * Example: |
|
193 * |
|
194 * @code |
|
195 * TLiwGenericParam param; |
|
196 * param.PushL(); //This pushes the parameter object "param" into the CleanupStack using TCleanupItem and ParamCleanup. |
|
197 * User::Leave(KErrGeneral); //This calls the ParamCleanup method which cleans up TLiwGenericParam |
|
198 * CleanupStack::Pop(¶m); //These statements are not executed |
|
199 * param.Reset(); |
|
200 * @endcode |
|
201 * |
|
202 * This method is recommended than explicitly pushing the parameter object into the CleanupStack |
|
203 * using TCleanupItem and ParamCleanup. |
|
204 * |
|
205 * @see ParamCleanup() method |
|
206 */ |
|
207 IMPORT_C void PushL(); |
|
208 |
|
209 private: // Interface for friend classes |
|
210 void Destroy(); |
|
211 void CopyLC(const TLiwGenericParam& aParam); |
|
212 static void CleanupDestroy(TAny* aObj); |
|
213 operator TCleanupItem(); |
|
214 void InternalizeL(RReadStream& aStream); |
|
215 void ExternalizeL(RWriteStream& aStream) const; |
|
216 TInt Size() const; |
|
217 |
|
218 private: // Data |
|
219 /// Own: semantic ID of this parameter |
|
220 LIW::TGenericParamId iSemanticId; |
|
221 /// Own: value of this parameter |
|
222 TLiwVariant iValue; |
|
223 /// Reserved member |
|
224 TAny* iReserved; |
|
225 |
|
226 private: // friend declarations |
|
227 friend class CLiwGenericParamList; |
|
228 friend class CLiwDefaultList; |
|
229 friend class CLiwDefaultMap; |
|
230 }; |
|
231 |
|
232 |
|
233 // FUNCTIONS |
|
234 |
|
235 /** |
|
236 * Returns ETrue if two generic params are equal. |
|
237 * |
|
238 * @param aLhs Left hand side. |
|
239 * @param aRhs Right hand side. |
|
240 * @return ETrue if equal, EFalse otherwise. |
|
241 */ |
|
242 IMPORT_C TBool operator==(const TLiwGenericParam& aLhs, const TLiwGenericParam& aRhs); |
|
243 |
|
244 /** |
|
245 * Returns ETrue if two generic params are not equal. |
|
246 * |
|
247 * @param aLhs Left hand side. |
|
248 * @param aRhs Right hand side. |
|
249 * @return ETrue if not equal, EFalse otherwise. |
|
250 */ |
|
251 inline TBool operator!=(const TLiwGenericParam& aLhs, const TLiwGenericParam& aRhs); |
|
252 |
|
253 |
|
254 /** |
|
255 * Generic parameter list. |
|
256 * A list containing TLiwGenericParam objects. Used for passing parameters |
|
257 * between consumers and providers. |
|
258 * |
|
259 * @lib ServiceHandler.lib |
|
260 * @since Series 60 2.6 |
|
261 */ |
|
262 NONSHARABLE_CLASS(CLiwGenericParamList): public CBase |
|
263 { |
|
264 public: // Constructors and destructor |
|
265 /** |
|
266 * Creates an instance of this class. |
|
267 * |
|
268 * @return A pointer to the new instance. |
|
269 */ |
|
270 IMPORT_C static CLiwGenericParamList* NewL(); |
|
271 |
|
272 /** |
|
273 * Creates an instance of this class. |
|
274 * |
|
275 * @param aReadStream A stream to initialize this parameter list from. |
|
276 * @return A pointer to the new instance. |
|
277 */ |
|
278 IMPORT_C static CLiwGenericParamList* NewL(RReadStream& aReadStream); |
|
279 |
|
280 /** |
|
281 * Creates an instance of this class. Leaves the created instance on the |
|
282 * cleanup stack. |
|
283 * |
|
284 * @return A pointer to the new instance. |
|
285 */ |
|
286 IMPORT_C static CLiwGenericParamList* NewLC(); |
|
287 |
|
288 /** |
|
289 * Creates an instance of this class. Leaves the created instance on the |
|
290 * cleanup stack. |
|
291 * |
|
292 * @param aReadStream A stream to initialize this parameter list from. |
|
293 * @return A pointer to the new instance. |
|
294 */ |
|
295 IMPORT_C static CLiwGenericParamList* NewLC(RReadStream& aReadStream); |
|
296 |
|
297 /** |
|
298 * Destructor. |
|
299 */ |
|
300 virtual ~CLiwGenericParamList(); |
|
301 |
|
302 public: // Interface |
|
303 /** |
|
304 * Returns the number of parameters in the list. |
|
305 * |
|
306 * @return The number of parameters in the list. |
|
307 */ |
|
308 IMPORT_C TInt Count() const; |
|
309 |
|
310 /** |
|
311 * Returns the number of the parameters in the list by semantic id and datatype. |
|
312 * |
|
313 * @param aSemanticId The semantic ID of the parameter. |
|
314 * @param aDataType The type id of data. Default is any type. |
|
315 * @return The number of parameters in the list by semantic id and datatype. |
|
316 */ |
|
317 IMPORT_C TInt Count(LIW::TGenericParamId aSemanticId, |
|
318 LIW::TVariantTypeId aDataType = LIW::EVariantTypeAny) const; |
|
319 |
|
320 /** |
|
321 * Returns a parameter from this list. |
|
322 * |
|
323 * @param aIndex Index of the parameter. |
|
324 * @return The parameter at the aIndex position. |
|
325 * @pre aIndex>=0 && aIndex<Count() |
|
326 */ |
|
327 IMPORT_C const TLiwGenericParam& operator[](TInt aIndex) const; |
|
328 |
|
329 /** |
|
330 * Gets an entry from the collection based on an integeral index. |
|
331 * Note ! This method allocates memory. To ensure proper cleanup you shall call PushL method beforehand. |
|
332 * |
|
333 * @param aIndex an index to get an entry from the collection |
|
334 * @param aEntry the returned element from the collection. |
|
335 * |
|
336 * !!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|
337 * |
|
338 * This is a copy of TLiwGenericParam present in the list at the particular index. To ensure proper cleanup |
|
339 * TLiwGenericParam::PushL method should be called beforehand. |
|
340 * |
|
341 * @code |
|
342 * CLiwGenericParamList* param = CLiwGenericParamList::NewLC(); |
|
343 * //... param is filled with some semantic Id and TLiwVariant value ... |
|
344 * |
|
345 * TLiwGenericParam outParam; |
|
346 * outParam.PushL(); |
|
347 * //This pushes the parameter object "outParam" into the CleanupStack using TCleanupItem and ParamCleanup. |
|
348 * |
|
349 * param->AtL(0,outParam); |
|
350 * //This fills the "outParam" with the parameter value present in the 0th position of parameter list, but |
|
351 * //if there is any Leave in AtL, then ParamCleanup method is called for proper cleanup |
|
352 * |
|
353 * CleanupStack::Pop(&outParam); |
|
354 * outParam.Reset(); |
|
355 * CleanupStack::PopAndDestroy(param); |
|
356 * @endcode |
|
357 * |
|
358 * @return false if no element is found at the passed index; |
|
359 * true if an element is found |
|
360 * |
|
361 * @see CLiwDefaultList::AtL |
|
362 * @see TLiwGenericParam::PushL |
|
363 */ |
|
364 IMPORT_C void AtL(TInt aIndex, TLiwGenericParam& aParam) const; |
|
365 |
|
366 /** |
|
367 * Appends a parameter to this list. |
|
368 * |
|
369 * @param aParam The parameter to append to this list. This object takes |
|
370 * an own copy of the data in aParam. |
|
371 */ |
|
372 IMPORT_C void AppendL(const TLiwGenericParam& aParam); |
|
373 |
|
374 /** |
|
375 * Copies the given list and appends it to end of this list. |
|
376 * |
|
377 * @since Series 60 2.8 |
|
378 * @param aList A list to be copied and appended. |
|
379 */ |
|
380 IMPORT_C void AppendL(const CLiwGenericParamList& aList); |
|
381 |
|
382 /** |
|
383 * Removes the first found item with given semantic id from the list. |
|
384 * |
|
385 * @param aSemanticId Semantic id for the item to be removed. |
|
386 * @return ETrue if an item for the given semantic id was found and removed. |
|
387 * EFalse otherwise. |
|
388 */ |
|
389 IMPORT_C TBool Remove(TInt aSemanticId); |
|
390 |
|
391 /** |
|
392 * Removes the first found item with given string based semantic id from the list. |
|
393 * |
|
394 * @param aSemanticId Semantic id for the item to be removed. |
|
395 * @return ETrue if an item for the given semantic id was found and removed. |
|
396 * EFalse otherwise. |
|
397 */ |
|
398 IMPORT_C void Remove(const TDesC8& aName); |
|
399 |
|
400 /** |
|
401 * Deletes all parameters in the list and resets the list. |
|
402 */ |
|
403 IMPORT_C void Reset(); |
|
404 |
|
405 /** |
|
406 * Returns the first item matching the given semantic ID. |
|
407 * |
|
408 * @param aIndex Position in which to start searching. On return it contains |
|
409 * the position of the found parameter. It is set to KErrNotFound, |
|
410 * if no matching items were found. |
|
411 * @param aSemanticId The semantic ID of the parameter. |
|
412 * @param aDataType The type id of data. Default is any type. |
|
413 * @return The first matching item. |
|
414 */ |
|
415 IMPORT_C const TLiwGenericParam* FindFirst( |
|
416 TInt& aIndex, |
|
417 LIW::TGenericParamId aSemanticId, |
|
418 LIW::TVariantTypeId aDataType = LIW::EVariantTypeAny) const; |
|
419 /** |
|
420 * Returns the next item matching the given semantic ID. |
|
421 * |
|
422 * @param aIndex Position after which to start searching. On return it contains |
|
423 * the position of the found parameter. It is set to KErrNotFound, |
|
424 * if no matching items were found. |
|
425 * @param aSemanticId The semantic ID of the parameter. |
|
426 * @param aDataType The type id of data. Default is any type. |
|
427 * @return The next matching item. |
|
428 */ |
|
429 IMPORT_C const TLiwGenericParam* FindNext( |
|
430 TInt& aIndex, |
|
431 LIW::TGenericParamId aSemanticId, |
|
432 LIW::TVariantTypeId aDataType = LIW::EVariantTypeAny) const; |
|
433 |
|
434 /** |
|
435 * Returns item matching the given name. |
|
436 * |
|
437 * @param aIndex Position in which to start searching, on return contains |
|
438 * position of the found parameter. Is set to KErrNotFound, |
|
439 * if no matching items were found. |
|
440 * @param aName Parameter name. |
|
441 * @param aDataType The type id of data. Default is any type. |
|
442 * @return The first matching item. |
|
443 */ |
|
444 IMPORT_C const TLiwGenericParam* FindFirst( |
|
445 TInt& aIndex, |
|
446 const TDesC8& aName, |
|
447 LIW::TVariantTypeId aDataType = LIW::EVariantTypeAny) const; |
|
448 |
|
449 /** |
|
450 * Returns item matching the given name. |
|
451 * |
|
452 * @param aIndex Position in which to start searching, on return contains |
|
453 * position of the found parameter. Is set to KErrNotFound, |
|
454 * if no matching items were found. |
|
455 * @param aName Parameter name. |
|
456 * @param aDataType The type id of data. Default is any type. |
|
457 * @return The first matching item. |
|
458 */ |
|
459 IMPORT_C const TLiwGenericParam* FindNext( |
|
460 TInt& aIndex, |
|
461 const TDesC8& aName, |
|
462 LIW::TVariantTypeId aDataType = LIW::EVariantTypeAny) const; |
|
463 |
|
464 /** |
|
465 * Externalizes this parameter list to a stream. |
|
466 * |
|
467 * @param aStream The stream. |
|
468 * @see NewL(RReadStream& aStream) |
|
469 * @see NewLC(RReadStream& aStream) |
|
470 */ |
|
471 IMPORT_C void ExternalizeL(RWriteStream& aStream) const; |
|
472 |
|
473 /** |
|
474 * Returns the externalized size of the parameter list in bytes. |
|
475 * |
|
476 * @return The size. |
|
477 */ |
|
478 IMPORT_C TInt Size() const; |
|
479 |
|
480 /** |
|
481 * Internalizes the parameter list from a stream. |
|
482 * |
|
483 * @since Series60 2.8 |
|
484 * @param aStream The stream. |
|
485 */ |
|
486 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
487 |
|
488 /** |
|
489 * Packs the parameter list to TIpcArgs structure for |
|
490 * passing the generic param list to server over process boundary. |
|
491 * Only one RFile handle parameter can be passed over process boundary. |
|
492 * |
|
493 * @since Series60 3.0 |
|
494 * @param aArgs Inter process call arguments. |
|
495 * @return Packed parameter list. |
|
496 */ |
|
497 IMPORT_C HBufC8* PackForServerL(TIpcArgs& aArgs); |
|
498 |
|
499 /** |
|
500 * Unpacks the list from client message structure. |
|
501 * |
|
502 * @since Series60 3.0 |
|
503 * @param aArgs The list to be unpacked. |
|
504 */ |
|
505 IMPORT_C void UnpackFromClientL(const RMessage2& aArgs); |
|
506 |
|
507 private: // Implementation |
|
508 CLiwGenericParamList(); |
|
509 void ConstructL(); |
|
510 void AppendL(RReadStream& aReadStream); |
|
511 |
|
512 private: // Data |
|
513 /// Own: the parameter list |
|
514 RArray<TLiwGenericParam> iParameters; |
|
515 friend class CLiwDefaultList; |
|
516 friend class CLiwDefaultMap; |
|
517 }; |
|
518 |
|
519 |
|
520 // INLINE FUNCTIONS |
|
521 #include "liwgenericparam.inl" |
|
522 |
|
523 #endif // LIW_GENERIC_PARAM_H |
|
524 |
|
525 // End of File |