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_RawDiskData sl@0: */ sl@0: sl@0: // User includes sl@0: #include "T_RawDiskData.h" sl@0: sl@0: /*@{*/ sl@0: /// Parameters sl@0: _LIT(KDrive, "drive"); sl@0: _LIT(KObjectName, "object_name"); sl@0: _LIT(KData, "data"); sl@0: _LIT(KPosition, "position"); sl@0: sl@0: ///Commands sl@0: _LIT(KCmdOpen, "Open"); sl@0: _LIT(KCmdClose, "Close"); sl@0: _LIT(KCmdNew, "new" ); sl@0: _LIT(KCmdDestructor, "~" ); sl@0: _LIT(KCmdRead, "Read"); sl@0: _LIT(KCmdWrite, "Write"); sl@0: sl@0: _LIT(KDriveA, "EDriveA"); sl@0: _LIT(KDriveB, "EDriveB"); sl@0: _LIT(KDriveC, "EDriveC"); sl@0: _LIT(KDriveD, "EDriveD"); sl@0: _LIT(KDriveE, "EDriveE"); sl@0: _LIT(KDriveF, "EDriveF"); sl@0: _LIT(KDriveG, "EDriveG"); sl@0: _LIT(KDriveH, "EDriveH"); sl@0: _LIT(KDriveI, "EDriveI"); sl@0: _LIT(KDriveJ, "EDriveJ"); sl@0: _LIT(KDriveK, "EDriveK"); sl@0: _LIT(KDriveL, "EDriveL"); sl@0: _LIT(KDriveM, "EDriveM"); sl@0: _LIT(KDriveN, "EDriveN"); sl@0: _LIT(KDriveO, "EDriveO"); sl@0: _LIT(KDriveP, "EDriveP"); sl@0: _LIT(KDriveQ, "EDriveQ"); sl@0: _LIT(KDriveR, "EDriveR"); sl@0: _LIT(KDriveS, "EDriveS"); sl@0: _LIT(KDriveT, "EDriveT"); sl@0: _LIT(KDriveU, "EDriveU"); sl@0: _LIT(KDriveV, "EDriveV"); sl@0: _LIT(KDriveW, "EDriveW"); sl@0: _LIT(KDriveX, "EDriveX"); sl@0: _LIT(KDriveY, "EDriveY"); sl@0: _LIT(KDriveZ, "EDriveZ"); sl@0: /*@}*/ sl@0: sl@0: CT_RawDiskData* CT_RawDiskData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_RawDiskData* ret = new (ELeave) CT_RawDiskData(); 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_RawDiskData::CT_RawDiskData() sl@0: : iRawDisk(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: void CT_RawDiskData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: CT_RawDiskData::~CT_RawDiskData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: void CT_RawDiskData::DoCleanup() sl@0: /** sl@0: * Contains cleanup implementation sl@0: */ sl@0: { sl@0: //Deleting RRawDisk. sl@0: if (iRawDisk) sl@0: { sl@0: DoCmdClose(); sl@0: INFO_PRINTF1(_L("Deleting current RRawDisk")); sl@0: delete iRawDisk; sl@0: iRawDisk = NULL; sl@0: } sl@0: } sl@0: sl@0: TAny* CT_RawDiskData::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 iRawDisk; sl@0: } sl@0: sl@0: TBool CT_RawDiskData::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 requiring command to be processed sl@0: * @param aSection the section 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: * @leave system wide error 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: DoCmdOpen(aSection); sl@0: } sl@0: else if (aCommand == KCmdClose) sl@0: { sl@0: DoCmdClose(); sl@0: } sl@0: else if (aCommand == KCmdRead) sl@0: { sl@0: DoCmdReadL(aSection); sl@0: } sl@0: else if (aCommand == KCmdWrite) sl@0: { sl@0: DoCmdWriteL(aSection); sl@0: } sl@0: else sl@0: { sl@0: retVal = EFalse; sl@0: } sl@0: return retVal; sl@0: } sl@0: sl@0: sl@0: void CT_RawDiskData::DoCmdNewL() sl@0: /** Creates new RRawDisk class instance */ sl@0: { sl@0: //Deletes previous RRawDisk class instance if it was already created. sl@0: DoCleanup(); sl@0: sl@0: INFO_PRINTF1(_L("Create new RRawDisk class instance")); sl@0: sl@0: // do create sl@0: TRAPD(err, iRawDisk = new (ELeave) RRawDisk()); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("new error %d"), err); sl@0: SetError(err); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Create new RRawDisk class instance completed successfully!")); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_RawDiskData::DoCmdDestructor() sl@0: /** Destroy RRawDisk the object */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: sl@0: void CT_RawDiskData::DoCmdOpen(const TDesC& aSection) sl@0: /** RRawDisk::Open */ sl@0: { sl@0: INFO_PRINTF1(_L("Opening a direct access channel to the disk!")); sl@0: sl@0: RFs* rfsObject = NULL; sl@0: TPtrC rfsObjectName; sl@0: if (GET_MANDATORY_STRING_PARAMETER(KObjectName, aSection, rfsObjectName)) sl@0: { sl@0: TRAPD(err, rfsObject = (RFs*)GetDataObjectL(rfsObjectName)); sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: // get drive number from parameters sl@0: TDriveNumber driveNumber = EDriveA; sl@0: if (!GetDriveNumber(aSection, KDrive(), driveNumber)) sl@0: { sl@0: ERR_PRINTF2(_L("No %S"), &KDrive()); sl@0: SetBlockResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: TInt err = KErrNone; sl@0: err = iRawDisk->Open(*rfsObject, driveNumber); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Opening iRawDisk failed with error : %d"), err); sl@0: SetError( err ); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Opening iRawDisk completed successfully!")); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Error with fileserver")); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_RawDiskData::DoCmdClose() sl@0: /** RRawDisk::Close */ sl@0: { sl@0: INFO_PRINTF1(_L("Closing current RRawDisk")); sl@0: iRawDisk->Close(); sl@0: } sl@0: sl@0: sl@0: void CT_RawDiskData::DoCmdReadL( const TDesC& aSection ) sl@0: { sl@0: INFO_PRINTF1(_L("Reading directly from disc!")); sl@0: TInt err = KErrNone; sl@0: sl@0: TPtrC expectedData; sl@0: if(GET_MANDATORY_STRING_PARAMETER(KData(), aSection, expectedData)) sl@0: { sl@0: HBufC* expectedResultBuf = HBufC::NewL(expectedData.Length()); sl@0: sl@0: TPtr expectedResult = expectedResultBuf->Des(); sl@0: expectedResult.Copy(expectedData); sl@0: sl@0: INFO_PRINTF2(_L("Expecting data: %S"), &expectedResult); sl@0: sl@0: HBufC8* readBuf = HBufC8::NewL( expectedData.Length()); sl@0: TPtr8 readBufPtr = readBuf->Des(); sl@0: sl@0: TInt64 pos = 0; sl@0: GET_OPTIONAL_INT64_PARAMETER(KPosition(), aSection, pos); sl@0: sl@0: err = iRawDisk->Read(pos, readBufPtr); sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: HBufC* readResultBuf = HBufC::NewL(readBufPtr.Length()); sl@0: sl@0: TPtr readResult = readResultBuf->Des(); sl@0: readResult.Copy(readBufPtr); sl@0: sl@0: INFO_PRINTF2(_L("Reading data: %S"), &readResult); sl@0: sl@0: if (readResult != expectedResult) sl@0: { sl@0: ERR_PRINTF3(_L("Read data does not match expected data! Read: %S expected: %S"), &readResult, &expectedResult); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Reading data directly from disc was successful!")); sl@0: } sl@0: delete readResultBuf; sl@0: readResultBuf = NULL; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Reading data directly from disc failed with error %d"), err); sl@0: SetError(err); sl@0: } sl@0: delete expectedResultBuf; sl@0: expectedResultBuf = NULL; sl@0: delete readBuf; sl@0: readBuf = NULL; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("No %S"), &KData()); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_RawDiskData::DoCmdWriteL( const TDesC& aSection ) sl@0: { sl@0: INFO_PRINTF1(_L("Writing directly to disc!")); sl@0: sl@0: TPtrC writeData; sl@0: if(GET_MANDATORY_STRING_PARAMETER(KData(), aSection, writeData)) sl@0: { sl@0: sl@0: INFO_PRINTF2(_L("Writing following data: %S"), &writeData); sl@0: sl@0: HBufC8* writeBuf = NULL; sl@0: TRAPD (err, writeBuf = HBufC8::NewL( writeData.Length() )); sl@0: if (err == KErrNone) sl@0: { sl@0: TPtr8 writeBufPtr = writeBuf->Des(); sl@0: writeBufPtr.Copy(writeData); sl@0: sl@0: TInt64 pos = 0; sl@0: GET_OPTIONAL_INT64_PARAMETER(KPosition(), aSection, pos); sl@0: sl@0: err = iRawDisk->Write(pos, writeBufPtr); sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Writing data directly to disc was successful!")); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Writing data directly to disc failed with error %d"), err); sl@0: SetError(err); sl@0: } sl@0: delete writeBuf; sl@0: writeBuf = NULL; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("No %S"), &KData()); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: sl@0: TBool CT_RawDiskData::GetDriveNumber(const TDesC& aSection, const TDesC& aParameterName, TDriveNumber& aDriveNumber) sl@0: /** Reads drive number from INI-file */ sl@0: { sl@0: // Read drive number from INI file sl@0: TPtrC driveNumberStr; sl@0: TBool ret = GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, driveNumberStr); sl@0: if (ret) sl@0: { sl@0: if (driveNumberStr == KDriveA) sl@0: { sl@0: aDriveNumber = EDriveA; sl@0: } sl@0: else if (driveNumberStr == KDriveB) sl@0: { sl@0: aDriveNumber = EDriveB; sl@0: } sl@0: else if (driveNumberStr == KDriveC) sl@0: { sl@0: aDriveNumber = EDriveC; sl@0: } sl@0: else if (driveNumberStr == KDriveD) sl@0: { sl@0: aDriveNumber = EDriveD; sl@0: } sl@0: else if (driveNumberStr == KDriveE) sl@0: { sl@0: aDriveNumber = EDriveE; sl@0: } sl@0: else if (driveNumberStr == KDriveF) sl@0: { sl@0: aDriveNumber = EDriveF; sl@0: } sl@0: else if (driveNumberStr == KDriveG) sl@0: { sl@0: aDriveNumber = EDriveG; sl@0: } sl@0: else if (driveNumberStr == KDriveH) sl@0: { sl@0: aDriveNumber = EDriveH; sl@0: } sl@0: else if (driveNumberStr == KDriveI) sl@0: { sl@0: aDriveNumber = EDriveI; sl@0: } sl@0: else if (driveNumberStr == KDriveJ) sl@0: { sl@0: aDriveNumber = EDriveJ; sl@0: } sl@0: else if (driveNumberStr == KDriveK) sl@0: { sl@0: aDriveNumber = EDriveK; sl@0: } sl@0: else if (driveNumberStr == KDriveL) sl@0: { sl@0: aDriveNumber = EDriveL; sl@0: } sl@0: else if (driveNumberStr == KDriveM) sl@0: { sl@0: aDriveNumber = EDriveM; sl@0: } sl@0: else if (driveNumberStr == KDriveN) sl@0: { sl@0: aDriveNumber = EDriveN; sl@0: } sl@0: else if (driveNumberStr == KDriveO) sl@0: { sl@0: aDriveNumber = EDriveO; sl@0: } sl@0: else if (driveNumberStr == KDriveP) sl@0: { sl@0: aDriveNumber = EDriveP; sl@0: } sl@0: else if (driveNumberStr == KDriveQ) sl@0: { sl@0: aDriveNumber = EDriveQ; sl@0: } sl@0: else if (driveNumberStr == KDriveR) sl@0: { sl@0: aDriveNumber = EDriveR; sl@0: } sl@0: else if (driveNumberStr == KDriveS) sl@0: { sl@0: aDriveNumber = EDriveS; sl@0: } sl@0: else if (driveNumberStr == KDriveT) sl@0: { sl@0: aDriveNumber = EDriveT; sl@0: } sl@0: else if (driveNumberStr == KDriveU) sl@0: { sl@0: aDriveNumber = EDriveU; sl@0: } sl@0: else if (driveNumberStr == KDriveV) sl@0: { sl@0: aDriveNumber = EDriveV; sl@0: } sl@0: else if (driveNumberStr == KDriveW) sl@0: { sl@0: aDriveNumber = EDriveW; sl@0: } sl@0: else if (driveNumberStr == KDriveX) sl@0: { sl@0: aDriveNumber = EDriveX; sl@0: } sl@0: else if (driveNumberStr == KDriveY) sl@0: { sl@0: aDriveNumber = EDriveY; sl@0: } sl@0: else if (driveNumberStr == KDriveZ) sl@0: { sl@0: aDriveNumber = EDriveZ; sl@0: } sl@0: else sl@0: { sl@0: TInt driveNumber = 0; sl@0: ret = GET_OPTIONAL_INT_PARAMETER(aParameterName, aSection, driveNumber); sl@0: if (ret) sl@0: { sl@0: aDriveNumber = (TDriveNumber) driveNumber ; sl@0: } sl@0: } sl@0: } sl@0: sl@0: return ret; sl@0: }