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: /** sl@0: @test sl@0: @internalComponent sl@0: v sl@0: This contains CT_RDirData sl@0: */ sl@0: sl@0: // User includes sl@0: #include "T_RDirData.h" sl@0: #include "T_SfSrvServer.h" sl@0: #include "FileserverUtil.h" sl@0: sl@0: sl@0: sl@0: /*@{*/ sl@0: /// Parameters sl@0: _LIT(KPath, "path"); sl@0: _LIT(KTUidType, "uidtype"); sl@0: _LIT(KRFsObjectName, "rfsObject"); sl@0: _LIT(KAsync, "async"); sl@0: _LIT(KArrayObjectName, "arrayObject"); sl@0: _LIT(KEntryObjectName, "entryObject"); sl@0: _LIT(KEntryAttMask, "attmask"); sl@0: _LIT(KParamExpectedFileName, "filename%d"); sl@0: _LIT(KReadArray, "readarray"); sl@0: _LIT(KCompareFiles, "compare"); sl@0: sl@0: sl@0: ///Commands sl@0: _LIT(KCmdNew, "new"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: _LIT(KCmdOpen, "Open"); sl@0: _LIT(KCmdRead, "Read"); sl@0: _LIT(KCmdClose, "Close"); sl@0: sl@0: //Constants sl@0: const TInt KBufferLength = 64; sl@0: sl@0: CT_RDirData* CT_RDirData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_RDirData* ret = new (ELeave) CT_RDirData(); sl@0: CleanupStack::PushL(ret); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop(ret); sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: CT_RDirData::CT_RDirData() sl@0: : iRDir(NULL) sl@0: , iRead(NULL) sl@0: , iReadBlock(NULL) sl@0: , iEntry(NULL) sl@0: , iExpectedNames(NULL) sl@0: , iObjName(NULL) sl@0: , iCompare(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: sl@0: void CT_RDirData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: iRead = CActiveCallback::NewL( *this ); sl@0: iReadBlock = CActiveCallback::NewL( *this ); sl@0: iExpectedNames = new(ELeave) RPointerArray(); sl@0: } sl@0: sl@0: sl@0: CT_RDirData::~CT_RDirData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: sl@0: TAny* CT_RDirData::GetObject() sl@0: { sl@0: return iRDir; sl@0: } sl@0: sl@0: sl@0: TBool CT_RDirData::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 ret = ETrue; sl@0: sl@0: if (aCommand == KCmdNew) sl@0: { sl@0: DoCmdNew(); sl@0: } sl@0: else if (aCommand == KCmdOpen) sl@0: { sl@0: DoCmdOpenL(aSection); sl@0: } sl@0: else if (aCommand == KCmdRead) sl@0: { sl@0: DoCmdReadL(aSection, aAsyncErrorIndex); sl@0: } sl@0: else if (aCommand == KCmdClose) sl@0: { sl@0: DoCmdClose(); sl@0: } sl@0: else if (aCommand == KCmdDestructor) sl@0: { sl@0: DoCmdDestructor(); sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: void CT_RDirData::DoCleanup() sl@0: { sl@0: INFO_PRINTF1(_L("Deleting current RDir")); sl@0: delete iEntry; sl@0: iEntry = NULL; sl@0: delete iRDir; sl@0: iRDir = NULL; sl@0: sl@0: delete iRead; sl@0: iRead = NULL; sl@0: delete iReadBlock; sl@0: iReadBlock = NULL; sl@0: iExpectedNames->ResetAndDestroy(); sl@0: } sl@0: sl@0: void CT_RDirData::DoCmdNew() sl@0: { sl@0: INFO_PRINTF1(_L("Create new RDirs class instance")); sl@0: sl@0: delete iRDir; sl@0: iRDir = NULL; sl@0: sl@0: TRAPD(err, iRDir = new (ELeave) RDir()); sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("new error %d"), err); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: sl@0: void CT_RDirData::DoCmdClose() sl@0: /** sl@0: * Close RDir handle sl@0: */ sl@0: { sl@0: INFO_PRINTF1(_L("Closing RDir")); sl@0: iRDir->Close(); sl@0: } sl@0: sl@0: void CT_RDirData::DoCmdDestructor() sl@0: /** sl@0: * Destroy RDir the object sl@0: */ sl@0: { sl@0: INFO_PRINTF1(_L("Destroying the RDir object")); sl@0: DoCleanup(); sl@0: } sl@0: sl@0: void CT_RDirData::DoCmdOpenL(const TDesC& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("Opening directory!")); sl@0: sl@0: TBool dataOk = ETrue; sl@0: sl@0: TPtrC rfsObjectName; sl@0: RFs* rfsObject = NULL; sl@0: if(GET_MANDATORY_STRING_PARAMETER(KRFsObjectName(), aSection, rfsObjectName)) sl@0: { sl@0: rfsObject = (RFs*)GetDataObjectL(rfsObjectName); sl@0: } sl@0: else sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TPtrC path; sl@0: if(!GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TUidType uidType = KNullUid; sl@0: TInt intUIDType; sl@0: TBool isUidType = EFalse; sl@0: sl@0: TUint attMask = KEntryAttNormal; sl@0: INFO_PRINTF2(_L("section name - %S"),&aSection); sl@0: sl@0: if(!FileserverUtil::GetAttMask(*this, aSection, KEntryAttMask(), attMask)) sl@0: { sl@0: if (GET_MANDATORY_INT_PARAMETER(KTUidType(), aSection, intUIDType)) sl@0: { sl@0: TUid id = TUid::Uid(intUIDType); sl@0: uidType = TUidType(id); sl@0: INFO_PRINTF2(_L("UID type set to %d"), uidType[0].iUid); sl@0: isUidType = ETrue; sl@0: } sl@0: else sl@0: { sl@0: dataOk = EFalse; sl@0: ERR_PRINTF2(_L("attmask or %S must be declared !!!"), &KTUidType); sl@0: } sl@0: } sl@0: sl@0: if (dataOk) sl@0: { sl@0: TInt err = KErrNone; sl@0: sl@0: if (isUidType) sl@0: { sl@0: err = iRDir->Open(*rfsObject, path, uidType); sl@0: } sl@0: else sl@0: { sl@0: err = iRDir->Open(*rfsObject, path, attMask); sl@0: } sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Open() error: %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Directory has been opened!")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_RDirData::DoCmdReadL(const TDesC& aSection, const TInt aAsyncErrorIndex) sl@0: { sl@0: INFO_PRINTF1(_L("Reading directory!")); sl@0: sl@0: TBool async = EFalse; sl@0: TBool readArray = EFalse; sl@0: TBool compare = EFalse; sl@0: sl@0: GET_OPTIONAL_BOOL_PARAMETER(KAsync(), aSection, async); sl@0: sl@0: if(GET_OPTIONAL_BOOL_PARAMETER(KReadArray(),aSection,readArray)) sl@0: { sl@0: ReadExpectedNamesL( aSection); sl@0: } sl@0: sl@0: if(GET_OPTIONAL_BOOL_PARAMETER(KCompareFiles(),aSection,compare)) sl@0: { sl@0: iCompare = compare; sl@0: } sl@0: sl@0: TPtrC entryArrayName; sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KArrayObjectName(), aSection, entryArrayName)) sl@0: { sl@0: TEntryArray* entryArray = new(ELeave) TEntryArray(); sl@0: CleanupStack::PushL(entryArray); sl@0: sl@0: CT_EntryArrayData* entryArrayWrapper = sl@0: static_cast (GetDataWrapperL(entryArrayName)); sl@0: if (entryArrayWrapper) sl@0: { sl@0: entryArrayWrapper->SetObjectL(entryArray); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Not initialized %S"), &entryArrayName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: CleanupStack::Pop(entryArray); sl@0: sl@0: if (async) sl@0: { sl@0: iObjName = entryArrayName; sl@0: iRDir->Read(*entryArray, iReadBlock->iStatus); sl@0: iReadBlock->Activate(aAsyncErrorIndex); sl@0: IncOutstanding(); sl@0: } sl@0: else sl@0: { sl@0: TInt err = iRDir->Read(*entryArray); sl@0: sl@0: if((err == KErrNone) || (err == KErrEof)) sl@0: { sl@0: INFO_PRINTF1(_L("Read function completed successfully")); sl@0: SetError(err); sl@0: if(compare) sl@0: { sl@0: CompareEntryArray(entryArray); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Read function failed with error: %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TPtrC entryName; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KEntryObjectName(), aSection, entryName)) sl@0: { sl@0: TEntry* entry = new(ELeave) TEntry(); sl@0: CleanupStack::PushL(entry); sl@0: sl@0: CT_EntryData* entryWrapper = sl@0: static_cast (GetDataWrapperL(entryName)); sl@0: sl@0: if (entryWrapper) sl@0: { sl@0: entryWrapper->SetObjectL(entry); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Not initialized %S"), &entryName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::Pop(entry); sl@0: sl@0: if (async) sl@0: { sl@0: iObjName = entryName; sl@0: delete iEntry; sl@0: iEntry = NULL; sl@0: iEntry = new(ELeave) TPckg(*entry); sl@0: iRDir->Read(*iEntry, iRead->iStatus); sl@0: iRead->Activate(aAsyncErrorIndex); sl@0: IncOutstanding(); sl@0: } sl@0: else sl@0: { sl@0: TInt err = iRDir->Read(*entry); sl@0: sl@0: if((err == KErrNone) || (err == KErrEof)) sl@0: { sl@0: INFO_PRINTF1(_L("Read function completed successfully")); sl@0: SetError(err); sl@0: if(compare) sl@0: { sl@0: CompareEntryData(entry); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Read function failed with error: %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_RDirData::ReadExpectedNamesL( const TDesC& aSection ) sl@0: /** sl@0: * Read list of expected file names from ili file sl@0: */ sl@0: { sl@0: iExpectedNames->ResetAndDestroy(); sl@0: sl@0: TBool moreData = EFalse; sl@0: TInt index = 0; sl@0: do sl@0: { sl@0: TBuf tempStore; sl@0: tempStore.Format(KParamExpectedFileName(), ++index); sl@0: TPtrC fileName; sl@0: moreData = GET_OPTIONAL_STRING_PARAMETER(tempStore, aSection, fileName); sl@0: if (moreData) sl@0: { sl@0: TPath* path = new(ELeave) TPath(fileName); sl@0: CleanupStack::PushL(path); sl@0: iExpectedNames->AppendL(path); sl@0: CleanupStack::Pop(); sl@0: } sl@0: } sl@0: while (moreData); sl@0: } sl@0: sl@0: sl@0: void CT_RDirData::CompareEntryArray(TEntryArray* aEntryArray) sl@0: /** sl@0: * Compare TEntryArray entryes with list of expected files sl@0: */ sl@0: { sl@0: if(aEntryArray->Count() == iExpectedNames->Count()) sl@0: { sl@0: for(TInt i = 0; i < aEntryArray->Count(); i++) sl@0: { sl@0: TBool eof = EFalse; sl@0: for(TInt k = 0; !eof && (k < iExpectedNames->Count()); k++) sl@0: { sl@0: TEntry* tmpEntry = new(ELeave) TEntry(); sl@0: *tmpEntry = aEntryArray->operator[](i); sl@0: if(*(iExpectedNames->operator[](k)) == tmpEntry->iName) sl@0: { sl@0: TPath* name = iExpectedNames->operator[](k); sl@0: INFO_PRINTF3( _L( "Entry name = expected name, %S = %S"), &tmpEntry->iName, name); sl@0: sl@0: iExpectedNames->Remove(k); sl@0: delete name; sl@0: eof = ETrue; sl@0: } sl@0: sl@0: delete tmpEntry; sl@0: } sl@0: } sl@0: if(iExpectedNames->Count() > 0) sl@0: { sl@0: ERR_PRINTF1(_L("TEntryArray members are not equal to expected")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1( _L( "TEntryArray members are equal to expected")); sl@0: } sl@0: } sl@0: else if(aEntryArray->Count() > iExpectedNames->Count()) sl@0: { sl@0: ERR_PRINTF1(_L("Found unexpecded file(s)")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else if(aEntryArray->Count() < iExpectedNames->Count()) sl@0: { sl@0: ERR_PRINTF1(_L("List of expected files more than amount of real files")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: void CT_RDirData::CompareEntryData(TEntry* aEntry) sl@0: /** sl@0: * Compare TEntry with entry in list of expected files sl@0: */ sl@0: { sl@0: TBool eof = EFalse; sl@0: TBool fileCompare = EFalse; sl@0: for(TInt i = 0; !eof && (i < iExpectedNames->Count()); i++) sl@0: { sl@0: if(*(iExpectedNames->operator[](i)) == aEntry->iName) sl@0: { sl@0: TPath* name = iExpectedNames->operator[](i); sl@0: fileCompare = ETrue; sl@0: sl@0: iExpectedNames->Remove(i); sl@0: delete name; sl@0: eof = ETrue; sl@0: } sl@0: } sl@0: if(!fileCompare) sl@0: { sl@0: ERR_PRINTF2(_L("Unexpected file - %S"),&aEntry->iName); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_RDirData::RunL(CActive* aActive, TInt aIndex) sl@0: { sl@0: INFO_PRINTF1(_L("RunL Called!")); sl@0: sl@0: if ((aActive == iReadBlock) || (aActive == iRead)) sl@0: { sl@0: sl@0: TInt err = aActive->iStatus.Int(); sl@0: if (err == KErrNone) sl@0: { sl@0: TEntry &actualEntry = iEntry->operator()(); sl@0: INFO_PRINTF2(_L("Asynchronous Read function completed successfully, %S"),&(actualEntry.iName)); sl@0: } sl@0: else if (err == KErrEof) sl@0: { sl@0: INFO_PRINTF1(_L("Asynchronous Read function reached the end and returned expectedly KErrEof")); sl@0: SetAsyncError(aIndex, err); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("RunL Error: %d"), err); sl@0: SetAsyncError(aIndex, err); sl@0: } sl@0: sl@0: sl@0: if(iCompare && ((err == KErrNone) || (err == KErrEof))) sl@0: { sl@0: if(aActive == iReadBlock) sl@0: { sl@0: TEntryArray *entryArray = static_cast(GetDataObjectL(iObjName)); sl@0: if (entryArray) sl@0: { sl@0: CompareEntryArray(entryArray); sl@0: } sl@0: else sl@0: { sl@0: SetBlockResult(EFail); sl@0: ERR_PRINTF2(_L("Empty Object: %S"), &iObjName); sl@0: } sl@0: } sl@0: else if(aActive == iRead) sl@0: { sl@0: TEntry* entry = static_cast(GetDataObjectL(iObjName)); sl@0: if (entry) sl@0: { sl@0: CompareEntryData(entry); sl@0: } sl@0: else sl@0: { sl@0: SetBlockResult(EFail); sl@0: ERR_PRINTF2(_L("Empty Object: %S"), &iObjName); sl@0: } sl@0: } sl@0: } sl@0: sl@0: delete iEntry; sl@0: iEntry = NULL; sl@0: sl@0: DecOutstanding(); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1( _L("Stray RunL signal") ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: sl@0: void CT_RDirData::DoCancel(CActive* aActive, TInt aIndex) sl@0: { sl@0: INFO_PRINTF1(_L("DoCancel Called!")); sl@0: sl@0: if ( aActive == iRead ) sl@0: { sl@0: TInt err = aActive->iStatus.Int(); sl@0: if(err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("DoCancel Error: %d"), err); sl@0: SetAsyncError(aIndex, err); sl@0: } sl@0: DecOutstanding(); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1( _L("Stray RunL signal") ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: }