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