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_FileData
27 #include "T_FileData.h"
33 _LIT(KUParamPath, "path");
34 _LIT(KUParamName, "name");
35 _LIT(KRFsName, "RFs");
36 _LIT(KFileMode, "file_mode");
37 _LIT(KUParamExpectedString, "expected_string");
38 _LIT(KUParamAsync, "async");
39 _LIT(KUParamBufferLength, "buffer_length");
40 _LIT(KUParamLength, "length");
41 _LIT(KUParamStartPos, "start_pos");
42 _LIT(KUParamEndPos, "end_pos");
43 _LIT(KUParamUsage, "usage");
44 _LIT(KUParamPos, "position");
46 _LIT(KUParamCancelAll, "cancel_all");
47 _LIT(KUParamData, "datawrite");
48 _LIT(KUParamSize, "size");
49 _LIT(KUParamExpectedSize, "expected_size");
50 _LIT(KUParamCompareValue, "compare_value");
51 _LIT(KUParamSetAttMask, "set_att_mask");
52 _LIT(KUParamClearAttMask, "clear_att_mask");
53 _LIT(KUParamDate, "date");
54 _LIT(KFileObjectName, "file_object_name");
55 _LIT(KUParamOwnerType, "owner_type");
56 _LIT(KUParamComparePath, "compare_path");
60 _LIT(KEOwnerProcess, "EOwnerProcess");
61 _LIT(KEOwnerThread, "EOwnerThread");
65 _LIT(KEBlockMapUsagePaging, "EBlockMapUsagePaging");
66 _LIT(KETestDebug, "ETestDebug");
69 _LIT(KEFileShareExclusive, "EFileShareExclusive");
70 _LIT(KEFileShareReadersOnly, "EFileShareReadersOnly");
71 _LIT(KEFileShareAny, "EFileShareAny");
72 _LIT(KEFileShareReadersOrWriters, "EFileShareReadersOrWriters");
73 _LIT(KEFileStream, "EFileStream");
74 _LIT(KEFileStreamText, "EFileStreamText");
75 _LIT(KEFileRead, "EFileRead");
76 _LIT(KEFileWrite, "EFileWrite");
77 _LIT(KEFileReadAsyncAll, "EFileReadAsyncAll");
81 _LIT(KESeekStart, "ESeekStart");
82 _LIT(KESeekCurrent, "ESeekCurrent");
83 _LIT(KESeekEnd, "ESeekEnd");
87 _LIT(KCmdClose, "Close");
88 _LIT(KCmdDestructor, "~");
89 _LIT(KCmdBlockMap, "BlockMap");
90 _LIT(KCmdOpen, "Open");
91 _LIT(KCmdCreate, "Create");
92 _LIT(KCmdWrite, "Write");
93 _LIT(KCmdReplace, "Replace");
94 _LIT(KCmdRead, "Read");
95 _LIT(KCmdFlush, "Flush");
96 _LIT(KCmdTemp, "Temp");
97 _LIT(KCmdRename, "Rename");
98 _LIT(KCmdSeek, "Seek");
99 _LIT(KCmdReadCancel, "ReadCancel");
100 _LIT(KCmdLock, "Lock");
101 _LIT(KCmdUnLock, "UnLock");
102 _LIT(KCmdSize, "Size");
103 _LIT(KCmdSetSize, "SetSize");
104 _LIT(KCmdAtt, "Att");
105 _LIT(KCmdSetAtt, "SetAtt");
106 _LIT(KCmdModified, "Modified");
107 _LIT(KCmdSetModified, "SetModified");
108 _LIT(KCmdSet, "Set");
109 _LIT(KCmdChangeMode, "ChangeMode");
110 _LIT(KCmdDrive, "Drive");
111 _LIT(KCmdDuplicate, "Duplicate");
112 _LIT(KCmdName, "Name");
113 _LIT(KCmdFullName, "FullName");
117 _LIT(KDEntryAttNormal, "KEntryAttNormal");
118 _LIT(KDEntryAttReadOnly, "KEntryAttReadOnly");
119 _LIT(KDEntryAttArchive, "KEntryAttArchive");
120 _LIT(KDEntryAttHidden, "KEntryAttHidden");
121 _LIT(KDEntryAttSystem, "KEntryAttSystem");
122 _LIT(KDEntryAttVolume, "KEntryAttVolume");
123 _LIT(KDEntryAttDir, "KEntryAttDir");
124 _LIT(KDEntryAttXIP, "KEntryAttXIP");
125 _LIT(KDEntryAttRemote, "KEntryAttRemote");
128 const TInt KDefaultDescSize = 64;
132 CT_FileData* CT_FileData::NewL()
134 * Two phase constructor
137 CT_FileData* ret = new (ELeave) CT_FileData();
138 CleanupStack::PushL(ret);
140 CleanupStack::Pop(ret);
144 CT_FileData::CT_FileData()
146 * Protected constructor. First phase construction
152 void CT_FileData::ConstructL()
154 * Protected constructor. Second phase construction
157 iFileOpened = EFalse;
160 CT_FileData::~CT_FileData()
168 void CT_FileData::DoCleanup()
170 * Contains cleanup implementation
176 INFO_PRINTF1(_L("Deleting current RFile"));
180 iReadCallbackArray.Close();
181 iWriteCallbackArray.Close();
182 iFlushCallbackArray.Close();
185 TAny* CT_FileData::GetObject()
187 * Return a pointer to the object that the data wraps
189 * @return pointer to the object that the data wraps
195 TBool CT_FileData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
197 * Process a command read from the ini file
199 * @param aCommand the command to process
200 * @param aSection the entry in the ini file requiring the command to be processed
201 * @param aAsyncErrorIndex the index of asynchronous command error code belongs to.
203 * @return ETrue if the command is processed
206 TBool retVal = ETrue;
208 if (aCommand == KCmdNew)
212 else if (aCommand == KCmdDestructor)
216 else if (aCommand == KCmdOpen)
218 DoCmdOpenL(aSection);
220 else if (aCommand == KCmdWrite)
222 DoCmdWriteL(aSection, aAsyncErrorIndex);
224 else if (aCommand == KCmdClose)
228 else if (aCommand == KCmdCreate)
230 DoCmdCreateL(aSection);
232 else if (aCommand == KCmdReplace)
234 DoCmdReplaceL(aSection);
236 else if (aCommand == KCmdRead)
238 DoCmdReadL(aSection, aAsyncErrorIndex);
240 else if (aCommand == KCmdFlush)
242 DoCmdFlushL(aSection, aAsyncErrorIndex);
244 else if (aCommand == KCmdTemp)
246 DoCmdTempL(aSection);
248 else if (aCommand == KCmdRename)
250 DoCmdRenameL(aSection);
252 else if (aCommand == KCmdSeek)
254 DoCmdSeekL(aSection);
256 else if (aCommand == KCmdReadCancel)
258 DoCmdReadCancelL(aSection);
260 else if (aCommand == KCmdLock)
262 DoCmdLockL(aSection);
264 else if (aCommand == KCmdUnLock)
266 DoCmdUnLockL(aSection);
268 else if (aCommand == KCmdSize)
270 DoCmdSizeL(aSection);
272 else if (aCommand == KCmdSetSize)
274 DoCmdSetSizeL(aSection);
276 else if (aCommand == KCmdAtt)
280 else if (aCommand == KCmdSetAtt)
282 DoCmdSetAttL(aSection);
284 else if (aCommand == KCmdModified)
286 DoCmdModifiedL(aSection);
288 else if (aCommand == KCmdSetModified)
290 DoCmdSetModifiedL(aSection);
292 else if (aCommand == KCmdSet)
296 else if (aCommand == KCmdChangeMode)
298 DoCmdChangeModeL(aSection);
300 else if (aCommand == KCmdDrive)
302 DoCmdDriveL(aSection);
304 else if (aCommand == KCmdName)
306 DoCmdNameL(aSection);
308 else if (aCommand == KCmdDuplicate)
310 DoCmdDuplicateL(aSection);
312 else if (aCommand == KCmdFullName)
314 DoCmdFullName(aSection);
316 else if (aCommand == KCmdBlockMap)
318 DoCmdBlockMap(aSection);
327 void CT_FileData::DoCmdNewL()
328 /** Creates new RFile class instance */
330 //Deletes previous RFile class instance if it was already created.
333 INFO_PRINTF1(_L("Create new RFile class instance"));
336 TRAPD(err, iFile = new (ELeave) RFile());
339 ERR_PRINTF2(_L("Error returned by New()%d"), err);
344 void CT_FileData::DoCmdDestructor()
345 /** Destroy RFile the object */
350 void CT_FileData::DoCmdOpenL(const TDesC& aSection)
355 TBool dataOk=GET_MANDATORY_STRING_PARAMETER(KRFsName(), aSection, rfsObjectName);
358 rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
362 if ( !GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, filePath) )
368 if ( !GetFileModeL(KFileMode, aSection, fileMode) )
370 ERR_PRINTF2(_L("Open() error reading parameter. %S"), &KFileMode());
371 SetBlockResult(EFail);
379 TInt err = iFile->Open(*rfsObject, filePath, fileMode);
382 ERR_PRINTF2(_L("Open() failed with Error:%d"), err);
392 ERR_PRINTF1(_L("RFs object is NULL"));
393 SetBlockResult(EFail);
399 void CT_FileData::DoCmdClose()
402 INFO_PRINTF1(_L("Closing RFile"));
406 void CT_FileData::DoCmdCreateL(const TDesC& aSection)
407 /** create a new file */
411 TBool dataOk = ETrue;
412 if ( GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName) )
414 rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
421 // Gets name of file from ini file.
423 if ( !GET_MANDATORY_STRING_PARAMETER(KUParamName(), aSection, name) )
429 if ( !GetFileModeL(KFileMode, aSection, fileMode) )
431 ERR_PRINTF2(_L("Create() error reading parameter. %S"), &KFileMode());
432 SetBlockResult(EFail);
438 // Creates and opens a new file for writing.
441 TInt err = iFile->Create(*rfsObject, name, fileMode);
444 ERR_PRINTF2(_L("Create(), error create() = %d"), err);
450 ERR_PRINTF1(_L("RFs object is NULL"));
451 SetBlockResult(EFail);
456 void CT_FileData::DoCmdReplaceL(const TDesC& aSection)
457 /** replace a existing file or create new */
460 RFs* rfsObject = NULL;
462 TBool dataOk = ETrue;
463 if ( GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName) )
465 rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
468 // Gets name of file from ini file.
470 if (!GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, path))
476 if(!GetFileModeL(KFileMode, aSection, fileMode))
478 ERR_PRINTF2(_L("Replace() error reading parameter. %S"), &KFileMode());
479 SetBlockResult(EFail);
483 // Creates and opens a new file for writing.
486 // Creates and opens a new file for writing.
489 TInt err = iFile->Replace(*rfsObject, path, fileMode);
492 ERR_PRINTF2(_L("Replace() failed with error = %d"), err);
498 INFO_PRINTF2(_L("File: %S is replaced successfuly"), &path);
503 ERR_PRINTF1(_L("RFs object is NULL"));
504 SetBlockResult(EFail);
510 void CT_FileData::DoCmdReadL(const TDesC& aSection, const TInt aAsyncErrorIndex)
511 /** wrapper for read commands */
513 TBool async = EFalse;
514 if(GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async))
518 DoAsynchronousReadsL(aSection, aAsyncErrorIndex);
522 DoSynchronousReadsL(aSection);
528 DoSynchronousReadsL(aSection);
532 TBool CT_FileData::GetFileModeL(const TDesC& aParameterName, const TDesC& aSection, TUint& aFileMode)
533 /** process the filemode from ini */
539 if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, aModeStr))
541 //break the file mode string to array of file modes
542 //in case there's more than one filemode
543 RPointerArray<HBufC> fileModes = SplitL(aModeStr, "|");
545 for ( int i = 0 ; i < fileModes.Count() ; i++ )
547 if (*fileModes[i] == KEFileShareExclusive)
549 aFileMode = aFileMode | EFileShareExclusive ;
551 else if (*fileModes[i] == KEFileShareReadersOnly)
553 aFileMode = aFileMode | EFileShareReadersOnly;
555 else if (*fileModes[i] == KEFileShareAny)
557 aFileMode = aFileMode | EFileShareAny;
559 else if (*fileModes[i] == KEFileShareReadersOrWriters)
561 aFileMode = aFileMode | EFileShareReadersOrWriters;
563 else if (*fileModes[i] == KEFileStream)
565 aFileMode = aFileMode | EFileStream;
567 else if (*fileModes[i] == KEFileStreamText)
569 aFileMode = aFileMode | EFileStreamText;
571 else if (*fileModes[i] == KEFileRead)
573 aFileMode = aFileMode | EFileRead;
575 else if (*fileModes[i] == KEFileWrite)
577 aFileMode = aFileMode | EFileWrite;
579 else if (*fileModes[i] == KEFileReadAsyncAll)
581 aFileMode = aFileMode | EFileReadAsyncAll;
585 aFileMode = EFileShareAny;
590 for (int j=0 ; j<fileModes.Count() ; j++)
592 HBufC* temp = fileModes[j];
608 void CT_FileData::DoSynchronousReadsL(const TDesC& aSection)
609 /** process all synchronous reads */
614 HBufC8* filedata = NULL;
617 //get optional buffer length from ini file
618 if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
620 filedata = HBufC8::NewLC(bufferLength);
624 filedata = HBufC8::NewLC(KDefaultDescSize);
628 TPtr8 filedataPtr = filedata->Des();
630 //devide which read to call, by switching between parameters fetched from ini file.
631 if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
633 if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
635 INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TInt aLen)"));
636 err = iFile->Read(pos, filedataPtr, length);
637 HandleExpectedString(filedataPtr, aSection);
641 INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData, TInt aLen)"));
642 err = iFile->Read(filedataPtr, length);
643 HandleExpectedString(filedataPtr, aSection);
648 if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
650 INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData)"));
651 err = iFile->Read(pos, filedataPtr);
652 HandleExpectedString(filedataPtr, aSection);
656 INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData)"));
657 err = iFile->Read(filedataPtr);
658 HandleExpectedString(filedataPtr, aSection);
662 TBuf<KDefaultDescSize> filedata16;
663 filedata16.Copy(filedataPtr);
664 INFO_PRINTF2(_L("read \"%S\" from file"), &filedata16);
666 //did the read complete with error code?
669 ERR_PRINTF2(_L("error executing synchronous read %d"), err);
673 CleanupStack::PopAndDestroy(1);
677 void CT_FileData::DoAsynchronousReadsL(const TDesC& aSection, const TInt aAsyncErrorIndex)
678 /**process all asynchronous reads */
683 CT_FileActiveCallback* active = CT_FileActiveCallback::NewL(*this);
684 iReadCallbackArray.Append(active);
688 //Get the buffer length, and create the buffer for activeCallback object
689 if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
691 active->CreateFileDataBufferL(bufferLength);
695 active->CreateFileDataBufferL(KDefaultDescSize);
698 TPtr8 fileDataPtr = active->iFileData->Des();
700 //decide which read to call
701 if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
703 if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
705 INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TInt aLen, TRequestiStatus aiStatus)"));
706 iFile->Read(pos, fileDataPtr, length,active->iStatus);
710 INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData, TInt aLen, TRequestiStatus aiStatus)"));
711 iFile->Read(fileDataPtr, length, active->iStatus);
716 if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
718 INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TRequestiStatus aiStatus)"));
719 iFile->Read(pos, fileDataPtr, active->iStatus);
723 INFO_PRINTF1(_L("calling RFile::Read(TDesC &aData, TRequestiStatus aiStatus)"));
724 iFile->Read(fileDataPtr, active->iStatus);
728 //acitvate callback object
729 active->SetSection(aSection);
730 active->Activate(aAsyncErrorIndex);
736 void CT_FileData::HandleExpectedString(const TDesC& aReadedData, const TDesC& aSection)
737 /** compare the expected string with readed string, takes 16-bit parameter*/
739 TPtrC expectedString;
740 if(GET_OPTIONAL_STRING_PARAMETER(KUParamExpectedString, aSection, expectedString))
742 if (aReadedData == expectedString)
744 INFO_PRINTF1(_L("expected string matches with the data read"));
748 ERR_PRINTF1(_L("expected string does not match with the data read"));
749 SetBlockResult(EFail);
755 void CT_FileData::HandleExpectedString(const TDesC8& aReadedData, const TDesC& aSection)
756 /** compare the expected string with readed string, takes 16-bit parameter */
758 TBuf<KDefaultDescSize> readedData16;
759 readedData16.Copy(aReadedData);
760 TPtrC expectedString;
761 if(GET_OPTIONAL_STRING_PARAMETER(KUParamExpectedString, aSection, expectedString))
763 if (readedData16 == expectedString)
765 INFO_PRINTF1(_L("expected string matches with the data read"));
769 ERR_PRINTF1(_L("expected string does not match with the data read"));
770 SetBlockResult(EFail);
776 void CT_FileData::DoCmdFlushL(const TDesC& aSection, const TInt aAsyncErrorIndex)
777 /** flush all the internal buffers to file */
781 //get the parameter from ini, to decide which version of RFile::Flush to call
782 GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async);
785 CActiveCallback* active = CActiveCallback::NewL(*this);
786 iFlushCallbackArray.Append( active );
787 iFile->Flush(active->iStatus);
788 active->Activate(aAsyncErrorIndex);
793 err = iFile->Flush();
796 ERR_PRINTF2(_L("Flush() failed with error code. %d"), err);
801 INFO_PRINTF1(_L("Succesfully flushed the file"));
807 void CT_FileData::DoCmdTempL(const TDesC& aSection)
808 /* create temporary file */
812 RFs* rfsObject = NULL;
814 TBool dataOk=GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName);
817 rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
820 // Gets name of file from ini file.
822 if (!GET_MANDATORY_STRING_PARAMETER(KUParamPath(), aSection, path))
828 if(!GetFileModeL(KFileMode, aSection, fileMode))
830 ERR_PRINTF2(_L("Temp() error reading parameter. %S"), &KFileMode());
831 SetBlockResult(EFail);
835 // Creates Temporary file.
841 TInt err = iFile->Temp(*rfsObject, path, fileName,fileMode);
842 INFO_PRINTF2(_L("File: %S is created"), &fileName);
845 ERR_PRINTF2(_L("Temp() failed with error = %d"), err);
855 ERR_PRINTF1(_L("RFs object is NULL"));
856 SetBlockResult(EFail);
862 void CT_FileData::DoCmdRenameL(const TDesC& aSection)
863 /** rename the file */
867 //get the name from ini and rename the file.
868 if(GET_MANDATORY_STRING_PARAMETER(KUParamName(), aSection, newName))
870 TInt err = iFile->Rename(newName);
874 ERR_PRINTF2(_L("Rename() failed with error code %d"), err);
881 void CT_FileData::DoCmdSeekL(const TDesC& aSection)
882 /** set the file cursor to specified location in file */
884 TSeek seek = ESeekStart;
885 TBool dataOk = EFalse;
888 //convert the mode string from ini to TSeek
889 if(ConvertToSeek(KSeek, aSection,seek))
891 dataOk = GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos);
896 TInt err = iFile->Seek(seek, pos);
900 ERR_PRINTF2(_L("Seek(), error seeking() = %d"), err);
905 INFO_PRINTF1(_L("Succesfully seeked the file"));
910 TBool CT_FileData::ConvertToSeek(const TDesC& aParameterName, const TDesC& aSection, TSeek& aSeek)
911 /** convert a seek mode string from ini to TSeek */
917 if(GET_MANDATORY_STRING_PARAMETER(aParameterName, aSection, aModeStr))
920 if (aModeStr == KESeekStart)
924 else if (aModeStr == KESeekCurrent)
926 aSeek = ESeekCurrent;
928 else if (aModeStr == KESeekEnd)
947 void CT_FileData::DoCmdReadCancelL(const TDesC& aSection)
948 /** wrapper for readcancels */
953 //decide which ReadCancel to call
954 if(GET_OPTIONAL_BOOL_PARAMETER(KUParamCancelAll, aSection, cancelAll))
956 if (cancelAll == true)
971 void CT_FileData::ReadCancel()
972 /** will cancel the last active request by default */
974 iFile->ReadCancel(iReadCallbackArray[iReadCallbackArray.Count()-1]->iStatus);
977 void CT_FileData::ReadCancelAll()
978 /** cancel all outstanding read requests */
983 // the write implementation
984 void CT_FileData::DoCmdWriteL(const TDesC& aSection, const TInt aAsyncErrorIndex)
985 /** wrapper for write commands */
987 TBool async = EFalse;
988 //decide which write to call
989 GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async);
992 DoAsynchronousWritesL(aSection, aAsyncErrorIndex);
996 DoSynchronousWritesL(aSection);
1000 void CT_FileData::DoAsynchronousWritesL(const TDesC& aSection, const TInt aAsyncErrorIndex)
1001 /** call asynchronous writes */
1006 //Get the buffer length, and create the buffer for activeCallback object
1007 if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
1009 dataWrite8 = HBufC8::NewLC(bufferLength);
1013 dataWrite8 = HBufC8::NewLC(KDefaultDescSize);
1015 TPtr8 data8Ptr = dataWrite8->Des();
1018 // Get the data to write
1019 if(GET_MANDATORY_STRING_PARAMETER(KUParamData(), aSection, data))
1021 //convert it to 8-bit
1022 data8Ptr.Copy(data);
1024 CActiveCallback* active = CActiveCallback::NewL(*this);
1026 iWriteCallbackArray.Append( active );
1030 //now, decide which read to call
1031 if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
1033 if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
1035 INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TInt aLen, TRequestStatus &aStatus)"));
1036 iFile->Write(pos, *dataWrite8, length, active->iStatus);
1040 INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TInt aLen, , TRequestStatus &aStatus)"));
1041 iFile->Write(*dataWrite8, length, active->iStatus);
1046 if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
1048 INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TRequestStatus &aStatus)"));
1049 iFile->Write(pos, *dataWrite8, active->iStatus);
1053 INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TRequestStatus &aStatus)"));
1054 iFile->Write(*dataWrite8, active->iStatus);
1058 active->Activate(aAsyncErrorIndex);
1062 CleanupStack::PopAndDestroy();
1065 void CT_FileData::DoSynchronousWritesL(const TDesC& aSection)
1066 /** cakk synchronous writes */
1071 //Get the buffer length, and create the buffer for activeCallback object
1072 if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
1074 dataWrite8 = HBufC8::NewLC(bufferLength);
1078 dataWrite8 = HBufC8::NewLC(KDefaultDescSize);
1080 TPtr8 data8Ptr = dataWrite8->Des();
1085 if (GET_MANDATORY_STRING_PARAMETER(KUParamData(), aSection, data))
1087 //convert it to 8-bit
1088 data8Ptr.Copy(data);
1093 //will decide which write to call
1094 if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
1096 if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
1098 INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TInt aLen)"));
1099 err = iFile->Write(pos, *dataWrite8, length);
1103 INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TInt aLen)"));
1104 err = iFile->Write(*dataWrite8, length);
1109 if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
1111 INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData)"));
1112 err = iFile->Write(pos, *dataWrite8);
1116 INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData)"));
1117 err = iFile->Write(*dataWrite8);
1121 if (err == KErrNone)
1123 INFO_PRINTF2(_L("written \"%S\" to file"), &data);
1127 ERR_PRINTF2(_L("Error executing synchronous write %d"), err);
1131 CleanupStack::PopAndDestroy();
1134 void CT_FileData::DoCmdLockL(const TDesC& aSection)
1135 /** lock a region in file */
1139 TBool dataOk = ETrue;
1142 if(!GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos))
1150 if(!GET_MANDATORY_INT_PARAMETER(KUParamLength(), aSection, length))
1158 TInt err = iFile->Lock(pos, length);
1162 ERR_PRINTF2(_L("Lock() error locking file. %d"), err);
1170 void CT_FileData::DoCmdUnLockL(const TDesC& aSection)
1171 /** unlock a region that has been previously locked */
1173 TBool dataOk = ETrue;
1178 if(!GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos))
1186 if(!GET_MANDATORY_INT_PARAMETER(KUParamLength(), aSection, length))
1194 TInt err = iFile->UnLock(pos, length);
1198 ERR_PRINTF2(_L("UnLock() error unlocking file. %d"), err);
1203 INFO_PRINTF1(_L("Succesfully unlocked the file"));
1210 void CT_FileData::DoCmdSizeL(const TDesC& aSection)
1211 /** get file size */
1214 TInt expectedSize = 0;
1217 TInt err = iFile->Size(size);
1218 INFO_PRINTF2(_L("The Size of the file is %d bytes"), size);
1220 if (err != KErrNone)
1222 ERR_PRINTF2(_L("Size() error getting file size. %d"), err);
1227 //get expected size from ini
1228 if(GET_OPTIONAL_INT_PARAMETER(KUParamExpectedSize(), aSection, expectedSize))
1230 if(expectedSize != size)
1232 ERR_PRINTF3(_L("The file size does not match the expected size %d != %d"), size, expectedSize)
1233 SetBlockResult(EFail);
1240 void CT_FileData::DoCmdSetSizeL(const TDesC& aSection)
1241 /** set file size */
1245 if(GET_MANDATORY_INT_PARAMETER(KUParamSize(), aSection, size))
1247 TInt err = iFile->SetSize(size);
1249 if (err != KErrNone)
1251 ERR_PRINTF2(_L("SetSize() error setting file size. %d"), err);
1256 INFO_PRINTF2(_L("The Size of the fail is set to %d bytes"), size);
1261 void CT_FileData::DoCmdAttL(const TDesC& aSection)
1262 /** get file attributes */
1267 TInt err = iFile->Att(attValue);
1269 PrintFileAttributes(attValue);
1271 if (err != KErrNone)
1273 ERR_PRINTF2(_L("Att() getting attributes. %d"), err);
1278 TUint bitmask = 0x000000FF;
1279 //lets filter out symbian specific bits
1280 attValue = attValue & bitmask;
1282 TUint attCompare = 0;
1284 //compare the expected att value with the file attributes
1285 if (ConvertToAttributeL(KUParamCompareValue, aSection, attCompare))
1287 if (attCompare == attValue)
1289 INFO_PRINTF1(_L("attributes match"));
1293 ERR_PRINTF1(_L("Attributes does not match"));
1294 SetBlockResult(EFail);
1302 void CT_FileData::DoCmdSetAttL(const TDesC& aSection)
1303 /** set file attributes */
1306 TUint setAttMask = 0;
1307 TBool dataOk = ETrue;
1309 //get the attribute mask to set
1310 if(!ConvertToAttributeL(KUParamSetAttMask, aSection, setAttMask))
1312 ERR_PRINTF2(_L("SetATt() error reading parameter. %S"), &KUParamSetAttMask());
1313 SetBlockResult(EFail);
1317 TUint clearAttMask = 0;
1319 //get the attribute mask to clear
1320 if(!ConvertToAttributeL(KUParamClearAttMask, aSection, clearAttMask))
1322 ERR_PRINTF2(_L("SetAtt() error reading parameter. %S"), &KUParamClearAttMask());
1323 SetBlockResult(EFail);
1327 // all ok? let's call SetAtt
1330 TInt err = iFile->SetAtt(setAttMask, clearAttMask);
1332 if (err != KErrNone)
1334 ERR_PRINTF2(_L("SetAtt() failed with, err: %d"), err);
1339 INFO_PRINTF1(_L("The attribute value has been set"));
1346 TBool CT_FileData::ConvertToAttributeL(const TDesC& aParameterName, const TDesC& aSection, TUint& aAttribute)
1347 /** convert attribute string from ini to file attribute bitmask */
1353 if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, aModeStr))
1355 //break the file mode string to array of file modes
1356 //in case there's more than one filemode
1357 RPointerArray<HBufC> fileModes = SplitL(aModeStr, "|");
1359 for ( int i = 0 ; i < fileModes.Count() ; i++ )
1361 if (aModeStr == KDEntryAttNormal)
1363 aAttribute = aAttribute | KEntryAttNormal;
1365 else if (aModeStr == KDEntryAttReadOnly)
1367 aAttribute = aAttribute | KEntryAttReadOnly;
1369 else if (aModeStr == KDEntryAttArchive)
1371 aAttribute = aAttribute | KEntryAttArchive;
1373 else if (aModeStr == KDEntryAttHidden)
1375 aAttribute = aAttribute | KEntryAttHidden;
1378 else if (aModeStr == KDEntryAttSystem)
1380 aAttribute = aAttribute | KEntryAttSystem;
1383 else if (aModeStr == KDEntryAttVolume)
1385 aAttribute = aAttribute | KEntryAttVolume;
1388 else if (aModeStr == KDEntryAttDir)
1390 aAttribute = aAttribute | KEntryAttDir;
1393 else if (aModeStr == KDEntryAttXIP)
1395 aAttribute = aAttribute | KEntryAttXIP;
1398 else if (aModeStr == KDEntryAttRemote)
1400 aAttribute = aAttribute | KEntryAttRemote;
1408 for (int j=0 ; j<fileModes.Count() ; j++)
1410 HBufC* temp = fileModes[j];
1426 void CT_FileData::DoCmdModifiedL(const TDesC& aSection)
1427 /** get file modification date */
1432 TInt err = iFile->Modified(time);
1434 _LIT(KDateString,"%E%D%X%N%Y %1 %2 %3");
1436 TBuf<KDefaultDescSize> dateString;
1438 //format the time to string
1439 TRAPD(err2, time.FormatL(dateString, KDateString));
1441 if(err2 != KErrNone)
1443 ERR_PRINTF2(_L("Modified() error formating date string err: %d"), err);
1446 INFO_PRINTF2(_L("Modified() returned: %S"), &dateString);
1448 if (err != KErrNone)
1450 ERR_PRINTF2(_L("Modified() failed with, err: %d"), err);
1456 //compare the file modification date with the date readed from inin
1459 if (GET_OPTIONAL_STRING_PARAMETER(KUParamCompareValue, aSection, compValue))
1463 err = compTime.Set(compValue);
1465 if ( err != KErrNone )
1467 ERR_PRINTF1(_L("invalid compare value"));
1471 if (compTime == time)
1473 INFO_PRINTF1(_L("The dates match"));
1477 ERR_PRINTF1(_L("The values do not match"));
1478 SetBlockResult(EFail);
1486 void CT_FileData::DoCmdSetModifiedL(const TDesC& aSection)
1487 /** set file modification date */
1491 TBool dataOk = ETrue;
1493 TInt err = KErrNone;
1495 if(!GET_MANDATORY_STRING_PARAMETER(KUParamDate(), aSection, dateDesc))
1501 err = time.Set(dateDesc);
1504 if (err != KErrNone)
1506 ERR_PRINTF2(_L("time.Set() failed with error code %d"), err);
1507 SetBlockResult(EFail);
1513 err = iFile->SetModified(time);
1515 if (err != KErrNone)
1517 ERR_PRINTF2(_L("SetModified() failed with error code %d"), err);
1523 void CT_FileData::DoCmdSetL(const TDesC& aSection)
1524 /** set file attributes and modification time */
1527 TBool dataOk = ETrue;
1528 TInt err = KErrNone;
1531 //get and process the date string
1532 if(!GET_MANDATORY_STRING_PARAMETER(KUParamDate(), aSection, dateDesc))
1538 err = time.Set(dateDesc);
1541 TUint setAttMask = 0;
1543 // get the attribute masks
1544 if(!ConvertToAttributeL(KUParamSetAttMask, aSection,setAttMask))
1549 TUint clearAttMask = 0;
1551 if(!ConvertToAttributeL(KUParamClearAttMask, aSection, clearAttMask))
1555 // if all Ok then proceed with Set
1558 err = iFile->Set(time, setAttMask, clearAttMask);
1560 if ( err != KErrNone)
1562 ERR_PRINTF2(_L("Set() failed with error code %d"), err);
1568 void CT_FileData::DoCmdChangeModeL(const TDesC& aSection)
1569 /** Change the file mode */
1573 if(!GetFileModeL(KFileMode, aSection, fileMode))
1575 ERR_PRINTF2(_L("Set() error reading parameter. %S"), &KFileMode());
1576 SetBlockResult(EFail);
1580 TInt err = iFile->ChangeMode((TFileMode)fileMode);
1582 if ( err != KErrNone )
1584 ERR_PRINTF2(_L("ChangeMode() failed with error code %d"), err);
1590 void CT_FileData::DoCmdDriveL(const TDesC& aSection)
1591 /** Get the drive info, in which the file is stored */
1593 TDriveInfo driveInfo;
1595 int err = iFile->Drive(driveNumber, driveInfo);
1597 INFO_PRINTF2(_L("TDriveInfo.iType =%d"), driveInfo.iType);
1598 INFO_PRINTF2(_L("TDriveInfo.iBattery =%d"), driveInfo.iBattery);
1599 INFO_PRINTF2(_L("TDriveInfo.iDriveAtt=0x%X"), driveInfo.iDriveAtt);
1600 INFO_PRINTF2(_L("Drivenumber =%d"), driveNumber);
1602 if (err != KErrNone)
1604 ERR_PRINTF2(_L("Drive() failed with error code %d"), err);
1609 TInt compDriveNumber;
1611 if ( GET_OPTIONAL_INT_PARAMETER(KUParamCompareValue, aSection, compDriveNumber))
1613 if ( compDriveNumber == driveNumber )
1615 INFO_PRINTF3(_L("drivenumbers match %d == %d "), compDriveNumber, driveNumber);
1619 ERR_PRINTF3(_L("drivenumbers do not match %d != %d"), compDriveNumber, driveNumber);
1620 SetBlockResult(EFail);
1627 void CT_FileData::DoCmdDuplicateL(const TDesC& aSection)
1628 /** Duplicate the file */
1630 TPtrC rFileObjectName;
1631 TBool dataOk = GET_MANDATORY_STRING_PARAMETER(KFileObjectName, aSection, rFileObjectName);
1633 // get the RFile handle to duplicate
1634 RFile* rFileObject = NULL;
1637 rFileObject=(RFile*)GetDataObjectL(rFileObjectName);
1639 if(rFileObject == NULL)
1641 ERR_PRINTF2(_L("Duplicate() error getting object. %S"), KFileObjectName);
1642 SetBlockResult(EFail);
1647 // if handle ok then procees with duplication
1650 TOwnerType ownerType;
1652 TInt err = KErrNone;
1653 // determine the owner type to pass to duplicate
1654 if (ConvertToOwnerType(KUParamOwnerType, aSection, ownerType) && dataOk)
1656 err = iFile->Duplicate(*rFileObject, ownerType);
1660 err = iFile->Duplicate(*rFileObject);
1664 if (err != KErrNone)
1666 ERR_PRINTF2(_L("Duplicate() error duplicating %d"), err);
1671 //lets mark the file to be opened
1672 iFileOpened = ETrue;
1678 TBool CT_FileData::ConvertToOwnerType(const TDesC& aParameterName, const TDesC& aSection, TOwnerType& aResult)
1679 /** convert the ownerType string from ini to EOwnerType */
1684 TPtrC ownerTypeString;
1686 if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, ownerTypeString))
1689 if (ownerTypeString == KEOwnerProcess )
1691 aResult = EOwnerProcess;
1693 else if (ownerTypeString == KEOwnerThread)
1695 aResult = EOwnerThread;
1711 void CT_FileData::DoCmdFullName(const TDesC& aSection)
1712 /** get the file fullname */
1715 TInt err = iFile->FullName(name);
1717 INFO_PRINTF2(_L("FullName() returned %S"), &name);
1721 ERR_PRINTF2(_L("FullName() error, returned. %d"), err);
1727 if(GET_OPTIONAL_STRING_PARAMETER(KUParamComparePath, aSection, path))
1731 INFO_PRINTF1(_L("the paths match"));
1735 ERR_PRINTF1(_L("the paths do not match"));
1736 SetBlockResult(EFail);
1742 void CT_FileData::DoCmdNameL(const TDesC& aSection)
1743 /** get the file name */
1745 TBuf<KDefaultDescSize> name;
1746 TInt err = iFile->Name(name);
1747 INFO_PRINTF2(_L("Name() returned %S"), &name);
1751 ERR_PRINTF2(_L("Name() error, returned. %d"), err);
1760 if (GET_OPTIONAL_STRING_PARAMETER(KUParamCompareValue, aSection, compValue))
1762 if (compValue == name)
1764 INFO_PRINTF3(_L("The names match %S == %S"), &name, &compValue);
1768 ERR_PRINTF3(_L("The names do not match %S == %S"), &name, &compValue);
1769 SetBlockResult(EFail);
1775 TBool CT_FileData::ConvertToBlockMapUsage(const TDesC& aParameterName, const TDesC& aSection, TBlockMapUsage& aResult)
1780 TPtrC blockmapeUsageString;
1782 if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, blockmapeUsageString))
1785 if (blockmapeUsageString == KEBlockMapUsagePaging )
1787 aResult = EBlockMapUsagePaging;
1789 else if (blockmapeUsageString == KETestDebug)
1791 aResult = ETestDebug;
1807 void CT_FileData::DoCmdBlockMap(const TDesC& aSection)
1809 TInt64 startPos = 0;
1810 GET_OPTIONAL_INT64_PARAMETER(KUParamStartPos, aSection, startPos);
1812 SBlockMapInfo blockMapInfo;
1813 TInt err = KErrNone;
1815 if (GET_OPTIONAL_INT64_PARAMETER(KUParamEndPos, aSection, endPos))
1817 TBlockMapUsage usage;
1818 if (ConvertToBlockMapUsage(KUParamUsage, aSection, usage))
1820 err = iFile->BlockMap(blockMapInfo, startPos, endPos, usage);
1824 err = iFile->BlockMap(blockMapInfo, startPos, endPos);
1829 TBlockMapUsage usage;
1830 if (ConvertToBlockMapUsage(KUParamUsage, aSection, usage))
1832 err = iFile->BlockMap(blockMapInfo, startPos, usage);
1836 err = iFile->BlockMap(blockMapInfo, startPos);
1840 if (KErrNone != err)
1842 ERR_PRINTF2(_L("BlockMap Returned an error %d"), err);
1845 if (KErrNone == err || KErrCompletion == err)
1847 INFO_PRINTF2(_L("Returned start position %d"), startPos);
1849 INFO_PRINTF2(_L("Local drive number %d"), blockMapInfo.iLocalDriveNumber);
1850 INFO_PRINTF2(_L("Block start address %d"), blockMapInfo.iStartBlockAddress);
1851 INFO_PRINTF2(_L("Block start offset %u"), blockMapInfo.iBlockStartOffset);
1852 INFO_PRINTF2(_L("Block graduality %u"), blockMapInfo.iBlockGranularity);
1857 //function that adds the buffer to the end of the array
1858 void CT_FileData::ToArrayL(RPointerArray<HBufC>& aArray, HBufC*& aBuffer)
1860 HBufC* arrayElement = HBufC::NewL(aBuffer->Length());
1861 TPtr arrayElementPtr = arrayElement->Des();
1862 arrayElementPtr.Copy(*aBuffer);
1863 arrayElementPtr.TrimAll();
1864 aArray.Append(arrayElement);
1865 arrayElement = NULL;
1869 // helper function to split filemodes or attributes to array
1870 RPointerArray<HBufC> CT_FileData::SplitL(const TDesC& aInput, const char* aToken)
1872 RPointerArray<HBufC> fileModeArray;
1873 HBufC* buffer = HBufC::NewL(aInput.Length());
1874 TPtr bufferPtr = buffer->Des();
1875 for (int i=0;i<aInput.Length();i++)
1877 if (aInput[i] == *aToken)
1879 ToArrayL(fileModeArray, buffer);
1883 buffer = HBufC::NewL( aInput.Length() - i);
1884 bufferPtr = buffer->Des();
1888 bufferPtr.Append(aInput[i]);
1892 ToArrayL(fileModeArray, buffer);
1897 return fileModeArray;
1901 void CT_FileData::DoCancel(CActive* aActive, TInt aIndex)
1903 TBool foundActiveObject = EFalse;
1908 count=iReadCallbackArray.Count();
1909 for( index=0; (index<count) && (!foundActiveObject); ++index )
1911 if( aActive == iReadCallbackArray[index] )
1913 INFO_PRINTF1(_L("DoCancel iReadCallbackArray called"));
1914 foundActiveObject = ETrue;
1915 iReadCallbackArray.Remove(index);
1919 count=iWriteCallbackArray.Count();
1920 for( index=0; (index<count) && (!foundActiveObject); ++index )
1922 if( aActive == iWriteCallbackArray[index] )
1924 INFO_PRINTF1(_L("DoCancel iWriteCallbackArray called"));
1925 foundActiveObject = ETrue;
1926 iWriteCallbackArray.Remove(index);
1930 // See if it is in iFlushCallbackArray
1931 count=iFlushCallbackArray.Count();
1932 for( index=0; (index<count) && (!foundActiveObject); ++index )
1934 if( aActive == iFlushCallbackArray[index] )
1936 INFO_PRINTF1(_L("DoCancel iFlushCallbackArray called"));
1937 foundActiveObject = ETrue;
1938 iFlushCallbackArray.Remove(index);
1942 if( foundActiveObject )
1944 TInt err = aActive->iStatus.Int();
1945 if( err != KErrNone )
1947 ERR_PRINTF2(_L("DoCancel Error %d"), err);
1948 SetAsyncError( aIndex, err );
1951 // Reset the outstanding request state
1958 ERR_PRINTF1(_L("Stray DoCancel signal"));
1959 SetBlockResult(EFail);
1963 void CT_FileData::RunL(CActive* aActive, TInt aIndex)
1967 TBool foundActiveObject = EFalse;
1971 count=iReadCallbackArray.Count();
1972 for( index=0; (index<count) && (!foundActiveObject); ++index )
1974 if( aActive == iReadCallbackArray[index] )
1976 foundActiveObject = ETrue;
1977 TInt err = aActive->iStatus.Int();
1979 TBuf<KDefaultDescSize> info;
1980 info.Copy(iReadCallbackArray[index]->iFileData->Des());
1981 INFO_PRINTF2(_L("readed \"%S\" from file"), &info);
1983 HandleExpectedString(iReadCallbackArray[index]->iFileData->Des(), *iReadCallbackArray[index]->iSection);
1985 if( err != KErrNone )
1987 ERR_PRINTF2(_L("Async Read error %d"), err);
1988 SetAsyncError( aIndex, err );
1992 INFO_PRINTF1(_L("Succesfully completed Async Read"));
1995 iReadCallbackArray.Remove(index);
2001 count=iWriteCallbackArray.Count();
2002 for( index=0; (index<count) && (!foundActiveObject); ++index )
2004 if( aActive == iWriteCallbackArray[index] )
2006 foundActiveObject = ETrue;
2007 TInt err = aActive->iStatus.Int();
2009 if( err != KErrNone )
2011 ERR_PRINTF2(_L("Async Write Error %d"), err);
2012 SetAsyncError( aIndex, err );
2016 INFO_PRINTF1(_L("Succesfully completed Async Write"));
2018 iWriteCallbackArray.Remove(index);
2023 count=iFlushCallbackArray.Count();
2024 for( index=0; (index<count) && (!foundActiveObject); ++index )
2026 if( aActive == iFlushCallbackArray[index] )
2028 foundActiveObject = ETrue;
2029 TInt err = aActive->iStatus.Int();
2031 if( err != KErrNone )
2033 ERR_PRINTF2(_L("Async Flush Error %d"), err);
2034 SetAsyncError( aIndex, err );
2036 iFlushCallbackArray.Remove(index);
2044 void CT_FileData::PrintFileAttributes(TUint aAttValue)
2045 /** Prints file attributes */
2047 if ((aAttValue & KEntryAttNormal) == KEntryAttNormal)
2049 INFO_PRINTF1(_L("KEntryAttNormal"));
2051 if ((aAttValue & KEntryAttReadOnly) == KEntryAttReadOnly)
2053 INFO_PRINTF1(_L("KEntryAttReadOnly"));
2056 if ((aAttValue & KEntryAttHidden) == KEntryAttHidden)
2058 INFO_PRINTF1(_L("KEntryAttHidden"));
2061 if ((aAttValue & KEntryAttSystem) == KEntryAttSystem)
2063 INFO_PRINTF1(_L("KEntryAttSystem"));
2066 if ((aAttValue & KEntryAttVolume) == KEntryAttVolume)
2068 INFO_PRINTF1(_L("KEntryAttVolume"));
2071 if ((aAttValue & KEntryAttDir) == KEntryAttDir)
2073 INFO_PRINTF1(_L("KEntryAttDir"));
2076 if ((aAttValue & KEntryAttArchive) == KEntryAttArchive)
2078 INFO_PRINTF1(_L("KEntryAttArchive"));
2081 if ((aAttValue & KEntryAttXIP) == KEntryAttXIP)
2083 INFO_PRINTF1(_L("KEntryAttXIP"));
2086 if ((aAttValue & KEntryAttRemote) == KEntryAttRemote)
2088 INFO_PRINTF1(_L("KEntryAttRemote"));