0
|
1 |
// Copyright (c) 2007-2009 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 |
// Implementation of class COptionConfig configuration parameter interface
|
|
15 |
//
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
/**
|
|
20 |
@file
|
|
21 |
@see COptionConfig
|
|
22 |
*/
|
|
23 |
|
|
24 |
#include <debuglogging.h>
|
|
25 |
|
|
26 |
#include <optionconfig.h>
|
|
27 |
|
|
28 |
|
|
29 |
/**
|
|
30 |
Allocates and constructs a COptionConfig object.
|
|
31 |
@param aIndex Internal index to the component that owns the object
|
|
32 |
@param aUID UID of the component that owns the object
|
|
33 |
@param aSource Type of component that owns the object
|
|
34 |
@param aType Type of parameter
|
|
35 |
@param aPrompt Prompt to present to user
|
|
36 |
@param aNumOptions Number of options that the parameter can be set to. Only applies if type is ETMultiEntryEnum.
|
|
37 |
@param aOptions Comma separated list of options. Applies to ETMultiEntryEnum and ETBool.
|
|
38 |
@param aVal Integer value. Applies to ETInt, ETUInt, ETBool.
|
|
39 |
@param aStrValue String value. Applies to ETString, ETFileName, ETMultiEntry, ETBool.
|
|
40 |
*/
|
|
41 |
EXPORT_C COptionConfig* COptionConfig::NewL(
|
|
42 |
const TUint32 & aIndex,
|
|
43 |
const TUint32 & aUID,
|
|
44 |
const TParameterSource & aSource,
|
|
45 |
const TOptionType & aType,
|
|
46 |
const TDesC & aPrompt,
|
|
47 |
const TUint32 & aNumOptions,
|
|
48 |
const TDesC & aOptions,
|
|
49 |
const TInt32 & aVal,
|
|
50 |
const TDesC & aStrValue)
|
|
51 |
|
|
52 |
{
|
|
53 |
|
|
54 |
|
|
55 |
const TInt size =
|
|
56 |
sizeof( TUint32 ) // iType
|
|
57 |
+ sizeof( TUint32 ) // iSource
|
|
58 |
+ sizeof( TUint32 ) // iIndex
|
|
59 |
+ sizeof( TUint32 ) // iInstance
|
|
60 |
+ sizeof( TUint32 ) // iUID
|
|
61 |
|
|
62 |
+ sizeof( TUint32 ) // When externalized, we send the name length, so must include this
|
|
63 |
+ 2 // When externalized, the << operator writes 2 bytes for the descriptor size
|
|
64 |
+ aPrompt.Size() // iPrompt
|
|
65 |
|
|
66 |
+ sizeof( TUint32 ) // iNumOptions
|
|
67 |
|
|
68 |
+ sizeof( TUint32 ) // When externalized, we send the name length, so must include this
|
|
69 |
+ 2 // When externalized, the << operator writes 2 bytes for the descriptor size
|
|
70 |
+ aOptions.Size() // iOptions
|
|
71 |
|
|
72 |
+ sizeof ( TInt32 ) // iValue
|
|
73 |
|
|
74 |
+ sizeof( TUint32 ) // When externalized, we send the name length, so must include this
|
|
75 |
+ 2 // When externalized, the << operator writes 2 bytes for the descriptor size
|
|
76 |
+ aStrValue.Size() // iStrValue
|
|
77 |
|
|
78 |
+ sizeof( TUint32 );// iSize itself
|
|
79 |
|
|
80 |
if( size >= MaxSize() )
|
|
81 |
{
|
|
82 |
LOG_MSG3( "COptionConfig::NewL() : Attempting to allocate %d bytes but maximum is %d\n",
|
|
83 |
size, MaxSize() );
|
|
84 |
|
|
85 |
User::Leave( KErrTooBig );
|
|
86 |
}
|
|
87 |
|
|
88 |
COptionConfig * data = new (ELeave) COptionConfig( aType, aSource, aIndex, aUID, aNumOptions, aVal );
|
|
89 |
CleanupStack::PushL( data );
|
|
90 |
|
|
91 |
data->ConstructL( aPrompt, aOptions, aStrValue );
|
|
92 |
CleanupStack::Pop(data);
|
|
93 |
return (data);
|
|
94 |
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
/**
|
|
99 |
Allocates and constructs a COptionConfig object from a descriptor.
|
|
100 |
The descriptor contains an externalised version of a COptionConfig object.
|
|
101 |
This method is typically used to obtain a COptionConfig object from a
|
|
102 |
descriptor returned by the core dump server.
|
|
103 |
|
|
104 |
@param aStreamData Descriptor with externalised/streamed object
|
|
105 |
@see InternalizeL
|
|
106 |
@see ExternalizeL
|
|
107 |
*/
|
|
108 |
EXPORT_C COptionConfig* COptionConfig::NewL( const TDesC8 & aStreamData )
|
|
109 |
{
|
|
110 |
|
|
111 |
COptionConfig* data = new (ELeave) COptionConfig();
|
|
112 |
|
|
113 |
CleanupStack::PushL( data );
|
|
114 |
|
|
115 |
// Open a read stream for the descriptor
|
|
116 |
RDesReadStream stream( aStreamData );
|
|
117 |
|
|
118 |
CleanupClosePushL( stream );
|
|
119 |
|
|
120 |
data->InternalizeL( stream );
|
|
121 |
|
|
122 |
CleanupStack::PopAndDestroy( &stream ); // finished with the stream
|
|
123 |
|
|
124 |
CleanupStack::Pop( data );
|
|
125 |
|
|
126 |
return (data);
|
|
127 |
|
|
128 |
}
|
|
129 |
|
|
130 |
|
|
131 |
/**
|
|
132 |
Destructor. Deletes descriptors.
|
|
133 |
*/
|
|
134 |
EXPORT_C COptionConfig::~COptionConfig()
|
|
135 |
{
|
|
136 |
|
|
137 |
|
|
138 |
if( iPrompt )
|
|
139 |
{
|
|
140 |
delete iPrompt;
|
|
141 |
}
|
|
142 |
|
|
143 |
if( iOptions )
|
|
144 |
{
|
|
145 |
delete iOptions;
|
|
146 |
}
|
|
147 |
|
|
148 |
if( iStrValue )
|
|
149 |
{
|
|
150 |
delete iStrValue;
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
/**
|
|
156 |
First phase contructor. Sets the size to 0, descriptors to NULL.
|
|
157 |
@see COptionConfig::NewL()
|
|
158 |
*/
|
|
159 |
COptionConfig::COptionConfig(const TOptionType & aType,
|
|
160 |
const TParameterSource & aSource,
|
|
161 |
const TUint32 & aIndex,
|
|
162 |
const TUint32 & aUID,
|
|
163 |
const TUint32 & aNumOptions,
|
|
164 |
const TInt32 & aValue ) :
|
|
165 |
iType ( aType ),
|
|
166 |
iSource ( aSource ),
|
|
167 |
iIndex ( aIndex ),
|
|
168 |
iUID ( aUID ),
|
|
169 |
iPrompt ( NULL ),
|
|
170 |
iNumOptions ( aNumOptions ),
|
|
171 |
iOptions ( NULL ),
|
|
172 |
iValue ( aValue ),
|
|
173 |
iStrValue ( NULL ),
|
|
174 |
iSize ( 0 ),
|
|
175 |
iInstance ( 0 )
|
|
176 |
|
|
177 |
{
|
|
178 |
|
|
179 |
|
|
180 |
/*
|
|
181 |
LOG_MSG2( "COptionConfig::COptionConfig() : iSize=%d\n", iSize );
|
|
182 |
LOG_MSG4( " iType=%d, iSource=%d, iIndex=%d", iType, iSource, iIndex );
|
|
183 |
LOG_MSG4( " iUID=0x%X, iNumOpts=%d, iValue=%d\n", iUID, iNumOptions, iValue );
|
|
184 |
*/
|
|
185 |
|
|
186 |
}
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
void COptionConfig::ConstructStringL( const TDesC & aSource, HBufC ** aDest )
|
|
191 |
{
|
|
192 |
|
|
193 |
TInt sourceLength = aSource.Length();
|
|
194 |
|
|
195 |
if( sourceLength > 0 )
|
|
196 |
{
|
|
197 |
|
|
198 |
TInt newMaxLength = Align4( KCDSMaxConfigParamStr );
|
|
199 |
if( *aDest )
|
|
200 |
{
|
|
201 |
delete *aDest;
|
|
202 |
}
|
|
203 |
|
|
204 |
*aDest = HBufC::NewL( newMaxLength );
|
|
205 |
CleanupStack::PushL( *aDest );
|
|
206 |
|
|
207 |
TPtr destDes = (*aDest)->Des();
|
|
208 |
|
|
209 |
destDes.FillZ( newMaxLength );
|
|
210 |
|
|
211 |
if( sourceLength >= KCDSMaxConfigParamStr )
|
|
212 |
{
|
|
213 |
sourceLength = KCDSMaxConfigParamStr - 1; // We want to leave the null at the end always
|
|
214 |
}
|
|
215 |
|
|
216 |
destDes.Copy( aSource.Ptr(), sourceLength );
|
|
217 |
|
|
218 |
destDes.SetLength( sourceLength );
|
|
219 |
CleanupStack::Pop( *aDest );
|
|
220 |
|
|
221 |
}
|
|
222 |
else
|
|
223 |
{
|
|
224 |
*aDest = NULL;
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
/**
|
|
231 |
Second phase constructor initialises the descriptors
|
|
232 |
*/
|
|
233 |
void COptionConfig::ConstructL( const TDesC & aPrompt,
|
|
234 |
const TDesC & aOptions,
|
|
235 |
const TDesC & aStrValue )
|
|
236 |
{
|
|
237 |
|
|
238 |
ConstructStringL( aPrompt, &iPrompt );
|
|
239 |
ConstructStringL( aOptions, &iOptions );
|
|
240 |
ConstructStringL( aStrValue, &iStrValue );
|
|
241 |
|
|
242 |
}
|
|
243 |
|
|
244 |
|
|
245 |
/**
|
|
246 |
Initialise this object with the contents of RReadStream aStream.
|
|
247 |
The descriptor contains an externalised version of an object.
|
|
248 |
This method is typically used to obtain a COptionConfig object from
|
|
249 |
the core dump server.
|
|
250 |
Any modifications to this method should be synchronised with ExternalizeL().
|
|
251 |
Also note that the methods used from RReadStream (>> or ReadUint32L)
|
|
252 |
can behave differently, especially for descriptors.
|
|
253 |
@param aStream Stream with streamed object
|
|
254 |
@see ExternalizeL
|
|
255 |
@see RReadStream
|
|
256 |
@pre Call ExternaliseL to obtain the stream containing an externalised
|
|
257 |
version of this object.
|
|
258 |
*/
|
|
259 |
EXPORT_C void COptionConfig::InternalizeL( RReadStream & aStream )
|
|
260 |
{
|
|
261 |
|
|
262 |
|
|
263 |
iType = (TOptionType) aStream.ReadUint32L();
|
|
264 |
|
|
265 |
iSource = (TParameterSource) aStream.ReadUint32L();
|
|
266 |
|
|
267 |
iIndex = aStream.ReadUint32L();
|
|
268 |
|
|
269 |
iInstance = aStream.ReadUint32L();
|
|
270 |
|
|
271 |
iUID = aStream.ReadUint32L();
|
|
272 |
|
|
273 |
if( NULL != iPrompt )
|
|
274 |
{
|
|
275 |
delete iPrompt;
|
|
276 |
iPrompt = NULL;
|
|
277 |
}
|
|
278 |
|
|
279 |
TUint32 promptSize = aStream.ReadUint32L();
|
|
280 |
|
|
281 |
if ( promptSize > 0 )
|
|
282 |
{
|
|
283 |
//iPrompt = HBufC::NewL( aStream, KCDSMaxConfigParamStr );
|
|
284 |
iPrompt = HBufC::NewL( aStream, promptSize );
|
|
285 |
}
|
|
286 |
else
|
|
287 |
{
|
|
288 |
iPrompt = NULL;
|
|
289 |
}
|
|
290 |
|
|
291 |
iNumOptions = aStream.ReadUint32L();
|
|
292 |
|
|
293 |
if( NULL != iOptions )
|
|
294 |
{
|
|
295 |
delete iOptions;
|
|
296 |
iOptions = NULL;
|
|
297 |
}
|
|
298 |
|
|
299 |
TUint32 optionSize = aStream.ReadUint32L();
|
|
300 |
|
|
301 |
if ( optionSize > 0 )
|
|
302 |
{
|
|
303 |
//iOptions = HBufC::NewL( aStream, KCDSMaxConfigParamStr );
|
|
304 |
iOptions = HBufC::NewL( aStream, optionSize );
|
|
305 |
}
|
|
306 |
else
|
|
307 |
{
|
|
308 |
iOptions = NULL;
|
|
309 |
}
|
|
310 |
|
|
311 |
|
|
312 |
iValue = aStream.ReadInt32L();
|
|
313 |
|
|
314 |
if( NULL != iStrValue )
|
|
315 |
{
|
|
316 |
delete iStrValue;
|
|
317 |
iStrValue = NULL;
|
|
318 |
}
|
|
319 |
|
|
320 |
TUint32 strValueSize = aStream.ReadUint32L();
|
|
321 |
|
|
322 |
if ( strValueSize > 0 )
|
|
323 |
{
|
|
324 |
//iStrValue = HBufC::NewL( aStream, KCDSMaxConfigParamStr );
|
|
325 |
iStrValue = HBufC::NewL( aStream, strValueSize );
|
|
326 |
}
|
|
327 |
else
|
|
328 |
{
|
|
329 |
iStrValue = NULL;
|
|
330 |
}
|
|
331 |
|
|
332 |
iSize = aStream.ReadUint32L() ;
|
|
333 |
|
|
334 |
}
|
|
335 |
|
|
336 |
|
|
337 |
/**
|
|
338 |
Make a streamed representation of this object to a RWriteStream.
|
|
339 |
|
|
340 |
This method is typically by the core dump server when contructing a list of
|
|
341 |
COptionConfig for a client.
|
|
342 |
Any modifications to this method should be synchronised with InternalizeL().
|
|
343 |
Also note that the methods used from RWriteStream (>> or WriteUint32L) can behave differently,
|
|
344 |
especially for descriptors.
|
|
345 |
@param aStream Stream to stream object onto
|
|
346 |
@param buf Buffer onto the same stream, used to obtain correct size of externalised object
|
|
347 |
@see InternalizeL
|
|
348 |
@see RReadStream
|
|
349 |
@see RWriteStream
|
|
350 |
@post The stream contains an externalised version of this object.
|
|
351 |
*/
|
|
352 |
EXPORT_C void COptionConfig::ExternalizeL( RWriteStream & aStream, CBufFlat* buf )
|
|
353 |
{
|
|
354 |
|
|
355 |
|
|
356 |
// Take the size of the buffer before we add anything to it.
|
|
357 |
TUint startBufSize = buf->Size();
|
|
358 |
|
|
359 |
aStream.WriteUint32L( iType );
|
|
360 |
|
|
361 |
aStream.WriteUint32L( iSource );
|
|
362 |
|
|
363 |
aStream.WriteUint32L( iIndex );
|
|
364 |
|
|
365 |
aStream.WriteUint32L( iInstance );
|
|
366 |
|
|
367 |
aStream.WriteUint32L( iUID );
|
|
368 |
|
|
369 |
TInt promptSize = 0;
|
|
370 |
if ( iPrompt != NULL )
|
|
371 |
{
|
|
372 |
promptSize = iPrompt->Des().Length();
|
|
373 |
if( promptSize > 0 )
|
|
374 |
{
|
|
375 |
aStream.WriteUint32L( promptSize );
|
|
376 |
aStream << iPrompt->Des();
|
|
377 |
}
|
|
378 |
}
|
|
379 |
|
|
380 |
if( promptSize == 0 )
|
|
381 |
{
|
|
382 |
aStream.WriteUint32L( 0 );
|
|
383 |
}
|
|
384 |
|
|
385 |
aStream.WriteUint32L( iNumOptions );
|
|
386 |
|
|
387 |
TInt optionSize = 0;
|
|
388 |
if ( iOptions != NULL )
|
|
389 |
{
|
|
390 |
optionSize = iOptions->Des().Length();
|
|
391 |
if( optionSize > 0 )
|
|
392 |
{
|
|
393 |
aStream.WriteUint32L( optionSize );
|
|
394 |
aStream << iOptions->Des();
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
if( optionSize == 0 )
|
|
399 |
{
|
|
400 |
aStream.WriteUint32L( 0 );
|
|
401 |
}
|
|
402 |
|
|
403 |
aStream.WriteInt32L( iValue );
|
|
404 |
|
|
405 |
TInt valueSize = 0;
|
|
406 |
if ( iStrValue != NULL )
|
|
407 |
{
|
|
408 |
valueSize = iStrValue->Des().Length();
|
|
409 |
if( valueSize > 0 )
|
|
410 |
{
|
|
411 |
aStream.WriteUint32L( valueSize );
|
|
412 |
aStream << iStrValue->Des();
|
|
413 |
}
|
|
414 |
}
|
|
415 |
|
|
416 |
if( valueSize == 0 )
|
|
417 |
{
|
|
418 |
aStream.WriteUint32L( 0 );
|
|
419 |
}
|
|
420 |
|
|
421 |
// The real exteranlized size is the size of the buffer up to here plus the
|
|
422 |
// 4 bytes for the size itself
|
|
423 |
iSize = buf->Size() - startBufSize + 4;
|
|
424 |
aStream.WriteUint32L( iSize );
|
|
425 |
|
|
426 |
}
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
/**
|
|
431 |
Obtain the type of parameter.
|
|
432 |
@see TOptionType
|
|
433 |
*/
|
|
434 |
EXPORT_C COptionConfig::TOptionType COptionConfig::Type() const
|
|
435 |
{
|
|
436 |
return ( iType );
|
|
437 |
}
|
|
438 |
|
|
439 |
/**
|
|
440 |
Obtain the source component type of the parameter.
|
|
441 |
@see TParameterSource
|
|
442 |
*/
|
|
443 |
EXPORT_C COptionConfig::TParameterSource COptionConfig::Source() const
|
|
444 |
{
|
|
445 |
return ( iSource );
|
|
446 |
}
|
|
447 |
|
|
448 |
/**
|
|
449 |
Obtain the internal index to the component that owns the object.
|
|
450 |
*/
|
|
451 |
EXPORT_C TUint32 COptionConfig::Index() const
|
|
452 |
{
|
|
453 |
return ( iIndex );
|
|
454 |
}
|
|
455 |
|
|
456 |
/**
|
|
457 |
Obtain the internal index to the component that owns the object.
|
|
458 |
*/
|
|
459 |
EXPORT_C TUint32 COptionConfig::Instance() const
|
|
460 |
{
|
|
461 |
return ( iInstance );
|
|
462 |
}
|
|
463 |
|
|
464 |
/**
|
|
465 |
Set the internal index to the component that owns the object.
|
|
466 |
*/
|
|
467 |
EXPORT_C void COptionConfig::Instance(TInt32 aInstance)
|
|
468 |
{
|
|
469 |
iInstance = aInstance;
|
|
470 |
}
|
|
471 |
|
|
472 |
/**
|
|
473 |
Obtain the UID of the component that owns the object.
|
|
474 |
*/
|
|
475 |
EXPORT_C TUint32 COptionConfig::Uid( ) const
|
|
476 |
{
|
|
477 |
return iUID;
|
|
478 |
}
|
|
479 |
|
|
480 |
|
|
481 |
/**
|
|
482 |
Obtain the prompt to present to the user.
|
|
483 |
*/
|
|
484 |
EXPORT_C const TDesC & COptionConfig::Prompt() const
|
|
485 |
{
|
|
486 |
if( iPrompt )
|
|
487 |
{
|
|
488 |
return ( *iPrompt );
|
|
489 |
}
|
|
490 |
else
|
|
491 |
{
|
|
492 |
return KNullDesC;
|
|
493 |
}
|
|
494 |
}
|
|
495 |
|
|
496 |
|
|
497 |
/**
|
|
498 |
Obtain the number of options that the parameter can be set to.
|
|
499 |
Only applies if type is ETMultiEntryEnum.
|
|
500 |
*/
|
|
501 |
EXPORT_C TUint32 COptionConfig::NumOptions( ) const
|
|
502 |
{
|
|
503 |
return iNumOptions;
|
|
504 |
}
|
|
505 |
|
|
506 |
|
|
507 |
/**
|
|
508 |
Obtain the comma separated list of options. Applies to ETMultiEntryEnum and ETBool.
|
|
509 |
*/
|
|
510 |
EXPORT_C const TDesC & COptionConfig::Options() const
|
|
511 |
{
|
|
512 |
if( iOptions )
|
|
513 |
{
|
|
514 |
return ( *iOptions );
|
|
515 |
}
|
|
516 |
else
|
|
517 |
{
|
|
518 |
return KNullDesC;
|
|
519 |
}
|
|
520 |
}
|
|
521 |
|
|
522 |
|
|
523 |
/** Obtain the integer value of the parameter. */
|
|
524 |
EXPORT_C TInt32 COptionConfig::Value() const
|
|
525 |
{
|
|
526 |
return ( iValue );
|
|
527 |
}
|
|
528 |
|
|
529 |
|
|
530 |
/** Obtain the value of the parameter as a Boolean. */
|
|
531 |
EXPORT_C TBool COptionConfig::ValueAsBool() const
|
|
532 |
{
|
|
533 |
if( 0 == iValue )
|
|
534 |
{
|
|
535 |
return EFalse;
|
|
536 |
}
|
|
537 |
else
|
|
538 |
{
|
|
539 |
return ETrue;
|
|
540 |
}
|
|
541 |
}
|
|
542 |
|
|
543 |
|
|
544 |
/** Obtain the value of the parameter as a descriptor. Does not apply to ETInt or ETUInt. */
|
|
545 |
EXPORT_C const TDesC & COptionConfig::ValueAsDesc() const
|
|
546 |
{
|
|
547 |
|
|
548 |
if( iStrValue )
|
|
549 |
{
|
|
550 |
return ( *iStrValue );
|
|
551 |
}
|
|
552 |
else
|
|
553 |
{
|
|
554 |
return KNullDesC;
|
|
555 |
}
|
|
556 |
}
|
|
557 |
|
|
558 |
/** Set the integer value of the parameter. */
|
|
559 |
EXPORT_C void COptionConfig::Value( const TInt32 aValue )
|
|
560 |
{
|
|
561 |
iValue = aValue;
|
|
562 |
}
|
|
563 |
|
|
564 |
/** Set the descriptor value of the parameter. */
|
|
565 |
EXPORT_C void COptionConfig::ValueL( const TDesC & aValue )
|
|
566 |
{
|
|
567 |
|
|
568 |
TInt valSize = aValue.Size();
|
|
569 |
|
|
570 |
TInt newSize = Size() + valSize ;
|
|
571 |
|
|
572 |
if( iStrValue )
|
|
573 |
{
|
|
574 |
newSize -= iStrValue->Size();
|
|
575 |
}
|
|
576 |
|
|
577 |
if( aValue.Length() > KCDSMaxConfigParamStr )
|
|
578 |
{
|
|
579 |
LOG_MSG( "if( aValue.Length() > KCDSMaxConfigParamStr ) -> User::Leave( KErrTooBig )\n" );
|
|
580 |
User::Leave( KErrTooBig );
|
|
581 |
}
|
|
582 |
|
|
583 |
if( newSize >= MaxSize() )
|
|
584 |
{
|
|
585 |
LOG_MSG( "if( newSize >= MaxSize() ) -> User::Leave( KErrTooBig )\n" );
|
|
586 |
User::Leave( KErrTooBig );
|
|
587 |
}
|
|
588 |
|
|
589 |
|
|
590 |
if( valSize == 0 )
|
|
591 |
{
|
|
592 |
iStrValue = NULL;
|
|
593 |
}
|
|
594 |
else
|
|
595 |
{
|
|
596 |
ConstructStringL( aValue, & iStrValue );
|
|
597 |
}
|
|
598 |
|
|
599 |
iSize = newSize;
|
|
600 |
|
|
601 |
}
|
|
602 |
|
|
603 |
|
|
604 |
|
|
605 |
EXPORT_C COptionConfig::COptionConfig()
|
|
606 |
{
|
|
607 |
}
|
|
608 |
|
|
609 |
|
|
610 |
/**
|
|
611 |
Gets the size of the object when externalized. The sizeofs used to calculate this
|
|
612 |
must match the operators used in ExternalizeL and InternalizeL.
|
|
613 |
Special attention must be paid to the name. If the object has not been
|
|
614 |
externalized yet then this method returns the maximum that it could take.
|
|
615 |
The name descriptor is compressed when externalized, so it is not its Size().
|
|
616 |
Furthermore the << operator adds two bytes to the stream when externalizing
|
|
617 |
a descriptor.
|
|
618 |
*/
|
|
619 |
EXPORT_C TInt COptionConfig::Size() const
|
|
620 |
{
|
|
621 |
|
|
622 |
if( iSize != 0 )
|
|
623 |
{
|
|
624 |
return iSize;
|
|
625 |
}
|
|
626 |
|
|
627 |
TUint extDecSize = 0;
|
|
628 |
if( iPrompt )
|
|
629 |
{
|
|
630 |
extDecSize += 2 // When externalized, the << operator writes 2 bytes for the descriptor size
|
|
631 |
+ iPrompt->Size(); // iPrompt itself, in bytes. Worst case
|
|
632 |
}
|
|
633 |
|
|
634 |
if( iOptions )
|
|
635 |
{
|
|
636 |
extDecSize += 2 // When externalized, the << operator writes 2 bytes for the descriptor size
|
|
637 |
+ iOptions->Size(); // iOptions itself, in bytes. Worst case
|
|
638 |
}
|
|
639 |
|
|
640 |
if( iStrValue )
|
|
641 |
{
|
|
642 |
extDecSize += 2 // When externalized, the << operator writes 2 bytes for the descriptor size
|
|
643 |
+ iStrValue->Size(); // iStrValue itself, in bytes. Worst case
|
|
644 |
}
|
|
645 |
|
|
646 |
|
|
647 |
const TInt size =
|
|
648 |
sizeof( TUint32 ) // iType
|
|
649 |
+ sizeof( TUint32 ) // iSource
|
|
650 |
+ sizeof( TUint32 ) // iIndex
|
|
651 |
+ sizeof( TUint32 ) // iInstance
|
|
652 |
+ sizeof( TUint32 ) // iUID
|
|
653 |
+ sizeof( TUint32 ) // iPrompt size
|
|
654 |
+ extDecSize // all the descriptors and their 2 bytes due to <<
|
|
655 |
+ sizeof( TUint32 ) // iNumOptions
|
|
656 |
+ sizeof( TUint32 ) // iOptions size
|
|
657 |
+ sizeof( TInt32 ) // iValue
|
|
658 |
+ sizeof( TUint32 ) // iStrValue size
|
|
659 |
+ sizeof( TUint32 ); // iSize itself
|
|
660 |
|
|
661 |
return size;
|
|
662 |
}
|
|
663 |
|
|
664 |
|
|
665 |
/**
|
|
666 |
Get the maximum size allowed for this object. This is needed as the object is passed
|
|
667 |
across the Client Server interface.
|
|
668 |
*/
|
|
669 |
EXPORT_C TInt COptionConfig::MaxSize()
|
|
670 |
{
|
|
671 |
|
|
672 |
const TInt maxSize = 1024;
|
|
673 |
return maxSize;
|
|
674 |
}
|
|
675 |
|