2 * Copyright (c) 2003-2005 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: A generic parameter class.
22 #ifndef AIW_GENERIC_PARAM_H
23 #define AIW_GENERIC_PARAM_H
27 #include "AiwGenericParam.hrh"
28 #include "AiwVariant.h"
31 * AIW generic parameter id. This data type should always be used when dealing
32 * with AIW generic parameters. UIDs can be used as AIW generic parameter IDs.
33 * However, values from 0 to 131071 are reserved.
34 * @see TAiwGenericParam
35 * @see TGenericParamIdValue
37 typedef TInt TGenericParamId;
42 * Generic parameter class for passing data between applications.
43 * A generic parameter is a pair of semantic ID and
44 * variant value. The semantic ID tells the purpose of the parameter,
45 * for example a file name, URL or phone number. The variant value contains
46 * the data format and actual value. This class does not implement any
47 * consistency checks between the semantic ID and value's data format.
48 * So one semantic ID can be expressed as alternative data formats.
50 * @lib ServiceHandler.lib
51 * @since Series 60 2.6
53 * @see CAiwGenericParamList
55 class TAiwGenericParam
57 public: // Constructors and destructor
59 * Constructs a generic parameter.
61 inline TAiwGenericParam();
64 * Constructs a generic parameter.
66 * @param aSemanticId The semantic ID of the parameter, one of TGenericParamId values.
68 inline TAiwGenericParam(TGenericParamId aSemanticId);
71 * Constructs a generic parameter.
73 * @param aSemanticId The semantic ID of the parameter, one of TGenericParamId values.
74 * @param aValue The parameter value.
76 inline TAiwGenericParam(TGenericParamId aSemanticId, const TAiwVariant& aValue);
80 * Sets the semantic ID. Possibly set previous ID is overwritten.
82 * @param aSemanticId The semantic ID of the parameter.
84 inline void SetSemanticId(TGenericParamId aSemanticId);
87 * Returns the semantic ID of this parameter.
89 * @return The semantic ID.
91 inline TGenericParamId SemanticId() const;
94 * Returns the value of this parameter.
96 * @return The value of the parameter.
98 inline TAiwVariant& Value();
101 * Returns the const value of this parameter.
103 * @return The const value of the parameter.
105 inline const TAiwVariant& Value() const;
108 * Resets the semantic ID and the value of this parameter.
112 private: // Interface for friend classes
114 void CopyLC(const TAiwGenericParam& aParam);
115 static void CleanupDestroy(TAny* aObj);
116 operator TCleanupItem();
117 void InternalizeL(RReadStream& aStream);
118 void ExternalizeL(RWriteStream& aStream) const;
122 /// Own: semantic ID of this parameter
123 TGenericParamId iSemanticId;
124 /// Own: value of this parameter
129 private: // friend declarations
130 friend class CAiwGenericParamList;
137 * Returns ETrue if two generic params are equal.
139 * @param aLhs Left hand side.
140 * @param aRhs Right hand side.
141 * @return ETrue if equal, EFalse otherwise.
143 IMPORT_C TBool operator==(const TAiwGenericParam& aLhs, const TAiwGenericParam& aRhs);
146 * Returns ETrue if two generic params are not equal.
148 * @param aLhs Left hand side.
149 * @param aRhs Right hand side.
150 * @return ETrue if not equal, EFalse otherwise.
152 inline TBool operator!=(const TAiwGenericParam& aLhs, const TAiwGenericParam& aRhs);
156 * Generic parameter list.
157 * A list containing TAiwGenericParam objects. Used for passing parameters
158 * between consumers and providers.
160 * @lib ServiceHandler.lib
161 * @since Series 60 2.6
163 NONSHARABLE_CLASS(CAiwGenericParamList): public CBase
165 public: // Constructors and destructor
167 * Creates an instance of this class.
169 * @return A pointer to the new instance.
171 IMPORT_C static CAiwGenericParamList* NewL();
174 * Creates an instance of this class.
176 * @param aReadStream A stream to initialize this parameter list from.
177 * @return A pointer to the new instance.
179 IMPORT_C static CAiwGenericParamList* NewL(RReadStream& aReadStream);
182 * Creates an instance of this class. Leaves the created instance on the
185 * @return A pointer to the new instance.
187 IMPORT_C static CAiwGenericParamList* NewLC();
190 * Creates an instance of this class. Leaves the created instance on the
193 * @param aReadStream A stream to initialize this parameter list from.
194 * @return A pointer to the new instance.
196 IMPORT_C static CAiwGenericParamList* NewLC(RReadStream& aReadStream);
201 virtual ~CAiwGenericParamList();
205 * Returns the number of parameters in the list.
207 * @return The number of parameters in the list.
209 IMPORT_C TInt Count() const;
212 * Returns the number of the parameters in the list by semantic id and datatype.
214 * @param aSemanticId The semantic ID of the parameter.
215 * @param aDataType The type id of data. Default is any type.
216 * @return The number of parameters in the list by semantic id and datatype.
218 IMPORT_C TInt Count(TGenericParamId aSemanticId,
219 TVariantTypeId aDataType = EVariantTypeAny) const;
222 * Returns a parameter from this list.
224 * @param aIndex Index of the parameter.
225 * @return The parameter at the aIndex position.
226 * @pre aIndex>=0 && aIndex<Count()
228 IMPORT_C const TAiwGenericParam& operator[](TInt aIndex) const;
231 * Appends a parameter to this list.
233 * @param aParam The parameter to append to this list. This object takes
234 * an own copy of the data in aParam.
236 IMPORT_C void AppendL(const TAiwGenericParam& aParam);
239 * Copies the given list and appends it to end of this list.
241 * @since Series 60 2.8
242 * @param aList A list to be copied and appended.
244 IMPORT_C void AppendL(const CAiwGenericParamList& aList);
247 * Removes the first found item with given semantic id from the list.
249 * @param aSemanticId Semantic id for the item to be removed.
250 * @return ETrue if an item for the given semantic id was found and removed.
253 IMPORT_C TBool Remove(TInt aSemanticId);
256 * Deletes all parameters in the list and resets the list.
258 IMPORT_C void Reset();
261 * Returns the first item matching the given semantic ID.
263 * @param aIndex Position in which to start searching. On return it contains
264 * the position of the found parameter. It is set to KErrNotFound,
265 * if no matching items were found.
266 * @param aSemanticId The semantic ID of the parameter.
267 * @param aDataType The type id of data. Default is any type.
268 * @return The first matching item.
270 IMPORT_C const TAiwGenericParam* FindFirst(
272 TGenericParamId aSemanticId,
273 TVariantTypeId aDataType = EVariantTypeAny) const;
275 * Returns the next item matching the given semantic ID.
277 * @param aIndex Position after which to start searching. On return it contains
278 * the position of the found parameter. It is set to KErrNotFound,
279 * if no matching items were found.
280 * @param aSemanticId The semantic ID of the parameter.
281 * @param aDataType The type id of data. Default is any type.
282 * @return The next matching item.
284 IMPORT_C const TAiwGenericParam* FindNext(
286 TGenericParamId aSemanticId,
287 TVariantTypeId aDataType = EVariantTypeAny) const;
290 * Externalizes this parameter list to a stream.
292 * @param aStream The stream.
293 * @see NewL(RReadStream& aStream)
294 * @see NewLC(RReadStream& aStream)
296 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
299 * Returns the externalized size of the parameter list in bytes.
303 IMPORT_C TInt Size() const;
306 * Internalizes the parameter list from a stream.
308 * @since Series60 2.8
309 * @param aStream The stream.
311 IMPORT_C void InternalizeL(RReadStream& aStream);
314 * Packs the parameter list to TIpcArgs structure for
315 * passing the generic param list to server over process boundary.
316 * Only one RFile handle parameter can be passed over process boundary.
318 * @since Series60 3.0
319 * @param aArgs Inter process call arguments.
320 * @return Packed parameter list.
322 IMPORT_C HBufC8* PackForServerL(TIpcArgs& aArgs);
325 * Unpacks the list from client message structure.
327 * @since Series60 3.0
328 * @param aArgs The list to be unpacked.
330 IMPORT_C void UnpackFromClientL(const RMessage2& aArgs);
332 private: // Implementation
333 CAiwGenericParamList();
335 void AppendL(RReadStream& aReadStream);
338 /// Own: the parameter list
339 RArray<TAiwGenericParam> iParameters;
344 #include "AiwGenericParam.inl"
346 #endif // AIW_GENERIC_PARAM_H