os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_FindFileData.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 #include "T_FindFileData.h"
    20 
    21 // Commands
    22 _LIT( KCmdDelete,				"~" );
    23 _LIT( KCmdNew,					"new" );
    24 _LIT( KCmdFile,					"File" );
    25 _LIT( KCmdFind,					"Find" );
    26 _LIT( KCmdFindByDir, 			"FindByDir" );
    27 _LIT( KCmdFindByPath,			"FindByPath" );
    28 _LIT( KCmdFindWild,				"FindWild" );
    29 _LIT( KCmdFindWildByDir,		"FindWildByDir" );
    30 _LIT( KCmdFindWildByPath,		"FindWildByPath" );
    31 _LIT( KCmdSetFindMask,			"SetFindMask" );
    32 
    33 // Parameters
    34 _LIT( KParamFileName,			"filename" );
    35 _LIT( KParamFileSession,		"FileSession" );
    36 _LIT( KParamExpected,			"expected" );
    37 _LIT( KParamPathList,			"pathlist" );
    38 _LIT( KDriveAtt,				"drive_att");
    39 _LIT( KDirWrapper,				"dir_wrapper");
    40 
    41 // Utility variables
    42 _LIT(KDriveAttLocalStr,				"KDriveAttLocal");
    43 _LIT(KDriveAttRomStr,				"KDriveAttRom");
    44 _LIT(KDriveAttRedirectedStr,		"KDriveAttRedirected");
    45 _LIT(KDriveAttSubstedStr,			"KDriveAttSubsted");
    46 _LIT(KDriveAttInternalStr,			"KDriveAttInternal");
    47 _LIT(KDriveAttRemovableStr,			"KDriveAttRemovable");
    48 
    49 
    50 CT_FindFileData* CT_FindFileData::NewL()
    51 /**
    52 * Two phase constructor
    53 */
    54 	{
    55 	CT_FindFileData* ret = new (ELeave) CT_FindFileData();
    56 	CleanupStack::PushL( ret );
    57 	ret->ConstructL();
    58 	CleanupStack::Pop( ret );
    59 	return ret;
    60 	}
    61 
    62 CT_FindFileData::CT_FindFileData()
    63 :	iFindFile(NULL)
    64 /**
    65 * Protected constructor. First phase construction
    66 */
    67 	{
    68 	}
    69 	
    70 void CT_FindFileData::ConstructL()
    71 /**
    72 * Protected constructor. Second phase construction
    73 */
    74 	{
    75 	}
    76 	
    77 CT_FindFileData::~CT_FindFileData()
    78 /**
    79 * Destructor.
    80 */
    81 	{
    82 	DoCleanup();
    83 	}
    84 	
    85 TAny* CT_FindFileData::GetObject()
    86 /**
    87 * Return a pointer to the object that the data wraps
    88 *
    89 * @return pointer to the object that the data wraps
    90 */
    91 	{
    92 	return iFindFile;
    93 	}
    94 
    95 TBool CT_FindFileData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/  )
    96 /**
    97 * Process a command read from the ini file
    98 *
    99 * @param aCommand	the command to process
   100 * @param aSection		the entry in the ini file requiring the command to be processed
   101 *
   102 * @return ETrue if the command is processed
   103 */
   104 	{
   105 	TBool retVal = ETrue;
   106 	
   107 	if ( aCommand == KCmdDelete )
   108 		{
   109 		DoCleanup();
   110 		}
   111 	else if ( aCommand == KCmdFile )
   112 		{
   113 		DoCmdFile( aSection );
   114 		}
   115 	else if ( aCommand == KCmdFind )
   116 		{
   117 		DoCmdFind( aSection );
   118 		}
   119 	else if ( aCommand == KCmdFindByDir )
   120 		{
   121 		DoCmdFindByDir( aSection );
   122 		}
   123 	else if ( aCommand == KCmdFindByPath )
   124 		{
   125 		DoCmdFindByPath( aSection );
   126 		}
   127 	else if ( aCommand == KCmdFindWild )
   128 		{
   129 		DoCmdFindWildL( aSection );
   130 		}
   131 	else if ( aCommand == KCmdFindWildByDir )
   132 		{
   133 		DoCmdFindWildByDirL( aSection );
   134 		}
   135 	else if ( aCommand == KCmdFindWildByPath )
   136 		{
   137 		DoCmdFindWildByPathL( aSection );
   138 		}
   139 	else if ( aCommand == KCmdNew )
   140 		{
   141 		DoCmdNew( aSection);
   142 		}
   143 	else if ( aCommand == KCmdSetFindMask )
   144 		{
   145 		DoCmdSetFindMask( aSection);
   146 		}
   147 	else
   148 	    {
   149 	    retVal = EFalse;    
   150 	    }
   151 	
   152 	return retVal;
   153 	}
   154 	
   155 void CT_FindFileData::DoCleanup()
   156 /** Deletes TFindFile class instance */
   157 	{
   158 	INFO_PRINTF1( _L( "Delete TFindFile class instance" ) );
   159 	delete iFindFile;
   160 	iFindFile = NULL;
   161 	}
   162 	
   163 void CT_FindFileData::DoCmdFile( const TDesC& aSection )
   164 /** calls File() and comaperes the result with the expected */
   165 	{
   166 	TPtrC strResult;
   167 	strResult.Set( iFindFile->File() );
   168 	INFO_PRINTF2( _L( "File(): %S" ),  &strResult );
   169 	
   170 	TPtrC strExpected;
   171 	if ( GET_OPTIONAL_STRING_PARAMETER (KParamExpected, aSection, strExpected) )
   172 		{
   173 		if ( strExpected.CompareF(strResult) )
   174 			{
   175 			ERR_PRINTF3( _L( "File returned %S, expected %S") , &strResult, &strExpected );
   176 			SetBlockResult( EFail );
   177 			}
   178 		}
   179 	}
   180 	
   181 void CT_FindFileData::DoCmdFind( const TDesC& /*aSection*/ )
   182 /** performs a search of a file using Find */
   183 	{
   184 	TInt result = iFindFile->Find();
   185 	
   186 	if( result != KErrNone)
   187 		{
   188 		ERR_PRINTF2( _L( "Find() return error = %d"), result );
   189 		SetError(result);
   190 		}
   191 	}
   192 	
   193 void CT_FindFileData::DoCmdFindByDir( const TDesC& aSection )
   194 /** performs a search of a file using FindByDir */
   195 	{
   196 	TPtrC fileName;	
   197 	if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
   198 		GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) )
   199 		{
   200 		TInt err = iFindFile->FindByDir( fileName, iPathList );
   201 		
   202 		if( err != KErrNone)
   203 			{
   204 			ERR_PRINTF2( _L( "FindByDir() return error = %d"), err );
   205 			SetError(err);
   206 			}		
   207 		}
   208 	}
   209 
   210 void CT_FindFileData::DoCmdFindByPath( const TDesC& aSection )
   211 /** performs a search of a file using FindByPath */
   212 	{
   213 	TPtrC fileName;	
   214 	if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
   215 		GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) )
   216 		{
   217 		TInt err = iFindFile->FindByPath( fileName, &iPathList );
   218 		
   219 		if( err != KErrNone)
   220 			{
   221 			ERR_PRINTF2( _L( "FindByPath() return error = %d"), err );
   222 			SetError(err);
   223 			}
   224 		
   225 		}
   226 	
   227 	}
   228 	
   229 void CT_FindFileData::DoCmdFindWildL( const TDesC& aSection)
   230 /** performs a search of a file using FindWild */
   231 	{
   232 	TPtrC dirWrapperName;
   233 	if (GET_MANDATORY_STRING_PARAMETER(KDirWrapper, aSection, dirWrapperName))
   234 		{
   235 		CT_DirData *dirWrapper = NULL;
   236 		TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
   237 		
   238 		if( dirWrapper && (error == KErrNone) )
   239 			{
   240 			CDir* dir = NULL;
   241 			TInt err = iFindFile->FindWild( dir );
   242 		
   243 			if( err != KErrNone)
   244 				{
   245 				ERR_PRINTF2( _L( "FindWild() return error = %d"), err );
   246 				SetError(err);
   247 				}
   248 			else
   249 				{
   250 				dirWrapper->SetObjectL(dir);
   251 				}
   252 			}
   253 		else
   254 			{
   255 			ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
   256 			SetBlockResult( EFail );
   257 			}
   258 		}
   259 	}
   260 	
   261 void CT_FindFileData::DoCmdFindWildByDirL( const TDesC& aSection )
   262 /** performs a search of a file using FindWildByDir */
   263 	{
   264 	TPtrC fileName;	
   265 	TPtrC dirWrapperName;
   266 	if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
   267 		GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) &&
   268 		GET_MANDATORY_STRING_PARAMETER( KDirWrapper, aSection, dirWrapperName) )
   269 		{
   270 		CT_DirData *dirWrapper = NULL;
   271 		TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
   272 		
   273 		if(dirWrapper && (error == KErrNone) )
   274 			{	
   275 			CDir* dir = NULL;
   276 			TInt err = iFindFile->FindWildByDir( fileName, iPathList, dir );
   277 			
   278 			if( err != KErrNone)
   279 				{
   280 				ERR_PRINTF2( _L( "FindWildByDir() return error = %d"), err );
   281 				SetError(err);
   282 				}
   283 			else
   284 				{
   285 				dirWrapper->SetObjectL(dir);
   286 				}
   287 			}
   288 		else
   289 			{
   290 			ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
   291 			SetBlockResult( EFail );
   292 			}
   293 		}
   294 	}
   295 	
   296 void CT_FindFileData::DoCmdFindWildByPathL( const TDesC& aSection )
   297 /** performs a search of a file using FindWildByPath */
   298 	{
   299 	TPtrC fileName;	
   300 	TPtrC dirWrapperName;
   301 	if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
   302 		GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) &&
   303 		GET_MANDATORY_STRING_PARAMETER( KDirWrapper, aSection, dirWrapperName) )
   304 		{
   305 		CT_DirData *dirWrapper = NULL;
   306 		TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
   307 		
   308 		if( dirWrapper && (error == KErrNone))
   309 			{
   310 			CDir* dir = NULL;
   311 			TInt err = iFindFile->FindWildByPath( fileName, &iPathList, dir );
   312 			
   313 			if( err != KErrNone)
   314 				{
   315 				ERR_PRINTF2( _L( "FindWildByPath() return error = %d"), err );
   316 				SetError(err);
   317 				}
   318 			else
   319 				{
   320 				dirWrapper->SetObjectL(dir);
   321 				}
   322 			}
   323 		else
   324 			{
   325 			ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
   326 			SetBlockResult( EFail );
   327 			}
   328 		}
   329 	
   330 	}
   331 
   332 	
   333 void CT_FindFileData::DoCmdNew( const TDesC& aSection )
   334 /** Creates new TFindFile class instance */
   335 	{
   336 	DoCleanup();
   337 	
   338 	TPtrC fsObjectName;	
   339 	if( GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, fsObjectName ) )
   340 		{
   341 		RFs* fsObject = NULL;
   342 		TRAPD( err, fsObject = (RFs*)GetDataObjectL(fsObjectName));
   343 		if ( err == KErrNone )
   344 			{
   345 			INFO_PRINTF1( _L( "Create new TFindFile class instance." ) );
   346 			TRAP( err, iFindFile = new (ELeave) TFindFile( *fsObject ) );
   347 			if ( err != KErrNone )
   348 				{
   349 				ERR_PRINTF3( _L( "new TFindFile(%S) error %d" ), &fsObjectName, err );
   350 				SetBlockResult( EFail );
   351 				}
   352 			}
   353 		else
   354 			{
   355 			ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &fsObjectName, err );
   356 			SetBlockResult( EFail );
   357 			}
   358 		}
   359 	}
   360  
   361 void CT_FindFileData::DoCmdSetFindMask( const TDesC& aSection )
   362 /** Specify a combination of drive attributes */
   363 	{
   364 	TUint iniMask;
   365 	if( GetDriveAttsFromConfig( aSection, iniMask ) )
   366 		{
   367 		INFO_PRINTF2( _L( "Mask is  %d"), iniMask );
   368 		TInt err = iFindFile->SetFindMask( iniMask );
   369 		
   370 		if ( err != KErrNone)
   371 			{
   372 			ERR_PRINTF2( _L( "SetFindMask return error = %d"), err );
   373 			SetError( err );
   374 			}
   375 		else
   376 			{
   377 			INFO_PRINTF1( _L( "SetFindMask OK"));
   378 			}
   379 		}	
   380 	}
   381 
   382 
   383 TBool CT_FindFileData::ConvertToDriveAtts(const TDesC& aDriveAttStr, TUint& aDriveAtt)
   384 /** Convert string to mask */
   385 	{
   386 	TBool	ret = ETrue;
   387 	if ( aDriveAttStr==KDriveAttLocalStr )
   388 		{
   389 		aDriveAtt=KDriveAttLocal;
   390 		}
   391 	else if ( aDriveAttStr==KDriveAttRomStr )
   392 		{
   393 		aDriveAtt=KDriveAttRom;
   394 		}
   395 	else if ( aDriveAttStr==KDriveAttRedirectedStr )
   396 		{
   397 		aDriveAtt=KDriveAttRedirected;
   398 		}
   399 	else if ( aDriveAttStr==KDriveAttSubstedStr )
   400 		{
   401 		aDriveAtt=KDriveAttSubsted;
   402 		}
   403 	else if ( aDriveAttStr==KDriveAttInternalStr )
   404 		{
   405 		aDriveAtt=KDriveAttInternal;
   406 		}
   407 	else if ( aDriveAttStr==KDriveAttRemovableStr )
   408 		{
   409 		aDriveAtt=KDriveAttRemovable;
   410 		}
   411 	else
   412 		{
   413 		TInt	location = aDriveAttStr.Match(_L("*|*"));
   414 		if( location!=KErrNotFound )
   415 			{
   416 			//Converting Left part of the data
   417 			TPtrC	tempStr = aDriveAttStr.Left(location);
   418 			ret=ConvertToDriveAtts(tempStr, aDriveAtt);
   419 
   420 			//Converting right data can be with another "|"
   421 			tempStr.Set(aDriveAttStr.Mid(location+1));
   422 
   423 			TUint	driveAttTmp;
   424 			if ( ConvertToDriveAtts(tempStr, driveAttTmp) )
   425 				{
   426 				aDriveAtt=aDriveAtt|driveAttTmp;
   427 				}
   428 			else
   429 				{
   430 				ret=EFalse;
   431 				}
   432 			}
   433 		else
   434 			{
   435 			ret=EFalse;
   436 			}
   437 		}
   438 
   439 	return ret;
   440 	}
   441 		
   442 	
   443 TBool CT_FindFileData::GetDriveAttsFromConfig(const TDesC& aSection, TUint& aDriveAtt)
   444 	{
   445 	TPtrC	driveAttStr;
   446 	TBool ret = GET_MANDATORY_STRING_PARAMETER(KDriveAtt(), aSection, driveAttStr);
   447 	if ( ret )
   448 		{
   449 		aDriveAtt = 0;
   450 		if ( !ConvertToDriveAtts(driveAttStr, aDriveAtt) )
   451 			{
   452 			TInt	intTemp;
   453 			ret=GET_MANDATORY_INT_PARAMETER(KDriveAtt(), aSection, intTemp);
   454 			if ( ret )
   455 				{
   456 				aDriveAtt=intTemp;
   457 				}
   458 			}
   459 		}
   460 
   461 	return ret;
   462 	}
   463 
   464