baseapitest/basesvs/validation/f32/sfsrv/src/T_OpenFileScanData.cpp
changeset 0 a41df078684a
child 15 4122176ea935
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 the License "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 #include "T_OpenFileScanData.h"
       
    19 #include "FileserverUtil.h"
       
    20 
       
    21 //Constants
       
    22 const TInt	KBufferLength		= 64;
       
    23 
       
    24 
       
    25 // Commands
       
    26 _LIT( KCmdDestructor,					"~" );
       
    27 _LIT( KCmdNew,						"new" );
       
    28 _LIT( KCmdNextL,					"NextL" );
       
    29 _LIT( KCmdThreadId,					"ThreadId" );
       
    30 
       
    31 // Parameters
       
    32 _LIT( KParamFileSession,				"FileSession" );
       
    33 _LIT( KParamExpectedFileName,			"expected_filename%d");
       
    34 _LIT( KParamDirWrapper,					"wrapper");
       
    35 
       
    36 
       
    37 CT_OpenFileScanData* CT_OpenFileScanData::NewL()
       
    38 /**
       
    39 * Two phase constructor
       
    40 */
       
    41 	{
       
    42 	CT_OpenFileScanData* ret = new (ELeave) CT_OpenFileScanData();
       
    43 	CleanupStack::PushL( ret );
       
    44 	ret->ConstructL();
       
    45 	CleanupStack::Pop( ret );
       
    46 	return ret;
       
    47 	}
       
    48 
       
    49 CT_OpenFileScanData::CT_OpenFileScanData()
       
    50 :	iOpenFileScan(NULL)
       
    51 /**
       
    52 * Protected constructor. First phase construction
       
    53 */
       
    54 	{
       
    55 	}
       
    56 	
       
    57 void CT_OpenFileScanData::ConstructL()
       
    58 /**
       
    59 * Protected constructor. Second phase construction
       
    60 */
       
    61 	{
       
    62 	}
       
    63 	
       
    64 CT_OpenFileScanData::~CT_OpenFileScanData()
       
    65 /**
       
    66 * Destructor.
       
    67 */
       
    68 	{
       
    69 	DoCleanup();
       
    70 	}
       
    71 	
       
    72 void CT_OpenFileScanData::DoCleanup()
       
    73 /**
       
    74 * Contains cleanup implementation
       
    75 */
       
    76 	{		
       
    77 	delete iOpenFileScan;
       
    78 	iOpenFileScan = NULL;
       
    79 	}
       
    80 	
       
    81 TAny* CT_OpenFileScanData::GetObject()
       
    82 /**
       
    83 * Return a pointer to the object that the data wraps
       
    84 *
       
    85 * @return pointer to the object that the data wraps
       
    86 */
       
    87 	{
       
    88 	return iOpenFileScan;
       
    89 	}
       
    90 
       
    91 TBool CT_OpenFileScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
    92 /**
       
    93 * Process a command read from the ini file
       
    94 *
       
    95 * @param aCommand	the command to process
       
    96 * @param aSection		the entry in the ini file requiring the command to be processed
       
    97 *
       
    98 * @return ETrue if the command is processed
       
    99 */
       
   100 	{
       
   101 	TBool retVal = ETrue;
       
   102 	
       
   103 	if ( aCommand == KCmdDestructor )
       
   104 		{
       
   105 		DoCleanup();
       
   106 		}
       
   107 	else if ( aCommand == KCmdNew )
       
   108 		{
       
   109 		DoCmdNew( aSection );
       
   110 		}
       
   111 	else if ( aCommand == KCmdNextL )
       
   112 		{
       
   113 		DoCmdNextL( aSection );
       
   114 		}
       
   115 	else if ( aCommand == KCmdThreadId )
       
   116 		{
       
   117 		DoCmdThreadId( aSection );
       
   118 		}
       
   119 	else
       
   120 	    {
       
   121 	    retVal = EFalse;    
       
   122 	    }
       
   123 	
       
   124 	return retVal;
       
   125 	}
       
   126 	
       
   127 void CT_OpenFileScanData::DoCmdNew( const TDesC& aSection )
       
   128 /** Creates new TOpenFileScan class instance */
       
   129 	{
       
   130 	TPtrC rfsName;
       
   131 	RFs* rfs = NULL;
       
   132 	if ( GetRfsParam( aSection, rfs, rfsName ) )
       
   133 		{
       
   134 		INFO_PRINTF2( _L( "Create new TOpenFileScan(%S) class instance." ), &rfsName );
       
   135 		
       
   136 		// do create		
       
   137 		TRAPD( err, iOpenFileScan = new (ELeave) TOpenFileScan( *rfs ) );
       
   138 		if ( err != KErrNone )
       
   139 			{
       
   140 			ERR_PRINTF3( _L( "new TOpenFileScan(%S) error=%d" ), &rfsName, err );
       
   141 			SetError( err );
       
   142 			}
       
   143 		}
       
   144 	}
       
   145 	
       
   146 void CT_OpenFileScanData::DoCmdNextL( const TDesC& aSection )
       
   147 /** Calls NextL() function */
       
   148 	{
       
   149 	RPointerArray<TPath> pathsToFind;
       
   150 	CleanupResetAndDestroyPushL(pathsToFind);
       
   151 	
       
   152 	// Read expected file names into array
       
   153 	TBool eof = EFalse;
       
   154 	TInt index = 0;
       
   155 	do
       
   156 		{
       
   157 		TBuf<KBufferLength> tempStore;
       
   158 		tempStore.Format(KParamExpectedFileName(), ++index);
       
   159 		TPtrC fileName;
       
   160 		eof = !GET_OPTIONAL_STRING_PARAMETER(tempStore, aSection, fileName);
       
   161 		if (!eof)
       
   162 			{
       
   163 			TPath* path = new(ELeave) TPath(fileName);
       
   164 			CleanupStack::PushL(path);
       
   165 			pathsToFind.AppendL(path);
       
   166 			CleanupStack::Pop();
       
   167 			}
       
   168 		}
       
   169 	while (!eof);
       
   170  
       
   171 	TInt err = KErrNone;
       
   172 
       
   173 	CFileList* fileList = NULL;
       
   174 	if(pathsToFind.Count() == 0)
       
   175 		{
       
   176 		TRAP( err, iOpenFileScan->NextL( fileList ));
       
   177 		
       
   178 		if( fileList)
       
   179 			{
       
   180 			CleanupStack::PushL(fileList);
       
   181 			// NB! CDir == CFileList
       
   182 			TPtrC wrapperName;
       
   183 			if (!err && GET_OPTIONAL_STRING_PARAMETER(KParamDirWrapper, aSection, wrapperName))
       
   184 				{
       
   185 				CT_DirData *wrapper = NULL;
       
   186 				
       
   187 				TRAPD( error, wrapper = static_cast<CT_DirData*>(GetDataWrapperL(wrapperName)))
       
   188 				
       
   189 				if( wrapper && (error==KErrNone) )
       
   190 					{
       
   191 					wrapper->SetObjectL(fileList);
       
   192 					fileList = NULL;
       
   193 					}
       
   194 				else
       
   195 					{
       
   196 					ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &wrapperName );
       
   197 					SetBlockResult( EFail );
       
   198 					}
       
   199 				}
       
   200 			
       
   201 			CleanupStack::Pop();
       
   202 			delete fileList;
       
   203 			fileList = NULL;
       
   204 			}
       
   205 		}
       
   206 	else
       
   207 		{
       
   208 		// Check expected file names
       
   209 		for( eof = EFalse ; !eof && (pathsToFind.Count() > 0);  ) 
       
   210 			{
       
   211 			iOpenFileScan->NextL(fileList);
       
   212 			if( fileList)
       
   213 				{
       
   214 				for ( TInt i = 0; i < fileList->Count(); i++ )
       
   215 					{
       
   216 					INFO_PRINTF1((*fileList)[i].iName );
       
   217 					for(TInt j =  pathsToFind.Count() - 1 ; j >= 0; j--)
       
   218 						{			
       
   219 						if( *(pathsToFind[j]) == (*fileList)[i].iName )
       
   220 							{
       
   221 							TPath* elemForRemove = pathsToFind[j];
       
   222 							pathsToFind.Remove(j);
       
   223 							delete elemForRemove;
       
   224 							}
       
   225 						}
       
   226 					}
       
   227 					
       
   228 				delete fileList;
       
   229 				fileList = NULL;
       
   230 				}
       
   231 			else
       
   232 				{
       
   233 				eof = ETrue;
       
   234 				}
       
   235 			}
       
   236 			
       
   237 		// Some file names are not found
       
   238 		if (pathsToFind.Count() > 0)
       
   239 			{
       
   240 			for(TInt i = 0; i < pathsToFind.Count(); i++)
       
   241 				{
       
   242 				ERR_PRINTF2( _L( "File %S haven't been found" ), pathsToFind[i] );
       
   243 				}
       
   244 			SetBlockResult( EFail );
       
   245 			}
       
   246 		}
       
   247 	
       
   248    	if ( err != KErrNone )
       
   249 		{
       
   250 		ERR_PRINTF2( _L( "NextL() error=%d" ), err );
       
   251 		SetError( err );
       
   252 		}
       
   253 	
       
   254 	//Free massive
       
   255 	CleanupStack::PopAndDestroy(&pathsToFind);
       
   256 	}
       
   257 	
       
   258 // Calls ThreadId() function
       
   259 void CT_OpenFileScanData::DoCmdThreadId( const TDesC& aSection )
       
   260 	{
       
   261 	TPtrC rfsName;
       
   262 	
       
   263 	if(GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, rfsName))
       
   264 		{
       
   265 		CT_FsData *fsData = NULL;
       
   266 		
       
   267 		TRAPD(err,fsData =  static_cast<CT_FsData*>(GetDataWrapperL(rfsName)));
       
   268 		
       
   269 		if( err==KErrNone )
       
   270 			{
       
   271 			//Recieving thread ids.
       
   272 			TUint64 rfsThreadId = fsData->ThreadId();
       
   273 			TUint64 id = iOpenFileScan->ThreadId().Id();
       
   274 			//Comparing id's
       
   275 			if(rfsThreadId != id)
       
   276 				{
       
   277 				ERR_PRINTF3( _L( "Diffrent thread id's %u %u"),rfsThreadId,id);
       
   278 				SetBlockResult( EFail );
       
   279 				}
       
   280 			}
       
   281 		else
       
   282 			{
       
   283 			ERR_PRINTF2( _L( "Wrong session name:%S"),&rfsName);
       
   284 			SetBlockResult( EFail );
       
   285 			}
       
   286 		}
       
   287 
       
   288 	}
       
   289 	
       
   290 TBool CT_OpenFileScanData::GetRfsParam( const TDesC& aSection, RFs*& aRfs, TPtrC& aRfsName )
       
   291 /** this function retrieves the "rfs" current command parameter using
       
   292 *	GET_MANDATORY_STRING_PAREMETER macro
       
   293 * 
       
   294 *	@param	aSection		- the entry in the ini file requiring the command to be processed
       
   295 *	@param	aRfs 		- the returned RFs pointer
       
   296 *	@param	aRfsName	- the returned RFs's name as stated in ini file
       
   297 *
       
   298 *	@return	ETrue 		- if the the parameter has been successfully read and interpreted
       
   299 *				EFalse		- otherwise
       
   300 */
       
   301 	{
       
   302 	TBool result = EFalse;
       
   303 	
       
   304 	if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, aRfsName ) )
       
   305 		{
       
   306 		TRAPD( err, aRfs = (RFs*)GetDataObjectL( aRfsName ) );
       
   307 		
       
   308 		if ( err != KErrNone )
       
   309 			{
       
   310 			ERR_PRINTF3( _L( "Unrecognized object name: %S (error = %d)" ), &aRfsName, err );
       
   311 			SetBlockResult( EFail );
       
   312 			}
       
   313 		else
       
   314 			{
       
   315 			result = ETrue;	
       
   316 			}
       
   317 		}
       
   318 	
       
   319 	return result;
       
   320 	}
       
   321