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: sl@0: This contains CT_FileData sl@0: */ sl@0: sl@0: // User includes sl@0: #include "T_FileData.h" sl@0: sl@0: sl@0: /*@{*/ sl@0: /// Parameters sl@0: _LIT(KFile, "file"); sl@0: _LIT(KUParamPath, "path"); sl@0: _LIT(KUParamName, "name"); sl@0: _LIT(KRFsName, "RFs"); sl@0: _LIT(KFileMode, "file_mode"); sl@0: _LIT(KUParamExpectedString, "expected_string"); sl@0: _LIT(KUParamAsync, "async"); sl@0: _LIT(KUParamBufferLength, "buffer_length"); sl@0: _LIT(KUParamLength, "length"); sl@0: _LIT(KUParamStartPos, "start_pos"); sl@0: _LIT(KUParamEndPos, "end_pos"); sl@0: _LIT(KUParamUsage, "usage"); sl@0: _LIT(KUParamPos, "position"); sl@0: _LIT(KSeek, "seek"); sl@0: _LIT(KUParamCancelAll, "cancel_all"); sl@0: _LIT(KUParamData, "datawrite"); sl@0: _LIT(KUParamSize, "size"); sl@0: _LIT(KUParamExpectedSize, "expected_size"); sl@0: _LIT(KUParamCompareValue, "compare_value"); sl@0: _LIT(KUParamSetAttMask, "set_att_mask"); sl@0: _LIT(KUParamClearAttMask, "clear_att_mask"); sl@0: _LIT(KUParamDate, "date"); sl@0: _LIT(KFileObjectName, "file_object_name"); sl@0: _LIT(KUParamOwnerType, "owner_type"); sl@0: _LIT(KUParamComparePath, "compare_path"); sl@0: sl@0: // OwnerType sl@0: sl@0: _LIT(KEOwnerProcess, "EOwnerProcess"); sl@0: _LIT(KEOwnerThread, "EOwnerThread"); sl@0: sl@0: // Block Usage sl@0: sl@0: _LIT(KEBlockMapUsagePaging, "EBlockMapUsagePaging"); sl@0: _LIT(KETestDebug, "ETestDebug"); sl@0: sl@0: // FileMode sl@0: _LIT(KEFileShareExclusive, "EFileShareExclusive"); sl@0: _LIT(KEFileShareReadersOnly, "EFileShareReadersOnly"); sl@0: _LIT(KEFileShareAny, "EFileShareAny"); sl@0: _LIT(KEFileShareReadersOrWriters, "EFileShareReadersOrWriters"); sl@0: _LIT(KEFileStream, "EFileStream"); sl@0: _LIT(KEFileStreamText, "EFileStreamText"); sl@0: _LIT(KEFileRead, "EFileRead"); sl@0: _LIT(KEFileWrite, "EFileWrite"); sl@0: _LIT(KEFileReadAsyncAll, "EFileReadAsyncAll"); sl@0: sl@0: sl@0: // Seek sl@0: _LIT(KESeekStart, "ESeekStart"); sl@0: _LIT(KESeekCurrent, "ESeekCurrent"); sl@0: _LIT(KESeekEnd, "ESeekEnd"); sl@0: sl@0: /// Commands sl@0: _LIT(KCmdNew, "new"); sl@0: _LIT(KCmdClose, "Close"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: _LIT(KCmdBlockMap, "BlockMap"); sl@0: _LIT(KCmdOpen, "Open"); sl@0: _LIT(KCmdCreate, "Create"); sl@0: _LIT(KCmdWrite, "Write"); sl@0: _LIT(KCmdReplace, "Replace"); sl@0: _LIT(KCmdRead, "Read"); sl@0: _LIT(KCmdFlush, "Flush"); sl@0: _LIT(KCmdTemp, "Temp"); sl@0: _LIT(KCmdRename, "Rename"); sl@0: _LIT(KCmdSeek, "Seek"); sl@0: _LIT(KCmdReadCancel, "ReadCancel"); sl@0: _LIT(KCmdLock, "Lock"); sl@0: _LIT(KCmdUnLock, "UnLock"); sl@0: _LIT(KCmdSize, "Size"); sl@0: _LIT(KCmdSetSize, "SetSize"); sl@0: _LIT(KCmdAtt, "Att"); sl@0: _LIT(KCmdSetAtt, "SetAtt"); sl@0: _LIT(KCmdModified, "Modified"); sl@0: _LIT(KCmdSetModified, "SetModified"); sl@0: _LIT(KCmdSet, "Set"); sl@0: _LIT(KCmdChangeMode, "ChangeMode"); sl@0: _LIT(KCmdDrive, "Drive"); sl@0: _LIT(KCmdDuplicate, "Duplicate"); sl@0: _LIT(KCmdName, "Name"); sl@0: _LIT(KCmdFullName, "FullName"); sl@0: sl@0: sl@0: //Attributes sl@0: _LIT(KDEntryAttNormal, "KEntryAttNormal"); sl@0: _LIT(KDEntryAttReadOnly, "KEntryAttReadOnly"); sl@0: _LIT(KDEntryAttArchive, "KEntryAttArchive"); sl@0: _LIT(KDEntryAttHidden, "KEntryAttHidden"); sl@0: _LIT(KDEntryAttSystem, "KEntryAttSystem"); sl@0: _LIT(KDEntryAttVolume, "KEntryAttVolume"); sl@0: _LIT(KDEntryAttDir, "KEntryAttDir"); sl@0: _LIT(KDEntryAttXIP, "KEntryAttXIP"); sl@0: _LIT(KDEntryAttRemote, "KEntryAttRemote"); sl@0: sl@0: //constants sl@0: const TInt KDefaultDescSize = 64; sl@0: sl@0: /*@}*/ sl@0: sl@0: CT_FileData* CT_FileData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_FileData* ret = new (ELeave) CT_FileData(); 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_FileData::CT_FileData() sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: : iFile(NULL) sl@0: { sl@0: } sl@0: sl@0: void CT_FileData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: iFileOpened = EFalse; sl@0: } sl@0: sl@0: CT_FileData::~CT_FileData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: void CT_FileData::DoCleanup() sl@0: /** sl@0: * Contains cleanup implementation sl@0: */ sl@0: { sl@0: //Deleting RFile. sl@0: if(iFile != NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Deleting current RFile")); sl@0: delete iFile; sl@0: iFile = NULL; sl@0: } sl@0: iReadCallbackArray.Close(); sl@0: iWriteCallbackArray.Close(); sl@0: iFlushCallbackArray.Close(); sl@0: } sl@0: sl@0: TAny* CT_FileData::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: return iFile; sl@0: } sl@0: sl@0: TBool CT_FileData::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: * @param aAsyncErrorIndex the index of asynchronous command error code belongs to. 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 == KCmdNew) sl@0: { sl@0: DoCmdNewL(); sl@0: } sl@0: else if (aCommand == KCmdDestructor) sl@0: { sl@0: DoCmdDestructor(); sl@0: } sl@0: else if (aCommand == KCmdOpen) sl@0: { sl@0: DoCmdOpenL(aSection); sl@0: } sl@0: else if (aCommand == KCmdWrite) sl@0: { sl@0: DoCmdWriteL(aSection, aAsyncErrorIndex); sl@0: } sl@0: else if (aCommand == KCmdClose) sl@0: { sl@0: DoCmdClose(); sl@0: } sl@0: else if (aCommand == KCmdCreate) sl@0: { sl@0: DoCmdCreateL(aSection); sl@0: } sl@0: else if (aCommand == KCmdReplace) sl@0: { sl@0: DoCmdReplaceL(aSection); sl@0: } sl@0: else if (aCommand == KCmdRead) sl@0: { sl@0: DoCmdReadL(aSection, aAsyncErrorIndex); sl@0: } sl@0: else if (aCommand == KCmdFlush) sl@0: { sl@0: DoCmdFlushL(aSection, aAsyncErrorIndex); sl@0: } sl@0: else if (aCommand == KCmdTemp) sl@0: { sl@0: DoCmdTempL(aSection); sl@0: } sl@0: else if (aCommand == KCmdRename) sl@0: { sl@0: DoCmdRenameL(aSection); sl@0: } sl@0: else if (aCommand == KCmdSeek) sl@0: { sl@0: DoCmdSeekL(aSection); sl@0: } sl@0: else if (aCommand == KCmdReadCancel) sl@0: { sl@0: DoCmdReadCancelL(aSection); sl@0: } sl@0: else if (aCommand == KCmdLock) sl@0: { sl@0: DoCmdLockL(aSection); sl@0: } sl@0: else if (aCommand == KCmdUnLock) sl@0: { sl@0: DoCmdUnLockL(aSection); sl@0: } sl@0: else if (aCommand == KCmdSize) sl@0: { sl@0: DoCmdSizeL(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetSize) sl@0: { sl@0: DoCmdSetSizeL(aSection); sl@0: } sl@0: else if (aCommand == KCmdAtt) sl@0: { sl@0: DoCmdAttL(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetAtt) sl@0: { sl@0: DoCmdSetAttL(aSection); sl@0: } sl@0: else if (aCommand == KCmdModified) sl@0: { sl@0: DoCmdModifiedL(aSection); sl@0: } sl@0: else if (aCommand == KCmdSetModified) sl@0: { sl@0: DoCmdSetModifiedL(aSection); sl@0: } sl@0: else if (aCommand == KCmdSet) sl@0: { sl@0: DoCmdSetL(aSection); sl@0: } sl@0: else if (aCommand == KCmdChangeMode) sl@0: { sl@0: DoCmdChangeModeL(aSection); sl@0: } sl@0: else if (aCommand == KCmdDrive) sl@0: { sl@0: DoCmdDriveL(aSection); sl@0: } sl@0: else if (aCommand == KCmdName) sl@0: { sl@0: DoCmdNameL(aSection); sl@0: } sl@0: else if (aCommand == KCmdDuplicate) sl@0: { sl@0: DoCmdDuplicateL(aSection); sl@0: } sl@0: else if (aCommand == KCmdFullName) sl@0: { sl@0: DoCmdFullName(aSection); sl@0: } sl@0: else if (aCommand == KCmdBlockMap) sl@0: { sl@0: DoCmdBlockMap(aSection); sl@0: } sl@0: else sl@0: { sl@0: retVal = EFalse; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: void CT_FileData::DoCmdNewL() sl@0: /** Creates new RFile class instance */ sl@0: { sl@0: //Deletes previous RFile class instance if it was already created. sl@0: DoCleanup(); sl@0: sl@0: INFO_PRINTF1(_L("Create new RFile class instance")); sl@0: sl@0: // do create sl@0: TRAPD(err, iFile = new (ELeave) RFile()); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Error returned by New()%d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoCmdDestructor() sl@0: /** Destroy RFile the object */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: void CT_FileData::DoCmdOpenL(const TDesC& aSection) sl@0: /** Opens files */ sl@0: { sl@0: RFs* rfsObject=NULL; sl@0: TPtrC rfsObjectName; sl@0: TBool dataOk=GET_MANDATORY_STRING_PARAMETER(KRFsName(), aSection, rfsObjectName); sl@0: if ( dataOk ) sl@0: { sl@0: rfsObject=(RFs*)GetDataObjectL(rfsObjectName); sl@0: } sl@0: sl@0: TPtrC filePath; sl@0: if ( !GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, filePath) ) sl@0: { sl@0: dataOk=EFalse; sl@0: } sl@0: sl@0: TUint fileMode = 0; sl@0: if ( !GetFileModeL(KFileMode, aSection, fileMode) ) sl@0: { sl@0: ERR_PRINTF2(_L("Open() error reading parameter. %S"), &KFileMode()); sl@0: SetBlockResult(EFail); sl@0: dataOk=EFalse; sl@0: } sl@0: sl@0: if ( dataOk ) sl@0: { sl@0: if (rfsObject) sl@0: { sl@0: TInt err = iFile->Open(*rfsObject, filePath, fileMode); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Open() failed with Error:%d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: iFileOpened = true; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("RFs object is NULL")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_FileData::DoCmdClose() sl@0: /** Close file */ sl@0: { sl@0: INFO_PRINTF1(_L("Closing RFile")); sl@0: iFile->Close(); sl@0: } sl@0: sl@0: void CT_FileData::DoCmdCreateL(const TDesC& aSection) sl@0: /** create a new file */ sl@0: { sl@0: RFs* rfsObject=NULL; sl@0: TPtrC rfsObjectName; sl@0: TBool dataOk = ETrue; sl@0: if ( GET_MANDATORY_STRING_PARAMETER(KRFsName, 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: // Gets name of file from ini file. sl@0: TPtrC name; sl@0: if ( !GET_MANDATORY_STRING_PARAMETER(KUParamName(), aSection, name) ) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TUint fileMode = 0; sl@0: if ( !GetFileModeL(KFileMode, aSection, fileMode) ) sl@0: { sl@0: ERR_PRINTF2(_L("Create() error reading parameter. %S"), &KFileMode()); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: if ( dataOk ) sl@0: { sl@0: // Creates and opens a new file for writing. sl@0: if (rfsObject) sl@0: { sl@0: TInt err = iFile->Create(*rfsObject, name, fileMode); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Create(), error create() = %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("RFs object is NULL")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoCmdReplaceL(const TDesC& aSection) sl@0: /** replace a existing file or create new */ sl@0: { sl@0: TPtrC rfsObjectName; sl@0: RFs* rfsObject = NULL; sl@0: sl@0: TBool dataOk = ETrue; sl@0: if ( GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName) ) sl@0: { sl@0: rfsObject=(RFs*)GetDataObjectL(rfsObjectName); sl@0: } sl@0: sl@0: // Gets name of file from ini file. sl@0: TPtrC path; sl@0: if (!GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, path)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TUint fileMode = 0; sl@0: if(!GetFileModeL(KFileMode, aSection, fileMode)) sl@0: { sl@0: ERR_PRINTF2(_L("Replace() error reading parameter. %S"), &KFileMode()); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: // Creates and opens a new file for writing. sl@0: if ( dataOk ) sl@0: { sl@0: // Creates and opens a new file for writing. sl@0: if (rfsObject) sl@0: { sl@0: TInt err = iFile->Replace(*rfsObject, path, fileMode); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Replace() failed with error = %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: iFileOpened = ETrue; sl@0: INFO_PRINTF2(_L("File: %S is replaced successfuly"), &path); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("RFs object is NULL")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: void CT_FileData::DoCmdReadL(const TDesC& aSection, const TInt aAsyncErrorIndex) sl@0: /** wrapper for read commands */ sl@0: { sl@0: TBool async = EFalse; sl@0: if(GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async)) sl@0: { sl@0: if (async) sl@0: { sl@0: DoAsynchronousReadsL(aSection, aAsyncErrorIndex); sl@0: } sl@0: else sl@0: { sl@0: DoSynchronousReadsL(aSection); sl@0: } sl@0: sl@0: } sl@0: else sl@0: { sl@0: DoSynchronousReadsL(aSection); sl@0: } sl@0: } sl@0: sl@0: TBool CT_FileData::GetFileModeL(const TDesC& aParameterName, const TDesC& aSection, TUint& aFileMode) sl@0: /** process the filemode from ini */ sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: TPtrC aModeStr; sl@0: sl@0: if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, aModeStr)) sl@0: { sl@0: //break the file mode string to array of file modes sl@0: //in case there's more than one filemode sl@0: RPointerArray fileModes = SplitL(aModeStr, "|"); sl@0: sl@0: for ( int i = 0 ; i < fileModes.Count() ; i++ ) sl@0: { sl@0: if (*fileModes[i] == KEFileShareExclusive) sl@0: { sl@0: aFileMode = aFileMode | EFileShareExclusive ; sl@0: } sl@0: else if (*fileModes[i] == KEFileShareReadersOnly) sl@0: { sl@0: aFileMode = aFileMode | EFileShareReadersOnly; sl@0: } sl@0: else if (*fileModes[i] == KEFileShareAny) sl@0: { sl@0: aFileMode = aFileMode | EFileShareAny; sl@0: } sl@0: else if (*fileModes[i] == KEFileShareReadersOrWriters) sl@0: { sl@0: aFileMode = aFileMode | EFileShareReadersOrWriters; sl@0: } sl@0: else if (*fileModes[i] == KEFileStream) sl@0: { sl@0: aFileMode = aFileMode | EFileStream; sl@0: } sl@0: else if (*fileModes[i] == KEFileStreamText) sl@0: { sl@0: aFileMode = aFileMode | EFileStreamText; sl@0: } sl@0: else if (*fileModes[i] == KEFileRead) sl@0: { sl@0: aFileMode = aFileMode | EFileRead; sl@0: } sl@0: else if (*fileModes[i] == KEFileWrite) sl@0: { sl@0: aFileMode = aFileMode | EFileWrite; sl@0: } sl@0: else if (*fileModes[i] == KEFileReadAsyncAll) sl@0: { sl@0: aFileMode = aFileMode | EFileReadAsyncAll; sl@0: } sl@0: else sl@0: { sl@0: aFileMode = EFileShareAny; sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: for (int j=0 ; jDes(); sl@0: TInt err = 0; sl@0: //devide which read to call, by switching between parameters fetched from ini file. sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length)) sl@0: { sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos)) sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TInt aLen)")); sl@0: err = iFile->Read(pos, filedataPtr, length); sl@0: HandleExpectedString(filedataPtr, aSection); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData, TInt aLen)")); sl@0: err = iFile->Read(filedataPtr, length); sl@0: HandleExpectedString(filedataPtr, aSection); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos)) sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData)")); sl@0: err = iFile->Read(pos, filedataPtr); sl@0: HandleExpectedString(filedataPtr, aSection); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData)")); sl@0: err = iFile->Read(filedataPtr); sl@0: HandleExpectedString(filedataPtr, aSection); sl@0: } sl@0: } sl@0: sl@0: TBuf filedata16; sl@0: filedata16.Copy(filedataPtr); sl@0: INFO_PRINTF2(_L("read \"%S\" from file"), &filedata16); sl@0: sl@0: //did the read complete with error code? sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("error executing synchronous read %d"), err); sl@0: SetError(err); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(1); sl@0: sl@0: } sl@0: sl@0: void CT_FileData::DoAsynchronousReadsL(const TDesC& aSection, const TInt aAsyncErrorIndex) sl@0: /**process all asynchronous reads */ sl@0: { sl@0: TInt length; sl@0: TInt pos; sl@0: sl@0: CT_FileActiveCallback* active = CT_FileActiveCallback::NewL(*this); sl@0: iReadCallbackArray.Append(active); sl@0: sl@0: TInt bufferLength; sl@0: sl@0: //Get the buffer length, and create the buffer for activeCallback object sl@0: if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength)) sl@0: { sl@0: active->CreateFileDataBufferL(bufferLength); sl@0: } sl@0: else sl@0: { sl@0: active->CreateFileDataBufferL(KDefaultDescSize); sl@0: } sl@0: sl@0: TPtr8 fileDataPtr = active->iFileData->Des(); sl@0: sl@0: //decide which read to call sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length)) sl@0: { sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos)) sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TInt aLen, TRequestiStatus aiStatus)")); sl@0: iFile->Read(pos, fileDataPtr, length,active->iStatus); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData, TInt aLen, TRequestiStatus aiStatus)")); sl@0: iFile->Read(fileDataPtr, length, active->iStatus); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos)) sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TRequestiStatus aiStatus)")); sl@0: iFile->Read(pos, fileDataPtr, active->iStatus); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Read(TDesC &aData, TRequestiStatus aiStatus)")); sl@0: iFile->Read(fileDataPtr, active->iStatus); sl@0: } sl@0: } sl@0: sl@0: //acitvate callback object sl@0: active->SetSection(aSection); sl@0: active->Activate(aAsyncErrorIndex); sl@0: IncOutstanding(); sl@0: sl@0: } sl@0: sl@0: sl@0: void CT_FileData::HandleExpectedString(const TDesC& aReadedData, const TDesC& aSection) sl@0: /** compare the expected string with readed string, takes 16-bit parameter*/ sl@0: { sl@0: TPtrC expectedString; sl@0: if(GET_OPTIONAL_STRING_PARAMETER(KUParamExpectedString, aSection, expectedString)) sl@0: { sl@0: if (aReadedData == expectedString) sl@0: { sl@0: INFO_PRINTF1(_L("expected string matches with the data read")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("expected string does not match with the data read")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_FileData::HandleExpectedString(const TDesC8& aReadedData, const TDesC& aSection) sl@0: /** compare the expected string with readed string, takes 16-bit parameter */ sl@0: { sl@0: TBuf readedData16; sl@0: readedData16.Copy(aReadedData); sl@0: TPtrC expectedString; sl@0: if(GET_OPTIONAL_STRING_PARAMETER(KUParamExpectedString, aSection, expectedString)) sl@0: { sl@0: if (readedData16 == expectedString) sl@0: { sl@0: INFO_PRINTF1(_L("expected string matches with the data read")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("expected string does not match with the data read")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_FileData::DoCmdFlushL(const TDesC& aSection, const TInt aAsyncErrorIndex) sl@0: /** flush all the internal buffers to file */ sl@0: { sl@0: TBool async = false; sl@0: TInt err = 0; sl@0: //get the parameter from ini, to decide which version of RFile::Flush to call sl@0: GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async); sl@0: if (async == true) sl@0: { sl@0: CActiveCallback* active = CActiveCallback::NewL(*this); sl@0: iFlushCallbackArray.Append( active ); sl@0: iFile->Flush(active->iStatus); sl@0: active->Activate(aAsyncErrorIndex); sl@0: IncOutstanding(); sl@0: } sl@0: else sl@0: { sl@0: err = iFile->Flush(); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Flush() failed with error code. %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Succesfully flushed the file")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_FileData::DoCmdTempL(const TDesC& aSection) sl@0: /* create temporary file */ sl@0: { sl@0: sl@0: TPtrC rfsObjectName; sl@0: RFs* rfsObject = NULL; sl@0: sl@0: TBool dataOk=GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName); sl@0: if ( dataOk ) sl@0: { sl@0: rfsObject=(RFs*)GetDataObjectL(rfsObjectName); sl@0: } sl@0: sl@0: // Gets name of file from ini file. sl@0: TPtrC path; sl@0: if (!GET_MANDATORY_STRING_PARAMETER(KUParamPath(), aSection, path)) sl@0: { sl@0: dataOk=EFalse; sl@0: } sl@0: sl@0: TUint fileMode = 0; sl@0: if(!GetFileModeL(KFileMode, aSection, fileMode)) sl@0: { sl@0: ERR_PRINTF2(_L("Temp() error reading parameter. %S"), &KFileMode()); sl@0: SetBlockResult(EFail); sl@0: dataOk=EFalse; sl@0: } sl@0: sl@0: // Creates Temporary file. sl@0: TFileName fileName; sl@0: if ( dataOk ) sl@0: { sl@0: if (rfsObject) sl@0: { sl@0: TInt err = iFile->Temp(*rfsObject, path, fileName,fileMode); sl@0: INFO_PRINTF2(_L("File: %S is created"), &fileName); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Temp() failed with error = %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: iFileOpened = ETrue; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("RFs object is NULL")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: void CT_FileData::DoCmdRenameL(const TDesC& aSection) sl@0: /** rename the file */ sl@0: { sl@0: sl@0: TPtrC newName; sl@0: //get the name from ini and rename the file. sl@0: if(GET_MANDATORY_STRING_PARAMETER(KUParamName(), aSection, newName)) sl@0: { sl@0: TInt err = iFile->Rename(newName); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Rename() failed with error code %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: void CT_FileData::DoCmdSeekL(const TDesC& aSection) sl@0: /** set the file cursor to specified location in file */ sl@0: { sl@0: TSeek seek = ESeekStart; sl@0: TBool dataOk = EFalse; sl@0: TInt pos; sl@0: sl@0: //convert the mode string from ini to TSeek sl@0: if(ConvertToSeek(KSeek, aSection,seek)) sl@0: { sl@0: dataOk = GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos); sl@0: } sl@0: sl@0: if(dataOk) sl@0: { sl@0: TInt err = iFile->Seek(seek, pos); sl@0: sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Seek(), error seeking() = %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Succesfully seeked the file")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: TBool CT_FileData::ConvertToSeek(const TDesC& aParameterName, const TDesC& aSection, TSeek& aSeek) sl@0: /** convert a seek mode string from ini to TSeek */ sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: TPtrC aModeStr; sl@0: sl@0: if(GET_MANDATORY_STRING_PARAMETER(aParameterName, aSection, aModeStr)) sl@0: { sl@0: sl@0: if (aModeStr == KESeekStart) sl@0: { sl@0: aSeek = ESeekStart; sl@0: } sl@0: else if (aModeStr == KESeekCurrent) sl@0: { sl@0: aSeek = ESeekCurrent; sl@0: } sl@0: else if (aModeStr == KESeekEnd) sl@0: { sl@0: aSeek = ESeekEnd; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: void CT_FileData::DoCmdReadCancelL(const TDesC& aSection) sl@0: /** wrapper for readcancels */ sl@0: { sl@0: sl@0: TBool cancelAll; sl@0: sl@0: //decide which ReadCancel to call sl@0: if(GET_OPTIONAL_BOOL_PARAMETER(KUParamCancelAll, aSection, cancelAll)) sl@0: { sl@0: if (cancelAll == true) sl@0: { sl@0: ReadCancelAll(); sl@0: } sl@0: else sl@0: { sl@0: ReadCancel(); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ReadCancel(); sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::ReadCancel() sl@0: /** will cancel the last active request by default */ sl@0: { sl@0: iFile->ReadCancel(iReadCallbackArray[iReadCallbackArray.Count()-1]->iStatus); sl@0: } sl@0: sl@0: void CT_FileData::ReadCancelAll() sl@0: /** cancel all outstanding read requests */ sl@0: { sl@0: iFile->ReadCancel(); sl@0: } sl@0: sl@0: // the write implementation sl@0: void CT_FileData::DoCmdWriteL(const TDesC& aSection, const TInt aAsyncErrorIndex) sl@0: /** wrapper for write commands */ sl@0: { sl@0: TBool async = EFalse; sl@0: //decide which write to call sl@0: GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async); sl@0: if (async == true) sl@0: { sl@0: DoAsynchronousWritesL(aSection, aAsyncErrorIndex); sl@0: } sl@0: else sl@0: { sl@0: DoSynchronousWritesL(aSection); sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoAsynchronousWritesL(const TDesC& aSection, const TInt aAsyncErrorIndex) sl@0: /** call asynchronous writes */ sl@0: { sl@0: HBufC8* dataWrite8; sl@0: TInt bufferLength; sl@0: sl@0: //Get the buffer length, and create the buffer for activeCallback object sl@0: if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength)) sl@0: { sl@0: dataWrite8 = HBufC8::NewLC(bufferLength); sl@0: } sl@0: else sl@0: { sl@0: dataWrite8 = HBufC8::NewLC(KDefaultDescSize); sl@0: } sl@0: TPtr8 data8Ptr = dataWrite8->Des(); sl@0: sl@0: TPtrC data; sl@0: // Get the data to write sl@0: if(GET_MANDATORY_STRING_PARAMETER(KUParamData(), aSection, data)) sl@0: { sl@0: //convert it to 8-bit sl@0: data8Ptr.Copy(data); sl@0: sl@0: CActiveCallback* active = CActiveCallback::NewL(*this); sl@0: sl@0: iWriteCallbackArray.Append( active ); sl@0: sl@0: TInt length; sl@0: TInt pos; sl@0: //now, decide which read to call sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length)) sl@0: { sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos)) sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TInt aLen, TRequestStatus &aStatus)")); sl@0: iFile->Write(pos, *dataWrite8, length, active->iStatus); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TInt aLen, , TRequestStatus &aStatus)")); sl@0: iFile->Write(*dataWrite8, length, active->iStatus); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos)) sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TRequestStatus &aStatus)")); sl@0: iFile->Write(pos, *dataWrite8, active->iStatus); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TRequestStatus &aStatus)")); sl@0: iFile->Write(*dataWrite8, active->iStatus); sl@0: } sl@0: } sl@0: sl@0: active->Activate(aAsyncErrorIndex); sl@0: IncOutstanding(); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: void CT_FileData::DoSynchronousWritesL(const TDesC& aSection) sl@0: /** cakk synchronous writes */ sl@0: { sl@0: HBufC8* dataWrite8; sl@0: TInt bufferLength; sl@0: sl@0: //Get the buffer length, and create the buffer for activeCallback object sl@0: if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength)) sl@0: { sl@0: dataWrite8 = HBufC8::NewLC(bufferLength); sl@0: } sl@0: else sl@0: { sl@0: dataWrite8 = HBufC8::NewLC(KDefaultDescSize); sl@0: } sl@0: TPtr8 data8Ptr = dataWrite8->Des(); sl@0: TInt err = 0; sl@0: sl@0: TPtrC data; sl@0: // get the data sl@0: if (GET_MANDATORY_STRING_PARAMETER(KUParamData(), aSection, data)) sl@0: { sl@0: //convert it to 8-bit sl@0: data8Ptr.Copy(data); sl@0: sl@0: TInt length; sl@0: TInt pos; sl@0: sl@0: //will decide which write to call sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length)) sl@0: { sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos)) sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TInt aLen)")); sl@0: err = iFile->Write(pos, *dataWrite8, length); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TInt aLen)")); sl@0: err = iFile->Write(*dataWrite8, length); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos)) sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData)")); sl@0: err = iFile->Write(pos, *dataWrite8); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData)")); sl@0: err = iFile->Write(*dataWrite8); sl@0: } sl@0: } sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("written \"%S\" to file"), &data); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Error executing synchronous write %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: void CT_FileData::DoCmdLockL(const TDesC& aSection) sl@0: /** lock a region in file */ sl@0: { sl@0: sl@0: TInt pos=0; sl@0: TBool dataOk = ETrue; sl@0: sl@0: //get the position sl@0: if(!GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TInt length=0; sl@0: sl@0: // get the length sl@0: if(!GET_MANDATORY_INT_PARAMETER(KUParamLength(), aSection, length)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: //Lock!! sl@0: if (dataOk) sl@0: { sl@0: TInt err = iFile->Lock(pos, length); sl@0: sl@0: if(err!=KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Lock() error locking file. %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: sl@0: void CT_FileData::DoCmdUnLockL(const TDesC& aSection) sl@0: /** unlock a region that has been previously locked */ sl@0: { sl@0: TBool dataOk = ETrue; sl@0: sl@0: TInt pos=0; sl@0: sl@0: //get the position sl@0: if(!GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TInt length=0; sl@0: sl@0: // get the length sl@0: if(!GET_MANDATORY_INT_PARAMETER(KUParamLength(), aSection, length)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: //call UnLock sl@0: if (dataOk) sl@0: { sl@0: TInt err = iFile->UnLock(pos, length); sl@0: sl@0: if(err!=KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("UnLock() error unlocking file. %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Succesfully unlocked the file")); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: sl@0: void CT_FileData::DoCmdSizeL(const TDesC& aSection) sl@0: /** get file size */ sl@0: { sl@0: sl@0: TInt expectedSize = 0; sl@0: sl@0: TInt size = 0; sl@0: TInt err = iFile->Size(size); sl@0: INFO_PRINTF2(_L("The Size of the file is %d bytes"), size); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Size() error getting file size. %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: //get expected size from ini sl@0: if(GET_OPTIONAL_INT_PARAMETER(KUParamExpectedSize(), aSection, expectedSize)) sl@0: { sl@0: if(expectedSize != size) sl@0: { sl@0: ERR_PRINTF3(_L("The file size does not match the expected size %d != %d"), size, expectedSize) sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: void CT_FileData::DoCmdSetSizeL(const TDesC& aSection) sl@0: /** set file size */ sl@0: { sl@0: TInt size=0; sl@0: sl@0: if(GET_MANDATORY_INT_PARAMETER(KUParamSize(), aSection, size)) sl@0: { sl@0: TInt err = iFile->SetSize(size); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SetSize() error setting file size. %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("The Size of the fail is set to %d bytes"), size); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoCmdAttL(const TDesC& aSection) sl@0: /** get file attributes */ sl@0: { sl@0: sl@0: TUint attValue = 0; sl@0: sl@0: TInt err = iFile->Att(attValue); sl@0: sl@0: PrintFileAttributes(attValue); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Att() getting attributes. %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: TUint bitmask = 0x000000FF; sl@0: //lets filter out symbian specific bits sl@0: attValue = attValue & bitmask; sl@0: sl@0: TUint attCompare = 0; sl@0: sl@0: //compare the expected att value with the file attributes sl@0: if (ConvertToAttributeL(KUParamCompareValue, aSection, attCompare)) sl@0: { sl@0: if (attCompare == attValue) sl@0: { sl@0: INFO_PRINTF1(_L("attributes match")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Attributes does not match")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: } sl@0: sl@0: void CT_FileData::DoCmdSetAttL(const TDesC& aSection) sl@0: /** set file attributes */ sl@0: { sl@0: sl@0: TUint setAttMask = 0; sl@0: TBool dataOk = ETrue; sl@0: sl@0: //get the attribute mask to set sl@0: if(!ConvertToAttributeL(KUParamSetAttMask, aSection, setAttMask)) sl@0: { sl@0: ERR_PRINTF2(_L("SetATt() error reading parameter. %S"), &KUParamSetAttMask()); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TUint clearAttMask = 0; sl@0: sl@0: //get the attribute mask to clear sl@0: if(!ConvertToAttributeL(KUParamClearAttMask, aSection, clearAttMask)) sl@0: { sl@0: ERR_PRINTF2(_L("SetAtt() error reading parameter. %S"), &KUParamClearAttMask()); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: // all ok? let's call SetAtt sl@0: if (dataOk) sl@0: { sl@0: TInt err = iFile->SetAtt(setAttMask, clearAttMask); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SetAtt() failed with, err: %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("The attribute value has been set")); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: sl@0: TBool CT_FileData::ConvertToAttributeL(const TDesC& aParameterName, const TDesC& aSection, TUint& aAttribute) sl@0: /** convert attribute string from ini to file attribute bitmask */ sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: TPtrC aModeStr; sl@0: sl@0: if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, aModeStr)) sl@0: { sl@0: //break the file mode string to array of file modes sl@0: //in case there's more than one filemode sl@0: RPointerArray fileModes = SplitL(aModeStr, "|"); sl@0: sl@0: for ( int i = 0 ; i < fileModes.Count() ; i++ ) sl@0: { sl@0: if (aModeStr == KDEntryAttNormal) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttNormal; sl@0: } sl@0: else if (aModeStr == KDEntryAttReadOnly) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttReadOnly; sl@0: } sl@0: else if (aModeStr == KDEntryAttArchive) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttArchive; sl@0: } sl@0: else if (aModeStr == KDEntryAttHidden) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttHidden; sl@0: } sl@0: sl@0: else if (aModeStr == KDEntryAttSystem) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttSystem; sl@0: } sl@0: sl@0: else if (aModeStr == KDEntryAttVolume) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttVolume; sl@0: } sl@0: sl@0: else if (aModeStr == KDEntryAttDir) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttDir; sl@0: } sl@0: sl@0: else if (aModeStr == KDEntryAttXIP) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttXIP; sl@0: } sl@0: sl@0: else if (aModeStr == KDEntryAttRemote) sl@0: { sl@0: aAttribute = aAttribute | KEntryAttRemote; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: for (int j=0 ; jModified(time); sl@0: sl@0: _LIT(KDateString,"%E%D%X%N%Y %1 %2 %3"); sl@0: sl@0: TBuf dateString; sl@0: sl@0: //format the time to string sl@0: TRAPD(err2, time.FormatL(dateString, KDateString)); sl@0: sl@0: if(err2 != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Modified() error formating date string err: %d"), err); sl@0: } sl@0: sl@0: INFO_PRINTF2(_L("Modified() returned: %S"), &dateString); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Modified() failed with, err: %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: sl@0: //compare the file modification date with the date readed from inin sl@0: TPtrC compValue; sl@0: sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KUParamCompareValue, aSection, compValue)) sl@0: { sl@0: sl@0: TTime compTime; sl@0: err = compTime.Set(compValue); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF1(_L("invalid compare value")); sl@0: } sl@0: else sl@0: { sl@0: if (compTime == time) sl@0: { sl@0: INFO_PRINTF1(_L("The dates match")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("The values do not match")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoCmdSetModifiedL(const TDesC& aSection) sl@0: /** set file modification date */ sl@0: { sl@0: sl@0: TPtrC dateDesc; sl@0: TBool dataOk = ETrue; sl@0: TTime time; sl@0: TInt err = KErrNone; sl@0: sl@0: if(!GET_MANDATORY_STRING_PARAMETER(KUParamDate(), aSection, dateDesc)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: else sl@0: { sl@0: err = time.Set(dateDesc); sl@0: } sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("time.Set() failed with error code %d"), err); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: if (dataOk) sl@0: { sl@0: err = iFile->SetModified(time); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("SetModified() failed with error code %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoCmdSetL(const TDesC& aSection) sl@0: /** set file attributes and modification time */ sl@0: { sl@0: TPtrC dateDesc; sl@0: TBool dataOk = ETrue; sl@0: TInt err = KErrNone; sl@0: TTime time; sl@0: sl@0: //get and process the date string sl@0: if(!GET_MANDATORY_STRING_PARAMETER(KUParamDate(), aSection, dateDesc)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: else sl@0: { sl@0: err = time.Set(dateDesc); sl@0: } sl@0: sl@0: TUint setAttMask = 0; sl@0: sl@0: // get the attribute masks sl@0: if(!ConvertToAttributeL(KUParamSetAttMask, aSection,setAttMask)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TUint clearAttMask = 0; sl@0: sl@0: if(!ConvertToAttributeL(KUParamClearAttMask, aSection, clearAttMask)) sl@0: { sl@0: dataOk = EFalse; sl@0: } sl@0: // if all Ok then proceed with Set sl@0: if (dataOk) sl@0: { sl@0: err = iFile->Set(time, setAttMask, clearAttMask); sl@0: sl@0: if ( err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Set() failed with error code %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoCmdChangeModeL(const TDesC& aSection) sl@0: /** Change the file mode */ sl@0: { sl@0: TUint fileMode = 0; sl@0: sl@0: if(!GetFileModeL(KFileMode, aSection, fileMode)) sl@0: { sl@0: ERR_PRINTF2(_L("Set() error reading parameter. %S"), &KFileMode()); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: TInt err = iFile->ChangeMode((TFileMode)fileMode); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("ChangeMode() failed with error code %d"), err); sl@0: SetError(err); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoCmdDriveL(const TDesC& aSection) sl@0: /** Get the drive info, in which the file is stored */ sl@0: { sl@0: TDriveInfo driveInfo; sl@0: TInt driveNumber; sl@0: int err = iFile->Drive(driveNumber, driveInfo); sl@0: sl@0: INFO_PRINTF2(_L("TDriveInfo.iType =%d"), driveInfo.iType); sl@0: INFO_PRINTF2(_L("TDriveInfo.iBattery =%d"), driveInfo.iBattery); sl@0: INFO_PRINTF2(_L("TDriveInfo.iDriveAtt=0x%X"), driveInfo.iDriveAtt); sl@0: INFO_PRINTF2(_L("Drivenumber =%d"), driveNumber); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Drive() failed with error code %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: TInt compDriveNumber; sl@0: sl@0: if ( GET_OPTIONAL_INT_PARAMETER(KUParamCompareValue, aSection, compDriveNumber)) sl@0: { sl@0: if ( compDriveNumber == driveNumber ) sl@0: { sl@0: INFO_PRINTF3(_L("drivenumbers match %d == %d "), compDriveNumber, driveNumber); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF3(_L("drivenumbers do not match %d != %d"), compDriveNumber, driveNumber); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: void CT_FileData::DoCmdDuplicateL(const TDesC& aSection) sl@0: /** Duplicate the file */ sl@0: { sl@0: TPtrC rFileObjectName; sl@0: TBool dataOk = GET_MANDATORY_STRING_PARAMETER(KFileObjectName, aSection, rFileObjectName); sl@0: sl@0: // get the RFile handle to duplicate sl@0: RFile* rFileObject = NULL; sl@0: if (dataOk) sl@0: { sl@0: rFileObject=(RFile*)GetDataObjectL(rFileObjectName); sl@0: sl@0: if(rFileObject == NULL) sl@0: { sl@0: ERR_PRINTF2(_L("Duplicate() error getting object. %S"), KFileObjectName); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: } sl@0: sl@0: // if handle ok then procees with duplication sl@0: if (dataOk) sl@0: { sl@0: TOwnerType ownerType; sl@0: sl@0: TInt err = KErrNone; sl@0: // determine the owner type to pass to duplicate sl@0: if (ConvertToOwnerType(KUParamOwnerType, aSection, ownerType) && dataOk) sl@0: { sl@0: err = iFile->Duplicate(*rFileObject, ownerType); sl@0: } sl@0: else sl@0: { sl@0: err = iFile->Duplicate(*rFileObject); sl@0: } sl@0: sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Duplicate() error duplicating %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: //lets mark the file to be opened sl@0: iFileOpened = ETrue; sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: TBool CT_FileData::ConvertToOwnerType(const TDesC& aParameterName, const TDesC& aSection, TOwnerType& aResult) sl@0: /** convert the ownerType string from ini to EOwnerType */ sl@0: { sl@0: sl@0: TBool ret = ETrue; sl@0: sl@0: TPtrC ownerTypeString; sl@0: sl@0: if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, ownerTypeString)) sl@0: { sl@0: sl@0: if (ownerTypeString == KEOwnerProcess ) sl@0: { sl@0: aResult = EOwnerProcess; sl@0: } sl@0: else if (ownerTypeString == KEOwnerThread) sl@0: { sl@0: aResult = EOwnerThread; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: void CT_FileData::DoCmdFullName(const TDesC& aSection) sl@0: /** get the file fullname */ sl@0: { sl@0: TBuf<128> name; sl@0: TInt err = iFile->FullName(name); sl@0: sl@0: INFO_PRINTF2(_L("FullName() returned %S"), &name); sl@0: sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("FullName() error, returned. %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: TPtrC path; sl@0: if(GET_OPTIONAL_STRING_PARAMETER(KUParamComparePath, aSection, path)) sl@0: { sl@0: if (path == name) sl@0: { sl@0: INFO_PRINTF1(_L("the paths match")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("the paths do not match")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::DoCmdNameL(const TDesC& aSection) sl@0: /** get the file name */ sl@0: { sl@0: TBuf name; sl@0: TInt err = iFile->Name(name); sl@0: INFO_PRINTF2(_L("Name() returned %S"), &name); sl@0: sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Name() error, returned. %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: sl@0: sl@0: TPtrC compValue; sl@0: sl@0: if (GET_OPTIONAL_STRING_PARAMETER(KUParamCompareValue, aSection, compValue)) sl@0: { sl@0: if (compValue == name) sl@0: { sl@0: INFO_PRINTF3(_L("The names match %S == %S"), &name, &compValue); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF3(_L("The names do not match %S == %S"), &name, &compValue); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: TBool CT_FileData::ConvertToBlockMapUsage(const TDesC& aParameterName, const TDesC& aSection, TBlockMapUsage& aResult) sl@0: { sl@0: sl@0: TBool ret = ETrue; sl@0: sl@0: TPtrC blockmapeUsageString; sl@0: sl@0: if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, blockmapeUsageString)) sl@0: { sl@0: sl@0: if (blockmapeUsageString == KEBlockMapUsagePaging ) sl@0: { sl@0: aResult = EBlockMapUsagePaging; sl@0: } sl@0: else if (blockmapeUsageString == KETestDebug) sl@0: { sl@0: aResult = ETestDebug; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: void CT_FileData::DoCmdBlockMap(const TDesC& aSection) sl@0: { sl@0: TInt64 startPos = 0; sl@0: GET_OPTIONAL_INT64_PARAMETER(KUParamStartPos, aSection, startPos); sl@0: sl@0: SBlockMapInfo blockMapInfo; sl@0: TInt err = KErrNone; sl@0: TInt64 endPos = -1; sl@0: if (GET_OPTIONAL_INT64_PARAMETER(KUParamEndPos, aSection, endPos)) sl@0: { sl@0: TBlockMapUsage usage; sl@0: if (ConvertToBlockMapUsage(KUParamUsage, aSection, usage)) sl@0: { sl@0: err = iFile->BlockMap(blockMapInfo, startPos, endPos, usage); sl@0: } sl@0: else sl@0: { sl@0: err = iFile->BlockMap(blockMapInfo, startPos, endPos); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TBlockMapUsage usage; sl@0: if (ConvertToBlockMapUsage(KUParamUsage, aSection, usage)) sl@0: { sl@0: err = iFile->BlockMap(blockMapInfo, startPos, usage); sl@0: } sl@0: else sl@0: { sl@0: err = iFile->BlockMap(blockMapInfo, startPos); sl@0: } sl@0: } sl@0: sl@0: if (KErrNone != err) sl@0: { sl@0: ERR_PRINTF2(_L("BlockMap Returned an error %d"), err); sl@0: SetError(err); sl@0: } sl@0: if (KErrNone == err || KErrCompletion == err) sl@0: { sl@0: INFO_PRINTF2(_L("Returned start position %d"), startPos); sl@0: sl@0: INFO_PRINTF2(_L("Local drive number %d"), blockMapInfo.iLocalDriveNumber); sl@0: INFO_PRINTF2(_L("Block start address %d"), blockMapInfo.iStartBlockAddress); sl@0: INFO_PRINTF2(_L("Block start offset %u"), blockMapInfo.iBlockStartOffset); sl@0: INFO_PRINTF2(_L("Block graduality %u"), blockMapInfo.iBlockGranularity); sl@0: } sl@0: sl@0: } sl@0: sl@0: //function that adds the buffer to the end of the array sl@0: void CT_FileData::ToArrayL(RPointerArray& aArray, HBufC*& aBuffer) sl@0: { sl@0: HBufC* arrayElement = HBufC::NewL(aBuffer->Length()); sl@0: TPtr arrayElementPtr = arrayElement->Des(); sl@0: arrayElementPtr.Copy(*aBuffer); sl@0: arrayElementPtr.TrimAll(); sl@0: aArray.Append(arrayElement); sl@0: arrayElement = NULL; sl@0: } sl@0: sl@0: sl@0: // helper function to split filemodes or attributes to array sl@0: RPointerArray CT_FileData::SplitL(const TDesC& aInput, const char* aToken) sl@0: { sl@0: RPointerArray fileModeArray; sl@0: HBufC* buffer = HBufC::NewL(aInput.Length()); sl@0: TPtr bufferPtr = buffer->Des(); sl@0: for (int i=0;iDes(); sl@0: } sl@0: else sl@0: { sl@0: bufferPtr.Append(aInput[i]); sl@0: } sl@0: } sl@0: sl@0: ToArrayL(fileModeArray, buffer); sl@0: delete buffer; sl@0: sl@0: buffer = NULL; sl@0: sl@0: return fileModeArray; sl@0: sl@0: } sl@0: sl@0: void CT_FileData::DoCancel(CActive* aActive, TInt aIndex) sl@0: { sl@0: TBool foundActiveObject = EFalse; sl@0: sl@0: TInt index=0; sl@0: TInt count=0; sl@0: sl@0: count=iReadCallbackArray.Count(); sl@0: for( index=0; (indexiStatus.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: sl@0: // Reset the outstanding request state sl@0: DecOutstanding(); sl@0: sl@0: delete aActive; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Stray DoCancel signal")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: void CT_FileData::RunL(CActive* aActive, TInt aIndex) sl@0: { sl@0: sl@0: sl@0: TBool foundActiveObject = EFalse; sl@0: TInt index=0; sl@0: TInt count=0; sl@0: sl@0: count=iReadCallbackArray.Count(); sl@0: for( index=0; (indexiStatus.Int(); sl@0: sl@0: TBuf info; sl@0: info.Copy(iReadCallbackArray[index]->iFileData->Des()); sl@0: INFO_PRINTF2(_L("readed \"%S\" from file"), &info); sl@0: sl@0: HandleExpectedString(iReadCallbackArray[index]->iFileData->Des(), *iReadCallbackArray[index]->iSection); sl@0: sl@0: if( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Async Read error %d"), err); sl@0: SetAsyncError( aIndex, err ); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Succesfully completed Async Read")); sl@0: } sl@0: sl@0: iReadCallbackArray.Remove(index); sl@0: delete aActive; sl@0: sl@0: } sl@0: } sl@0: sl@0: count=iWriteCallbackArray.Count(); sl@0: for( index=0; (indexiStatus.Int(); sl@0: sl@0: if( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Async Write Error %d"), err); sl@0: SetAsyncError( aIndex, err ); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Succesfully completed Async Write")); sl@0: } sl@0: iWriteCallbackArray.Remove(index); sl@0: delete aActive; sl@0: } sl@0: } sl@0: sl@0: count=iFlushCallbackArray.Count(); sl@0: for( index=0; (indexiStatus.Int(); sl@0: sl@0: if( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Async Flush Error %d"), err); sl@0: SetAsyncError( aIndex, err ); sl@0: } sl@0: iFlushCallbackArray.Remove(index); sl@0: delete aActive; sl@0: } sl@0: } sl@0: sl@0: DecOutstanding(); sl@0: } sl@0: sl@0: void CT_FileData::PrintFileAttributes(TUint aAttValue) sl@0: /** Prints file attributes */ sl@0: { sl@0: if ((aAttValue & KEntryAttNormal) == KEntryAttNormal) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttNormal")); sl@0: } sl@0: if ((aAttValue & KEntryAttReadOnly) == KEntryAttReadOnly) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttReadOnly")); sl@0: } sl@0: sl@0: if ((aAttValue & KEntryAttHidden) == KEntryAttHidden) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttHidden")); sl@0: } sl@0: sl@0: if ((aAttValue & KEntryAttSystem) == KEntryAttSystem) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttSystem")); sl@0: } sl@0: sl@0: if ((aAttValue & KEntryAttVolume) == KEntryAttVolume) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttVolume")); sl@0: } sl@0: sl@0: if ((aAttValue & KEntryAttDir) == KEntryAttDir) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttDir")); sl@0: } sl@0: sl@0: if ((aAttValue & KEntryAttArchive) == KEntryAttArchive) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttArchive")); sl@0: } sl@0: sl@0: if ((aAttValue & KEntryAttXIP) == KEntryAttXIP) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttXIP")); sl@0: } sl@0: sl@0: if ((aAttValue & KEntryAttRemote) == KEntryAttRemote) sl@0: { sl@0: INFO_PRINTF1(_L("KEntryAttRemote")); sl@0: } sl@0: } sl@0: