os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_OpenFileScanData.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_OpenFileScanData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,322 @@
     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 +#include "T_OpenFileScanData.h"
    1.23 +#include "FileserverUtil.h"
    1.24 +
    1.25 +//Constants
    1.26 +const TInt	KBufferLength		= 64;
    1.27 +
    1.28 +
    1.29 +// Commands
    1.30 +_LIT( KCmdDestructor,					"~" );
    1.31 +_LIT( KCmdNew,						"new" );
    1.32 +_LIT( KCmdNextL,					"NextL" );
    1.33 +_LIT( KCmdThreadId,					"ThreadId" );
    1.34 +
    1.35 +// Parameters
    1.36 +_LIT( KParamFileSession,				"FileSession" );
    1.37 +_LIT( KParamExpectedFileName,			"expected_filename%d");
    1.38 +_LIT( KParamDirWrapper,					"wrapper");
    1.39 +
    1.40 +
    1.41 +CT_OpenFileScanData* CT_OpenFileScanData::NewL()
    1.42 +/**
    1.43 +* Two phase constructor
    1.44 +*/
    1.45 +	{
    1.46 +	CT_OpenFileScanData* ret = new (ELeave) CT_OpenFileScanData();
    1.47 +	CleanupStack::PushL( ret );
    1.48 +	ret->ConstructL();
    1.49 +	CleanupStack::Pop( ret );
    1.50 +	return ret;
    1.51 +	}
    1.52 +
    1.53 +CT_OpenFileScanData::CT_OpenFileScanData()
    1.54 +:	iOpenFileScan(NULL)
    1.55 +/**
    1.56 +* Protected constructor. First phase construction
    1.57 +*/
    1.58 +	{
    1.59 +	}
    1.60 +	
    1.61 +void CT_OpenFileScanData::ConstructL()
    1.62 +/**
    1.63 +* Protected constructor. Second phase construction
    1.64 +*/
    1.65 +	{
    1.66 +	}
    1.67 +	
    1.68 +CT_OpenFileScanData::~CT_OpenFileScanData()
    1.69 +/**
    1.70 +* Destructor.
    1.71 +*/
    1.72 +	{
    1.73 +	DoCleanup();
    1.74 +	}
    1.75 +	
    1.76 +void CT_OpenFileScanData::DoCleanup()
    1.77 +/**
    1.78 +* Contains cleanup implementation
    1.79 +*/
    1.80 +	{		
    1.81 +	delete iOpenFileScan;
    1.82 +	iOpenFileScan = NULL;
    1.83 +	}
    1.84 +	
    1.85 +TAny* CT_OpenFileScanData::GetObject()
    1.86 +/**
    1.87 +* Return a pointer to the object that the data wraps
    1.88 +*
    1.89 +* @return pointer to the object that the data wraps
    1.90 +*/
    1.91 +	{
    1.92 +	return iOpenFileScan;
    1.93 +	}
    1.94 +
    1.95 +TBool CT_OpenFileScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
    1.96 +/**
    1.97 +* Process a command read from the ini file
    1.98 +*
    1.99 +* @param aCommand	the command to process
   1.100 +* @param aSection		the entry in the ini file requiring the command to be processed
   1.101 +*
   1.102 +* @return ETrue if the command is processed
   1.103 +*/
   1.104 +	{
   1.105 +	TBool retVal = ETrue;
   1.106 +	
   1.107 +	if ( aCommand == KCmdDestructor )
   1.108 +		{
   1.109 +		DoCleanup();
   1.110 +		}
   1.111 +	else if ( aCommand == KCmdNew )
   1.112 +		{
   1.113 +		DoCmdNew( aSection );
   1.114 +		}
   1.115 +	else if ( aCommand == KCmdNextL )
   1.116 +		{
   1.117 +		DoCmdNextL( aSection );
   1.118 +		}
   1.119 +	else if ( aCommand == KCmdThreadId )
   1.120 +		{
   1.121 +		DoCmdThreadId( aSection );
   1.122 +		}
   1.123 +	else
   1.124 +	    {
   1.125 +	    retVal = EFalse;    
   1.126 +	    }
   1.127 +	
   1.128 +	return retVal;
   1.129 +	}
   1.130 +	
   1.131 +void CT_OpenFileScanData::DoCmdNew( const TDesC& aSection )
   1.132 +/** Creates new TOpenFileScan class instance */
   1.133 +	{
   1.134 +	TPtrC rfsName;
   1.135 +	RFs* rfs = NULL;
   1.136 +	if ( GetRfsParam( aSection, rfs, rfsName ) )
   1.137 +		{
   1.138 +		INFO_PRINTF2( _L( "Create new TOpenFileScan(%S) class instance." ), &rfsName );
   1.139 +		
   1.140 +		// do create		
   1.141 +		TRAPD( err, iOpenFileScan = new (ELeave) TOpenFileScan( *rfs ) );
   1.142 +		if ( err != KErrNone )
   1.143 +			{
   1.144 +			ERR_PRINTF3( _L( "new TOpenFileScan(%S) error=%d" ), &rfsName, err );
   1.145 +			SetError( err );
   1.146 +			}
   1.147 +		}
   1.148 +	}
   1.149 +	
   1.150 +void CT_OpenFileScanData::DoCmdNextL( const TDesC& aSection )
   1.151 +/** Calls NextL() function */
   1.152 +	{
   1.153 +	RPointerArray<TPath> pathsToFind;
   1.154 +	CleanupResetAndDestroyPushL(pathsToFind);
   1.155 +	
   1.156 +	// Read expected file names into array
   1.157 +	TBool eof = EFalse;
   1.158 +	TInt index = 0;
   1.159 +	do
   1.160 +		{
   1.161 +		TBuf<KBufferLength> tempStore;
   1.162 +		tempStore.Format(KParamExpectedFileName(), ++index);
   1.163 +		TPtrC fileName;
   1.164 +		eof = !GET_OPTIONAL_STRING_PARAMETER(tempStore, aSection, fileName);
   1.165 +		if (!eof)
   1.166 +			{
   1.167 +			TPath* path = new(ELeave) TPath(fileName);
   1.168 +			CleanupStack::PushL(path);
   1.169 +			pathsToFind.AppendL(path);
   1.170 +			CleanupStack::Pop();
   1.171 +			}
   1.172 +		}
   1.173 +	while (!eof);
   1.174 + 
   1.175 +	TInt err = KErrNone;
   1.176 +
   1.177 +	CFileList* fileList = NULL;
   1.178 +	if(pathsToFind.Count() == 0)
   1.179 +		{
   1.180 +		TRAP( err, iOpenFileScan->NextL( fileList ));
   1.181 +		
   1.182 +		if( fileList)
   1.183 +			{
   1.184 +			CleanupStack::PushL(fileList);
   1.185 +			// NB! CDir == CFileList
   1.186 +			TPtrC wrapperName;
   1.187 +			if (!err && GET_OPTIONAL_STRING_PARAMETER(KParamDirWrapper, aSection, wrapperName))
   1.188 +				{
   1.189 +				CT_DirData *wrapper = NULL;
   1.190 +				
   1.191 +				TRAPD( error, wrapper = static_cast<CT_DirData*>(GetDataWrapperL(wrapperName)))
   1.192 +				
   1.193 +				if( wrapper && (error==KErrNone) )
   1.194 +					{
   1.195 +					wrapper->SetObjectL(fileList);
   1.196 +					fileList = NULL;
   1.197 +					}
   1.198 +				else
   1.199 +					{
   1.200 +					ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &wrapperName );
   1.201 +					SetBlockResult( EFail );
   1.202 +					}
   1.203 +				}
   1.204 +			
   1.205 +			CleanupStack::Pop();
   1.206 +			delete fileList;
   1.207 +			fileList = NULL;
   1.208 +			}
   1.209 +		}
   1.210 +	else
   1.211 +		{
   1.212 +		// Check expected file names
   1.213 +		for( eof = EFalse ; !eof && (pathsToFind.Count() > 0);  ) 
   1.214 +			{
   1.215 +			iOpenFileScan->NextL(fileList);
   1.216 +			if( fileList)
   1.217 +				{
   1.218 +				for ( TInt i = 0; i < fileList->Count(); i++ )
   1.219 +					{
   1.220 +					INFO_PRINTF1((*fileList)[i].iName );
   1.221 +					for(TInt j =  pathsToFind.Count() - 1 ; j >= 0; j--)
   1.222 +						{			
   1.223 +						if( *(pathsToFind[j]) == (*fileList)[i].iName )
   1.224 +							{
   1.225 +							TPath* elemForRemove = pathsToFind[j];
   1.226 +							pathsToFind.Remove(j);
   1.227 +							delete elemForRemove;
   1.228 +							}
   1.229 +						}
   1.230 +					}
   1.231 +					
   1.232 +				delete fileList;
   1.233 +				fileList = NULL;
   1.234 +				}
   1.235 +			else
   1.236 +				{
   1.237 +				eof = ETrue;
   1.238 +				}
   1.239 +			}
   1.240 +			
   1.241 +		// Some file names are not found
   1.242 +		if (pathsToFind.Count() > 0)
   1.243 +			{
   1.244 +			for(TInt i = 0; i < pathsToFind.Count(); i++)
   1.245 +				{
   1.246 +				ERR_PRINTF2( _L( "File %S haven't been found" ), pathsToFind[i] );
   1.247 +				}
   1.248 +			SetBlockResult( EFail );
   1.249 +			}
   1.250 +		}
   1.251 +	
   1.252 +   	if ( err != KErrNone )
   1.253 +		{
   1.254 +		ERR_PRINTF2( _L( "NextL() error=%d" ), err );
   1.255 +		SetError( err );
   1.256 +		}
   1.257 +	
   1.258 +	//Free massive
   1.259 +	CleanupStack::PopAndDestroy(&pathsToFind);
   1.260 +	}
   1.261 +	
   1.262 +// Calls ThreadId() function
   1.263 +void CT_OpenFileScanData::DoCmdThreadId( const TDesC& aSection )
   1.264 +	{
   1.265 +	TPtrC rfsName;
   1.266 +	
   1.267 +	if(GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, rfsName))
   1.268 +		{
   1.269 +		CT_FsData *fsData = NULL;
   1.270 +		
   1.271 +		TRAPD(err,fsData =  static_cast<CT_FsData*>(GetDataWrapperL(rfsName)));
   1.272 +		
   1.273 +		if( err==KErrNone )
   1.274 +			{
   1.275 +			//Recieving thread ids.
   1.276 +			TUint64 rfsThreadId = fsData->ThreadId();
   1.277 +			TUint64 id = iOpenFileScan->ThreadId().Id();
   1.278 +			//Comparing id's
   1.279 +			if(rfsThreadId != id)
   1.280 +				{
   1.281 +				ERR_PRINTF3( _L( "Diffrent thread id's %u %u"),rfsThreadId,id);
   1.282 +				SetBlockResult( EFail );
   1.283 +				}
   1.284 +			}
   1.285 +		else
   1.286 +			{
   1.287 +			ERR_PRINTF2( _L( "Wrong session name:%S"),&rfsName);
   1.288 +			SetBlockResult( EFail );
   1.289 +			}
   1.290 +		}
   1.291 +
   1.292 +	}
   1.293 +	
   1.294 +TBool CT_OpenFileScanData::GetRfsParam( const TDesC& aSection, RFs*& aRfs, TPtrC& aRfsName )
   1.295 +/** this function retrieves the "rfs" current command parameter using
   1.296 +*	GET_MANDATORY_STRING_PAREMETER macro
   1.297 +* 
   1.298 +*	@param	aSection		- the entry in the ini file requiring the command to be processed
   1.299 +*	@param	aRfs 		- the returned RFs pointer
   1.300 +*	@param	aRfsName	- the returned RFs's name as stated in ini file
   1.301 +*
   1.302 +*	@return	ETrue 		- if the the parameter has been successfully read and interpreted
   1.303 +*				EFalse		- otherwise
   1.304 +*/
   1.305 +	{
   1.306 +	TBool result = EFalse;
   1.307 +	
   1.308 +	if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, aRfsName ) )
   1.309 +		{
   1.310 +		TRAPD( err, aRfs = (RFs*)GetDataObjectL( aRfsName ) );
   1.311 +		
   1.312 +		if ( err != KErrNone )
   1.313 +			{
   1.314 +			ERR_PRINTF3( _L( "Unrecognized object name: %S (error = %d)" ), &aRfsName, err );
   1.315 +			SetBlockResult( EFail );
   1.316 +			}
   1.317 +		else
   1.318 +			{
   1.319 +			result = ETrue;	
   1.320 +			}
   1.321 +		}
   1.322 +	
   1.323 +	return result;
   1.324 +	}
   1.325 +