os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_FileData.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_FileData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2091 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 +@test
    1.24 +@internalComponent
    1.25 +
    1.26 +This contains CT_FileData
    1.27 +*/
    1.28 +
    1.29 +//	User includes
    1.30 +#include "T_FileData.h"
    1.31 +
    1.32 +
    1.33 +/*@{*/
    1.34 +///	Parameters
    1.35 +_LIT(KFile,								"file");
    1.36 +_LIT(KUParamPath,						"path");
    1.37 +_LIT(KUParamName,						"name");
    1.38 +_LIT(KRFsName,							"RFs");
    1.39 +_LIT(KFileMode,							"file_mode");
    1.40 +_LIT(KUParamExpectedString,				"expected_string");
    1.41 +_LIT(KUParamAsync,						"async");
    1.42 +_LIT(KUParamBufferLength,				"buffer_length");
    1.43 +_LIT(KUParamLength,						"length");
    1.44 +_LIT(KUParamStartPos,					"start_pos");
    1.45 +_LIT(KUParamEndPos,						"end_pos");
    1.46 +_LIT(KUParamUsage,						"usage");
    1.47 +_LIT(KUParamPos,						"position");
    1.48 +_LIT(KSeek, 							"seek");
    1.49 +_LIT(KUParamCancelAll,					"cancel_all");
    1.50 +_LIT(KUParamData, 						"datawrite");
    1.51 +_LIT(KUParamSize, 						"size");
    1.52 +_LIT(KUParamExpectedSize,				"expected_size");
    1.53 +_LIT(KUParamCompareValue,				"compare_value");
    1.54 +_LIT(KUParamSetAttMask,					"set_att_mask");
    1.55 +_LIT(KUParamClearAttMask, 				"clear_att_mask");
    1.56 +_LIT(KUParamDate, 						"date");
    1.57 +_LIT(KFileObjectName,					"file_object_name");
    1.58 +_LIT(KUParamOwnerType,					"owner_type");
    1.59 +_LIT(KUParamComparePath,				"compare_path");
    1.60 +
    1.61 +// OwnerType
    1.62 +
    1.63 +_LIT(KEOwnerProcess, 					"EOwnerProcess");
    1.64 +_LIT(KEOwnerThread, 					"EOwnerThread");
    1.65 +
    1.66 +// Block Usage
    1.67 +
    1.68 +_LIT(KEBlockMapUsagePaging, 			"EBlockMapUsagePaging");
    1.69 +_LIT(KETestDebug, 						"ETestDebug");
    1.70 +
    1.71 +// FileMode
    1.72 +_LIT(KEFileShareExclusive,	 			"EFileShareExclusive");
    1.73 +_LIT(KEFileShareReadersOnly,	 		"EFileShareReadersOnly");
    1.74 +_LIT(KEFileShareAny,	 				"EFileShareAny");
    1.75 +_LIT(KEFileShareReadersOrWriters,	 	"EFileShareReadersOrWriters");
    1.76 +_LIT(KEFileStream,	 					"EFileStream");
    1.77 +_LIT(KEFileStreamText,					"EFileStreamText");
    1.78 +_LIT(KEFileRead,	 					"EFileRead");
    1.79 +_LIT(KEFileWrite,						"EFileWrite");
    1.80 +_LIT(KEFileReadAsyncAll,	 			"EFileReadAsyncAll");
    1.81 +
    1.82 +
    1.83 +// Seek
    1.84 +_LIT(KESeekStart,						"ESeekStart");
    1.85 +_LIT(KESeekCurrent,						"ESeekCurrent");
    1.86 +_LIT(KESeekEnd,							"ESeekEnd");
    1.87 +
    1.88 +///	Commands
    1.89 +_LIT(KCmdNew,							"new");
    1.90 +_LIT(KCmdClose,							"Close");
    1.91 +_LIT(KCmdDestructor,					"~");
    1.92 +_LIT(KCmdBlockMap,						"BlockMap");
    1.93 +_LIT(KCmdOpen,							"Open");
    1.94 +_LIT(KCmdCreate,						"Create");
    1.95 +_LIT(KCmdWrite,							"Write");
    1.96 +_LIT(KCmdReplace, 						"Replace");
    1.97 +_LIT(KCmdRead,							"Read");
    1.98 +_LIT(KCmdFlush,							"Flush");
    1.99 +_LIT(KCmdTemp,							"Temp");
   1.100 +_LIT(KCmdRename,						"Rename");
   1.101 +_LIT(KCmdSeek,							"Seek");
   1.102 +_LIT(KCmdReadCancel,					"ReadCancel");
   1.103 +_LIT(KCmdLock,							"Lock");
   1.104 +_LIT(KCmdUnLock,						"UnLock");
   1.105 +_LIT(KCmdSize, 							"Size");
   1.106 +_LIT(KCmdSetSize, 						"SetSize");
   1.107 +_LIT(KCmdAtt,							"Att");
   1.108 +_LIT(KCmdSetAtt,						"SetAtt");
   1.109 +_LIT(KCmdModified, 						"Modified");
   1.110 +_LIT(KCmdSetModified,					"SetModified");
   1.111 +_LIT(KCmdSet,							"Set");
   1.112 +_LIT(KCmdChangeMode, 					"ChangeMode");
   1.113 +_LIT(KCmdDrive,							"Drive");
   1.114 +_LIT(KCmdDuplicate, 					"Duplicate");
   1.115 +_LIT(KCmdName,							"Name");
   1.116 +_LIT(KCmdFullName,						"FullName");
   1.117 +
   1.118 +
   1.119 +//Attributes
   1.120 +_LIT(KDEntryAttNormal,  				"KEntryAttNormal");
   1.121 +_LIT(KDEntryAttReadOnly, 				"KEntryAttReadOnly");
   1.122 +_LIT(KDEntryAttArchive,					"KEntryAttArchive");
   1.123 +_LIT(KDEntryAttHidden,					"KEntryAttHidden");
   1.124 +_LIT(KDEntryAttSystem,					"KEntryAttSystem");
   1.125 +_LIT(KDEntryAttVolume,					"KEntryAttVolume");
   1.126 +_LIT(KDEntryAttDir,						"KEntryAttDir");
   1.127 +_LIT(KDEntryAttXIP,						"KEntryAttXIP");
   1.128 +_LIT(KDEntryAttRemote,					"KEntryAttRemote");
   1.129 +
   1.130 +//constants
   1.131 +const TInt KDefaultDescSize = 64;
   1.132 +
   1.133 +/*@}*/
   1.134 +
   1.135 +CT_FileData* CT_FileData::NewL()
   1.136 +/**
   1.137 + * Two phase constructor
   1.138 + */
   1.139 +	{
   1.140 +	CT_FileData* ret = new (ELeave) CT_FileData();
   1.141 +	CleanupStack::PushL(ret);
   1.142 +	ret->ConstructL();
   1.143 +	CleanupStack::Pop(ret);
   1.144 +	return ret;
   1.145 +	}
   1.146 +
   1.147 +CT_FileData::CT_FileData()
   1.148 +/**
   1.149 + * Protected constructor. First phase construction
   1.150 + */
   1.151 +:	iFile(NULL)
   1.152 +	{
   1.153 +	}
   1.154 +
   1.155 +void CT_FileData::ConstructL()
   1.156 +/**
   1.157 + * Protected constructor. Second phase construction
   1.158 + */
   1.159 +	{
   1.160 +	iFileOpened = EFalse;
   1.161 +	}
   1.162 +
   1.163 +CT_FileData::~CT_FileData()
   1.164 +/**
   1.165 + * Destructor.
   1.166 + */
   1.167 +	{
   1.168 +	DoCleanup();
   1.169 +	}
   1.170 +
   1.171 +void CT_FileData::DoCleanup()
   1.172 +/**
   1.173 + * Contains cleanup implementation
   1.174 + */
   1.175 +	{
   1.176 +	//Deleting RFile.
   1.177 +	if(iFile != NULL)
   1.178 +		{
   1.179 +		INFO_PRINTF1(_L("Deleting current RFile"));
   1.180 +		delete iFile;
   1.181 +		iFile = NULL;
   1.182 +		}
   1.183 +	iReadCallbackArray.Close();
   1.184 +	iWriteCallbackArray.Close();
   1.185 +	iFlushCallbackArray.Close();
   1.186 +	}
   1.187 +
   1.188 +TAny* CT_FileData::GetObject()
   1.189 +/**
   1.190 + * Return a pointer to the object that the data wraps
   1.191 + *
   1.192 + * @return pointer to the object that the data wraps
   1.193 + */
   1.194 +	{
   1.195 +	return iFile;
   1.196 +	}
   1.197 +
   1.198 +TBool CT_FileData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
   1.199 +/**
   1.200 + * Process a command read from the ini file
   1.201 + *
   1.202 + * @param aCommand	the command to process
   1.203 + * @param aSection		the entry in the ini file requiring the command to be processed
   1.204 + * @param aAsyncErrorIndex the index of asynchronous command error code belongs to.
   1.205 + *
   1.206 + * @return ETrue if the command is processed
   1.207 + */
   1.208 +	{
   1.209 +	TBool retVal = ETrue;
   1.210 +
   1.211 +	if (aCommand == KCmdNew)
   1.212 +		{
   1.213 +		DoCmdNewL();
   1.214 +		}
   1.215 +	else if (aCommand == KCmdDestructor)
   1.216 +		{
   1.217 +		DoCmdDestructor();
   1.218 +		}
   1.219 +	else if (aCommand == KCmdOpen)
   1.220 +		{
   1.221 +		DoCmdOpenL(aSection);
   1.222 +		}
   1.223 +	else if (aCommand == KCmdWrite)
   1.224 +		{
   1.225 +		DoCmdWriteL(aSection, aAsyncErrorIndex);
   1.226 +		}
   1.227 +	else if (aCommand == KCmdClose)
   1.228 +		{
   1.229 +		DoCmdClose();
   1.230 +		}
   1.231 +	else if (aCommand == KCmdCreate)
   1.232 +		{
   1.233 +		DoCmdCreateL(aSection);
   1.234 +		}
   1.235 +	else if (aCommand == KCmdReplace)
   1.236 +		{
   1.237 +		DoCmdReplaceL(aSection);
   1.238 +		}
   1.239 +	else if (aCommand == KCmdRead)
   1.240 +		{
   1.241 +		DoCmdReadL(aSection, aAsyncErrorIndex);
   1.242 +		}	
   1.243 +	else if (aCommand == KCmdFlush)
   1.244 +		{
   1.245 +		DoCmdFlushL(aSection, aAsyncErrorIndex);
   1.246 +		}
   1.247 +	else if (aCommand == KCmdTemp)
   1.248 +		{
   1.249 +		DoCmdTempL(aSection);
   1.250 +		}	
   1.251 +	else if (aCommand == KCmdRename)
   1.252 +		{
   1.253 +		DoCmdRenameL(aSection);
   1.254 +		}
   1.255 +	else if (aCommand == KCmdSeek)
   1.256 +		{
   1.257 +		DoCmdSeekL(aSection);
   1.258 +		}
   1.259 +	else if (aCommand == KCmdReadCancel)
   1.260 +		{
   1.261 +		DoCmdReadCancelL(aSection);
   1.262 +		}	
   1.263 +	else if (aCommand == KCmdLock)
   1.264 +		{
   1.265 +		DoCmdLockL(aSection);
   1.266 +		}
   1.267 +	else if (aCommand == KCmdUnLock)
   1.268 +		{
   1.269 +		DoCmdUnLockL(aSection);
   1.270 +		}
   1.271 +	else if (aCommand == KCmdSize)
   1.272 +		{
   1.273 +		DoCmdSizeL(aSection);
   1.274 +		}		
   1.275 +	else if (aCommand == KCmdSetSize)
   1.276 +		{
   1.277 +		DoCmdSetSizeL(aSection);
   1.278 +		}
   1.279 +	else if (aCommand == KCmdAtt)
   1.280 +		{
   1.281 +		DoCmdAttL(aSection);
   1.282 +		}		
   1.283 +	else if (aCommand == KCmdSetAtt)
   1.284 +		{
   1.285 +		DoCmdSetAttL(aSection);
   1.286 +		}		
   1.287 +	else if (aCommand == KCmdModified)
   1.288 +		{
   1.289 +		DoCmdModifiedL(aSection);
   1.290 +		}
   1.291 +	else if (aCommand == KCmdSetModified)
   1.292 +		{
   1.293 +		DoCmdSetModifiedL(aSection);
   1.294 +		}
   1.295 +	else if (aCommand == KCmdSet)
   1.296 +		{
   1.297 +		DoCmdSetL(aSection);
   1.298 +		}
   1.299 +	else if (aCommand == KCmdChangeMode)
   1.300 +		{
   1.301 +		DoCmdChangeModeL(aSection);
   1.302 +		}
   1.303 +	else if (aCommand == KCmdDrive)
   1.304 +		{
   1.305 +		DoCmdDriveL(aSection);
   1.306 +		}
   1.307 +	else if (aCommand == KCmdName)
   1.308 +		{
   1.309 +		DoCmdNameL(aSection);
   1.310 +		}
   1.311 +	else if (aCommand == KCmdDuplicate)
   1.312 +		{
   1.313 +		DoCmdDuplicateL(aSection);
   1.314 +		}
   1.315 +	else if (aCommand == KCmdFullName)
   1.316 +		{
   1.317 +		DoCmdFullName(aSection);
   1.318 +		}
   1.319 +	else if (aCommand == KCmdBlockMap)
   1.320 +		{
   1.321 +		DoCmdBlockMap(aSection);
   1.322 +		}
   1.323 +	else
   1.324 +		{
   1.325 +		retVal = EFalse;
   1.326 +		}
   1.327 +	return retVal;
   1.328 +	}
   1.329 +
   1.330 +void CT_FileData::DoCmdNewL()
   1.331 +/** Creates new RFile class instance */
   1.332 +	{
   1.333 +	//Deletes previous RFile class instance if it was already created.
   1.334 +	DoCleanup();
   1.335 +
   1.336 +	INFO_PRINTF1(_L("Create new RFile class instance"));
   1.337 +
   1.338 +	// do create
   1.339 +	TRAPD(err, iFile = new (ELeave) RFile());
   1.340 +	if ( err!=KErrNone )
   1.341 +		{
   1.342 +		ERR_PRINTF2(_L("Error returned by New()%d"), err);
   1.343 +		SetError(err);
   1.344 +		}
   1.345 +	}
   1.346 +
   1.347 +void CT_FileData::DoCmdDestructor()
   1.348 +/** Destroy RFile the object */
   1.349 +	{
   1.350 +	DoCleanup();
   1.351 +	}
   1.352 +
   1.353 +void CT_FileData::DoCmdOpenL(const TDesC& aSection)
   1.354 +/**	Opens files */
   1.355 +	{
   1.356 +	RFs*	rfsObject=NULL;
   1.357 +	TPtrC	rfsObjectName;
   1.358 +	TBool	dataOk=GET_MANDATORY_STRING_PARAMETER(KRFsName(), aSection, rfsObjectName);
   1.359 +	if ( dataOk )
   1.360 +		{
   1.361 +		rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
   1.362 +		}
   1.363 +
   1.364 +	TPtrC	filePath;
   1.365 +	if ( !GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, filePath) )
   1.366 +		{
   1.367 +		dataOk=EFalse;
   1.368 +		}
   1.369 +
   1.370 +	TUint	fileMode = 0;
   1.371 +	if ( !GetFileModeL(KFileMode, aSection, fileMode) )
   1.372 +		{
   1.373 +		ERR_PRINTF2(_L("Open() error reading parameter. %S"), &KFileMode());
   1.374 +		SetBlockResult(EFail);
   1.375 +		dataOk=EFalse;
   1.376 +		}
   1.377 +
   1.378 +	if ( dataOk )
   1.379 +		{
   1.380 +		if (rfsObject)
   1.381 +			{
   1.382 +			TInt	err = iFile->Open(*rfsObject, filePath, fileMode);
   1.383 +			if ( err!=KErrNone )
   1.384 +				{
   1.385 +				ERR_PRINTF2(_L("Open() failed with Error:%d"), err);
   1.386 +				SetError(err);
   1.387 +				}
   1.388 +			else
   1.389 +				{
   1.390 +				iFileOpened = true;
   1.391 +				}
   1.392 +			}
   1.393 +		else
   1.394 +			{
   1.395 +			ERR_PRINTF1(_L("RFs object is NULL"));
   1.396 +			SetBlockResult(EFail);
   1.397 +			}
   1.398 +		}
   1.399 +	}
   1.400 +
   1.401 +
   1.402 +void CT_FileData::DoCmdClose()
   1.403 +/** Close file	 */
   1.404 +	{
   1.405 +	INFO_PRINTF1(_L("Closing RFile"));
   1.406 +	iFile->Close();
   1.407 +	}
   1.408 +
   1.409 +void CT_FileData::DoCmdCreateL(const TDesC& aSection)
   1.410 +/** create a new file */
   1.411 +	{
   1.412 +	RFs*	rfsObject=NULL;
   1.413 +	TPtrC	rfsObjectName;
   1.414 +	TBool	dataOk = ETrue;
   1.415 +	if ( GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName) )
   1.416 +		{
   1.417 +		rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
   1.418 +		}
   1.419 +	else
   1.420 +		{
   1.421 +		dataOk = EFalse;
   1.422 +		}
   1.423 +
   1.424 +	//	Gets name of file from ini file.
   1.425 +	TPtrC	name;
   1.426 +	if ( !GET_MANDATORY_STRING_PARAMETER(KUParamName(), aSection, name) )
   1.427 +		{
   1.428 +		dataOk = EFalse;
   1.429 +		}
   1.430 +
   1.431 +	TUint	fileMode = 0;
   1.432 +	if ( !GetFileModeL(KFileMode, aSection, fileMode) )
   1.433 +		{
   1.434 +		ERR_PRINTF2(_L("Create() error reading parameter. %S"), &KFileMode());
   1.435 +		SetBlockResult(EFail);
   1.436 +		dataOk = EFalse;
   1.437 +		}
   1.438 +
   1.439 +	if ( dataOk )
   1.440 +		{
   1.441 +		//	Creates and opens a new file for writing.
   1.442 +		if (rfsObject)
   1.443 +			{
   1.444 +			TInt	err = iFile->Create(*rfsObject, name, fileMode);
   1.445 +			if ( err!=KErrNone )
   1.446 +				{
   1.447 +				ERR_PRINTF2(_L("Create(), error create() = %d"), err);
   1.448 +				SetError(err);
   1.449 +				}
   1.450 +			}
   1.451 +		else
   1.452 +			{
   1.453 +			ERR_PRINTF1(_L("RFs object is NULL"));
   1.454 +			SetBlockResult(EFail);
   1.455 +			}
   1.456 +		}
   1.457 +	}
   1.458 +	
   1.459 +void CT_FileData::DoCmdReplaceL(const TDesC& aSection)
   1.460 +/** replace a existing file or create new */
   1.461 +	{
   1.462 +	TPtrC rfsObjectName;
   1.463 +	RFs* rfsObject = NULL;
   1.464 +	
   1.465 +	TBool	dataOk = ETrue;
   1.466 +	if ( GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName) )
   1.467 +		{
   1.468 +		rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
   1.469 +		}
   1.470 +
   1.471 +	//	Gets name of file from ini file.
   1.472 +	TPtrC path;
   1.473 +	if (!GET_MANDATORY_STRING_PARAMETER(KFile(), aSection, path))
   1.474 +		{
   1.475 +		dataOk = EFalse;
   1.476 +		}
   1.477 +	
   1.478 +	TUint fileMode = 0;
   1.479 +	if(!GetFileModeL(KFileMode, aSection, fileMode))
   1.480 +		{
   1.481 +		ERR_PRINTF2(_L("Replace() error reading parameter. %S"), &KFileMode());
   1.482 +		SetBlockResult(EFail);
   1.483 +		dataOk = EFalse;
   1.484 +		}
   1.485 +
   1.486 +	//	Creates and opens a new file for writing.
   1.487 +	if ( dataOk )
   1.488 +		{
   1.489 +		//	Creates and opens a new file for writing.
   1.490 +		if (rfsObject)
   1.491 +			{
   1.492 +			TInt	err = iFile->Replace(*rfsObject, path, fileMode);
   1.493 +			if ( err!=KErrNone )
   1.494 +				{
   1.495 +				ERR_PRINTF2(_L("Replace() failed with error = %d"), err);
   1.496 +				SetError(err);
   1.497 +				}
   1.498 +			else
   1.499 +				{
   1.500 +				iFileOpened = ETrue;
   1.501 +				INFO_PRINTF2(_L("File: %S is replaced successfuly"), &path);				
   1.502 +				}
   1.503 +			}
   1.504 +		else
   1.505 +			{
   1.506 +			ERR_PRINTF1(_L("RFs object is NULL"));
   1.507 +			SetBlockResult(EFail);
   1.508 +			}
   1.509 +		}
   1.510 +
   1.511 +	}	
   1.512 +
   1.513 +void CT_FileData::DoCmdReadL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   1.514 +/** wrapper for read commands */
   1.515 +	{
   1.516 +	TBool async = EFalse;
   1.517 +		if(GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async))
   1.518 +			{
   1.519 +			if (async)
   1.520 +				{
   1.521 +				DoAsynchronousReadsL(aSection, aAsyncErrorIndex);	
   1.522 +				}
   1.523 +			else
   1.524 +				{
   1.525 +				DoSynchronousReadsL(aSection);
   1.526 +				}
   1.527 +			
   1.528 +			}
   1.529 +		else
   1.530 +			{
   1.531 +			DoSynchronousReadsL(aSection);
   1.532 +			}
   1.533 +	}
   1.534 +
   1.535 +TBool CT_FileData::GetFileModeL(const TDesC& aParameterName, const TDesC& aSection, TUint& aFileMode)
   1.536 +/** process the filemode from ini  */
   1.537 +	{
   1.538 +	TBool ret = ETrue;
   1.539 +	
   1.540 +	TPtrC aModeStr;
   1.541 +	
   1.542 +	if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, aModeStr))
   1.543 +		{
   1.544 +		//break the file mode string to array of file modes
   1.545 +		//in case there's more than one filemode		
   1.546 +		RPointerArray<HBufC> fileModes = SplitL(aModeStr, "|");		
   1.547 +			
   1.548 +		for ( int i = 0 ; i < fileModes.Count() ; i++ )
   1.549 +			{
   1.550 +			if (*fileModes[i] == KEFileShareExclusive)
   1.551 +				{
   1.552 +				aFileMode = aFileMode | EFileShareExclusive ;
   1.553 +				}
   1.554 +			else if (*fileModes[i] ==  KEFileShareReadersOnly)
   1.555 +				{
   1.556 +				aFileMode = aFileMode | EFileShareReadersOnly;
   1.557 +				}
   1.558 +			else if (*fileModes[i] ==  KEFileShareAny)
   1.559 +				{
   1.560 +				aFileMode = aFileMode | EFileShareAny;
   1.561 +				}		
   1.562 +			else if (*fileModes[i] ==  KEFileShareReadersOrWriters)
   1.563 +				{
   1.564 +				aFileMode = aFileMode | EFileShareReadersOrWriters;
   1.565 +				}					
   1.566 +			else if (*fileModes[i] ==  KEFileStream)
   1.567 +				{
   1.568 +				aFileMode = aFileMode | EFileStream;
   1.569 +				}					
   1.570 +			else if (*fileModes[i] ==  KEFileStreamText)
   1.571 +				{
   1.572 +				aFileMode = aFileMode | EFileStreamText;
   1.573 +				}					
   1.574 +			else if (*fileModes[i] ==  KEFileRead)
   1.575 +				{
   1.576 +				aFileMode = aFileMode | EFileRead;
   1.577 +				}					
   1.578 +			else if (*fileModes[i] ==  KEFileWrite)
   1.579 +				{
   1.580 +				aFileMode = aFileMode | EFileWrite;
   1.581 +				}
   1.582 +			else if (*fileModes[i] ==  KEFileReadAsyncAll)
   1.583 +				{
   1.584 +				aFileMode = aFileMode | EFileReadAsyncAll;
   1.585 +				}
   1.586 +			else
   1.587 +				{
   1.588 +				aFileMode = EFileShareAny;
   1.589 +				ret = EFalse;
   1.590 +				}
   1.591 +			}
   1.592 +			
   1.593 +		for (int j=0 ; j<fileModes.Count() ; j++)
   1.594 +			{
   1.595 +			HBufC* temp = fileModes[j];
   1.596 +			delete temp;
   1.597 +			temp = NULL;
   1.598 +			}
   1.599 +			
   1.600 +		fileModes.Close();
   1.601 +		}
   1.602 +	else
   1.603 +		{
   1.604 +		ret = EFalse;
   1.605 +		}
   1.606 +
   1.607 +	return ret;
   1.608 +	}
   1.609 +
   1.610 +
   1.611 +void CT_FileData::DoSynchronousReadsL(const TDesC& aSection)
   1.612 +/** process all synchronous reads */
   1.613 +	{	
   1.614 +	TInt length;
   1.615 +	TInt pos;
   1.616 +	
   1.617 +	HBufC8* filedata = NULL;	
   1.618 +	TInt bufferLength;
   1.619 +	
   1.620 +//get optional buffer length from ini file	
   1.621 +	if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
   1.622 +		{
   1.623 +		filedata = HBufC8::NewLC(bufferLength);
   1.624 +		}
   1.625 +	else
   1.626 +		{
   1.627 +		filedata = HBufC8::NewLC(KDefaultDescSize);
   1.628 +		}
   1.629 +				
   1.630 +		
   1.631 +	TPtr8 filedataPtr = filedata->Des();
   1.632 +	TInt err = 0;
   1.633 +//devide which read to call, by switching between parameters fetched from ini file.	
   1.634 +	if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
   1.635 +		{
   1.636 +		if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
   1.637 +			{
   1.638 +			INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TInt aLen)"));
   1.639 +			err = iFile->Read(pos, filedataPtr, length);
   1.640 +			HandleExpectedString(filedataPtr, aSection);
   1.641 +			}
   1.642 +		else
   1.643 +			{
   1.644 +			INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData, TInt aLen)"));
   1.645 +			err = iFile->Read(filedataPtr, length);
   1.646 +			HandleExpectedString(filedataPtr, aSection);
   1.647 +			}
   1.648 +		}
   1.649 +	else
   1.650 +		{
   1.651 +		if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
   1.652 +			{
   1.653 +			INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData)"));
   1.654 +			err = iFile->Read(pos, filedataPtr);
   1.655 +			HandleExpectedString(filedataPtr, aSection);
   1.656 +			}
   1.657 +		else
   1.658 +			{
   1.659 +			INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData)"));
   1.660 +			err = iFile->Read(filedataPtr);
   1.661 +			HandleExpectedString(filedataPtr, aSection);
   1.662 +			}
   1.663 +		}
   1.664 +		
   1.665 +	TBuf<KDefaultDescSize> filedata16;
   1.666 +	filedata16.Copy(filedataPtr);
   1.667 +	INFO_PRINTF2(_L("read \"%S\" from file"), &filedata16);		
   1.668 +		
   1.669 +//did the read complete with error code?		
   1.670 +	if (err != KErrNone)
   1.671 +		{
   1.672 +		ERR_PRINTF2(_L("error executing synchronous read %d"), err);
   1.673 +		SetError(err);
   1.674 +		}
   1.675 +		
   1.676 +	CleanupStack::PopAndDestroy(1);		
   1.677 +		
   1.678 +	}
   1.679 +		
   1.680 +void CT_FileData::DoAsynchronousReadsL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   1.681 +/**process all asynchronous reads */
   1.682 +	{
   1.683 +	TInt length;
   1.684 +	TInt pos;
   1.685 +	
   1.686 +	CT_FileActiveCallback* active = CT_FileActiveCallback::NewL(*this);
   1.687 +	iReadCallbackArray.Append(active);
   1.688 +		
   1.689 +	TInt bufferLength;
   1.690 +	
   1.691 +	//Get the buffer length, and create the buffer for activeCallback object
   1.692 +	if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
   1.693 +		{
   1.694 +		active->CreateFileDataBufferL(bufferLength);
   1.695 +		}
   1.696 +	else
   1.697 +		{
   1.698 +		active->CreateFileDataBufferL(KDefaultDescSize);
   1.699 +		}	
   1.700 +		
   1.701 +	TPtr8 fileDataPtr = active->iFileData->Des();
   1.702 +		
   1.703 +	//decide which read to call	
   1.704 +	if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
   1.705 +		{
   1.706 +		if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
   1.707 +			{
   1.708 +			INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TInt aLen, TRequestiStatus aiStatus)"));
   1.709 +			iFile->Read(pos, fileDataPtr, length,active->iStatus);
   1.710 +			}
   1.711 +		else
   1.712 +			{
   1.713 +			INFO_PRINTF1(_L("calling RFile::Read(TDes8 &aData, TInt aLen, TRequestiStatus aiStatus)"));
   1.714 +			iFile->Read(fileDataPtr, length, active->iStatus);
   1.715 +			}
   1.716 +		}
   1.717 +	else
   1.718 +		{
   1.719 +		if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
   1.720 +			{
   1.721 +			INFO_PRINTF1(_L("calling RFile::Read(TInt& aPos, TDes8 &aData, TRequestiStatus aiStatus)"));
   1.722 +			iFile->Read(pos, fileDataPtr, active->iStatus);
   1.723 +			}
   1.724 +		else
   1.725 +			{
   1.726 +			INFO_PRINTF1(_L("calling RFile::Read(TDesC &aData, TRequestiStatus aiStatus)"));
   1.727 +			iFile->Read(fileDataPtr, active->iStatus);
   1.728 +			}
   1.729 +		}
   1.730 +		
   1.731 +	//acitvate callback object
   1.732 +	active->SetSection(aSection);
   1.733 +	active->Activate(aAsyncErrorIndex);
   1.734 +	IncOutstanding();
   1.735 +
   1.736 +	}
   1.737 +	
   1.738 +	
   1.739 +void CT_FileData::HandleExpectedString(const TDesC& aReadedData, const TDesC& aSection)
   1.740 +/** compare the expected string with readed string, takes 16-bit parameter*/
   1.741 +	{
   1.742 +	TPtrC expectedString;
   1.743 +	if(GET_OPTIONAL_STRING_PARAMETER(KUParamExpectedString, aSection, expectedString))
   1.744 +		{
   1.745 +		if (aReadedData == expectedString)
   1.746 +			{
   1.747 +			INFO_PRINTF1(_L("expected string matches with the data read"));			
   1.748 +			}
   1.749 +		else
   1.750 +			{
   1.751 +			ERR_PRINTF1(_L("expected string does not match with the data read"));
   1.752 +			SetBlockResult(EFail);
   1.753 +			}
   1.754 +		}
   1.755 +	}
   1.756 +	
   1.757 +
   1.758 +void CT_FileData::HandleExpectedString(const TDesC8& aReadedData, const TDesC& aSection)
   1.759 +/** compare the expected string with readed string, takes 16-bit parameter */
   1.760 +	{
   1.761 +	TBuf<KDefaultDescSize> readedData16;
   1.762 +	readedData16.Copy(aReadedData);
   1.763 +	TPtrC expectedString;
   1.764 +	if(GET_OPTIONAL_STRING_PARAMETER(KUParamExpectedString, aSection, expectedString))
   1.765 +		{
   1.766 +		if (readedData16 == expectedString)
   1.767 +			{
   1.768 +			INFO_PRINTF1(_L("expected string matches with the data read"));			
   1.769 +			}
   1.770 +		else
   1.771 +			{
   1.772 +			ERR_PRINTF1(_L("expected string does not match with the data read"));
   1.773 +			SetBlockResult(EFail);
   1.774 +			}
   1.775 +		}
   1.776 +	}		
   1.777 +	
   1.778 +	
   1.779 +void CT_FileData::DoCmdFlushL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   1.780 +/** flush all the internal buffers to file */
   1.781 +	{
   1.782 +	TBool async = false;
   1.783 +	TInt err = 0;
   1.784 +	//get the parameter from ini, to decide which version of RFile::Flush to call
   1.785 +	GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async);
   1.786 +	if (async == true)
   1.787 +		{		
   1.788 +		CActiveCallback* active = CActiveCallback::NewL(*this);
   1.789 +		iFlushCallbackArray.Append( active );
   1.790 +		iFile->Flush(active->iStatus);
   1.791 +		active->Activate(aAsyncErrorIndex);
   1.792 +		IncOutstanding();
   1.793 +		}
   1.794 +	else
   1.795 +		{
   1.796 +		err = iFile->Flush();
   1.797 +		if (err != KErrNone)
   1.798 +			{
   1.799 +			ERR_PRINTF2(_L("Flush() failed with error code. %d"), err);
   1.800 +			SetError(err);
   1.801 +			}
   1.802 +		else
   1.803 +			{
   1.804 +			INFO_PRINTF1(_L("Succesfully flushed the file"));
   1.805 +			}
   1.806 +		}	
   1.807 +	}	
   1.808 +	
   1.809 +
   1.810 +void CT_FileData::DoCmdTempL(const TDesC& aSection)
   1.811 +/* create temporary file */
   1.812 +	{
   1.813 +	
   1.814 +	TPtrC rfsObjectName;
   1.815 +	RFs* rfsObject = NULL;
   1.816 +	
   1.817 +	TBool	dataOk=GET_MANDATORY_STRING_PARAMETER(KRFsName, aSection, rfsObjectName);
   1.818 +	if ( dataOk )
   1.819 +		{
   1.820 +		rfsObject=(RFs*)GetDataObjectL(rfsObjectName);
   1.821 +		}
   1.822 +
   1.823 +	//	Gets name of file from ini file.
   1.824 +	TPtrC path;
   1.825 +	if (!GET_MANDATORY_STRING_PARAMETER(KUParamPath(), aSection, path))
   1.826 +		{
   1.827 +		dataOk=EFalse;
   1.828 +		}
   1.829 +	
   1.830 +	TUint fileMode = 0;
   1.831 +	if(!GetFileModeL(KFileMode, aSection, fileMode))
   1.832 +		{
   1.833 +		ERR_PRINTF2(_L("Temp() error reading parameter. %S"), &KFileMode());
   1.834 +		SetBlockResult(EFail);
   1.835 +		dataOk=EFalse;
   1.836 +		}
   1.837 +
   1.838 +	//	Creates Temporary file.
   1.839 +	TFileName fileName;
   1.840 +	if ( dataOk )
   1.841 +		{
   1.842 +		if (rfsObject)
   1.843 +			{
   1.844 +			TInt	err = iFile->Temp(*rfsObject, path, fileName,fileMode);
   1.845 +			INFO_PRINTF2(_L("File: %S is created"), &fileName);			
   1.846 +			if ( err!=KErrNone )
   1.847 +				{
   1.848 +				ERR_PRINTF2(_L("Temp() failed with error = %d"), err);
   1.849 +				SetError(err);
   1.850 +				}
   1.851 +			else
   1.852 +				{
   1.853 +				iFileOpened = ETrue;				
   1.854 +				}				
   1.855 +			}
   1.856 +		else
   1.857 +			{
   1.858 +			ERR_PRINTF1(_L("RFs object is NULL"));
   1.859 +			SetBlockResult(EFail);
   1.860 +			}
   1.861 +		}	
   1.862 +	
   1.863 +	}	
   1.864 +	
   1.865 +void CT_FileData::DoCmdRenameL(const TDesC& aSection)
   1.866 +/** rename the file */
   1.867 +	{
   1.868 +	
   1.869 +	TPtrC newName;
   1.870 +	//get the name from ini and rename the file.
   1.871 +	if(GET_MANDATORY_STRING_PARAMETER(KUParamName(), aSection, newName))
   1.872 +		{	
   1.873 +		TInt err = iFile->Rename(newName);
   1.874 +	
   1.875 +		if (err != KErrNone)
   1.876 +			{
   1.877 +			ERR_PRINTF2(_L("Rename() failed with error code %d"), err);
   1.878 +			SetError(err);
   1.879 +			}
   1.880 +		}
   1.881 +	
   1.882 +	}	
   1.883 +	
   1.884 +void CT_FileData::DoCmdSeekL(const TDesC& aSection)
   1.885 +/** set the file cursor to specified location in file */
   1.886 +	{
   1.887 +	TSeek seek = ESeekStart;
   1.888 +	TBool dataOk = EFalse;
   1.889 +	TInt pos;
   1.890 +
   1.891 +	//convert the mode string from ini to TSeek
   1.892 +	if(ConvertToSeek(KSeek, aSection,seek))
   1.893 +		{
   1.894 +		dataOk = GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos);		
   1.895 +		}	
   1.896 +		
   1.897 +	if(dataOk)
   1.898 +		{
   1.899 +		TInt err = iFile->Seek(seek, pos);
   1.900 +	
   1.901 +		if(err != KErrNone)	
   1.902 +			{
   1.903 +			ERR_PRINTF2(_L("Seek(), error seeking() = %d"), err);
   1.904 +			SetError(err);
   1.905 +			}
   1.906 +		else
   1.907 +			{
   1.908 +			INFO_PRINTF1(_L("Succesfully seeked the file"));
   1.909 +			}
   1.910 +		}
   1.911 +	}	
   1.912 +	
   1.913 +TBool CT_FileData::ConvertToSeek(const TDesC& aParameterName, const TDesC& aSection, TSeek& aSeek)
   1.914 +/** convert a seek mode string from ini to TSeek */
   1.915 +	{
   1.916 +	TBool ret = ETrue;
   1.917 +	
   1.918 +	TPtrC aModeStr;
   1.919 +	
   1.920 +	if(GET_MANDATORY_STRING_PARAMETER(aParameterName, aSection, aModeStr))
   1.921 +		{
   1.922 +		
   1.923 +		if (aModeStr == KESeekStart)
   1.924 +			{
   1.925 +			aSeek = ESeekStart;
   1.926 +			}
   1.927 +		else if (aModeStr == KESeekCurrent)
   1.928 +			{
   1.929 +			aSeek = ESeekCurrent;
   1.930 +			}
   1.931 +		else if (aModeStr == KESeekEnd)
   1.932 +			{
   1.933 +			aSeek = ESeekEnd;
   1.934 +			}
   1.935 +		else
   1.936 +			{
   1.937 +			ret = EFalse;
   1.938 +			}
   1.939 +		
   1.940 +		}
   1.941 +	else
   1.942 +		{
   1.943 +		ret = EFalse;
   1.944 +		}
   1.945 +
   1.946 +	return ret;
   1.947 +	}	
   1.948 +	
   1.949 +	
   1.950 +void CT_FileData::DoCmdReadCancelL(const TDesC& aSection)
   1.951 +/** wrapper for readcancels */
   1.952 +	{
   1.953 +	
   1.954 +	TBool cancelAll;
   1.955 +	
   1.956 +	//decide which ReadCancel to call
   1.957 +	if(GET_OPTIONAL_BOOL_PARAMETER(KUParamCancelAll, aSection, cancelAll))
   1.958 +		{
   1.959 +		if (cancelAll == true)
   1.960 +			{
   1.961 +			ReadCancelAll();
   1.962 +			}
   1.963 +		else
   1.964 +			{
   1.965 +			ReadCancel();
   1.966 +			}
   1.967 +		}
   1.968 +	else
   1.969 +		{
   1.970 +		ReadCancel();
   1.971 +		}
   1.972 +	}	
   1.973 +		
   1.974 +void CT_FileData::ReadCancel()
   1.975 +/** will cancel the last active request by default */
   1.976 +	{
   1.977 +	iFile->ReadCancel(iReadCallbackArray[iReadCallbackArray.Count()-1]->iStatus);
   1.978 +	}
   1.979 +	
   1.980 +void CT_FileData::ReadCancelAll()
   1.981 +/** cancel all outstanding read requests */
   1.982 +	{
   1.983 +	iFile->ReadCancel();
   1.984 +	}
   1.985 +
   1.986 +// the write implementation
   1.987 +void CT_FileData::DoCmdWriteL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   1.988 +/** wrapper for write commands */
   1.989 +	{
   1.990 +	TBool async = EFalse;
   1.991 +	//decide which write to call
   1.992 +	GET_OPTIONAL_BOOL_PARAMETER(KUParamAsync, aSection, async);
   1.993 +	if (async == true)
   1.994 +		{
   1.995 +		DoAsynchronousWritesL(aSection, aAsyncErrorIndex);	
   1.996 +		}
   1.997 +	else
   1.998 +		{
   1.999 +		DoSynchronousWritesL(aSection);
  1.1000 +		}
  1.1001 +	}
  1.1002 +	
  1.1003 +void CT_FileData::DoAsynchronousWritesL(const TDesC& aSection, const TInt aAsyncErrorIndex)
  1.1004 +/** call asynchronous writes */
  1.1005 +	{
  1.1006 +	HBufC8* dataWrite8;
  1.1007 +	TInt bufferLength;
  1.1008 +	
  1.1009 +	//Get the buffer length, and create the buffer for activeCallback object
  1.1010 +	if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
  1.1011 +		{
  1.1012 +		dataWrite8 = HBufC8::NewLC(bufferLength);
  1.1013 +		}
  1.1014 +	else
  1.1015 +		{
  1.1016 +		dataWrite8 = HBufC8::NewLC(KDefaultDescSize);
  1.1017 +		}	
  1.1018 +	TPtr8 data8Ptr = dataWrite8->Des();
  1.1019 +	
  1.1020 +	TPtrC data;
  1.1021 +	// Get the data to write
  1.1022 +	if(GET_MANDATORY_STRING_PARAMETER(KUParamData(), aSection, data))
  1.1023 +		{
  1.1024 +		//convert it to 8-bit
  1.1025 +		data8Ptr.Copy(data);
  1.1026 +		
  1.1027 +		CActiveCallback* active = CActiveCallback::NewL(*this);
  1.1028 +	
  1.1029 +		iWriteCallbackArray.Append( active );
  1.1030 +		
  1.1031 +		TInt length;
  1.1032 +		TInt pos;	
  1.1033 +		//now, decide which read to call
  1.1034 +		if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
  1.1035 +			{
  1.1036 +			if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
  1.1037 +				{
  1.1038 +				INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TInt aLen, TRequestStatus &aStatus)"));
  1.1039 +				iFile->Write(pos, *dataWrite8, length, active->iStatus);
  1.1040 +				}
  1.1041 +			else
  1.1042 +				{
  1.1043 +				INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TInt aLen, , TRequestStatus &aStatus)"));
  1.1044 +				iFile->Write(*dataWrite8, length, active->iStatus);
  1.1045 +				}
  1.1046 +			}
  1.1047 +		else
  1.1048 +			{
  1.1049 +			if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
  1.1050 +				{
  1.1051 +				INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TRequestStatus &aStatus)"));
  1.1052 +				iFile->Write(pos, *dataWrite8, active->iStatus);
  1.1053 +				}
  1.1054 +			else
  1.1055 +				{
  1.1056 +				INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TRequestStatus &aStatus)"));
  1.1057 +				iFile->Write(*dataWrite8, active->iStatus);
  1.1058 +				}
  1.1059 +			}
  1.1060 +			
  1.1061 +		active->Activate(aAsyncErrorIndex);
  1.1062 +		IncOutstanding();
  1.1063 +		}
  1.1064 +
  1.1065 +	CleanupStack::PopAndDestroy();	
  1.1066 +	}
  1.1067 +	
  1.1068 +void CT_FileData::DoSynchronousWritesL(const TDesC& aSection)
  1.1069 +/** cakk synchronous writes */
  1.1070 +	{
  1.1071 +	HBufC8* dataWrite8;
  1.1072 +	TInt bufferLength;
  1.1073 +	
  1.1074 +	//Get the buffer length, and create the buffer for activeCallback object
  1.1075 +	if (GET_OPTIONAL_INT_PARAMETER(KUParamBufferLength, aSection, bufferLength))
  1.1076 +		{
  1.1077 +		dataWrite8 = HBufC8::NewLC(bufferLength);
  1.1078 +		}
  1.1079 +	else
  1.1080 +		{
  1.1081 +		dataWrite8 = HBufC8::NewLC(KDefaultDescSize);
  1.1082 +		}	
  1.1083 +	TPtr8 data8Ptr = dataWrite8->Des();
  1.1084 +	TInt err = 0;
  1.1085 +	
  1.1086 +	TPtrC data;	
  1.1087 +	// get the data
  1.1088 +	if (GET_MANDATORY_STRING_PARAMETER(KUParamData(), aSection, data))
  1.1089 +		{
  1.1090 +		//convert it to 8-bit		
  1.1091 +		data8Ptr.Copy(data);
  1.1092 +		
  1.1093 +		TInt length;
  1.1094 +		TInt pos;
  1.1095 +		
  1.1096 +		//will decide which write to call 
  1.1097 +		if(GET_OPTIONAL_INT_PARAMETER(KUParamLength, aSection, length))
  1.1098 +			{
  1.1099 +			if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
  1.1100 +				{
  1.1101 +				INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData, TInt aLen)"));
  1.1102 +				err = iFile->Write(pos, *dataWrite8, length);
  1.1103 +				}
  1.1104 +			else
  1.1105 +				{
  1.1106 +				INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData, TInt aLen)"));
  1.1107 +				err = iFile->Write(*dataWrite8, length);
  1.1108 +				}
  1.1109 +			}
  1.1110 +		else
  1.1111 +			{
  1.1112 +			if(GET_OPTIONAL_INT_PARAMETER(KUParamPos, aSection, pos))
  1.1113 +				{
  1.1114 +				INFO_PRINTF1(_L("calling RFile::Write(TInt& aPos, TDesC8 &aData)"));
  1.1115 +				err = iFile->Write(pos, *dataWrite8);
  1.1116 +				}
  1.1117 +			else
  1.1118 +				{
  1.1119 +				INFO_PRINTF1(_L("calling RFile::Write(TDesC8 &aData)"));
  1.1120 +				err = iFile->Write(*dataWrite8);
  1.1121 +				}
  1.1122 +			}
  1.1123 +			
  1.1124 +		if (err == KErrNone)
  1.1125 +			{
  1.1126 +			INFO_PRINTF2(_L("written \"%S\" to file"), &data);
  1.1127 +			}
  1.1128 +		else
  1.1129 +			{
  1.1130 +			ERR_PRINTF2(_L("Error executing synchronous write %d"), err);
  1.1131 +			SetError(err);
  1.1132 +			}
  1.1133 +		}
  1.1134 +	CleanupStack::PopAndDestroy();	
  1.1135 +	}	
  1.1136 +	
  1.1137 +void CT_FileData::DoCmdLockL(const TDesC& aSection)
  1.1138 +/** lock a region in file */
  1.1139 +	{
  1.1140 +	
  1.1141 +	TInt pos=0;
  1.1142 +	TBool dataOk = ETrue;
  1.1143 +	
  1.1144 +	//get the position
  1.1145 +	if(!GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos))
  1.1146 +		{
  1.1147 +		dataOk = EFalse;
  1.1148 +		}
  1.1149 +		
  1.1150 +	TInt length=0;	
  1.1151 +	
  1.1152 +	// get the length
  1.1153 +	if(!GET_MANDATORY_INT_PARAMETER(KUParamLength(), aSection, length))
  1.1154 +		{
  1.1155 +		dataOk = EFalse;
  1.1156 +		}
  1.1157 +	
  1.1158 +	//Lock!!
  1.1159 +	if (dataOk)
  1.1160 +		{
  1.1161 +		TInt err = iFile->Lock(pos, length);
  1.1162 +		
  1.1163 +		if(err!=KErrNone)
  1.1164 +			{
  1.1165 +			ERR_PRINTF2(_L("Lock() error locking file. %d"), err);
  1.1166 +			SetError(err);	
  1.1167 +			}	
  1.1168 +		}
  1.1169 +
  1.1170 +	}	
  1.1171 +	
  1.1172 +	
  1.1173 +void CT_FileData::DoCmdUnLockL(const TDesC& aSection)
  1.1174 +/** unlock a region that has been previously locked */
  1.1175 +	{
  1.1176 +	TBool dataOk = ETrue;
  1.1177 +	
  1.1178 +	TInt pos=0;
  1.1179 +	
  1.1180 +	//get the position
  1.1181 +	if(!GET_MANDATORY_INT_PARAMETER(KUParamPos(), aSection, pos))
  1.1182 +		{
  1.1183 +		dataOk = EFalse;
  1.1184 +		}
  1.1185 +
  1.1186 +	TInt length=0;
  1.1187 +	
  1.1188 +	// get the length
  1.1189 +	if(!GET_MANDATORY_INT_PARAMETER(KUParamLength(), aSection, length))
  1.1190 +		{
  1.1191 +		dataOk = EFalse;
  1.1192 +		}
  1.1193 +	
  1.1194 +	//call UnLock
  1.1195 +	if (dataOk)
  1.1196 +		{
  1.1197 +		TInt err = iFile->UnLock(pos, length);
  1.1198 +		
  1.1199 +		if(err!=KErrNone)
  1.1200 +			{
  1.1201 +			ERR_PRINTF2(_L("UnLock() error unlocking file. %d"), err);
  1.1202 +			SetError(err);	
  1.1203 +			}
  1.1204 +		else
  1.1205 +			{
  1.1206 +			INFO_PRINTF1(_L("Succesfully unlocked the file"));
  1.1207 +			}
  1.1208 +		}
  1.1209 +	
  1.1210 +	}	
  1.1211 +	
  1.1212 +	
  1.1213 +void CT_FileData::DoCmdSizeL(const TDesC& aSection)
  1.1214 +/** get file size */
  1.1215 +	{
  1.1216 +	
  1.1217 +	TInt expectedSize =  0;
  1.1218 +	
  1.1219 +	TInt size = 0;
  1.1220 +	TInt err = iFile->Size(size);
  1.1221 +	INFO_PRINTF2(_L("The Size of the file is %d bytes"), size);	
  1.1222 +	
  1.1223 +	if (err != KErrNone)
  1.1224 +		{
  1.1225 +		ERR_PRINTF2(_L("Size() error getting file size. %d"), err);
  1.1226 +		SetError(err);
  1.1227 +		}
  1.1228 +	else
  1.1229 +		{
  1.1230 +		//get expected size from ini
  1.1231 +		if(GET_OPTIONAL_INT_PARAMETER(KUParamExpectedSize(), aSection, expectedSize))		
  1.1232 +			{
  1.1233 +			if(expectedSize != size)
  1.1234 +				{
  1.1235 +				ERR_PRINTF3(_L("The file size does not match the expected size %d != %d"), size, expectedSize)				
  1.1236 +				SetBlockResult(EFail);
  1.1237 +				}
  1.1238 +			}
  1.1239 +		}
  1.1240 +	
  1.1241 +	}
  1.1242 +
  1.1243 +void CT_FileData::DoCmdSetSizeL(const TDesC& aSection)
  1.1244 +/** set file size */
  1.1245 +	{
  1.1246 +	TInt size=0;
  1.1247 +	
  1.1248 +	if(GET_MANDATORY_INT_PARAMETER(KUParamSize(), aSection, size))
  1.1249 +		{
  1.1250 +		TInt err = iFile->SetSize(size);
  1.1251 +		
  1.1252 +		if (err != KErrNone)
  1.1253 +			{
  1.1254 +			ERR_PRINTF2(_L("SetSize() error setting file size. %d"), err);
  1.1255 +			SetError(err);	
  1.1256 +			}
  1.1257 +		else
  1.1258 +			{
  1.1259 +			INFO_PRINTF2(_L("The Size of the fail is set to %d bytes"), size);	
  1.1260 +			}			
  1.1261 +		}
  1.1262 +	}	
  1.1263 +	
  1.1264 +void CT_FileData::DoCmdAttL(const TDesC& aSection)
  1.1265 +/** get file attributes */
  1.1266 +	{
  1.1267 +	
  1.1268 +	TUint attValue = 0;
  1.1269 +	
  1.1270 +	TInt err = iFile->Att(attValue);
  1.1271 +	
  1.1272 +	PrintFileAttributes(attValue);
  1.1273 +	
  1.1274 +	if (err != KErrNone)
  1.1275 +		{
  1.1276 +		ERR_PRINTF2(_L("Att() getting attributes. %d"), err);
  1.1277 +		SetError(err);	
  1.1278 +		}
  1.1279 +	else
  1.1280 +		{
  1.1281 +		TUint bitmask = 0x000000FF;
  1.1282 +		//lets filter out symbian specific bits
  1.1283 +		attValue = attValue & bitmask;
  1.1284 +			
  1.1285 +		TUint attCompare = 0;
  1.1286 +		
  1.1287 +		//compare the expected att value with the file attributes
  1.1288 +		if (ConvertToAttributeL(KUParamCompareValue, aSection, attCompare))
  1.1289 +			{
  1.1290 +			if (attCompare == attValue)
  1.1291 +				{
  1.1292 +				INFO_PRINTF1(_L("attributes match"));
  1.1293 +				}
  1.1294 +			else
  1.1295 +				{
  1.1296 +				ERR_PRINTF1(_L("Attributes does not match"));
  1.1297 +				SetBlockResult(EFail);
  1.1298 +				}
  1.1299 +			}
  1.1300 +				
  1.1301 +		}
  1.1302 +	
  1.1303 +	}
  1.1304 +	
  1.1305 +void CT_FileData::DoCmdSetAttL(const TDesC& aSection)
  1.1306 +/** set file attributes */
  1.1307 +	{
  1.1308 +	
  1.1309 +	TUint setAttMask = 0;
  1.1310 +	TBool dataOk = ETrue;
  1.1311 +	
  1.1312 +	//get the attribute mask to set
  1.1313 +	if(!ConvertToAttributeL(KUParamSetAttMask, aSection, setAttMask))
  1.1314 +		{
  1.1315 +		ERR_PRINTF2(_L("SetATt() error reading parameter. %S"), &KUParamSetAttMask());
  1.1316 +		SetBlockResult(EFail);	
  1.1317 +		dataOk = EFalse;
  1.1318 +		}
  1.1319 +		
  1.1320 +	TUint clearAttMask = 0;
  1.1321 +	
  1.1322 +	//get the attribute mask to clear
  1.1323 +	if(!ConvertToAttributeL(KUParamClearAttMask, aSection, clearAttMask))
  1.1324 +		{
  1.1325 +		ERR_PRINTF2(_L("SetAtt() error reading parameter. %S"), &KUParamClearAttMask());
  1.1326 +		SetBlockResult(EFail);	
  1.1327 +		dataOk = EFalse;
  1.1328 +		}
  1.1329 +		
  1.1330 +	// all ok? let's call SetAtt		
  1.1331 +	if (dataOk)
  1.1332 +		{
  1.1333 +		TInt err = iFile->SetAtt(setAttMask, clearAttMask);
  1.1334 +		
  1.1335 +		if (err != KErrNone)
  1.1336 +			{
  1.1337 +			ERR_PRINTF2(_L("SetAtt() failed with, err: %d"), err);
  1.1338 +			SetError(err);	
  1.1339 +			}
  1.1340 +		else
  1.1341 +			{
  1.1342 +			INFO_PRINTF1(_L("The attribute value has been set"));	
  1.1343 +			}	
  1.1344 +		}
  1.1345 +		
  1.1346 +	}	
  1.1347 +	
  1.1348 +	
  1.1349 +TBool CT_FileData::ConvertToAttributeL(const TDesC& aParameterName, const TDesC& aSection, TUint& aAttribute)
  1.1350 +/** convert attribute string from ini to file attribute bitmask */
  1.1351 +	{
  1.1352 +	TBool ret = ETrue;
  1.1353 +	
  1.1354 +	TPtrC aModeStr;
  1.1355 +	
  1.1356 +	if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, aModeStr))
  1.1357 +		{
  1.1358 +		//break the file mode string to array of file modes
  1.1359 +		//in case there's more than one filemode		
  1.1360 +		RPointerArray<HBufC> fileModes = SplitL(aModeStr, "|");		
  1.1361 +			
  1.1362 +		for ( int i = 0 ; i < fileModes.Count() ; i++ )
  1.1363 +			{
  1.1364 +			if (aModeStr == KDEntryAttNormal)
  1.1365 +				{
  1.1366 +				aAttribute = aAttribute | KEntryAttNormal;
  1.1367 +				}
  1.1368 +			else if (aModeStr == KDEntryAttReadOnly)
  1.1369 +				{
  1.1370 +				aAttribute = aAttribute | KEntryAttReadOnly;
  1.1371 +				}
  1.1372 +			else if (aModeStr == KDEntryAttArchive)
  1.1373 +				{
  1.1374 +				aAttribute = aAttribute | KEntryAttArchive;
  1.1375 +				}
  1.1376 +			else if (aModeStr == KDEntryAttHidden)
  1.1377 +				{
  1.1378 +				aAttribute = aAttribute | KEntryAttHidden;
  1.1379 +				}
  1.1380 +
  1.1381 +			else if (aModeStr == KDEntryAttSystem)
  1.1382 +				{
  1.1383 +				aAttribute = aAttribute | KEntryAttSystem;
  1.1384 +				}
  1.1385 +
  1.1386 +			else if (aModeStr == KDEntryAttVolume)
  1.1387 +				{
  1.1388 +				aAttribute = aAttribute | KEntryAttVolume;
  1.1389 +				}
  1.1390 +
  1.1391 +			else if (aModeStr == KDEntryAttDir)
  1.1392 +				{
  1.1393 +				aAttribute = aAttribute | KEntryAttDir;
  1.1394 +				}
  1.1395 +
  1.1396 +			else if (aModeStr == KDEntryAttXIP)
  1.1397 +				{
  1.1398 +				aAttribute = aAttribute | KEntryAttXIP;
  1.1399 +				}
  1.1400 +
  1.1401 +			else if (aModeStr == KDEntryAttRemote)
  1.1402 +				{
  1.1403 +				aAttribute = aAttribute | KEntryAttRemote;
  1.1404 +				}
  1.1405 +			else
  1.1406 +				{
  1.1407 +				ret = EFalse;
  1.1408 +				}
  1.1409 +			}
  1.1410 +			
  1.1411 +		for (int j=0 ; j<fileModes.Count() ; j++)
  1.1412 +			{
  1.1413 +			HBufC* temp = fileModes[j];
  1.1414 +			delete temp;
  1.1415 +			temp = NULL;
  1.1416 +			}
  1.1417 +			
  1.1418 +		fileModes.Close();
  1.1419 +		}
  1.1420 +	else
  1.1421 +		{
  1.1422 +		ret = EFalse;
  1.1423 +		}
  1.1424 +
  1.1425 +	return ret;
  1.1426 +	
  1.1427 +	}	
  1.1428 +	
  1.1429 +void CT_FileData::DoCmdModifiedL(const TDesC& aSection)
  1.1430 +/** get file modification date */
  1.1431 +	{
  1.1432 +	
  1.1433 +	TTime time;
  1.1434 +	
  1.1435 +	TInt err = iFile->Modified(time);
  1.1436 +	
  1.1437 +	_LIT(KDateString,"%E%D%X%N%Y %1 %2 %3");	
  1.1438 +		
  1.1439 +	TBuf<KDefaultDescSize> dateString;
  1.1440 +	
  1.1441 +	//format the time to string	
  1.1442 +	TRAPD(err2, time.FormatL(dateString, KDateString));
  1.1443 +	
  1.1444 +	if(err2 != KErrNone)
  1.1445 +		{
  1.1446 +		ERR_PRINTF2(_L("Modified() error formating date string err: %d"), err);
  1.1447 +		}
  1.1448 +	
  1.1449 +	INFO_PRINTF2(_L("Modified() returned: %S"), &dateString);
  1.1450 +	
  1.1451 +	if (err != KErrNone)
  1.1452 +		{
  1.1453 +		ERR_PRINTF2(_L("Modified() failed with, err: %d"), err);
  1.1454 +		SetError(err);	
  1.1455 +		}
  1.1456 +	else
  1.1457 +		{
  1.1458 +		
  1.1459 +		//compare the file modification date with the date readed from inin
  1.1460 +		TPtrC compValue;
  1.1461 +		
  1.1462 +		if (GET_OPTIONAL_STRING_PARAMETER(KUParamCompareValue, aSection, compValue))
  1.1463 +			{
  1.1464 +			
  1.1465 +			TTime compTime;
  1.1466 +			err = compTime.Set(compValue);
  1.1467 +			
  1.1468 +			if ( err != KErrNone )
  1.1469 +				{
  1.1470 +				ERR_PRINTF1(_L("invalid compare value"));
  1.1471 +				}
  1.1472 +			else
  1.1473 +				{
  1.1474 +				if (compTime == time)
  1.1475 +					{
  1.1476 +					INFO_PRINTF1(_L("The dates match"));
  1.1477 +					}
  1.1478 +				else
  1.1479 +					{
  1.1480 +					ERR_PRINTF1(_L("The values do not match"));
  1.1481 +					SetBlockResult(EFail);
  1.1482 +					}
  1.1483 +				}
  1.1484 +				
  1.1485 +			}		
  1.1486 +		}		
  1.1487 +	}
  1.1488 +
  1.1489 +void CT_FileData::DoCmdSetModifiedL(const TDesC& aSection)
  1.1490 +/** set file modification date */
  1.1491 +	{
  1.1492 +	
  1.1493 +	TPtrC dateDesc;
  1.1494 +	TBool dataOk = ETrue;
  1.1495 +	TTime time;
  1.1496 +	TInt err = KErrNone;
  1.1497 +	
  1.1498 +	if(!GET_MANDATORY_STRING_PARAMETER(KUParamDate(), aSection, dateDesc))
  1.1499 +		{
  1.1500 +		dataOk = EFalse;
  1.1501 +		}
  1.1502 +	else
  1.1503 +		{
  1.1504 +		err = time.Set(dateDesc);
  1.1505 +		}
  1.1506 +	
  1.1507 +	if (err != KErrNone)
  1.1508 +		{
  1.1509 +		ERR_PRINTF2(_L("time.Set() failed with error code %d"), err);
  1.1510 +		SetBlockResult(EFail);
  1.1511 +		dataOk = EFalse;
  1.1512 +		}
  1.1513 +		
  1.1514 +	if (dataOk)
  1.1515 +		{
  1.1516 +		err = iFile->SetModified(time);
  1.1517 +		
  1.1518 +		if (err != KErrNone)
  1.1519 +			{
  1.1520 +			ERR_PRINTF2(_L("SetModified() failed with error code %d"), err);
  1.1521 +			SetError(err);			
  1.1522 +			}		
  1.1523 +		}
  1.1524 +	}
  1.1525 +	
  1.1526 +void CT_FileData::DoCmdSetL(const TDesC& aSection)
  1.1527 +/** set file attributes and modification time */
  1.1528 +	{
  1.1529 +	TPtrC dateDesc;
  1.1530 +	TBool dataOk = ETrue;
  1.1531 +	TInt err = KErrNone;
  1.1532 +	TTime time;
  1.1533 +	
  1.1534 +	//get and process the date string
  1.1535 +	if(!GET_MANDATORY_STRING_PARAMETER(KUParamDate(), aSection, dateDesc))
  1.1536 +		{
  1.1537 +		dataOk = EFalse;
  1.1538 +		}
  1.1539 +	else
  1.1540 +		{
  1.1541 +		err = time.Set(dateDesc);
  1.1542 +		}		
  1.1543 +		
  1.1544 +	TUint setAttMask = 0;
  1.1545 +		
  1.1546 +	// get the attribute masks	
  1.1547 +	if(!ConvertToAttributeL(KUParamSetAttMask, aSection,setAttMask))
  1.1548 +		{
  1.1549 +		dataOk = EFalse;
  1.1550 +		}	
  1.1551 +		
  1.1552 +	TUint clearAttMask = 0;	
  1.1553 +		
  1.1554 +	if(!ConvertToAttributeL(KUParamClearAttMask, aSection, clearAttMask))
  1.1555 +		{
  1.1556 +		dataOk = EFalse;
  1.1557 +		}			
  1.1558 +	// if all Ok then proceed with Set	
  1.1559 +	if (dataOk)
  1.1560 +		{
  1.1561 +		err = iFile->Set(time, setAttMask, clearAttMask);
  1.1562 +		
  1.1563 +		if ( err != KErrNone)
  1.1564 +			{
  1.1565 +			ERR_PRINTF2(_L("Set() failed with error code %d"), err);
  1.1566 +			SetError(err);
  1.1567 +			}		
  1.1568 +		}
  1.1569 +	}
  1.1570 +	
  1.1571 +void CT_FileData::DoCmdChangeModeL(const TDesC& aSection)
  1.1572 +/** Change the file mode */
  1.1573 +	{
  1.1574 +	TUint fileMode = 0;
  1.1575 +	
  1.1576 +	if(!GetFileModeL(KFileMode, aSection, fileMode))
  1.1577 +		{
  1.1578 +		ERR_PRINTF2(_L("Set() error reading parameter. %S"), &KFileMode());
  1.1579 +		SetBlockResult(EFail);	
  1.1580 +		}
  1.1581 +	else
  1.1582 +		{
  1.1583 +		TInt err = iFile->ChangeMode((TFileMode)fileMode);
  1.1584 +		
  1.1585 +		if ( err != KErrNone )
  1.1586 +			{
  1.1587 +			ERR_PRINTF2(_L("ChangeMode() failed with error code %d"), err);
  1.1588 +			SetError(err);
  1.1589 +			}	
  1.1590 +		}
  1.1591 +	}	
  1.1592 +	
  1.1593 +void CT_FileData::DoCmdDriveL(const TDesC& aSection)
  1.1594 +/** Get the drive info, in which the file is stored */
  1.1595 +	{
  1.1596 +	TDriveInfo driveInfo;
  1.1597 +	TInt driveNumber;
  1.1598 +	int err = iFile->Drive(driveNumber, driveInfo);
  1.1599 +	
  1.1600 +	INFO_PRINTF2(_L("TDriveInfo.iType    =%d"), driveInfo.iType);
  1.1601 +	INFO_PRINTF2(_L("TDriveInfo.iBattery =%d"), driveInfo.iBattery);
  1.1602 +	INFO_PRINTF2(_L("TDriveInfo.iDriveAtt=0x%X"), driveInfo.iDriveAtt);
  1.1603 +	INFO_PRINTF2(_L("Drivenumber 		 =%d"), driveNumber);	
  1.1604 +	
  1.1605 +	if (err != KErrNone)
  1.1606 +		{
  1.1607 +		ERR_PRINTF2(_L("Drive() failed with error code %d"), err);
  1.1608 +		SetError(err);
  1.1609 +		}
  1.1610 +	else
  1.1611 +		{
  1.1612 +		TInt compDriveNumber;
  1.1613 +			
  1.1614 +		if ( GET_OPTIONAL_INT_PARAMETER(KUParamCompareValue, aSection, compDriveNumber))
  1.1615 +			{
  1.1616 +				if ( compDriveNumber == driveNumber )
  1.1617 +					{
  1.1618 +					INFO_PRINTF3(_L("drivenumbers match %d == %d "), compDriveNumber, driveNumber);
  1.1619 +					}
  1.1620 +				else 
  1.1621 +					{
  1.1622 +					ERR_PRINTF3(_L("drivenumbers do not match %d != %d"), compDriveNumber, driveNumber);
  1.1623 +					SetBlockResult(EFail);
  1.1624 +					}
  1.1625 +			}		
  1.1626 +		}
  1.1627 +	
  1.1628 +	}	
  1.1629 +	
  1.1630 +void CT_FileData::DoCmdDuplicateL(const TDesC& aSection)
  1.1631 +/** Duplicate the file */
  1.1632 +	{
  1.1633 +	TPtrC rFileObjectName;
  1.1634 +	TBool dataOk = GET_MANDATORY_STRING_PARAMETER(KFileObjectName, aSection, rFileObjectName);
  1.1635 +		
  1.1636 +	// get the RFile handle to duplicate	
  1.1637 +	RFile* rFileObject = NULL;
  1.1638 +	if (dataOk)
  1.1639 +		{
  1.1640 +		rFileObject=(RFile*)GetDataObjectL(rFileObjectName);
  1.1641 +	
  1.1642 +		if(rFileObject == NULL)
  1.1643 +			{
  1.1644 +			ERR_PRINTF2(_L("Duplicate() error getting object. %S"), KFileObjectName);
  1.1645 +			SetBlockResult(EFail);	
  1.1646 +			dataOk = EFalse;
  1.1647 +			}
  1.1648 +		}
  1.1649 +		
  1.1650 +	// if handle ok then procees with duplication	
  1.1651 +	if (dataOk)
  1.1652 +		{
  1.1653 +		TOwnerType ownerType;
  1.1654 +			
  1.1655 +		TInt err = KErrNone;	
  1.1656 +		// determine the owner type to pass to duplicate
  1.1657 +		if (ConvertToOwnerType(KUParamOwnerType, aSection, ownerType) && dataOk)
  1.1658 +			{
  1.1659 +			err = iFile->Duplicate(*rFileObject, ownerType);
  1.1660 +			}
  1.1661 +		else
  1.1662 +			{
  1.1663 +			err = iFile->Duplicate(*rFileObject);
  1.1664 +			}
  1.1665 +			
  1.1666 +		
  1.1667 +		if (err != KErrNone)
  1.1668 +			{
  1.1669 +			ERR_PRINTF2(_L("Duplicate() error duplicating %d"), err);
  1.1670 +			SetError(err);
  1.1671 +			}
  1.1672 +		else
  1.1673 +			{	
  1.1674 +			//lets mark the file to be opened
  1.1675 +			iFileOpened = ETrue;		
  1.1676 +			}
  1.1677 +		}
  1.1678 +	
  1.1679 +	}	
  1.1680 +	
  1.1681 +TBool CT_FileData::ConvertToOwnerType(const TDesC& aParameterName, const TDesC& aSection, TOwnerType& aResult)
  1.1682 +/** convert the ownerType string from ini to EOwnerType */
  1.1683 +	{
  1.1684 +	
  1.1685 +	TBool ret = ETrue;
  1.1686 +	
  1.1687 +	TPtrC ownerTypeString;
  1.1688 +	
  1.1689 +	if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, ownerTypeString))
  1.1690 +		{
  1.1691 +		
  1.1692 +		if (ownerTypeString == KEOwnerProcess )
  1.1693 +			{
  1.1694 +			aResult = EOwnerProcess;
  1.1695 +			}
  1.1696 +		else if (ownerTypeString == KEOwnerThread)
  1.1697 +			{
  1.1698 +			aResult = EOwnerThread;
  1.1699 +			}
  1.1700 +		else
  1.1701 +			{
  1.1702 +			ret = EFalse;
  1.1703 +			}
  1.1704 +		
  1.1705 +		}
  1.1706 +	else
  1.1707 +		{
  1.1708 +		ret = EFalse;
  1.1709 +		}
  1.1710 +
  1.1711 +	return ret;
  1.1712 +	}	
  1.1713 +	
  1.1714 +void CT_FileData::DoCmdFullName(const TDesC& aSection)
  1.1715 +/** get the file fullname */
  1.1716 +	{
  1.1717 +	TBuf<128> name;
  1.1718 +	TInt err = iFile->FullName(name);
  1.1719 +	
  1.1720 +	INFO_PRINTF2(_L("FullName() returned  %S"), &name);		
  1.1721 +	
  1.1722 +	if(err != KErrNone)
  1.1723 +		{
  1.1724 +		ERR_PRINTF2(_L("FullName() error, returned. %d"), err);
  1.1725 +		SetError(err);	
  1.1726 +		}
  1.1727 +	else
  1.1728 +		{
  1.1729 +		TPtrC path;	
  1.1730 +		if(GET_OPTIONAL_STRING_PARAMETER(KUParamComparePath, aSection, path))
  1.1731 +			{
  1.1732 +			if (path == name)
  1.1733 +				{
  1.1734 +				INFO_PRINTF1(_L("the paths match"));	
  1.1735 +				}
  1.1736 +			else
  1.1737 +				{
  1.1738 +				ERR_PRINTF1(_L("the paths do not match"));
  1.1739 +				SetBlockResult(EFail);
  1.1740 +				}
  1.1741 +			}				
  1.1742 +		}
  1.1743 +	}	
  1.1744 +	
  1.1745 +void CT_FileData::DoCmdNameL(const TDesC& aSection)
  1.1746 +/** get the file name */
  1.1747 +	{
  1.1748 +	TBuf<KDefaultDescSize> name;
  1.1749 +	TInt err = iFile->Name(name);
  1.1750 +	INFO_PRINTF2(_L("Name() returned  %S"), &name);	
  1.1751 +	
  1.1752 +	if(err != KErrNone)
  1.1753 +		{
  1.1754 +		ERR_PRINTF2(_L("Name() error, returned. %d"), err);
  1.1755 +		SetError(err);	
  1.1756 +		}
  1.1757 +	else	
  1.1758 +		{
  1.1759 +		
  1.1760 +				
  1.1761 +		TPtrC compValue;	
  1.1762 +			
  1.1763 +		if (GET_OPTIONAL_STRING_PARAMETER(KUParamCompareValue, aSection, compValue))
  1.1764 +			{
  1.1765 +			if (compValue == name)
  1.1766 +				{
  1.1767 +				INFO_PRINTF3(_L("The names match %S == %S"), &name, &compValue);
  1.1768 +				}
  1.1769 +			else
  1.1770 +				{
  1.1771 +				ERR_PRINTF3(_L("The names do not match %S == %S"), &name, &compValue);			
  1.1772 +				SetBlockResult(EFail);
  1.1773 +				}
  1.1774 +			}		
  1.1775 +		}
  1.1776 +	}	
  1.1777 +
  1.1778 +TBool CT_FileData::ConvertToBlockMapUsage(const TDesC& aParameterName, const TDesC& aSection, TBlockMapUsage& aResult)
  1.1779 +	{
  1.1780 +	
  1.1781 +	TBool ret = ETrue;
  1.1782 +	
  1.1783 +	TPtrC blockmapeUsageString;
  1.1784 +	
  1.1785 +	if(GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, blockmapeUsageString))
  1.1786 +		{
  1.1787 +		
  1.1788 +		if (blockmapeUsageString == KEBlockMapUsagePaging )
  1.1789 +			{
  1.1790 +			aResult = EBlockMapUsagePaging;
  1.1791 +			}
  1.1792 +		else if (blockmapeUsageString == KETestDebug)
  1.1793 +			{
  1.1794 +			aResult = ETestDebug;
  1.1795 +			}
  1.1796 +		else
  1.1797 +			{
  1.1798 +			ret = EFalse;
  1.1799 +			}
  1.1800 +		
  1.1801 +		}
  1.1802 +	else
  1.1803 +		{
  1.1804 +		ret = EFalse;
  1.1805 +		}
  1.1806 +
  1.1807 +	return ret;
  1.1808 +	}	
  1.1809 +	
  1.1810 +void CT_FileData::DoCmdBlockMap(const TDesC& aSection)
  1.1811 +	{
  1.1812 +	TInt64 startPos = 0;
  1.1813 +	GET_OPTIONAL_INT64_PARAMETER(KUParamStartPos, aSection, startPos);
  1.1814 +		
  1.1815 +	SBlockMapInfo blockMapInfo;
  1.1816 +	TInt err = KErrNone;
  1.1817 +	TInt64 endPos = -1;
  1.1818 +	if (GET_OPTIONAL_INT64_PARAMETER(KUParamEndPos, aSection, endPos))
  1.1819 +		{
  1.1820 +		TBlockMapUsage usage;
  1.1821 +		if (ConvertToBlockMapUsage(KUParamUsage, aSection, usage))
  1.1822 +			{
  1.1823 +			err = iFile->BlockMap(blockMapInfo, startPos, endPos, usage);
  1.1824 +			}
  1.1825 +		else
  1.1826 +			{
  1.1827 +			err = iFile->BlockMap(blockMapInfo, startPos, endPos);
  1.1828 +			}
  1.1829 +		}
  1.1830 +	else
  1.1831 +		{
  1.1832 +		TBlockMapUsage usage;
  1.1833 +		if (ConvertToBlockMapUsage(KUParamUsage, aSection, usage))
  1.1834 +			{
  1.1835 +			err = iFile->BlockMap(blockMapInfo, startPos, usage);
  1.1836 +			}
  1.1837 +		else
  1.1838 +			{		
  1.1839 +			err = iFile->BlockMap(blockMapInfo, startPos);
  1.1840 +			}
  1.1841 +		}
  1.1842 +		
  1.1843 +	if (KErrNone != err)
  1.1844 +		{
  1.1845 +		ERR_PRINTF2(_L("BlockMap Returned an error %d"), err);
  1.1846 +		SetError(err);
  1.1847 +		}
  1.1848 +	if (KErrNone == err || KErrCompletion == err)
  1.1849 +		{
  1.1850 +		INFO_PRINTF2(_L("Returned start position %d"), startPos);
  1.1851 +
  1.1852 +		INFO_PRINTF2(_L("Local drive number %d"), blockMapInfo.iLocalDriveNumber);
  1.1853 +		INFO_PRINTF2(_L("Block start address %d"), blockMapInfo.iStartBlockAddress);
  1.1854 +		INFO_PRINTF2(_L("Block start offset %u"), blockMapInfo.iBlockStartOffset);
  1.1855 +		INFO_PRINTF2(_L("Block graduality %u"), blockMapInfo.iBlockGranularity);	
  1.1856 +		}
  1.1857 +	
  1.1858 +	}
  1.1859 +
  1.1860 +//function that adds the buffer to the end of the array
  1.1861 +void CT_FileData::ToArrayL(RPointerArray<HBufC>& aArray, HBufC*& aBuffer)
  1.1862 +	{
  1.1863 +	HBufC* arrayElement = HBufC::NewL(aBuffer->Length());
  1.1864 +	TPtr arrayElementPtr = arrayElement->Des();
  1.1865 +	arrayElementPtr.Copy(*aBuffer);
  1.1866 +	arrayElementPtr.TrimAll();
  1.1867 +	aArray.Append(arrayElement);
  1.1868 +	arrayElement = NULL;
  1.1869 +	}
  1.1870 +	
  1.1871 +
  1.1872 +// helper function to split filemodes or attributes to array
  1.1873 +RPointerArray<HBufC> CT_FileData::SplitL(const TDesC& aInput, const char* aToken)
  1.1874 +	{
  1.1875 +	RPointerArray<HBufC> fileModeArray;
  1.1876 +	HBufC*  buffer = HBufC::NewL(aInput.Length());
  1.1877 +	TPtr bufferPtr = buffer->Des();
  1.1878 +	for (int i=0;i<aInput.Length();i++)
  1.1879 +		{
  1.1880 +		if (aInput[i] == *aToken)
  1.1881 +			{
  1.1882 +			ToArrayL(fileModeArray, buffer);
  1.1883 +			delete buffer;	
  1.1884 +				
  1.1885 +			buffer = NULL;
  1.1886 +			buffer = HBufC::NewL( aInput.Length() - i);	
  1.1887 +			bufferPtr = buffer->Des();
  1.1888 +			}
  1.1889 +		else
  1.1890 +			{
  1.1891 +			bufferPtr.Append(aInput[i]);
  1.1892 +			}
  1.1893 +		}
  1.1894 +	
  1.1895 +	ToArrayL(fileModeArray, buffer);		
  1.1896 +	delete buffer;
  1.1897 +	
  1.1898 +	buffer = NULL;		
  1.1899 +		
  1.1900 +	return fileModeArray;
  1.1901 + 	
  1.1902 +	}
  1.1903 +	
  1.1904 +void CT_FileData::DoCancel(CActive* aActive, TInt aIndex)
  1.1905 +	{
  1.1906 +	TBool	foundActiveObject = EFalse;
  1.1907 +
  1.1908 +	TInt	index=0;
  1.1909 +	TInt	count=0;
  1.1910 +
  1.1911 +	count=iReadCallbackArray.Count();
  1.1912 +	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1.1913 + 		{
  1.1914 + 		if( aActive == iReadCallbackArray[index] )
  1.1915 +			{
  1.1916 +			INFO_PRINTF1(_L("DoCancel iReadCallbackArray called"));
  1.1917 +			foundActiveObject = ETrue;
  1.1918 +			iReadCallbackArray.Remove(index);
  1.1919 +	 		}
  1.1920 +		}
  1.1921 +
  1.1922 +	count=iWriteCallbackArray.Count();
  1.1923 +	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1.1924 + 		{
  1.1925 + 		if( aActive == iWriteCallbackArray[index] )
  1.1926 +			{
  1.1927 +			INFO_PRINTF1(_L("DoCancel iWriteCallbackArray called"));
  1.1928 +			foundActiveObject = ETrue;
  1.1929 +			iWriteCallbackArray.Remove(index);
  1.1930 +	 		}
  1.1931 +		}
  1.1932 +
  1.1933 +	// See if it is in iFlushCallbackArray
  1.1934 +	count=iFlushCallbackArray.Count();
  1.1935 +	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1.1936 + 		{
  1.1937 + 		if( aActive == iFlushCallbackArray[index] )
  1.1938 +			{
  1.1939 +			INFO_PRINTF1(_L("DoCancel iFlushCallbackArray called"));
  1.1940 +			foundActiveObject = ETrue;
  1.1941 +			iFlushCallbackArray.Remove(index);
  1.1942 +	 		}
  1.1943 +		}
  1.1944 +
  1.1945 + 	if( foundActiveObject )
  1.1946 + 		{
  1.1947 +		TInt	err = aActive->iStatus.Int();
  1.1948 +		if( err != KErrNone )
  1.1949 +			{
  1.1950 +			ERR_PRINTF2(_L("DoCancel Error %d"), err);
  1.1951 +			SetAsyncError( aIndex, err );
  1.1952 +			}
  1.1953 +
  1.1954 +		// Reset the outstanding request state
  1.1955 +		DecOutstanding();
  1.1956 +
  1.1957 +		delete aActive;
  1.1958 +		}
  1.1959 +	else
  1.1960 +		{
  1.1961 + 		ERR_PRINTF1(_L("Stray DoCancel signal"));
  1.1962 + 		SetBlockResult(EFail);
  1.1963 +		}
  1.1964 +	}
  1.1965 +
  1.1966 +void CT_FileData::RunL(CActive* aActive, TInt aIndex)
  1.1967 +	{
  1.1968 +
  1.1969 +	
  1.1970 +	TBool	foundActiveObject = EFalse;
  1.1971 +	TInt	index=0;
  1.1972 +	TInt	count=0;
  1.1973 +	
  1.1974 +	count=iReadCallbackArray.Count();
  1.1975 +	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1.1976 + 		{
  1.1977 + 		if( aActive == iReadCallbackArray[index] )
  1.1978 +			{
  1.1979 +			foundActiveObject = ETrue;
  1.1980 +			TInt	err = aActive->iStatus.Int();
  1.1981 +			
  1.1982 +			TBuf<KDefaultDescSize> info;
  1.1983 +			info.Copy(iReadCallbackArray[index]->iFileData->Des());
  1.1984 +			INFO_PRINTF2(_L("readed \"%S\" from file"), &info);
  1.1985 +			
  1.1986 +			HandleExpectedString(iReadCallbackArray[index]->iFileData->Des(), *iReadCallbackArray[index]->iSection);
  1.1987 +			
  1.1988 +			if( err != KErrNone )
  1.1989 +				{
  1.1990 +				ERR_PRINTF2(_L("Async Read error %d"), err);
  1.1991 +				SetAsyncError( aIndex, err );
  1.1992 +				}
  1.1993 +			else
  1.1994 +				{
  1.1995 +				INFO_PRINTF1(_L("Succesfully completed Async Read"));
  1.1996 +				}
  1.1997 +				
  1.1998 +			iReadCallbackArray.Remove(index);	
  1.1999 +			delete aActive;
  1.2000 +			
  1.2001 +	 		}
  1.2002 +		}
  1.2003 +		
  1.2004 +	count=iWriteCallbackArray.Count();
  1.2005 +	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1.2006 + 		{
  1.2007 + 		if( aActive == iWriteCallbackArray[index] )
  1.2008 +			{
  1.2009 +			foundActiveObject = ETrue;
  1.2010 +			TInt	err = aActive->iStatus.Int();
  1.2011 +			
  1.2012 +			if( err != KErrNone )
  1.2013 +				{
  1.2014 +				ERR_PRINTF2(_L("Async Write Error %d"), err);
  1.2015 +				SetAsyncError( aIndex, err );
  1.2016 +				}				
  1.2017 +			else
  1.2018 +				{
  1.2019 +				INFO_PRINTF1(_L("Succesfully completed Async Write"));
  1.2020 +				}
  1.2021 +			iWriteCallbackArray.Remove(index);				
  1.2022 +			delete aActive;			
  1.2023 +	 		}
  1.2024 +		}	
  1.2025 +		
  1.2026 +	count=iFlushCallbackArray.Count();
  1.2027 +	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1.2028 + 		{
  1.2029 + 		if( aActive == iFlushCallbackArray[index] )
  1.2030 +			{
  1.2031 +			foundActiveObject = ETrue;
  1.2032 +			TInt	err = aActive->iStatus.Int();
  1.2033 +			
  1.2034 +			if( err != KErrNone )
  1.2035 +				{
  1.2036 +				ERR_PRINTF2(_L("Async Flush Error %d"), err);
  1.2037 +				SetAsyncError( aIndex, err );
  1.2038 +				}				
  1.2039 +			iFlushCallbackArray.Remove(index);				
  1.2040 +			delete aActive;			
  1.2041 +	 		}
  1.2042 +		}				
  1.2043 +	
  1.2044 +	DecOutstanding();
  1.2045 +	}
  1.2046 +
  1.2047 +void CT_FileData::PrintFileAttributes(TUint aAttValue)
  1.2048 +/** Prints file attributes */
  1.2049 +	{
  1.2050 +	if ((aAttValue & KEntryAttNormal) == KEntryAttNormal)
  1.2051 +		{
  1.2052 +		INFO_PRINTF1(_L("KEntryAttNormal"));
  1.2053 +		}
  1.2054 +	if ((aAttValue & KEntryAttReadOnly) == KEntryAttReadOnly)
  1.2055 +		{
  1.2056 +		INFO_PRINTF1(_L("KEntryAttReadOnly"));
  1.2057 +		}
  1.2058 +		
  1.2059 +	if ((aAttValue & KEntryAttHidden) == KEntryAttHidden)
  1.2060 +		{
  1.2061 +		INFO_PRINTF1(_L("KEntryAttHidden"));
  1.2062 +		}
  1.2063 +
  1.2064 +	if ((aAttValue & KEntryAttSystem) == KEntryAttSystem)
  1.2065 +		{
  1.2066 +		INFO_PRINTF1(_L("KEntryAttSystem"));
  1.2067 +		}
  1.2068 +
  1.2069 +	if ((aAttValue & KEntryAttVolume) == KEntryAttVolume)
  1.2070 +		{
  1.2071 +		INFO_PRINTF1(_L("KEntryAttVolume"));
  1.2072 +		}
  1.2073 +
  1.2074 +	if ((aAttValue & KEntryAttDir) == KEntryAttDir)
  1.2075 +		{
  1.2076 +		INFO_PRINTF1(_L("KEntryAttDir"));
  1.2077 +		}
  1.2078 +
  1.2079 +	if ((aAttValue & KEntryAttArchive) == KEntryAttArchive)
  1.2080 +		{
  1.2081 +		INFO_PRINTF1(_L("KEntryAttArchive"));
  1.2082 +		}
  1.2083 +
  1.2084 +	if ((aAttValue & KEntryAttXIP) == KEntryAttXIP)
  1.2085 +		{
  1.2086 +		INFO_PRINTF1(_L("KEntryAttXIP"));
  1.2087 +		}
  1.2088 +
  1.2089 +	if ((aAttValue & KEntryAttRemote) == KEntryAttRemote)
  1.2090 +		{
  1.2091 +		INFO_PRINTF1(_L("KEntryAttRemote"));
  1.2092 +		}	
  1.2093 +	}
  1.2094 +