|
1 /* |
|
2 * Copyright (c) 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: Service Provider Settings property |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "spproperty.h" |
|
20 #include "spdefaultvalues.h" |
|
21 |
|
22 const TInt KMaxIntLen = 15; |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Constructor |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CSPProperty::CSPProperty() |
|
31 : iDataType( EDataTypeNotSet ), |
|
32 iPropertyType( EItemTypeNotDefined ) |
|
33 { |
|
34 } |
|
35 |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Constructor |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 void CSPProperty::ConstructL() |
|
42 { |
|
43 } |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // Constructor |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CSPProperty* CSPProperty::NewL() |
|
51 { |
|
52 CSPProperty* self = CSPProperty::NewLC(); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // Constructor |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C CSPProperty* CSPProperty::NewLC() |
|
63 { |
|
64 CSPProperty* self = new( ELeave ) CSPProperty(); |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Destructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C CSPProperty::~CSPProperty() |
|
76 { |
|
77 iPropertyValue.Close(); |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Returns name (type) of property |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 EXPORT_C TServicePropertyName CSPProperty::GetName() const |
|
86 { |
|
87 return iPropertyName; |
|
88 } |
|
89 |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // Sets the name and corresponding datatype of property |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C TInt CSPProperty::SetName( TServicePropertyName aPropertyName ) |
|
96 { |
|
97 iPropertyName = aPropertyName; |
|
98 iDataType = CSPProperty::DataType( aPropertyName ); |
|
99 iPropertyType = CSPProperty::PropertyType( aPropertyName ); |
|
100 |
|
101 return KErrNone; |
|
102 } |
|
103 |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // Return datatype of this property |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C TPropertyDataType CSPProperty::GetDataType() const |
|
110 { |
|
111 return iDataType; |
|
112 } |
|
113 |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // Set the datatype of this property |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CSPProperty::SetDataType( TPropertyDataType aDataType ) |
|
120 { |
|
121 iDataType = aDataType; |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Returns value of property |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 EXPORT_C TInt CSPProperty::GetValue( TInt& aValue ) const |
|
130 { |
|
131 TLex convert( iPropertyValue ); |
|
132 TInt err = convert.Val( aValue ); |
|
133 return err; |
|
134 } |
|
135 |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // Sets value of property. Value must match to datatype. |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C TInt CSPProperty::SetValue( TInt aValue ) |
|
142 { |
|
143 TInt ret( 0 ); |
|
144 if ( EDataTypeInt != iDataType ) |
|
145 { |
|
146 ret = KErrArgument; |
|
147 } |
|
148 else |
|
149 { |
|
150 TBuf<KMaxIntLen> val; |
|
151 val.AppendNum( aValue ); |
|
152 iPropertyValue.Close(); |
|
153 ret = iPropertyValue.Create( val ); |
|
154 } |
|
155 return ret; |
|
156 } |
|
157 |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // Returns value of property |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C TInt CSPProperty::GetValue( TOnOff& aValue ) const |
|
164 { |
|
165 TLex convert( iPropertyValue ); |
|
166 TInt value; |
|
167 TInt err = convert.Val( value ); |
|
168 if( err == KErrNone ) |
|
169 { |
|
170 if( value != EOONotSet && value != EOff && value != EOn ) |
|
171 { |
|
172 return KErrOverflow; |
|
173 } |
|
174 else |
|
175 { |
|
176 aValue = static_cast<TOnOff>( value ); |
|
177 return KErrNone; |
|
178 } |
|
179 } |
|
180 else |
|
181 { |
|
182 return err; |
|
183 } |
|
184 } |
|
185 |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // Sets value of property. Value must match to datatype. |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C TInt CSPProperty::SetValue( TOnOff aValue ) |
|
192 { |
|
193 TInt ret( 0 ); |
|
194 if ( EDataTypeOnOff != iDataType ) |
|
195 { |
|
196 ret = KErrArgument; |
|
197 } |
|
198 else |
|
199 { |
|
200 TBuf<KMaxIntLen> val; |
|
201 val.AppendNum( aValue ); |
|
202 iPropertyValue.Close(); |
|
203 ret = iPropertyValue.Create( val ); |
|
204 } |
|
205 return ret; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // Returns value of property |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 EXPORT_C TInt CSPProperty::GetValue( TDes& aValue ) const |
|
213 { |
|
214 aValue.Zero(); |
|
215 |
|
216 if ( aValue.MaxLength() >= iPropertyValue.Length() ) |
|
217 { |
|
218 aValue.Copy( iPropertyValue ); |
|
219 return KErrNone; |
|
220 } |
|
221 else |
|
222 { |
|
223 return KErrOverflow; |
|
224 } |
|
225 } |
|
226 |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // Sets value of property. Value must match to datatype. |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 EXPORT_C TInt CSPProperty::SetValue( const TDesC& aValue ) |
|
233 { |
|
234 TInt ret( 0 ); |
|
235 if ( aValue.Length() > KSPMaxDesLength ) |
|
236 { |
|
237 ret = KErrOverflow; |
|
238 } |
|
239 else |
|
240 { |
|
241 iPropertyValue.Close(); |
|
242 ret = iPropertyValue.Create( aValue ); |
|
243 } |
|
244 |
|
245 return ret; |
|
246 } |
|
247 |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // Copies data from other property |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 EXPORT_C void CSPProperty::CopyL( const CSPProperty& aSource ) |
|
254 { |
|
255 if( this != &aSource ) |
|
256 { |
|
257 User::LeaveIfError( SetName( aSource.GetName() ) ); |
|
258 SetDataType( aSource.GetDataType() ); |
|
259 SetPropertyType( aSource.GetPropertyType() ); |
|
260 |
|
261 iPropertyValue.Close(); |
|
262 User::LeaveIfError( iPropertyValue.Create( KSPMaxDesLength ) ); |
|
263 User::LeaveIfError( aSource.GetValue( iPropertyValue ) ); |
|
264 } |
|
265 } |
|
266 |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // Sets value of property without checking the datatype |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 TInt CSPProperty::SetValueNoDataTypeCheck( const TDesC& aValue ) |
|
273 { |
|
274 TInt ret( 0 ); |
|
275 if ( aValue.Length() > KSPMaxDesLength ) |
|
276 { |
|
277 ret = KErrOverflow; |
|
278 } |
|
279 else |
|
280 { |
|
281 iPropertyValue.Close(); |
|
282 ret = iPropertyValue.Create( aValue ); |
|
283 } |
|
284 |
|
285 return ret; |
|
286 } |
|
287 |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // Returns datatype by property name |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 EXPORT_C TPropertyDataType CSPProperty::DataType( TServicePropertyName aProperty ) |
|
294 { |
|
295 if ( aProperty >= EPropertyServiceAttributeMask && aProperty <= ESubPropertyVMBXLaunchUid ) |
|
296 { |
|
297 return EDataTypeInt; |
|
298 } |
|
299 else if ( aProperty >= EPropertyBrandId && aProperty <= ESubPropertyVMBXAddrScheme ) |
|
300 { |
|
301 return EDataTypeDes; |
|
302 } |
|
303 else if ( aProperty >= ESubPropertyVoIPEnabled && aProperty <= ESubPropertyVMBXEnabled ) |
|
304 { |
|
305 return EDataTypeOnOff; |
|
306 } |
|
307 else |
|
308 { |
|
309 return EDataTypeUnknown; |
|
310 } |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // Returns property type by property name |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C TSPItemType CSPProperty::PropertyType( TServicePropertyName aProperty ) |
|
318 { |
|
319 if ( ( aProperty >= ESubPropertyVoIPSettingsId && aProperty <= ESubPropertyVoIPTemporaryIAPId ) || |
|
320 ( aProperty >= ESubPropertyVoIPRelNumber && aProperty <= ESubPropertyVoIPAddrScheme ) || |
|
321 ( aProperty >= ESubPropertyVoIPEnabled && aProperty <= ESubPropertyVoIPEnabled ) ) |
|
322 { |
|
323 return EItemTypeVoIPSubProperty; |
|
324 } |
|
325 else if ( ( aProperty >= ESubPropertyPresenceSettingsId && aProperty <= ESubPropertyPresenceLaunchUid ) || |
|
326 ( aProperty >= ESubPropertyPresenceAddrScheme && aProperty <= ESubPropertyPresenceAddrScheme ) || |
|
327 ( aProperty >= ESubPropertyPresenceEnabled && aProperty <= ESubPropertyPresenceRequestPreference ) ) |
|
328 { |
|
329 return EItemTypePresenceSubProperty; |
|
330 } |
|
331 else if ( ( aProperty >= ESubPropertyIMSettingsId && aProperty <= ESubPropertyIMLaunchUid ) || |
|
332 ( aProperty >= ESubPropertyIMAddrScheme && aProperty <= ESubPropertyIMAddrScheme ) || |
|
333 ( aProperty >= ESubPropertyIMEnabled && aProperty <= ESubPropertyIMEnabled ) ) |
|
334 { |
|
335 return EItemTypeIMSubProperty; |
|
336 } |
|
337 else if ( ( aProperty >= ESubPropertyVMBXSettingsId && aProperty <= ESubPropertyVMBXLaunchUid ) || |
|
338 ( aProperty >= ESubPropertyVMBXListenAddress && aProperty <= ESubPropertyVMBXAddrScheme ) || |
|
339 ( aProperty >= ESubPropertyVMBXListenRegister && aProperty <= ESubPropertyVMBXEnabled ) ) |
|
340 { |
|
341 return EItemTypeVMBXSubProperty; |
|
342 } |
|
343 else if( ( aProperty >= EPropertyServiceAttributeMask && aProperty <= EPropertyRingtoneTimeout ) || |
|
344 ( aProperty >= EPropertyBrandId && aProperty <= EPropertyIncomingEmailserver ) ) |
|
345 { |
|
346 return EItemTypeProperty; |
|
347 } |
|
348 else |
|
349 { |
|
350 return EItemTypeNotDefined; |
|
351 } |
|
352 } |
|
353 |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // Compare operator |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 EXPORT_C TBool CSPProperty::operator==( const CSPProperty& aProperty ) const |
|
360 { |
|
361 TBool result( EFalse ); |
|
362 |
|
363 RBuf tmp; |
|
364 TInt err = tmp.Create( KSPMaxDesLength ); |
|
365 if( err != KErrNone ) |
|
366 { |
|
367 return EFalse; |
|
368 } |
|
369 err = aProperty.GetValue( tmp ); |
|
370 if( err != KErrNone ) |
|
371 { |
|
372 return EFalse; |
|
373 } |
|
374 |
|
375 result = ( iPropertyType == aProperty.GetPropertyType() && |
|
376 iPropertyName == aProperty.GetName() && |
|
377 iDataType == aProperty.GetDataType() && |
|
378 0 == iPropertyValue.Compare( tmp ) ); |
|
379 tmp.Close(); |
|
380 |
|
381 return result; |
|
382 } |
|
383 |
|
384 |
|
385 // --------------------------------------------------------------------------- |
|
386 // Get property type |
|
387 // --------------------------------------------------------------------------- |
|
388 // |
|
389 EXPORT_C TSPItemType CSPProperty::GetPropertyType() const |
|
390 { |
|
391 return iPropertyType; |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // Set default value for property |
|
396 // --------------------------------------------------------------------------- |
|
397 // |
|
398 TInt CSPProperty::SetPropertyType( TSPItemType aPropertyType ) |
|
399 { |
|
400 iPropertyType = aPropertyType; |
|
401 |
|
402 return KErrNone; |
|
403 } |
|
404 |
|
405 |