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.
23 This contains CT_RawDiskData
27 #include "T_RawDiskData.h"
31 _LIT(KDrive, "drive");
32 _LIT(KObjectName, "object_name");
34 _LIT(KPosition, "position");
37 _LIT(KCmdOpen, "Open");
38 _LIT(KCmdClose, "Close");
39 _LIT(KCmdNew, "new" );
40 _LIT(KCmdDestructor, "~" );
41 _LIT(KCmdRead, "Read");
42 _LIT(KCmdWrite, "Write");
44 _LIT(KDriveA, "EDriveA");
45 _LIT(KDriveB, "EDriveB");
46 _LIT(KDriveC, "EDriveC");
47 _LIT(KDriveD, "EDriveD");
48 _LIT(KDriveE, "EDriveE");
49 _LIT(KDriveF, "EDriveF");
50 _LIT(KDriveG, "EDriveG");
51 _LIT(KDriveH, "EDriveH");
52 _LIT(KDriveI, "EDriveI");
53 _LIT(KDriveJ, "EDriveJ");
54 _LIT(KDriveK, "EDriveK");
55 _LIT(KDriveL, "EDriveL");
56 _LIT(KDriveM, "EDriveM");
57 _LIT(KDriveN, "EDriveN");
58 _LIT(KDriveO, "EDriveO");
59 _LIT(KDriveP, "EDriveP");
60 _LIT(KDriveQ, "EDriveQ");
61 _LIT(KDriveR, "EDriveR");
62 _LIT(KDriveS, "EDriveS");
63 _LIT(KDriveT, "EDriveT");
64 _LIT(KDriveU, "EDriveU");
65 _LIT(KDriveV, "EDriveV");
66 _LIT(KDriveW, "EDriveW");
67 _LIT(KDriveX, "EDriveX");
68 _LIT(KDriveY, "EDriveY");
69 _LIT(KDriveZ, "EDriveZ");
72 CT_RawDiskData* CT_RawDiskData::NewL()
74 * Two phase constructor
77 CT_RawDiskData* ret = new (ELeave) CT_RawDiskData();
78 CleanupStack::PushL(ret);
80 CleanupStack::Pop(ret);
84 CT_RawDiskData::CT_RawDiskData()
87 * Protected constructor. First phase construction
92 void CT_RawDiskData::ConstructL()
94 * Protected constructor. Second phase construction
99 CT_RawDiskData::~CT_RawDiskData()
107 void CT_RawDiskData::DoCleanup()
109 * Contains cleanup implementation
116 INFO_PRINTF1(_L("Deleting current RRawDisk"));
122 TAny* CT_RawDiskData::GetObject()
124 * Return a pointer to the object that the data wraps
126 * @return pointer to the object that the data wraps
132 TBool CT_RawDiskData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
134 * Process a command read from the ini file
136 * @param aCommand requiring command to be processed
137 * @param aSection the section in the ini file requiring the command to be processed
138 * @param aAsyncErrorIndex the index of asynchronous command error code belongs to.
140 * @leave system wide error
142 * @return ETrue if the command is processed
145 TBool retVal = ETrue;
147 if (aCommand == KCmdNew)
151 else if (aCommand == KCmdDestructor)
155 else if (aCommand == KCmdOpen)
159 else if (aCommand == KCmdClose)
163 else if (aCommand == KCmdRead)
165 DoCmdReadL(aSection);
167 else if (aCommand == KCmdWrite)
169 DoCmdWriteL(aSection);
179 void CT_RawDiskData::DoCmdNewL()
180 /** Creates new RRawDisk class instance */
182 //Deletes previous RRawDisk class instance if it was already created.
185 INFO_PRINTF1(_L("Create new RRawDisk class instance"));
188 TRAPD(err, iRawDisk = new (ELeave) RRawDisk());
191 ERR_PRINTF2(_L("new error %d"), err);
196 INFO_PRINTF1(_L("Create new RRawDisk class instance completed successfully!"));
201 void CT_RawDiskData::DoCmdDestructor()
202 /** Destroy RRawDisk the object */
208 void CT_RawDiskData::DoCmdOpen(const TDesC& aSection)
209 /** RRawDisk::Open */
211 INFO_PRINTF1(_L("Opening a direct access channel to the disk!"));
213 RFs* rfsObject = NULL;
215 if (GET_MANDATORY_STRING_PARAMETER(KObjectName, aSection, rfsObjectName))
217 TRAPD(err, rfsObject = (RFs*)GetDataObjectL(rfsObjectName));
221 // get drive number from parameters
222 TDriveNumber driveNumber = EDriveA;
223 if (!GetDriveNumber(aSection, KDrive(), driveNumber))
225 ERR_PRINTF2(_L("No %S"), &KDrive());
226 SetBlockResult(EFail);
231 err = iRawDisk->Open(*rfsObject, driveNumber);
235 ERR_PRINTF2(_L("Opening iRawDisk failed with error : %d"), err);
240 INFO_PRINTF1(_L("Opening iRawDisk completed successfully!"));
246 ERR_PRINTF1(_L("Error with fileserver"));
247 SetBlockResult(EFail);
253 void CT_RawDiskData::DoCmdClose()
254 /** RRawDisk::Close */
256 INFO_PRINTF1(_L("Closing current RRawDisk"));
261 void CT_RawDiskData::DoCmdReadL( const TDesC& aSection )
263 INFO_PRINTF1(_L("Reading directly from disc!"));
267 if(GET_MANDATORY_STRING_PARAMETER(KData(), aSection, expectedData))
269 HBufC* expectedResultBuf = HBufC::NewL(expectedData.Length());
271 TPtr expectedResult = expectedResultBuf->Des();
272 expectedResult.Copy(expectedData);
274 INFO_PRINTF2(_L("Expecting data: %S"), &expectedResult);
276 HBufC8* readBuf = HBufC8::NewL( expectedData.Length());
277 TPtr8 readBufPtr = readBuf->Des();
280 GET_OPTIONAL_INT64_PARAMETER(KPosition(), aSection, pos);
282 err = iRawDisk->Read(pos, readBufPtr);
286 HBufC* readResultBuf = HBufC::NewL(readBufPtr.Length());
288 TPtr readResult = readResultBuf->Des();
289 readResult.Copy(readBufPtr);
291 INFO_PRINTF2(_L("Reading data: %S"), &readResult);
293 if (readResult != expectedResult)
295 ERR_PRINTF3(_L("Read data does not match expected data! Read: %S expected: %S"), &readResult, &expectedResult);
296 SetBlockResult( EFail );
300 INFO_PRINTF1(_L("Reading data directly from disc was successful!"));
302 delete readResultBuf;
303 readResultBuf = NULL;
307 ERR_PRINTF2(_L("Reading data directly from disc failed with error %d"), err);
310 delete expectedResultBuf;
311 expectedResultBuf = NULL;
317 ERR_PRINTF2(_L("No %S"), &KData());
318 SetBlockResult(EFail);
323 void CT_RawDiskData::DoCmdWriteL( const TDesC& aSection )
325 INFO_PRINTF1(_L("Writing directly to disc!"));
328 if(GET_MANDATORY_STRING_PARAMETER(KData(), aSection, writeData))
331 INFO_PRINTF2(_L("Writing following data: %S"), &writeData);
333 HBufC8* writeBuf = NULL;
334 TRAPD (err, writeBuf = HBufC8::NewL( writeData.Length() ));
337 TPtr8 writeBufPtr = writeBuf->Des();
338 writeBufPtr.Copy(writeData);
341 GET_OPTIONAL_INT64_PARAMETER(KPosition(), aSection, pos);
343 err = iRawDisk->Write(pos, writeBufPtr);
347 INFO_PRINTF1(_L("Writing data directly to disc was successful!"));
351 ERR_PRINTF2(_L("Writing data directly to disc failed with error %d"), err);
360 ERR_PRINTF2(_L("No %S"), &KData());
361 SetBlockResult(EFail);
366 TBool CT_RawDiskData::GetDriveNumber(const TDesC& aSection, const TDesC& aParameterName, TDriveNumber& aDriveNumber)
367 /** Reads drive number from INI-file */
369 // Read drive number from INI file
370 TPtrC driveNumberStr;
371 TBool ret = GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, driveNumberStr);
374 if (driveNumberStr == KDriveA)
376 aDriveNumber = EDriveA;
378 else if (driveNumberStr == KDriveB)
380 aDriveNumber = EDriveB;
382 else if (driveNumberStr == KDriveC)
384 aDriveNumber = EDriveC;
386 else if (driveNumberStr == KDriveD)
388 aDriveNumber = EDriveD;
390 else if (driveNumberStr == KDriveE)
392 aDriveNumber = EDriveE;
394 else if (driveNumberStr == KDriveF)
396 aDriveNumber = EDriveF;
398 else if (driveNumberStr == KDriveG)
400 aDriveNumber = EDriveG;
402 else if (driveNumberStr == KDriveH)
404 aDriveNumber = EDriveH;
406 else if (driveNumberStr == KDriveI)
408 aDriveNumber = EDriveI;
410 else if (driveNumberStr == KDriveJ)
412 aDriveNumber = EDriveJ;
414 else if (driveNumberStr == KDriveK)
416 aDriveNumber = EDriveK;
418 else if (driveNumberStr == KDriveL)
420 aDriveNumber = EDriveL;
422 else if (driveNumberStr == KDriveM)
424 aDriveNumber = EDriveM;
426 else if (driveNumberStr == KDriveN)
428 aDriveNumber = EDriveN;
430 else if (driveNumberStr == KDriveO)
432 aDriveNumber = EDriveO;
434 else if (driveNumberStr == KDriveP)
436 aDriveNumber = EDriveP;
438 else if (driveNumberStr == KDriveQ)
440 aDriveNumber = EDriveQ;
442 else if (driveNumberStr == KDriveR)
444 aDriveNumber = EDriveR;
446 else if (driveNumberStr == KDriveS)
448 aDriveNumber = EDriveS;
450 else if (driveNumberStr == KDriveT)
452 aDriveNumber = EDriveT;
454 else if (driveNumberStr == KDriveU)
456 aDriveNumber = EDriveU;
458 else if (driveNumberStr == KDriveV)
460 aDriveNumber = EDriveV;
462 else if (driveNumberStr == KDriveW)
464 aDriveNumber = EDriveW;
466 else if (driveNumberStr == KDriveX)
468 aDriveNumber = EDriveX;
470 else if (driveNumberStr == KDriveY)
472 aDriveNumber = EDriveY;
474 else if (driveNumberStr == KDriveZ)
476 aDriveNumber = EDriveZ;
480 TInt driveNumber = 0;
481 ret = GET_OPTIONAL_INT_PARAMETER(aParameterName, aSection, driveNumber);
484 aDriveNumber = (TDriveNumber) driveNumber ;