Update contrib.
2 * Copyright (c) 2005-2009 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.
19 #include "T_EntryData.h"
20 #include "T_SfSrvServer.h"
21 #include "FileserverUtil.h"
24 _LIT( KCmdAssignmentOperator, "=" );
25 _LIT( KCmdIndexOperator, "[]" );
26 _LIT( KCmdDelete, "~" );
27 _LIT( KCmdIsArchive, "IsArchive" );
28 _LIT( KCmdIsDir, "IsDir" );
29 _LIT( KCmdIsHidden, "IsHidden" );
30 _LIT( KCmdIsReadOnly, "IsReadOnly" );
31 _LIT( KCmdIsSystem, "IsSystem" );
32 _LIT( KCmdIsTypeValid, "IsTypeValid" );
33 _LIT( KCmdIsUidPresent, "IsUidPresent" );
34 _LIT( KCmdMostDerivedUid, "MostDerivedUid" );
35 _LIT( KCmdNew, "new" );
36 _LIT( KCmdSetAttribute, "SetAttribute" );
39 _LIT( KParamAttribute, "attribute" );
40 _LIT( KParamObject, "object" );
41 _LIT( KExpected, "expected" );
42 _LIT( KParamIndex, "index" );
43 _LIT( KParamState, "state" );
44 _LIT( KValue, "value" );
47 _LIT(KEntryAttNormalStr, "KEntryAttNormal");
48 _LIT(KEntryAttReadOnlyStr, "KEntryAttReadOnly");
49 _LIT(KEntryAttHiddenStr, "KEntryAttHidden");
50 _LIT(KEntryAttSystemStr, "KEntryAttSystem");
51 _LIT(KEntryAttVolumeStr, "KEntryAttVolume");
52 _LIT(KEntryAttDirStr, "KEntryAttDir");
53 _LIT(KEntryAttArchiveStr, "KEntryAttArchive");
54 _LIT(KEntryAttXIPStr, "KEntryAttXIP");
57 // other string values
58 #define KTimeFormatSize 30
61 CT_EntryData* CT_EntryData::NewL( )
63 * Two phase constructor
66 CT_EntryData* ret = new (ELeave) CT_EntryData( );
67 CleanupStack::PushL( ret );
69 CleanupStack::Pop( ret );
73 CT_EntryData::CT_EntryData( )
78 * Protected constructor. First phase construction
83 void CT_EntryData::ConstructL()
85 * Protected constructor. Second phase construction
90 CT_EntryData::~CT_EntryData()
98 void CT_EntryData::DoCleanup()
99 /** Deltes TEntry class instance */
101 INFO_PRINTF1( _L( "Delete TEntry class instance" ) );
106 TAny* CT_EntryData::GetObject()
108 * Return a pointer to the object that the data wraps
110 * @return pointer to the object that the data wraps
116 void CT_EntryData::SetObjectL( TAny* aAny )
118 * Set the wrapped data object with new value
122 iEntry = static_cast<TEntry*> ( aAny );
125 void CT_EntryData::DisownObjectL()
127 * Clear the wrapped data object pointer w/o de-initialization
133 inline TCleanupOperation CT_EntryData::CleanupOperation()
135 * Return static cleanup function
138 return CleanupOperation;
141 void CT_EntryData::CleanupOperation( TAny* aAny )
143 * Static cleanup function
146 TEntry* entry = static_cast<TEntry*> ( aAny );
150 TBool CT_EntryData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
152 * Process a command read from the ini file
154 * @param aCommand the command to process
155 * @param aSection the entry in the ini file requiring the command to be processed
157 * @return ETrue if the command is processed
160 TBool retVal = ETrue;
162 if ( aCommand == KCmdAssignmentOperator )
164 DoCmdAssignmentOperatorL( aSection );
166 else if ( aCommand == KCmdIndexOperator )
168 DoCmdIndexOperator( aSection );
170 else if ( aCommand == KCmdDelete )
174 else if ( aCommand == KCmdIsArchive )
176 DoCmdIsArchive( aSection );
178 else if ( aCommand == KCmdIsDir )
180 DoCmdIsDir( aSection );
182 else if ( aCommand == KCmdIsHidden )
184 DoCmdIsHidden( aSection );
186 else if ( aCommand == KCmdIsReadOnly )
188 DoCmdIsReadOnly( aSection );
190 else if ( aCommand == KCmdIsSystem )
192 DoCmdIsSystem( aSection );
194 else if ( aCommand == KCmdIsTypeValid )
196 DoCmdIsTypeValid( aSection );
198 else if ( aCommand == KCmdIsUidPresent )
200 DoCmdIsUidPresent( aSection );
202 else if ( aCommand == KCmdMostDerivedUid )
204 DoCmdMostDerived( aSection );
206 else if ( aCommand == KCmdNew )
208 DoCmdNew( aSection );
210 else if ( aCommand == KCmdSetAttribute )
212 DoCmdSetAttribute( aSection );
222 void CT_EntryData::DoCmdNew( const TDesC& aSection )
223 /** Creates new TEntry class instance */
227 TPtrC entryObjectName;
228 if( GET_OPTIONAL_STRING_PARAMETER( KParamObject, aSection, entryObjectName ) )
230 INFO_PRINTF1( _L( "Create new TEntry(TEntry) class instance." ) );
232 TEntry* entryObject = NULL;
233 TRAPD( err, entryObject = (TEntry*)GetDataObjectL(entryObjectName));
234 if ( err == KErrNone )
236 TRAPD( err, iEntry = new (ELeave) TEntry(*entryObject) );
237 if ( err != KErrNone )
239 ERR_PRINTF2( _L( "new TEntry(TEntry) error %d" ), err );
245 ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &entryObjectName, err );
246 SetBlockResult( EFail );
251 INFO_PRINTF1( _L( "Create new TEntry() class instance." ) );
252 TRAPD( err, iEntry = new (ELeave) TEntry() );
255 ERR_PRINTF2( _L( "new TEntry() error %d" ), err );
261 void CT_EntryData::DoCmdIndexOperator( const TDesC& aSection )
262 /** Checks if the given UID is the same as required */
265 if ( GET_MANDATORY_INT_PARAMETER( KParamIndex, aSection, iniIndex ) )
267 TInt value = (*iEntry)[iniIndex].iUid;
268 INFO_PRINTF3( _L( "UID[%d] = %d" ), iniIndex, value );
271 if ( GET_OPTIONAL_INT_PARAMETER( KExpected, aSection, iniExpected ) )
273 if ( value != iniExpected )
275 INFO_PRINTF3( _L( "values not the same %d != %d" ), value, iniExpected );
276 SetBlockResult( EFail );
282 void CT_EntryData::DoCmdAssignmentOperatorL( const TDesC& aSection )
283 /** Assigns another TEntry to this TEntry using "=" operator */
285 TPtrC entryObjectName;
286 if( GET_MANDATORY_STRING_PARAMETER( KParamObject, aSection, entryObjectName ) )
288 INFO_PRINTF2( _L( "Assign a %S to this TEntry" ), &entryObjectName );
290 TEntry* entryObject = NULL;
291 TRAPD( err, entryObject = (TEntry*)GetDataObjectL(entryObjectName));
292 if ( err == KErrNone && entryObject)
294 *iEntry = iEntry->operator=(*entryObject);
298 ERR_PRINTF3( _L( "Object not found or not initialised: %S. Error %d"), &entryObjectName, err );
299 SetBlockResult( EFail );
303 if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *iEntry))
305 SetBlockResult(EFail);
309 void CT_EntryData::DoCmdIsArchive( const TDesC& aSection )
310 /** Checks if TEntry has Archive attribute using IsArchive() function */
312 INFO_PRINTF1( _L( "IsArchive()" ) );
313 TBool result = iEntry->IsArchive();
316 if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
318 if ( !( CompareBool(result, expected) ) )
320 ERR_PRINTF1( _L( "Error compare function result and expected value" ));
321 SetBlockResult(EFail);
326 void CT_EntryData::DoCmdIsDir( const TDesC& aSection )
327 /** Checks if TEntry has Dir attribute using IsDir() function */
329 INFO_PRINTF1( _L( "IsDir()" ) );
330 TBool result = iEntry->IsDir();
333 if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
335 if ( !( CompareBool(result, expected) ) )
337 ERR_PRINTF1( _L( "Error compare function result and expected value" ));
338 SetBlockResult(EFail);
343 void CT_EntryData::DoCmdIsHidden( const TDesC& aSection )
344 /** Checks if TEntry has Hidden attribute using IsHidden() function */
346 INFO_PRINTF1( _L( "IsHidden()" ) );
347 TBool result = iEntry->IsHidden();
350 if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
352 if ( !( CompareBool(result, expected) ) )
354 ERR_PRINTF1( _L( "Error compare function result and expected value" ));
355 SetBlockResult(EFail);
360 void CT_EntryData::DoCmdIsReadOnly( const TDesC& aSection )
361 /** Checks if TEntry has ReadOnly attribute using IsReadOnly() function */
363 INFO_PRINTF1( _L( "IsReadOnly()" ) );
364 TBool result = iEntry->IsReadOnly();
367 if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
369 if ( !( CompareBool(result, expected) ) )
371 ERR_PRINTF1( _L( "Error compare function result and expected value" ));
372 SetBlockResult(EFail);
377 void CT_EntryData::DoCmdIsSystem( const TDesC& aSection )
378 /** Checks if TEntry has System attribute using IsSystem() function */
380 INFO_PRINTF1( _L( "IsSystem()" ) );
381 TBool result = iEntry->IsSystem();
384 if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
386 if ( !( CompareBool(result, expected) ) )
388 ERR_PRINTF1( _L( "Error compare function result and expected value" ));
389 SetBlockResult(EFail);
394 void CT_EntryData::DoCmdIsTypeValid( const TDesC& aSection )
395 /** Checks if TEntry has a valid UID using IsTypeValid() function */
397 INFO_PRINTF1( _L( "IsTypeValid()" ) );
398 TBool result = iEntry->IsTypeValid();
401 if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
403 if ( !( CompareBool(result, expected) ) )
405 ERR_PRINTF1( _L( "Error compare function result and expected value" ));
406 SetBlockResult(EFail);
411 void CT_EntryData::DoCmdIsUidPresent( const TDesC& aSection )
412 /** Checks if TEntry has a valid UID using IsTypeValid() function */
416 if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) &&
417 GET_MANDATORY_INT_PARAMETER( KValue, aSection, theIntUid ) )
419 INFO_PRINTF2( _L( "IsUidPresent( Uid(%d) )" ), theIntUid );
421 theUid.iUid = theIntUid;
423 TBool result = iEntry->IsUidPresent( theUid );
425 if ( !( CompareBool(result, expected) ) )
427 ERR_PRINTF1( _L( "Error compare function result and expected value" ));
428 SetBlockResult(EFail);
433 void CT_EntryData::DoCmdMostDerived( const TDesC& aSection )
434 /** checks if UID with given index is the same as the most derived one by using MostDerived() function */
436 TInt id = iEntry->MostDerivedUid().iUid;
437 INFO_PRINTF2( _L( "MostDerivedUid = %d" ), id);
440 if( GET_OPTIONAL_INT_PARAMETER( KExpected, aSection, expected ) )
442 if ( expected != id )
444 ERR_PRINTF3( _L( "Error compare UID %d != expected %d" ), id, expected );
445 SetBlockResult( EFail );
450 void CT_EntryData::DoCmdSetAttribute( const TDesC& aSection )
451 /** Sets or resets attributes */
455 if( GET_MANDATORY_BOOL_PARAMETER( KParamState, aSection, attrState ) &&
456 GET_MANDATORY_STRING_PARAMETER( KParamAttribute, aSection, attrName ) )
458 TBool errHappened = EFalse;
460 if (attrName == KEntryAttNormalStr)
462 attr = KEntryAttNormal;
464 else if (attrName == KEntryAttReadOnlyStr)
466 attr = KEntryAttReadOnly;
468 else if (attrName == KEntryAttHiddenStr)
470 attr = KEntryAttHidden;
472 else if (attrName == KEntryAttSystemStr)
474 attr = KEntryAttSystem;
476 else if (attrName == KEntryAttVolumeStr)
478 attr = KEntryAttVolume;
480 else if (attrName == KEntryAttDirStr)
484 else if (attrName == KEntryAttArchiveStr)
486 attr = KEntryAttArchive;
488 else if (attrName == KEntryAttXIPStr)
499 ERR_PRINTF2( _L( "Unknown attribute name parameter: %S" ), &attrName );
500 SetBlockResult( EFail );
504 TPtrC attrStateString;
505 GET_MANDATORY_STRING_PARAMETER( KParamState, aSection, attrStateString );
506 INFO_PRINTF3( _L( "SetAttribute(%S, %S)" ), &attrName, &attrStateString);
508 if ( attrState ) // set attribute
510 iEntry->iAtt = iEntry->iAtt | attr;
512 else // reset attribute
514 iEntry->iAtt = iEntry->iAtt ^ ( iEntry->iAtt & attr );
521 TBool CT_EntryData::CompareBool( TBool aResult, TBool aExpected )
522 /** compare 2 TBool values, which can be !=0 and !=1 - some TEntry functions return 2, 3 etc */
524 return ( ( aResult > 0 ) == ( aExpected > 0 ) );