os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_FileData.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20 @test
    21 @internalComponent
    22 
    23 This contains CT_FileData
    24 */
    25 
    26 //	User includes
    27 #include "T_FileData.h"
    28 
    29 
    30 /*@{*/
    31 ///	Parameters
    32 _LIT(KFile,								"file");
    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");
    45 _LIT(KSeek, 							"seek");
    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");
    57 
    58 // OwnerType
    59 
    60 _LIT(KEOwnerProcess, 					"EOwnerProcess");
    61 _LIT(KEOwnerThread, 					"EOwnerThread");
    62 
    63 // Block Usage
    64 
    65 _LIT(KEBlockMapUsagePaging, 			"EBlockMapUsagePaging");
    66 _LIT(KETestDebug, 						"ETestDebug");
    67 
    68 // FileMode
    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");
    78 
    79 
    80 // Seek
    81 _LIT(KESeekStart,						"ESeekStart");
    82 _LIT(KESeekCurrent,						"ESeekCurrent");
    83 _LIT(KESeekEnd,							"ESeekEnd");
    84 
    85 ///	Commands
    86 _LIT(KCmdNew,							"new");
    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");
   114 
   115 
   116 //Attributes
   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");
   126 
   127 //constants
   128 const TInt KDefaultDescSize = 64;
   129 
   130 /*@}*/
   131 
   132 CT_FileData* CT_FileData::NewL()
   133 /**
   134  * Two phase constructor
   135  */
   136 	{
   137 	CT_FileData* ret = new (ELeave) CT_FileData();
   138 	CleanupStack::PushL(ret);
   139 	ret->ConstructL();
   140 	CleanupStack::Pop(ret);
   141 	return ret;
   142 	}
   143 
   144 CT_FileData::CT_FileData()
   145 /**
   146  * Protected constructor. First phase construction
   147  */
   148 :	iFile(NULL)
   149 	{
   150 	}
   151 
   152 void CT_FileData::ConstructL()
   153 /**
   154  * Protected constructor. Second phase construction
   155  */
   156 	{
   157 	iFileOpened = EFalse;
   158 	}
   159 
   160 CT_FileData::~CT_FileData()
   161 /**
   162  * Destructor.
   163  */
   164 	{
   165 	DoCleanup();
   166 	}
   167 
   168 void CT_FileData::DoCleanup()
   169 /**
   170  * Contains cleanup implementation
   171  */
   172 	{
   173 	//Deleting RFile.
   174 	if(iFile != NULL)
   175 		{
   176 		INFO_PRINTF1(_L("Deleting current RFile"));
   177 		delete iFile;
   178 		iFile = NULL;
   179 		}
   180 	iReadCallbackArray.Close();
   181 	iWriteCallbackArray.Close();
   182 	iFlushCallbackArray.Close();
   183 	}
   184 
   185 TAny* CT_FileData::GetObject()
   186 /**
   187  * Return a pointer to the object that the data wraps
   188  *
   189  * @return pointer to the object that the data wraps
   190  */
   191 	{
   192 	return iFile;
   193 	}
   194 
   195 TBool CT_FileData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
   196 /**
   197  * Process a command read from the ini file
   198  *
   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.
   202  *
   203  * @return ETrue if the command is processed
   204  */
   205 	{
   206 	TBool retVal = ETrue;
   207 
   208 	if (aCommand == KCmdNew)
   209 		{
   210 		DoCmdNewL();
   211 		}
   212 	else if (aCommand == KCmdDestructor)
   213 		{
   214 		DoCmdDestructor();
   215 		}
   216 	else if (aCommand == KCmdOpen)
   217 		{
   218 		DoCmdOpenL(aSection);
   219 		}
   220 	else if (aCommand == KCmdWrite)
   221 		{
   222 		DoCmdWriteL(aSection, aAsyncErrorIndex);
   223 		}
   224 	else if (aCommand == KCmdClose)
   225 		{
   226 		DoCmdClose();
   227 		}
   228 	else if (aCommand == KCmdCreate)
   229 		{
   230 		DoCmdCreateL(aSection);
   231 		}
   232 	else if (aCommand == KCmdReplace)
   233 		{
   234 		DoCmdReplaceL(aSection);
   235 		}
   236 	else if (aCommand == KCmdRead)
   237 		{
   238 		DoCmdReadL(aSection, aAsyncErrorIndex);
   239 		}	
   240 	else if (aCommand == KCmdFlush)
   241 		{
   242 		DoCmdFlushL(aSection, aAsyncErrorIndex);
   243 		}
   244 	else if (aCommand == KCmdTemp)
   245 		{
   246 		DoCmdTempL(aSection);
   247 		}	
   248 	else if (aCommand == KCmdRename)
   249 		{
   250 		DoCmdRenameL(aSection);
   251 		}
   252 	else if (aCommand == KCmdSeek)
   253 		{
   254 		DoCmdSeekL(aSection);
   255 		}
   256 	else if (aCommand == KCmdReadCancel)
   257 		{
   258 		DoCmdReadCancelL(aSection);
   259 		}	
   260 	else if (aCommand == KCmdLock)
   261 		{
   262 		DoCmdLockL(aSection);
   263 		}
   264 	else if (aCommand == KCmdUnLock)
   265 		{
   266 		DoCmdUnLockL(aSection);
   267 		}
   268 	else if (aCommand == KCmdSize)
   269 		{
   270 		DoCmdSizeL(aSection);
   271 		}		
   272 	else if (aCommand == KCmdSetSize)
   273 		{
   274 		DoCmdSetSizeL(aSection);
   275 		}
   276 	else if (aCommand == KCmdAtt)
   277 		{
   278 		DoCmdAttL(aSection);
   279 		}		
   280 	else if (aCommand == KCmdSetAtt)
   281 		{
   282 		DoCmdSetAttL(aSection);
   283 		}		
   284 	else if (aCommand == KCmdModified)
   285 		{
   286 		DoCmdModifiedL(aSection);
   287 		}
   288 	else if (aCommand == KCmdSetModified)
   289 		{
   290 		DoCmdSetModifiedL(aSection);
   291 		}
   292 	else if (aCommand == KCmdSet)
   293 		{
   294 		DoCmdSetL(aSection);
   295 		}
   296 	else if (aCommand == KCmdChangeMode)
   297 		{
   298 		DoCmdChangeModeL(aSection);
   299 		}
   300 	else if (aCommand == KCmdDrive)
   301 		{
   302 		DoCmdDriveL(aSection);
   303 		}
   304 	else if (aCommand == KCmdName)
   305 		{
   306 		DoCmdNameL(aSection);
   307 		}
   308 	else if (aCommand == KCmdDuplicate)
   309 		{
   310 		DoCmdDuplicateL(aSection);
   311 		}
   312 	else if (aCommand == KCmdFullName)
   313 		{
   314 		DoCmdFullName(aSection);
   315 		}
   316 	else if (aCommand == KCmdBlockMap)
   317 		{
   318 		DoCmdBlockMap(aSection);
   319 		}
   320 	else
   321 		{
   322 		retVal = EFalse;
   323 		}
   324 	return retVal;
   325 	}
   326 
   327 void CT_FileData::DoCmdNewL()
   328 /** Creates new RFile class instance */
   329 	{
   330 	//Deletes previous RFile class instance if it was already created.
   331 	DoCleanup();
   332 
   333 	INFO_PRINTF1(_L("Create new RFile class instance"));
   334 
   335 	// do create
   336 	TRAPD(err, iFile = new (ELeave) RFile());
   337 	if ( err!=KErrNone )
   338 		{
   339 		ERR_PRINTF2(_L("Error returned by New()%d"), err);
   340 		SetError(err);
   341 		}
   342 	}
   343 
   344 void CT_FileData::DoCmdDestructor()
   345 /** Destroy RFile the object */
   346 	{
   347 	DoCleanup();
   348 	}
   349 
   350 void CT_FileData::DoCmdOpenL(const TDesC& aSection)
   351 /**	Opens files */
   352 	{
   353 	RFs*	rfsObject=NULL;
   354 	TPtrC	rfsObjectName;
   355 	TBool	dataOk=GET_MANDATORY_STRING_PARAMETER(KRFsName(), aSection, rfsObjectName);
   356 	if ( dataOk )
   357 		{
   358 		rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
   359 		}
   360 
   361 	TPtrC	filePath;
   362 	if ( !GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, filePath) )
   363 		{
   364 		dataOk=EFalse;
   365 		}
   366 
   367 	TUint	fileMode = 0;
   368 	if ( !GetFileModeL(KFileMode, aSection, fileMode) )
   369 		{
   370 		ERR_PRINTF2(_L("Open() error reading parameter. %S"), &KFileMode());
   371 		SetBlockResult(EFail);
   372 		dataOk=EFalse;
   373 		}
   374 
   375 	if ( dataOk )
   376 		{
   377 		if (rfsObject)
   378 			{
   379 			TInt	err = iFile->Open(*rfsObject, filePath, fileMode);
   380 			if ( err!=KErrNone )
   381 				{
   382 				ERR_PRINTF2(_L("Open() failed with Error:%d"), err);
   383 				SetError(err);
   384 				}
   385 			else
   386 				{
   387 				iFileOpened = true;
   388 				}
   389 			}
   390 		else
   391 			{
   392 			ERR_PRINTF1(_L("RFs object is NULL"));
   393 			SetBlockResult(EFail);
   394 			}
   395 		}
   396 	}
   397 
   398 
   399 void CT_FileData::DoCmdClose()
   400 /** Close file	 */
   401 	{
   402 	INFO_PRINTF1(_L("Closing RFile"));
   403 	iFile->Close();
   404 	}
   405 
   406 void CT_FileData::DoCmdCreateL(const TDesC& aSection)
   407 /** create a new file */
   408 	{
   409 	RFs*	rfsObject=NULL;
   410 	TPtrC	rfsObjectName;
   411 	TBool	dataOk = ETrue;
   412 	if ( GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName) )
   413 		{
   414 		rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
   415 		}
   416 	else
   417 		{
   418 		dataOk = EFalse;
   419 		}
   420 
   421 	//	Gets name of file from ini file.
   422 	TPtrC	name;
   423 	if ( !GET_MANDATORY_STRING_PARAMETER(KUParamName(), aSection, name) )
   424 		{
   425 		dataOk = EFalse;
   426 		}
   427 
   428 	TUint	fileMode = 0;
   429 	if ( !GetFileModeL(KFileMode, aSection, fileMode) )
   430 		{
   431 		ERR_PRINTF2(_L("Create() error reading parameter. %S"), &KFileMode());
   432 		SetBlockResult(EFail);
   433 		dataOk = EFalse;
   434 		}
   435 
   436 	if ( dataOk )
   437 		{
   438 		//	Creates and opens a new file for writing.
   439 		if (rfsObject)
   440 			{
   441 			TInt	err = iFile->Create(*rfsObject, name, fileMode);
   442 			if ( err!=KErrNone )
   443 				{
   444 				ERR_PRINTF2(_L("Create(), error create() = %d"), err);
   445 				SetError(err);
   446 				}
   447 			}
   448 		else
   449 			{
   450 			ERR_PRINTF1(_L("RFs object is NULL"));
   451 			SetBlockResult(EFail);
   452 			}
   453 		}
   454 	}
   455 	
   456 void CT_FileData::DoCmdReplaceL(const TDesC& aSection)
   457 /** replace a existing file or create new */
   458 	{
   459 	TPtrC rfsObjectName;
   460 	RFs* rfsObject = NULL;
   461 	
   462 	TBool	dataOk = ETrue;
   463 	if ( GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName) )
   464 		{
   465 		rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
   466 		}
   467 
   468 	//	Gets name of file from ini file.
   469 	TPtrC path;
   470 	if (!GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, path))
   471 		{
   472 		dataOk = EFalse;
   473 		}
   474 	
   475 	TUint fileMode = 0;
   476 	if(!GetFileModeL(KFileMode, aSection, fileMode))
   477 		{
   478 		ERR_PRINTF2(_L("Replace() error reading parameter. %S"), &KFileMode());
   479 		SetBlockResult(EFail);
   480 		dataOk = EFalse;
   481 		}
   482 
   483 	//	Creates and opens a new file for writing.
   484 	if ( dataOk )
   485 		{
   486 		//	Creates and opens a new file for writing.
   487 		if (rfsObject)
   488 			{
   489 			TInt	err = iFile->Replace(*rfsObject, path, fileMode);
   490 			if ( err!=KErrNone )
   491 				{
   492 				ERR_PRINTF2(_L("Replace() failed with error = %d"), err);
   493 				SetError(err);
   494 				}
   495 			else
   496 				{
   497 				iFileOpened = ETrue;
   498 				INFO_PRINTF2(_L("File: %S is replaced successfuly"), &path);				
   499 				}
   500 			}
   501 		else
   502 			{
   503 			ERR_PRINTF1(_L("RFs object is NULL"));
   504 			SetBlockResult(EFail);
   505 			}
   506 		}
   507 
   508 	}	
   509 
   510 void CT_FileData::DoCmdReadL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   511 /** wrapper for read commands */
   512 	{
   513 	TBool async = EFalse;
   514 		if(GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async))
   515 			{
   516 			if (async)
   517 				{
   518 				DoAsynchronousReadsL(aSection, aAsyncErrorIndex);	
   519 				}
   520 			else
   521 				{
   522 				DoSynchronousReadsL(aSection);
   523 				}
   524 			
   525 			}
   526 		else
   527 			{
   528 			DoSynchronousReadsL(aSection);
   529 			}
   530 	}
   531 
   532 TBool CT_FileData::GetFileModeL(const TDesC& aParameterName, const TDesC& aSection, TUint& aFileMode)
   533 /** process the filemode from ini  */
   534 	{
   535 	TBool ret = ETrue;
   536 	
   537 	TPtrC aModeStr;
   538 	
   539 	if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, aModeStr))
   540 		{
   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, "|");		
   544 			
   545 		for ( int i = 0 ; i < fileModes.Count() ; i++ )
   546 			{
   547 			if (*fileModes[i] == KEFileShareExclusive)
   548 				{
   549 				aFileMode = aFileMode | EFileShareExclusive ;
   550 				}
   551 			else if (*fileModes[i] ==  KEFileShareReadersOnly)
   552 				{
   553 				aFileMode = aFileMode | EFileShareReadersOnly;
   554 				}
   555 			else if (*fileModes[i] ==  KEFileShareAny)
   556 				{
   557 				aFileMode = aFileMode | EFileShareAny;
   558 				}		
   559 			else if (*fileModes[i] ==  KEFileShareReadersOrWriters)
   560 				{
   561 				aFileMode = aFileMode | EFileShareReadersOrWriters;
   562 				}					
   563 			else if (*fileModes[i] ==  KEFileStream)
   564 				{
   565 				aFileMode = aFileMode | EFileStream;
   566 				}					
   567 			else if (*fileModes[i] ==  KEFileStreamText)
   568 				{
   569 				aFileMode = aFileMode | EFileStreamText;
   570 				}					
   571 			else if (*fileModes[i] ==  KEFileRead)
   572 				{
   573 				aFileMode = aFileMode | EFileRead;
   574 				}					
   575 			else if (*fileModes[i] ==  KEFileWrite)
   576 				{
   577 				aFileMode = aFileMode | EFileWrite;
   578 				}
   579 			else if (*fileModes[i] ==  KEFileReadAsyncAll)
   580 				{
   581 				aFileMode = aFileMode | EFileReadAsyncAll;
   582 				}
   583 			else
   584 				{
   585 				aFileMode = EFileShareAny;
   586 				ret = EFalse;
   587 				}
   588 			}
   589 			
   590 		for (int j=0 ; j<fileModes.Count() ; j++)
   591 			{
   592 			HBufC* temp = fileModes[j];
   593 			delete temp;
   594 			temp = NULL;
   595 			}
   596 			
   597 		fileModes.Close();
   598 		}
   599 	else
   600 		{
   601 		ret = EFalse;
   602 		}
   603 
   604 	return ret;
   605 	}
   606 
   607 
   608 void CT_FileData::DoSynchronousReadsL(const TDesC& aSection)
   609 /** process all synchronous reads */
   610 	{	
   611 	TInt length;
   612 	TInt pos;
   613 	
   614 	HBufC8* filedata = NULL;	
   615 	TInt bufferLength;
   616 	
   617 //get optional buffer length from ini file	
   618 	if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
   619 		{
   620 		filedata = HBufC8::NewLC(bufferLength);
   621 		}
   622 	else
   623 		{
   624 		filedata = HBufC8::NewLC(KDefaultDescSize);
   625 		}
   626 				
   627 		
   628 	TPtr8 filedataPtr = filedata->Des();
   629 	TInt err = 0;
   630 //devide which read to call, by switching between parameters fetched from ini file.	
   631 	if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
   632 		{
   633 		if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
   634 			{
   635 			INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TInt aLen)"));
   636 			err = iFile->Read(pos, filedataPtr, length);
   637 			HandleExpectedString(filedataPtr, aSection);
   638 			}
   639 		else
   640 			{
   641 			INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData, TInt aLen)"));
   642 			err = iFile->Read(filedataPtr, length);
   643 			HandleExpectedString(filedataPtr, aSection);
   644 			}
   645 		}
   646 	else
   647 		{
   648 		if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
   649 			{
   650 			INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData)"));
   651 			err = iFile->Read(pos, filedataPtr);
   652 			HandleExpectedString(filedataPtr, aSection);
   653 			}
   654 		else
   655 			{
   656 			INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData)"));
   657 			err = iFile->Read(filedataPtr);
   658 			HandleExpectedString(filedataPtr, aSection);
   659 			}
   660 		}
   661 		
   662 	TBuf<KDefaultDescSize> filedata16;
   663 	filedata16.Copy(filedataPtr);
   664 	INFO_PRINTF2(_L("read \"%S\" from file"), &filedata16);		
   665 		
   666 //did the read complete with error code?		
   667 	if (err != KErrNone)
   668 		{
   669 		ERR_PRINTF2(_L("error executing synchronous read %d"), err);
   670 		SetError(err);
   671 		}
   672 		
   673 	CleanupStack::PopAndDestroy(1);		
   674 		
   675 	}
   676 		
   677 void CT_FileData::DoAsynchronousReadsL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   678 /**process all asynchronous reads */
   679 	{
   680 	TInt length;
   681 	TInt pos;
   682 	
   683 	CT_FileActiveCallback* active = CT_FileActiveCallback::NewL(*this);
   684 	iReadCallbackArray.Append(active);
   685 		
   686 	TInt bufferLength;
   687 	
   688 	//Get the buffer length, and create the buffer for activeCallback object
   689 	if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
   690 		{
   691 		active->CreateFileDataBufferL(bufferLength);
   692 		}
   693 	else
   694 		{
   695 		active->CreateFileDataBufferL(KDefaultDescSize);
   696 		}	
   697 		
   698 	TPtr8 fileDataPtr = active->iFileData->Des();
   699 		
   700 	//decide which read to call	
   701 	if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
   702 		{
   703 		if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
   704 			{
   705 			INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TInt aLen, TRequestiStatus aiStatus)"));
   706 			iFile->Read(pos, fileDataPtr, length,active->iStatus);
   707 			}
   708 		else
   709 			{
   710 			INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData, TInt aLen, TRequestiStatus aiStatus)"));
   711 			iFile->Read(fileDataPtr, length, active->iStatus);
   712 			}
   713 		}
   714 	else
   715 		{
   716 		if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
   717 			{
   718 			INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TRequestiStatus aiStatus)"));
   719 			iFile->Read(pos, fileDataPtr, active->iStatus);
   720 			}
   721 		else
   722 			{
   723 			INFO_PRINTF1(_L("calling RFile::Read(TDesC &aData, TRequestiStatus aiStatus)"));
   724 			iFile->Read(fileDataPtr, active->iStatus);
   725 			}
   726 		}
   727 		
   728 	//acitvate callback object
   729 	active->SetSection(aSection);
   730 	active->Activate(aAsyncErrorIndex);
   731 	IncOutstanding();
   732 
   733 	}
   734 	
   735 	
   736 void CT_FileData::HandleExpectedString(const TDesC& aReadedData, const TDesC& aSection)
   737 /** compare the expected string with readed string, takes 16-bit parameter*/
   738 	{
   739 	TPtrC expectedString;
   740 	if(GET_OPTIONAL_STRING_PARAMETER(KUParamExpectedString, aSection, expectedString))
   741 		{
   742 		if (aReadedData == expectedString)
   743 			{
   744 			INFO_PRINTF1(_L("expected string matches with the data read"));			
   745 			}
   746 		else
   747 			{
   748 			ERR_PRINTF1(_L("expected string does not match with the data read"));
   749 			SetBlockResult(EFail);
   750 			}
   751 		}
   752 	}
   753 	
   754 
   755 void CT_FileData::HandleExpectedString(const TDesC8& aReadedData, const TDesC& aSection)
   756 /** compare the expected string with readed string, takes 16-bit parameter */
   757 	{
   758 	TBuf<KDefaultDescSize> readedData16;
   759 	readedData16.Copy(aReadedData);
   760 	TPtrC expectedString;
   761 	if(GET_OPTIONAL_STRING_PARAMETER(KUParamExpectedString, aSection, expectedString))
   762 		{
   763 		if (readedData16 == expectedString)
   764 			{
   765 			INFO_PRINTF1(_L("expected string matches with the data read"));			
   766 			}
   767 		else
   768 			{
   769 			ERR_PRINTF1(_L("expected string does not match with the data read"));
   770 			SetBlockResult(EFail);
   771 			}
   772 		}
   773 	}		
   774 	
   775 	
   776 void CT_FileData::DoCmdFlushL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   777 /** flush all the internal buffers to file */
   778 	{
   779 	TBool async = false;
   780 	TInt err = 0;
   781 	//get the parameter from ini, to decide which version of RFile::Flush to call
   782 	GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async);
   783 	if (async == true)
   784 		{		
   785 		CActiveCallback* active = CActiveCallback::NewL(*this);
   786 		iFlushCallbackArray.Append( active );
   787 		iFile->Flush(active->iStatus);
   788 		active->Activate(aAsyncErrorIndex);
   789 		IncOutstanding();
   790 		}
   791 	else
   792 		{
   793 		err = iFile->Flush();
   794 		if (err != KErrNone)
   795 			{
   796 			ERR_PRINTF2(_L("Flush() failed with error code. %d"), err);
   797 			SetError(err);
   798 			}
   799 		else
   800 			{
   801 			INFO_PRINTF1(_L("Succesfully flushed the file"));
   802 			}
   803 		}	
   804 	}	
   805 	
   806 
   807 void CT_FileData::DoCmdTempL(const TDesC& aSection)
   808 /* create temporary file */
   809 	{
   810 	
   811 	TPtrC rfsObjectName;
   812 	RFs* rfsObject = NULL;
   813 	
   814 	TBool	dataOk=GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName);
   815 	if ( dataOk )
   816 		{
   817 		rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
   818 		}
   819 
   820 	//	Gets name of file from ini file.
   821 	TPtrC path;
   822 	if (!GET_MANDATORY_STRING_PARAMETER(KUParamPath(), aSection, path))
   823 		{
   824 		dataOk=EFalse;
   825 		}
   826 	
   827 	TUint fileMode = 0;
   828 	if(!GetFileModeL(KFileMode, aSection, fileMode))
   829 		{
   830 		ERR_PRINTF2(_L("Temp() error reading parameter. %S"), &KFileMode());
   831 		SetBlockResult(EFail);
   832 		dataOk=EFalse;
   833 		}
   834 
   835 	//	Creates Temporary file.
   836 	TFileName fileName;
   837 	if ( dataOk )
   838 		{
   839 		if (rfsObject)
   840 			{
   841 			TInt	err = iFile->Temp(*rfsObject, path, fileName,fileMode);
   842 			INFO_PRINTF2(_L("File: %S is created"), &fileName);			
   843 			if ( err!=KErrNone )
   844 				{
   845 				ERR_PRINTF2(_L("Temp() failed with error = %d"), err);
   846 				SetError(err);
   847 				}
   848 			else
   849 				{
   850 				iFileOpened = ETrue;				
   851 				}				
   852 			}
   853 		else
   854 			{
   855 			ERR_PRINTF1(_L("RFs object is NULL"));
   856 			SetBlockResult(EFail);
   857 			}
   858 		}	
   859 	
   860 	}	
   861 	
   862 void CT_FileData::DoCmdRenameL(const TDesC& aSection)
   863 /** rename the file */
   864 	{
   865 	
   866 	TPtrC newName;
   867 	//get the name from ini and rename the file.
   868 	if(GET_MANDATORY_STRING_PARAMETER(KUParamName(), aSection, newName))
   869 		{	
   870 		TInt err = iFile->Rename(newName);
   871 	
   872 		if (err != KErrNone)
   873 			{
   874 			ERR_PRINTF2(_L("Rename() failed with error code %d"), err);
   875 			SetError(err);
   876 			}
   877 		}
   878 	
   879 	}	
   880 	
   881 void CT_FileData::DoCmdSeekL(const TDesC& aSection)
   882 /** set the file cursor to specified location in file */
   883 	{
   884 	TSeek seek = ESeekStart;
   885 	TBool dataOk = EFalse;
   886 	TInt pos;
   887 
   888 	//convert the mode string from ini to TSeek
   889 	if(ConvertToSeek(KSeek, aSection,seek))
   890 		{
   891 		dataOk = GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos);		
   892 		}	
   893 		
   894 	if(dataOk)
   895 		{
   896 		TInt err = iFile->Seek(seek, pos);
   897 	
   898 		if(err != KErrNone)	
   899 			{
   900 			ERR_PRINTF2(_L("Seek(), error seeking() = %d"), err);
   901 			SetError(err);
   902 			}
   903 		else
   904 			{
   905 			INFO_PRINTF1(_L("Succesfully seeked the file"));
   906 			}
   907 		}
   908 	}	
   909 	
   910 TBool CT_FileData::ConvertToSeek(const TDesC& aParameterName, const TDesC& aSection, TSeek& aSeek)
   911 /** convert a seek mode string from ini to TSeek */
   912 	{
   913 	TBool ret = ETrue;
   914 	
   915 	TPtrC aModeStr;
   916 	
   917 	if(GET_MANDATORY_STRING_PARAMETER(aParameterName, aSection, aModeStr))
   918 		{
   919 		
   920 		if (aModeStr == KESeekStart)
   921 			{
   922 			aSeek = ESeekStart;
   923 			}
   924 		else if (aModeStr == KESeekCurrent)
   925 			{
   926 			aSeek = ESeekCurrent;
   927 			}
   928 		else if (aModeStr == KESeekEnd)
   929 			{
   930 			aSeek = ESeekEnd;
   931 			}
   932 		else
   933 			{
   934 			ret = EFalse;
   935 			}
   936 		
   937 		}
   938 	else
   939 		{
   940 		ret = EFalse;
   941 		}
   942 
   943 	return ret;
   944 	}	
   945 	
   946 	
   947 void CT_FileData::DoCmdReadCancelL(const TDesC& aSection)
   948 /** wrapper for readcancels */
   949 	{
   950 	
   951 	TBool cancelAll;
   952 	
   953 	//decide which ReadCancel to call
   954 	if(GET_OPTIONAL_BOOL_PARAMETER(KUParamCancelAll, aSection, cancelAll))
   955 		{
   956 		if (cancelAll == true)
   957 			{
   958 			ReadCancelAll();
   959 			}
   960 		else
   961 			{
   962 			ReadCancel();
   963 			}
   964 		}
   965 	else
   966 		{
   967 		ReadCancel();
   968 		}
   969 	}	
   970 		
   971 void CT_FileData::ReadCancel()
   972 /** will cancel the last active request by default */
   973 	{
   974 	iFile->ReadCancel(iReadCallbackArray[iReadCallbackArray.Count()-1]->iStatus);
   975 	}
   976 	
   977 void CT_FileData::ReadCancelAll()
   978 /** cancel all outstanding read requests */
   979 	{
   980 	iFile->ReadCancel();
   981 	}
   982 
   983 // the write implementation
   984 void CT_FileData::DoCmdWriteL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   985 /** wrapper for write commands */
   986 	{
   987 	TBool async = EFalse;
   988 	//decide which write to call
   989 	GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async);
   990 	if (async == true)
   991 		{
   992 		DoAsynchronousWritesL(aSection, aAsyncErrorIndex);	
   993 		}
   994 	else
   995 		{
   996 		DoSynchronousWritesL(aSection);
   997 		}
   998 	}
   999 	
  1000 void CT_FileData::DoAsynchronousWritesL(const TDesC& aSection, const TInt aAsyncErrorIndex)
  1001 /** call asynchronous writes */
  1002 	{
  1003 	HBufC8* dataWrite8;
  1004 	TInt bufferLength;
  1005 	
  1006 	//Get the buffer length, and create the buffer for activeCallback object
  1007 	if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
  1008 		{
  1009 		dataWrite8 = HBufC8::NewLC(bufferLength);
  1010 		}
  1011 	else
  1012 		{
  1013 		dataWrite8 = HBufC8::NewLC(KDefaultDescSize);
  1014 		}	
  1015 	TPtr8 data8Ptr = dataWrite8->Des();
  1016 	
  1017 	TPtrC data;
  1018 	// Get the data to write
  1019 	if(GET_MANDATORY_STRING_PARAMETER(KUParamData(), aSection, data))
  1020 		{
  1021 		//convert it to 8-bit
  1022 		data8Ptr.Copy(data);
  1023 		
  1024 		CActiveCallback* active = CActiveCallback::NewL(*this);
  1025 	
  1026 		iWriteCallbackArray.Append( active );
  1027 		
  1028 		TInt length;
  1029 		TInt pos;	
  1030 		//now, decide which read to call
  1031 		if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
  1032 			{
  1033 			if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
  1034 				{
  1035 				INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TInt aLen, TRequestStatus &aStatus)"));
  1036 				iFile->Write(pos, *dataWrite8, length, active->iStatus);
  1037 				}
  1038 			else
  1039 				{
  1040 				INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TInt aLen, , TRequestStatus &aStatus)"));
  1041 				iFile->Write(*dataWrite8, length, active->iStatus);
  1042 				}
  1043 			}
  1044 		else
  1045 			{
  1046 			if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
  1047 				{
  1048 				INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TRequestStatus &aStatus)"));
  1049 				iFile->Write(pos, *dataWrite8, active->iStatus);
  1050 				}
  1051 			else
  1052 				{
  1053 				INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TRequestStatus &aStatus)"));
  1054 				iFile->Write(*dataWrite8, active->iStatus);
  1055 				}
  1056 			}
  1057 			
  1058 		active->Activate(aAsyncErrorIndex);
  1059 		IncOutstanding();
  1060 		}
  1061 
  1062 	CleanupStack::PopAndDestroy();	
  1063 	}
  1064 	
  1065 void CT_FileData::DoSynchronousWritesL(const TDesC& aSection)
  1066 /** cakk synchronous writes */
  1067 	{
  1068 	HBufC8* dataWrite8;
  1069 	TInt bufferLength;
  1070 	
  1071 	//Get the buffer length, and create the buffer for activeCallback object
  1072 	if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
  1073 		{
  1074 		dataWrite8 = HBufC8::NewLC(bufferLength);
  1075 		}
  1076 	else
  1077 		{
  1078 		dataWrite8 = HBufC8::NewLC(KDefaultDescSize);
  1079 		}	
  1080 	TPtr8 data8Ptr = dataWrite8->Des();
  1081 	TInt err = 0;
  1082 	
  1083 	TPtrC data;	
  1084 	// get the data
  1085 	if (GET_MANDATORY_STRING_PARAMETER(KUParamData(), aSection, data))
  1086 		{
  1087 		//convert it to 8-bit		
  1088 		data8Ptr.Copy(data);
  1089 		
  1090 		TInt length;
  1091 		TInt pos;
  1092 		
  1093 		//will decide which write to call 
  1094 		if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
  1095 			{
  1096 			if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
  1097 				{
  1098 				INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TInt aLen)"));
  1099 				err = iFile->Write(pos, *dataWrite8, length);
  1100 				}
  1101 			else
  1102 				{
  1103 				INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TInt aLen)"));
  1104 				err = iFile->Write(*dataWrite8, length);
  1105 				}
  1106 			}
  1107 		else
  1108 			{
  1109 			if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
  1110 				{
  1111 				INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData)"));
  1112 				err = iFile->Write(pos, *dataWrite8);
  1113 				}
  1114 			else
  1115 				{
  1116 				INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData)"));
  1117 				err = iFile->Write(*dataWrite8);
  1118 				}
  1119 			}
  1120 			
  1121 		if (err == KErrNone)
  1122 			{
  1123 			INFO_PRINTF2(_L("written \"%S\" to file"), &data);
  1124 			}
  1125 		else
  1126 			{
  1127 			ERR_PRINTF2(_L("Error executing synchronous write %d"), err);
  1128 			SetError(err);
  1129 			}
  1130 		}
  1131 	CleanupStack::PopAndDestroy();	
  1132 	}	
  1133 	
  1134 void CT_FileData::DoCmdLockL(const TDesC& aSection)
  1135 /** lock a region in file */
  1136 	{
  1137 	
  1138 	TInt pos=0;
  1139 	TBool dataOk = ETrue;
  1140 	
  1141 	//get the position
  1142 	if(!GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos))
  1143 		{
  1144 		dataOk = EFalse;
  1145 		}
  1146 		
  1147 	TInt length=0;	
  1148 	
  1149 	// get the length
  1150 	if(!GET_MANDATORY_INT_PARAMETER(KUParamLength(), aSection, length))
  1151 		{
  1152 		dataOk = EFalse;
  1153 		}
  1154 	
  1155 	//Lock!!
  1156 	if (dataOk)
  1157 		{
  1158 		TInt err = iFile->Lock(pos, length);
  1159 		
  1160 		if(err!=KErrNone)
  1161 			{
  1162 			ERR_PRINTF2(_L("Lock() error locking file. %d"), err);
  1163 			SetError(err);	
  1164 			}	
  1165 		}
  1166 
  1167 	}	
  1168 	
  1169 	
  1170 void CT_FileData::DoCmdUnLockL(const TDesC& aSection)
  1171 /** unlock a region that has been previously locked */
  1172 	{
  1173 	TBool dataOk = ETrue;
  1174 	
  1175 	TInt pos=0;
  1176 	
  1177 	//get the position
  1178 	if(!GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos))
  1179 		{
  1180 		dataOk = EFalse;
  1181 		}
  1182 
  1183 	TInt length=0;
  1184 	
  1185 	// get the length
  1186 	if(!GET_MANDATORY_INT_PARAMETER(KUParamLength(), aSection, length))
  1187 		{
  1188 		dataOk = EFalse;
  1189 		}
  1190 	
  1191 	//call UnLock
  1192 	if (dataOk)
  1193 		{
  1194 		TInt err = iFile->UnLock(pos, length);
  1195 		
  1196 		if(err!=KErrNone)
  1197 			{
  1198 			ERR_PRINTF2(_L("UnLock() error unlocking file. %d"), err);
  1199 			SetError(err);	
  1200 			}
  1201 		else
  1202 			{
  1203 			INFO_PRINTF1(_L("Succesfully unlocked the file"));
  1204 			}
  1205 		}
  1206 	
  1207 	}	
  1208 	
  1209 	
  1210 void CT_FileData::DoCmdSizeL(const TDesC& aSection)
  1211 /** get file size */
  1212 	{
  1213 	
  1214 	TInt expectedSize =  0;
  1215 	
  1216 	TInt size = 0;
  1217 	TInt err = iFile->Size(size);
  1218 	INFO_PRINTF2(_L("The Size of the file is %d bytes"), size);	
  1219 	
  1220 	if (err != KErrNone)
  1221 		{
  1222 		ERR_PRINTF2(_L("Size() error getting file size. %d"), err);
  1223 		SetError(err);
  1224 		}
  1225 	else
  1226 		{
  1227 		//get expected size from ini
  1228 		if(GET_OPTIONAL_INT_PARAMETER(KUParamExpectedSize(), aSection, expectedSize))		
  1229 			{
  1230 			if(expectedSize != size)
  1231 				{
  1232 				ERR_PRINTF3(_L("The file size does not match the expected size %d != %d"), size, expectedSize)				
  1233 				SetBlockResult(EFail);
  1234 				}
  1235 			}
  1236 		}
  1237 	
  1238 	}
  1239 
  1240 void CT_FileData::DoCmdSetSizeL(const TDesC& aSection)
  1241 /** set file size */
  1242 	{
  1243 	TInt size=0;
  1244 	
  1245 	if(GET_MANDATORY_INT_PARAMETER(KUParamSize(), aSection, size))
  1246 		{
  1247 		TInt err = iFile->SetSize(size);
  1248 		
  1249 		if (err != KErrNone)
  1250 			{
  1251 			ERR_PRINTF2(_L("SetSize() error setting file size. %d"), err);
  1252 			SetError(err);	
  1253 			}
  1254 		else
  1255 			{
  1256 			INFO_PRINTF2(_L("The Size of the fail is set to %d bytes"), size);	
  1257 			}			
  1258 		}
  1259 	}	
  1260 	
  1261 void CT_FileData::DoCmdAttL(const TDesC& aSection)
  1262 /** get file attributes */
  1263 	{
  1264 	
  1265 	TUint attValue = 0;
  1266 	
  1267 	TInt err = iFile->Att(attValue);
  1268 	
  1269 	PrintFileAttributes(attValue);
  1270 	
  1271 	if (err != KErrNone)
  1272 		{
  1273 		ERR_PRINTF2(_L("Att() getting attributes. %d"), err);
  1274 		SetError(err);	
  1275 		}
  1276 	else
  1277 		{
  1278 		TUint bitmask = 0x000000FF;
  1279 		//lets filter out symbian specific bits
  1280 		attValue = attValue & bitmask;
  1281 			
  1282 		TUint attCompare = 0;
  1283 		
  1284 		//compare the expected att value with the file attributes
  1285 		if (ConvertToAttributeL(KUParamCompareValue, aSection, attCompare))
  1286 			{
  1287 			if (attCompare == attValue)
  1288 				{
  1289 				INFO_PRINTF1(_L("attributes match"));
  1290 				}
  1291 			else
  1292 				{
  1293 				ERR_PRINTF1(_L("Attributes does not match"));
  1294 				SetBlockResult(EFail);
  1295 				}
  1296 			}
  1297 				
  1298 		}
  1299 	
  1300 	}
  1301 	
  1302 void CT_FileData::DoCmdSetAttL(const TDesC& aSection)
  1303 /** set file attributes */
  1304 	{
  1305 	
  1306 	TUint setAttMask = 0;
  1307 	TBool dataOk = ETrue;
  1308 	
  1309 	//get the attribute mask to set
  1310 	if(!ConvertToAttributeL(KUParamSetAttMask, aSection, setAttMask))
  1311 		{
  1312 		ERR_PRINTF2(_L("SetATt() error reading parameter. %S"), &KUParamSetAttMask());
  1313 		SetBlockResult(EFail);	
  1314 		dataOk = EFalse;
  1315 		}
  1316 		
  1317 	TUint clearAttMask = 0;
  1318 	
  1319 	//get the attribute mask to clear
  1320 	if(!ConvertToAttributeL(KUParamClearAttMask, aSection, clearAttMask))
  1321 		{
  1322 		ERR_PRINTF2(_L("SetAtt() error reading parameter. %S"), &KUParamClearAttMask());
  1323 		SetBlockResult(EFail);	
  1324 		dataOk = EFalse;
  1325 		}
  1326 		
  1327 	// all ok? let's call SetAtt		
  1328 	if (dataOk)
  1329 		{
  1330 		TInt err = iFile->SetAtt(setAttMask, clearAttMask);
  1331 		
  1332 		if (err != KErrNone)
  1333 			{
  1334 			ERR_PRINTF2(_L("SetAtt() failed with, err: %d"), err);
  1335 			SetError(err);	
  1336 			}
  1337 		else
  1338 			{
  1339 			INFO_PRINTF1(_L("The attribute value has been set"));	
  1340 			}	
  1341 		}
  1342 		
  1343 	}	
  1344 	
  1345 	
  1346 TBool CT_FileData::ConvertToAttributeL(const TDesC& aParameterName, const TDesC& aSection, TUint& aAttribute)
  1347 /** convert attribute string from ini to file attribute bitmask */
  1348 	{
  1349 	TBool ret = ETrue;
  1350 	
  1351 	TPtrC aModeStr;
  1352 	
  1353 	if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, aModeStr))
  1354 		{
  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, "|");		
  1358 			
  1359 		for ( int i = 0 ; i < fileModes.Count() ; i++ )
  1360 			{
  1361 			if (aModeStr == KDEntryAttNormal)
  1362 				{
  1363 				aAttribute = aAttribute | KEntryAttNormal;
  1364 				}
  1365 			else if (aModeStr == KDEntryAttReadOnly)
  1366 				{
  1367 				aAttribute = aAttribute | KEntryAttReadOnly;
  1368 				}
  1369 			else if (aModeStr == KDEntryAttArchive)
  1370 				{
  1371 				aAttribute = aAttribute | KEntryAttArchive;
  1372 				}
  1373 			else if (aModeStr == KDEntryAttHidden)
  1374 				{
  1375 				aAttribute = aAttribute | KEntryAttHidden;
  1376 				}
  1377 
  1378 			else if (aModeStr == KDEntryAttSystem)
  1379 				{
  1380 				aAttribute = aAttribute | KEntryAttSystem;
  1381 				}
  1382 
  1383 			else if (aModeStr == KDEntryAttVolume)
  1384 				{
  1385 				aAttribute = aAttribute | KEntryAttVolume;
  1386 				}
  1387 
  1388 			else if (aModeStr == KDEntryAttDir)
  1389 				{
  1390 				aAttribute = aAttribute | KEntryAttDir;
  1391 				}
  1392 
  1393 			else if (aModeStr == KDEntryAttXIP)
  1394 				{
  1395 				aAttribute = aAttribute | KEntryAttXIP;
  1396 				}
  1397 
  1398 			else if (aModeStr == KDEntryAttRemote)
  1399 				{
  1400 				aAttribute = aAttribute | KEntryAttRemote;
  1401 				}
  1402 			else
  1403 				{
  1404 				ret = EFalse;
  1405 				}
  1406 			}
  1407 			
  1408 		for (int j=0 ; j<fileModes.Count() ; j++)
  1409 			{
  1410 			HBufC* temp = fileModes[j];
  1411 			delete temp;
  1412 			temp = NULL;
  1413 			}
  1414 			
  1415 		fileModes.Close();
  1416 		}
  1417 	else
  1418 		{
  1419 		ret = EFalse;
  1420 		}
  1421 
  1422 	return ret;
  1423 	
  1424 	}	
  1425 	
  1426 void CT_FileData::DoCmdModifiedL(const TDesC& aSection)
  1427 /** get file modification date */
  1428 	{
  1429 	
  1430 	TTime time;
  1431 	
  1432 	TInt err = iFile->Modified(time);
  1433 	
  1434 	_LIT(KDateString,"%E%D%X%N%Y %1 %2 %3");	
  1435 		
  1436 	TBuf<KDefaultDescSize> dateString;
  1437 	
  1438 	//format the time to string	
  1439 	TRAPD(err2, time.FormatL(dateString, KDateString));
  1440 	
  1441 	if(err2 != KErrNone)
  1442 		{
  1443 		ERR_PRINTF2(_L("Modified() error formating date string err: %d"), err);
  1444 		}
  1445 	
  1446 	INFO_PRINTF2(_L("Modified() returned: %S"), &dateString);
  1447 	
  1448 	if (err != KErrNone)
  1449 		{
  1450 		ERR_PRINTF2(_L("Modified() failed with, err: %d"), err);
  1451 		SetError(err);	
  1452 		}
  1453 	else
  1454 		{
  1455 		
  1456 		//compare the file modification date with the date readed from inin
  1457 		TPtrC compValue;
  1458 		
  1459 		if (GET_OPTIONAL_STRING_PARAMETER(KUParamCompareValue, aSection, compValue))
  1460 			{
  1461 			
  1462 			TTime compTime;
  1463 			err = compTime.Set(compValue);
  1464 			
  1465 			if ( err != KErrNone )
  1466 				{
  1467 				ERR_PRINTF1(_L("invalid compare value"));
  1468 				}
  1469 			else
  1470 				{
  1471 				if (compTime == time)
  1472 					{
  1473 					INFO_PRINTF1(_L("The dates match"));
  1474 					}
  1475 				else
  1476 					{
  1477 					ERR_PRINTF1(_L("The values do not match"));
  1478 					SetBlockResult(EFail);
  1479 					}
  1480 				}
  1481 				
  1482 			}		
  1483 		}		
  1484 	}
  1485 
  1486 void CT_FileData::DoCmdSetModifiedL(const TDesC& aSection)
  1487 /** set file modification date */
  1488 	{
  1489 	
  1490 	TPtrC dateDesc;
  1491 	TBool dataOk = ETrue;
  1492 	TTime time;
  1493 	TInt err = KErrNone;
  1494 	
  1495 	if(!GET_MANDATORY_STRING_PARAMETER(KUParamDate(), aSection, dateDesc))
  1496 		{
  1497 		dataOk = EFalse;
  1498 		}
  1499 	else
  1500 		{
  1501 		err = time.Set(dateDesc);
  1502 		}
  1503 	
  1504 	if (err != KErrNone)
  1505 		{
  1506 		ERR_PRINTF2(_L("time.Set() failed with error code %d"), err);
  1507 		SetBlockResult(EFail);
  1508 		dataOk = EFalse;
  1509 		}
  1510 		
  1511 	if (dataOk)
  1512 		{
  1513 		err = iFile->SetModified(time);
  1514 		
  1515 		if (err != KErrNone)
  1516 			{
  1517 			ERR_PRINTF2(_L("SetModified() failed with error code %d"), err);
  1518 			SetError(err);			
  1519 			}		
  1520 		}
  1521 	}
  1522 	
  1523 void CT_FileData::DoCmdSetL(const TDesC& aSection)
  1524 /** set file attributes and modification time */
  1525 	{
  1526 	TPtrC dateDesc;
  1527 	TBool dataOk = ETrue;
  1528 	TInt err = KErrNone;
  1529 	TTime time;
  1530 	
  1531 	//get and process the date string
  1532 	if(!GET_MANDATORY_STRING_PARAMETER(KUParamDate(), aSection, dateDesc))
  1533 		{
  1534 		dataOk = EFalse;
  1535 		}
  1536 	else
  1537 		{
  1538 		err = time.Set(dateDesc);
  1539 		}		
  1540 		
  1541 	TUint setAttMask = 0;
  1542 		
  1543 	// get the attribute masks	
  1544 	if(!ConvertToAttributeL(KUParamSetAttMask, aSection,setAttMask))
  1545 		{
  1546 		dataOk = EFalse;
  1547 		}	
  1548 		
  1549 	TUint clearAttMask = 0;	
  1550 		
  1551 	if(!ConvertToAttributeL(KUParamClearAttMask, aSection, clearAttMask))
  1552 		{
  1553 		dataOk = EFalse;
  1554 		}			
  1555 	// if all Ok then proceed with Set	
  1556 	if (dataOk)
  1557 		{
  1558 		err = iFile->Set(time, setAttMask, clearAttMask);
  1559 		
  1560 		if ( err != KErrNone)
  1561 			{
  1562 			ERR_PRINTF2(_L("Set() failed with error code %d"), err);
  1563 			SetError(err);
  1564 			}		
  1565 		}
  1566 	}
  1567 	
  1568 void CT_FileData::DoCmdChangeModeL(const TDesC& aSection)
  1569 /** Change the file mode */
  1570 	{
  1571 	TUint fileMode = 0;
  1572 	
  1573 	if(!GetFileModeL(KFileMode, aSection, fileMode))
  1574 		{
  1575 		ERR_PRINTF2(_L("Set() error reading parameter. %S"), &KFileMode());
  1576 		SetBlockResult(EFail);	
  1577 		}
  1578 	else
  1579 		{
  1580 		TInt err = iFile->ChangeMode((TFileMode)fileMode);
  1581 		
  1582 		if ( err != KErrNone )
  1583 			{
  1584 			ERR_PRINTF2(_L("ChangeMode() failed with error code %d"), err);
  1585 			SetError(err);
  1586 			}	
  1587 		}
  1588 	}	
  1589 	
  1590 void CT_FileData::DoCmdDriveL(const TDesC& aSection)
  1591 /** Get the drive info, in which the file is stored */
  1592 	{
  1593 	TDriveInfo driveInfo;
  1594 	TInt driveNumber;
  1595 	int err = iFile->Drive(driveNumber, driveInfo);
  1596 	
  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);	
  1601 	
  1602 	if (err != KErrNone)
  1603 		{
  1604 		ERR_PRINTF2(_L("Drive() failed with error code %d"), err);
  1605 		SetError(err);
  1606 		}
  1607 	else
  1608 		{
  1609 		TInt compDriveNumber;
  1610 			
  1611 		if ( GET_OPTIONAL_INT_PARAMETER(KUParamCompareValue, aSection, compDriveNumber))
  1612 			{
  1613 				if ( compDriveNumber == driveNumber )
  1614 					{
  1615 					INFO_PRINTF3(_L("drivenumbers match %d == %d "), compDriveNumber, driveNumber);
  1616 					}
  1617 				else 
  1618 					{
  1619 					ERR_PRINTF3(_L("drivenumbers do not match %d != %d"), compDriveNumber, driveNumber);
  1620 					SetBlockResult(EFail);
  1621 					}
  1622 			}		
  1623 		}
  1624 	
  1625 	}	
  1626 	
  1627 void CT_FileData::DoCmdDuplicateL(const TDesC& aSection)
  1628 /** Duplicate the file */
  1629 	{
  1630 	TPtrC rFileObjectName;
  1631 	TBool dataOk = GET_MANDATORY_STRING_PARAMETER(KFileObjectName, aSection, rFileObjectName);
  1632 		
  1633 	// get the RFile handle to duplicate	
  1634 	RFile* rFileObject = NULL;
  1635 	if (dataOk)
  1636 		{
  1637 		rFileObject=(RFile*)GetDataObjectL(rFileObjectName);
  1638 	
  1639 		if(rFileObject == NULL)
  1640 			{
  1641 			ERR_PRINTF2(_L("Duplicate() error getting object. %S"), KFileObjectName);
  1642 			SetBlockResult(EFail);	
  1643 			dataOk = EFalse;
  1644 			}
  1645 		}
  1646 		
  1647 	// if handle ok then procees with duplication	
  1648 	if (dataOk)
  1649 		{
  1650 		TOwnerType ownerType;
  1651 			
  1652 		TInt err = KErrNone;	
  1653 		// determine the owner type to pass to duplicate
  1654 		if (ConvertToOwnerType(KUParamOwnerType, aSection, ownerType) && dataOk)
  1655 			{
  1656 			err = iFile->Duplicate(*rFileObject, ownerType);
  1657 			}
  1658 		else
  1659 			{
  1660 			err = iFile->Duplicate(*rFileObject);
  1661 			}
  1662 			
  1663 		
  1664 		if (err != KErrNone)
  1665 			{
  1666 			ERR_PRINTF2(_L("Duplicate() error duplicating %d"), err);
  1667 			SetError(err);
  1668 			}
  1669 		else
  1670 			{	
  1671 			//lets mark the file to be opened
  1672 			iFileOpened = ETrue;		
  1673 			}
  1674 		}
  1675 	
  1676 	}	
  1677 	
  1678 TBool CT_FileData::ConvertToOwnerType(const TDesC& aParameterName, const TDesC& aSection, TOwnerType& aResult)
  1679 /** convert the ownerType string from ini to EOwnerType */
  1680 	{
  1681 	
  1682 	TBool ret = ETrue;
  1683 	
  1684 	TPtrC ownerTypeString;
  1685 	
  1686 	if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, ownerTypeString))
  1687 		{
  1688 		
  1689 		if (ownerTypeString == KEOwnerProcess )
  1690 			{
  1691 			aResult = EOwnerProcess;
  1692 			}
  1693 		else if (ownerTypeString == KEOwnerThread)
  1694 			{
  1695 			aResult = EOwnerThread;
  1696 			}
  1697 		else
  1698 			{
  1699 			ret = EFalse;
  1700 			}
  1701 		
  1702 		}
  1703 	else
  1704 		{
  1705 		ret = EFalse;
  1706 		}
  1707 
  1708 	return ret;
  1709 	}	
  1710 	
  1711 void CT_FileData::DoCmdFullName(const TDesC& aSection)
  1712 /** get the file fullname */
  1713 	{
  1714 	TBuf<128> name;
  1715 	TInt err = iFile->FullName(name);
  1716 	
  1717 	INFO_PRINTF2(_L("FullName() returned  %S"), &name);		
  1718 	
  1719 	if(err != KErrNone)
  1720 		{
  1721 		ERR_PRINTF2(_L("FullName() error, returned. %d"), err);
  1722 		SetError(err);	
  1723 		}
  1724 	else
  1725 		{
  1726 		TPtrC path;	
  1727 		if(GET_OPTIONAL_STRING_PARAMETER(KUParamComparePath, aSection, path))
  1728 			{
  1729 			if (path == name)
  1730 				{
  1731 				INFO_PRINTF1(_L("the paths match"));	
  1732 				}
  1733 			else
  1734 				{
  1735 				ERR_PRINTF1(_L("the paths do not match"));
  1736 				SetBlockResult(EFail);
  1737 				}
  1738 			}				
  1739 		}
  1740 	}	
  1741 	
  1742 void CT_FileData::DoCmdNameL(const TDesC& aSection)
  1743 /** get the file name */
  1744 	{
  1745 	TBuf<KDefaultDescSize> name;
  1746 	TInt err = iFile->Name(name);
  1747 	INFO_PRINTF2(_L("Name() returned  %S"), &name);	
  1748 	
  1749 	if(err != KErrNone)
  1750 		{
  1751 		ERR_PRINTF2(_L("Name() error, returned. %d"), err);
  1752 		SetError(err);	
  1753 		}
  1754 	else	
  1755 		{
  1756 		
  1757 				
  1758 		TPtrC compValue;	
  1759 			
  1760 		if (GET_OPTIONAL_STRING_PARAMETER(KUParamCompareValue, aSection, compValue))
  1761 			{
  1762 			if (compValue == name)
  1763 				{
  1764 				INFO_PRINTF3(_L("The names match %S == %S"), &name, &compValue);
  1765 				}
  1766 			else
  1767 				{
  1768 				ERR_PRINTF3(_L("The names do not match %S == %S"), &name, &compValue);			
  1769 				SetBlockResult(EFail);
  1770 				}
  1771 			}		
  1772 		}
  1773 	}	
  1774 
  1775 TBool CT_FileData::ConvertToBlockMapUsage(const TDesC& aParameterName, const TDesC& aSection, TBlockMapUsage& aResult)
  1776 	{
  1777 	
  1778 	TBool ret = ETrue;
  1779 	
  1780 	TPtrC blockmapeUsageString;
  1781 	
  1782 	if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, blockmapeUsageString))
  1783 		{
  1784 		
  1785 		if (blockmapeUsageString == KEBlockMapUsagePaging )
  1786 			{
  1787 			aResult = EBlockMapUsagePaging;
  1788 			}
  1789 		else if (blockmapeUsageString == KETestDebug)
  1790 			{
  1791 			aResult = ETestDebug;
  1792 			}
  1793 		else
  1794 			{
  1795 			ret = EFalse;
  1796 			}
  1797 		
  1798 		}
  1799 	else
  1800 		{
  1801 		ret = EFalse;
  1802 		}
  1803 
  1804 	return ret;
  1805 	}	
  1806 	
  1807 void CT_FileData::DoCmdBlockMap(const TDesC& aSection)
  1808 	{
  1809 	TInt64 startPos = 0;
  1810 	GET_OPTIONAL_INT64_PARAMETER(KUParamStartPos, aSection, startPos);
  1811 		
  1812 	SBlockMapInfo blockMapInfo;
  1813 	TInt err = KErrNone;
  1814 	TInt64 endPos = -1;
  1815 	if (GET_OPTIONAL_INT64_PARAMETER(KUParamEndPos, aSection, endPos))
  1816 		{
  1817 		TBlockMapUsage usage;
  1818 		if (ConvertToBlockMapUsage(KUParamUsage, aSection, usage))
  1819 			{
  1820 			err = iFile->BlockMap(blockMapInfo, startPos, endPos, usage);
  1821 			}
  1822 		else
  1823 			{
  1824 			err = iFile->BlockMap(blockMapInfo, startPos, endPos);
  1825 			}
  1826 		}
  1827 	else
  1828 		{
  1829 		TBlockMapUsage usage;
  1830 		if (ConvertToBlockMapUsage(KUParamUsage, aSection, usage))
  1831 			{
  1832 			err = iFile->BlockMap(blockMapInfo, startPos, usage);
  1833 			}
  1834 		else
  1835 			{		
  1836 			err = iFile->BlockMap(blockMapInfo, startPos);
  1837 			}
  1838 		}
  1839 		
  1840 	if (KErrNone != err)
  1841 		{
  1842 		ERR_PRINTF2(_L("BlockMap Returned an error %d"), err);
  1843 		SetError(err);
  1844 		}
  1845 	if (KErrNone == err || KErrCompletion == err)
  1846 		{
  1847 		INFO_PRINTF2(_L("Returned start position %d"), startPos);
  1848 
  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);	
  1853 		}
  1854 	
  1855 	}
  1856 
  1857 //function that adds the buffer to the end of the array
  1858 void CT_FileData::ToArrayL(RPointerArray<HBufC>& aArray, HBufC*& aBuffer)
  1859 	{
  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;
  1866 	}
  1867 	
  1868 
  1869 // helper function to split filemodes or attributes to array
  1870 RPointerArray<HBufC> CT_FileData::SplitL(const TDesC& aInput, const char* aToken)
  1871 	{
  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++)
  1876 		{
  1877 		if (aInput[i] == *aToken)
  1878 			{
  1879 			ToArrayL(fileModeArray, buffer);
  1880 			delete buffer;	
  1881 				
  1882 			buffer = NULL;
  1883 			buffer = HBufC::NewL( aInput.Length() - i);	
  1884 			bufferPtr = buffer->Des();
  1885 			}
  1886 		else
  1887 			{
  1888 			bufferPtr.Append(aInput[i]);
  1889 			}
  1890 		}
  1891 	
  1892 	ToArrayL(fileModeArray, buffer);		
  1893 	delete buffer;
  1894 	
  1895 	buffer = NULL;		
  1896 		
  1897 	return fileModeArray;
  1898  	
  1899 	}
  1900 	
  1901 void CT_FileData::DoCancel(CActive* aActive, TInt aIndex)
  1902 	{
  1903 	TBool	foundActiveObject = EFalse;
  1904 
  1905 	TInt	index=0;
  1906 	TInt	count=0;
  1907 
  1908 	count=iReadCallbackArray.Count();
  1909 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1910  		{
  1911  		if( aActive == iReadCallbackArray[index] )
  1912 			{
  1913 			INFO_PRINTF1(_L("DoCancel iReadCallbackArray called"));
  1914 			foundActiveObject = ETrue;
  1915 			iReadCallbackArray.Remove(index);
  1916 	 		}
  1917 		}
  1918 
  1919 	count=iWriteCallbackArray.Count();
  1920 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1921  		{
  1922  		if( aActive == iWriteCallbackArray[index] )
  1923 			{
  1924 			INFO_PRINTF1(_L("DoCancel iWriteCallbackArray called"));
  1925 			foundActiveObject = ETrue;
  1926 			iWriteCallbackArray.Remove(index);
  1927 	 		}
  1928 		}
  1929 
  1930 	// See if it is in iFlushCallbackArray
  1931 	count=iFlushCallbackArray.Count();
  1932 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1933  		{
  1934  		if( aActive == iFlushCallbackArray[index] )
  1935 			{
  1936 			INFO_PRINTF1(_L("DoCancel iFlushCallbackArray called"));
  1937 			foundActiveObject = ETrue;
  1938 			iFlushCallbackArray.Remove(index);
  1939 	 		}
  1940 		}
  1941 
  1942  	if( foundActiveObject )
  1943  		{
  1944 		TInt	err = aActive->iStatus.Int();
  1945 		if( err != KErrNone )
  1946 			{
  1947 			ERR_PRINTF2(_L("DoCancel Error %d"), err);
  1948 			SetAsyncError( aIndex, err );
  1949 			}
  1950 
  1951 		// Reset the outstanding request state
  1952 		DecOutstanding();
  1953 
  1954 		delete aActive;
  1955 		}
  1956 	else
  1957 		{
  1958  		ERR_PRINTF1(_L("Stray DoCancel signal"));
  1959  		SetBlockResult(EFail);
  1960 		}
  1961 	}
  1962 
  1963 void CT_FileData::RunL(CActive* aActive, TInt aIndex)
  1964 	{
  1965 
  1966 	
  1967 	TBool	foundActiveObject = EFalse;
  1968 	TInt	index=0;
  1969 	TInt	count=0;
  1970 	
  1971 	count=iReadCallbackArray.Count();
  1972 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1973  		{
  1974  		if( aActive == iReadCallbackArray[index] )
  1975 			{
  1976 			foundActiveObject = ETrue;
  1977 			TInt	err = aActive->iStatus.Int();
  1978 			
  1979 			TBuf<KDefaultDescSize> info;
  1980 			info.Copy(iReadCallbackArray[index]->iFileData->Des());
  1981 			INFO_PRINTF2(_L("readed \"%S\" from file"), &info);
  1982 			
  1983 			HandleExpectedString(iReadCallbackArray[index]->iFileData->Des(), *iReadCallbackArray[index]->iSection);
  1984 			
  1985 			if( err != KErrNone )
  1986 				{
  1987 				ERR_PRINTF2(_L("Async Read error %d"), err);
  1988 				SetAsyncError( aIndex, err );
  1989 				}
  1990 			else
  1991 				{
  1992 				INFO_PRINTF1(_L("Succesfully completed Async Read"));
  1993 				}
  1994 				
  1995 			iReadCallbackArray.Remove(index);	
  1996 			delete aActive;
  1997 			
  1998 	 		}
  1999 		}
  2000 		
  2001 	count=iWriteCallbackArray.Count();
  2002 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  2003  		{
  2004  		if( aActive == iWriteCallbackArray[index] )
  2005 			{
  2006 			foundActiveObject = ETrue;
  2007 			TInt	err = aActive->iStatus.Int();
  2008 			
  2009 			if( err != KErrNone )
  2010 				{
  2011 				ERR_PRINTF2(_L("Async Write Error %d"), err);
  2012 				SetAsyncError( aIndex, err );
  2013 				}				
  2014 			else
  2015 				{
  2016 				INFO_PRINTF1(_L("Succesfully completed Async Write"));
  2017 				}
  2018 			iWriteCallbackArray.Remove(index);				
  2019 			delete aActive;			
  2020 	 		}
  2021 		}	
  2022 		
  2023 	count=iFlushCallbackArray.Count();
  2024 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  2025  		{
  2026  		if( aActive == iFlushCallbackArray[index] )
  2027 			{
  2028 			foundActiveObject = ETrue;
  2029 			TInt	err = aActive->iStatus.Int();
  2030 			
  2031 			if( err != KErrNone )
  2032 				{
  2033 				ERR_PRINTF2(_L("Async Flush Error %d"), err);
  2034 				SetAsyncError( aIndex, err );
  2035 				}				
  2036 			iFlushCallbackArray.Remove(index);				
  2037 			delete aActive;			
  2038 	 		}
  2039 		}				
  2040 	
  2041 	DecOutstanding();
  2042 	}
  2043 
  2044 void CT_FileData::PrintFileAttributes(TUint aAttValue)
  2045 /** Prints file attributes */
  2046 	{
  2047 	if ((aAttValue & KEntryAttNormal) == KEntryAttNormal)
  2048 		{
  2049 		INFO_PRINTF1(_L("KEntryAttNormal"));
  2050 		}
  2051 	if ((aAttValue & KEntryAttReadOnly) == KEntryAttReadOnly)
  2052 		{
  2053 		INFO_PRINTF1(_L("KEntryAttReadOnly"));
  2054 		}
  2055 		
  2056 	if ((aAttValue & KEntryAttHidden) == KEntryAttHidden)
  2057 		{
  2058 		INFO_PRINTF1(_L("KEntryAttHidden"));
  2059 		}
  2060 
  2061 	if ((aAttValue & KEntryAttSystem) == KEntryAttSystem)
  2062 		{
  2063 		INFO_PRINTF1(_L("KEntryAttSystem"));
  2064 		}
  2065 
  2066 	if ((aAttValue & KEntryAttVolume) == KEntryAttVolume)
  2067 		{
  2068 		INFO_PRINTF1(_L("KEntryAttVolume"));
  2069 		}
  2070 
  2071 	if ((aAttValue & KEntryAttDir) == KEntryAttDir)
  2072 		{
  2073 		INFO_PRINTF1(_L("KEntryAttDir"));
  2074 		}
  2075 
  2076 	if ((aAttValue & KEntryAttArchive) == KEntryAttArchive)
  2077 		{
  2078 		INFO_PRINTF1(_L("KEntryAttArchive"));
  2079 		}
  2080 
  2081 	if ((aAttValue & KEntryAttXIP) == KEntryAttXIP)
  2082 		{
  2083 		INFO_PRINTF1(_L("KEntryAttXIP"));
  2084 		}
  2085 
  2086 	if ((aAttValue & KEntryAttRemote) == KEntryAttRemote)
  2087 		{
  2088 		INFO_PRINTF1(_L("KEntryAttRemote"));
  2089 		}	
  2090 	}
  2091