sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "T_EntryArrayData.h" sl@0: #include "T_EntryData.h" sl@0: #include "FileserverUtil.h" sl@0: sl@0: // Commands sl@0: _LIT( KCmdCount, "count" ); sl@0: _LIT( KCmdDelete, "~" ); sl@0: _LIT( KCmdNew, "new" ); sl@0: _LIT( KCmdIndexOperator, "[]" ); sl@0: sl@0: // Parameters sl@0: _LIT( KParamDestination, "destination" ); sl@0: _LIT( KParamExpected, "expected" ); sl@0: _LIT( KParamIndex, "index" ); sl@0: sl@0: sl@0: CT_EntryArrayData* CT_EntryArrayData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_EntryArrayData* ret = new (ELeave) CT_EntryArrayData(); sl@0: CleanupStack::PushL( ret ); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop( ret ); sl@0: return ret; sl@0: } sl@0: sl@0: CT_EntryArrayData::CT_EntryArrayData() sl@0: : iEntryArray(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: void CT_EntryArrayData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: CT_EntryArrayData::~CT_EntryArrayData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: sl@0: { sl@0: DoCmdDelete(); sl@0: } sl@0: sl@0: TAny* CT_EntryArrayData::GetObject() sl@0: /** sl@0: * Return a pointer to the object that the data wraps sl@0: * sl@0: * @return pointer to the object that the data wraps sl@0: */ sl@0: sl@0: { sl@0: return iEntryArray; sl@0: } sl@0: sl@0: TBool CT_EntryArrayData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/ ) sl@0: /** sl@0: * Process a command read from the ini file sl@0: * sl@0: * @param aCommand the command to process sl@0: * @param aSection the entry in the ini file requiring the command to be processed sl@0: * sl@0: * @return ETrue if the command is processed sl@0: */ sl@0: { sl@0: TBool retVal = ETrue; sl@0: sl@0: if ( aCommand == KCmdIndexOperator ) sl@0: { sl@0: DoCmdIndexOperatorL( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdCount ) sl@0: { sl@0: DoCmdCount( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdDelete ) sl@0: { sl@0: DoCmdDelete(); sl@0: } sl@0: else if ( aCommand == KCmdNew ) sl@0: { sl@0: DoCmdNew(); sl@0: } sl@0: else sl@0: { sl@0: retVal = EFalse; sl@0: } sl@0: sl@0: return retVal; sl@0: } sl@0: sl@0: void CT_EntryArrayData::DoCmdIndexOperatorL( const TDesC& aSection ) sl@0: /** sl@0: * Assigns an element of TEntryArray to another TEntry object using "=" operator sl@0: */ sl@0: { sl@0: TInt index; sl@0: TPtrC entryObjectName; sl@0: sl@0: if( GET_MANDATORY_INT_PARAMETER( KParamIndex, aSection, index ) && sl@0: GET_MANDATORY_STRING_PARAMETER( KParamDestination, aSection, entryObjectName )) sl@0: { sl@0: TEntry* entry = new(ELeave) TEntry(); sl@0: CleanupStack::PushL(entry); sl@0: sl@0: *entry = iEntryArray->operator[](index); sl@0: CT_EntryData* entryWrapperObject = static_cast(GetDataWrapperL(entryObjectName)); sl@0: sl@0: if(!entryWrapperObject) sl@0: { sl@0: ERR_PRINTF2(_L("%S is not initialised"), &entryObjectName); sl@0: SetBlockResult(EFail); sl@0: CleanupStack::PopAndDestroy(entry); sl@0: } sl@0: else sl@0: { sl@0: entryWrapperObject->SetObjectL(entry); sl@0: CleanupStack::Pop(entry); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryArrayData::DoCmdCount( const TDesC& aSection ) sl@0: /** sl@0: * Checks if TEntryArray has expected number of elements sl@0: */ sl@0: { sl@0: TInt expected; sl@0: if( GET_MANDATORY_INT_PARAMETER( KParamExpected, aSection, expected ) ) sl@0: { sl@0: INFO_PRINTF2( _L( "Count(). Expected value = %d" ), expected ); sl@0: sl@0: TInt result = iEntryArray->Count(); sl@0: if ( result != expected ) sl@0: { sl@0: ERR_PRINTF3(_L("Count %d != expected %d"), result, expected ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryArrayData::DoCmdDelete() sl@0: /** sl@0: * Deletes TEntryArray class instance sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: void CT_EntryArrayData::DoCmdNew() sl@0: /** sl@0: * Creates new TEntryArray class instance sl@0: */ sl@0: { sl@0: DoCmdDelete(); sl@0: sl@0: INFO_PRINTF1( _L( "Create new TEntryArray() class instance." ) ); sl@0: TRAPD( err, iEntryArray = new (ELeave) TEntryArray() ); sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2( _L( "new TEntryArray() error %d" ), err ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_EntryArrayData::SetObjectL( TAny* aAny ) sl@0: /** sl@0: * Set the wrapped data object with new value sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: iEntryArray = static_cast ( aAny ); sl@0: } sl@0: sl@0: void CT_EntryArrayData::DoCleanup() sl@0: /** Deltes TEntry class instance */ sl@0: { sl@0: INFO_PRINTF1( _L( "Delete TEntryArray class instance" ) ); sl@0: delete iEntryArray; sl@0: iEntryArray = NULL; sl@0: } sl@0: sl@0: