baseapitest/basesvs/validation/f32/sfsrv/src/T_FormatData.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 /**
       
    19 @test
       
    20 @internalComponent
       
    21 
       
    22 This contains CT_FormatData
       
    23 */
       
    24 
       
    25 //	User includes
       
    26 #include "T_FormatData.h"
       
    27 
       
    28 /*@{*/
       
    29 ///	Parameters
       
    30 _LIT(KRFsName,							"RFs");
       
    31 _LIT(KDrive,							"drive");
       
    32 _LIT(KFormat,							"format");
       
    33 _LIT(KSpecialInfo,						"specialinfo");
       
    34 _LIT(KAsync,							"async");
       
    35 _LIT(KEnd,								"end");
       
    36 _LIT(KCount,							"count");
       
    37 
       
    38 //	Format mode
       
    39 _LIT(KFormatHighDensity,				"EHighDensity");
       
    40 _LIT(KFormatLowDensity,					"ELowDensity");
       
    41 _LIT(KFormatFullFormat,					"EFullFormat");
       
    42 _LIT(KFormatQuickFormat,				"EQuickFormat");
       
    43 _LIT(KFormatSpecialFormat,				"ESpecialFormat");
       
    44 _LIT(KFormatForceErase,					"EForceErase");
       
    45 
       
    46 ///	Commands
       
    47 _LIT(KCmdNew,							"new");
       
    48 _LIT(KCmdDestructor,					"~");
       
    49 _LIT(KCmdOpen,							"Open");
       
    50 _LIT(KCmdClose,							"Close");
       
    51 _LIT(KCmdNext,							"Next");
       
    52 /*@}*/
       
    53 
       
    54 CT_FormatData* CT_FormatData::NewL()
       
    55 /**
       
    56  * Two phase constructor
       
    57  */
       
    58 	{
       
    59 	CT_FormatData* ret = new ( ELeave ) CT_FormatData();
       
    60 	CleanupStack::PushL( ret );
       
    61 	ret->ConstructL();
       
    62 	CleanupStack::Pop( ret );
       
    63 	return ret;
       
    64 	}
       
    65 
       
    66 CT_FormatData::CT_FormatData()
       
    67 :	iFormat( NULL )
       
    68 ,	iNext( NULL )
       
    69 ,	iCount( 0 )
       
    70 ,	iCountNextEnd( 0 )
       
    71 /**
       
    72  * Protected constructor. First phase construction
       
    73  */
       
    74 	{
       
    75 	}
       
    76 
       
    77 void CT_FormatData::ConstructL()
       
    78 /**
       
    79  * Protected constructor. Second phase construction
       
    80  */
       
    81 	{
       
    82 	iNext = CActiveCallback::NewL( *this );
       
    83 	}
       
    84 
       
    85 CT_FormatData::~CT_FormatData()
       
    86 /**
       
    87  * Destructor.
       
    88  */
       
    89 	{
       
    90 	delete iNext;
       
    91 	iNext = NULL;
       
    92 	DoCleanup();
       
    93 	}
       
    94 
       
    95 void CT_FormatData::DoCleanup()
       
    96 /**
       
    97  * Contains cleanup implementation
       
    98  */
       
    99 	{
       
   100 	//Deleting RFormat.
       
   101 	if(iFormat != NULL)
       
   102 		{
       
   103 		INFO_PRINTF1( _L("Deleting current RFormat") );
       
   104 		delete iFormat;
       
   105 		iFormat = NULL;
       
   106 		}
       
   107 	}
       
   108 
       
   109 TAny* CT_FormatData::GetObject()
       
   110 /**
       
   111  * Return a pointer to the object that the data wraps
       
   112  *
       
   113  * @return	pointer to the object that the data wraps
       
   114  */
       
   115 	{
       
   116 	return iFormat;
       
   117 	}
       
   118 
       
   119 TBool CT_FormatData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex )
       
   120 /**
       
   121  * Process a command read from the ini file
       
   122  *
       
   123  * @param	aCommand requiring command to be processed
       
   124  * @param	aSection the section in the ini file requiring the command to be processed
       
   125  * @param	aAsyncErrorIndex the index of asynchronous command error code belongs to.
       
   126  *
       
   127  * @leave	system wide error
       
   128  *
       
   129  * @return	ETrue if the command is processed
       
   130  */
       
   131 	{
       
   132 	TBool retVal = ETrue;
       
   133 
       
   134 	if ( aCommand == KCmdNew )
       
   135 		{
       
   136 		DoCmdNewL();
       
   137 		}
       
   138 	else if ( aCommand == KCmdDestructor )
       
   139 		{
       
   140 		DoCmdDestructor();
       
   141 		}
       
   142 	else if ( aCommand == KCmdOpen )
       
   143 		{
       
   144 		DoCmdOpenL( aSection );
       
   145 		}
       
   146 	else if ( aCommand == KCmdClose )
       
   147 		{
       
   148 		DoCmdClose();
       
   149 		}
       
   150 	else if ( aCommand == KCmdNext )
       
   151 		{
       
   152 		DoCmdNext( aSection, aAsyncErrorIndex );
       
   153 		}
       
   154 	else
       
   155 		{
       
   156 		retVal = EFalse;
       
   157 		}
       
   158 	return retVal;
       
   159 	}
       
   160 
       
   161 void CT_FormatData::DoCmdNewL()
       
   162 /**
       
   163  * Creates new RFormat class instance
       
   164  */
       
   165 	{
       
   166 	//Deletes previous RFormat class instance if it was already created.
       
   167 	DoCleanup();
       
   168 
       
   169 	INFO_PRINTF1( _L("Create new RFormat class instance") );
       
   170 
       
   171 	// do create
       
   172 	TRAPD( err, iFormat = new ( ELeave ) RFormat() );
       
   173 	if ( err != KErrNone )
       
   174 		{
       
   175 		ERR_PRINTF2( _L("new error %d"), err );
       
   176 		SetError( err );
       
   177 		}
       
   178 	}
       
   179 
       
   180 void CT_FormatData::DoCmdDestructor()
       
   181 /**
       
   182  * Destroy RFormat the object
       
   183  */
       
   184 	{
       
   185 	DoCleanup();
       
   186 	}
       
   187 
       
   188 void CT_FormatData::DoCmdOpenL( const TDesC& aSection )
       
   189 /**
       
   190  * RFormat::Open
       
   191  *
       
   192  * @leave	system wide error
       
   193  */
       
   194 	{
       
   195 	TBool	dataOk = ETrue;
       
   196 
       
   197 	RFs*	rfsObject = NULL;
       
   198 	TPtrC	rfsObjectName;
       
   199 	if ( GET_MANDATORY_STRING_PARAMETER( KRFsName, aSection, rfsObjectName ) )
       
   200 		{
       
   201 		TRAPD( err, rfsObject = ( RFs* )GetDataObjectL( rfsObjectName ));
       
   202 		
       
   203 		if ( err != KErrNone )
       
   204 			{
       
   205 			ERR_PRINTF1( _L("Error with fileserver"));
       
   206 			SetBlockResult( EFail );
       
   207 			}
       
   208 		}
       
   209 	else
       
   210 		{
       
   211 		dataOk = EFalse;
       
   212 		}
       
   213 
       
   214 	TPtrC	drive;
       
   215 	if ( !GET_MANDATORY_STRING_PARAMETER( KDrive, aSection, drive ) )
       
   216 		{
       
   217 		dataOk = EFalse;
       
   218 		}
       
   219 
       
   220 	TUint	formatMode = 0;
       
   221 	if ( !GetFormatMode( KFormat, aSection, formatMode ) )
       
   222 		{
       
   223 		dataOk = EFalse;
       
   224 		}
       
   225 
       
   226 	if ( dataOk )
       
   227 		{
       
   228 		TInt	err = KErrNone;
       
   229 
       
   230 		TPtrC	specialInfo;
       
   231 		if ( GET_OPTIONAL_STRING_PARAMETER( KSpecialInfo, aSection, specialInfo ) )
       
   232 			{
       
   233 			HBufC8*	buf = HBufC8::NewLC( specialInfo.Length() );
       
   234 			buf->Des().Copy( specialInfo );
       
   235 			err = iFormat->Open( *rfsObject, drive, formatMode, iCount, buf->Des() );
       
   236 			CleanupStack::PopAndDestroy( buf );
       
   237 			}
       
   238 		else
       
   239 			{
       
   240 			err = iFormat->Open( *rfsObject, drive, formatMode, iCount );
       
   241 			}
       
   242 		INFO_PRINTF2( _L("iCount %d"), iCount );
       
   243 		iCountPckg = iCount;
       
   244 		if ( err != KErrNone )
       
   245 			{
       
   246 			ERR_PRINTF2( _L("Open() error %d"), err );
       
   247 			SetError( err );
       
   248 			}
       
   249 		}
       
   250 	}
       
   251 
       
   252 void CT_FormatData::DoCmdClose()
       
   253 /**
       
   254  * RFormat::Close
       
   255  */
       
   256 	{
       
   257 	iFormat->Close();
       
   258 	}
       
   259 
       
   260 void CT_FormatData::DoCmdNext( const TDesC& aSection, const TInt aAsyncErrorIndex )
       
   261 /**
       
   262  * RFormat::Next
       
   263  */
       
   264 	{
       
   265 	TBool	async = EFalse;
       
   266 	GET_OPTIONAL_BOOL_PARAMETER( KAsync, aSection, async );
       
   267 
       
   268 	iCountNextEnd = 0;
       
   269 	GET_OPTIONAL_INT_PARAMETER( KEnd, aSection, iCountNextEnd );
       
   270 	
       
   271 	GET_OPTIONAL_INT_PARAMETER( KCount, aSection, iCount );
       
   272 
       
   273 	if ( async )
       
   274 		{
       
   275 		iFormat->Next( iCountPckg, iNext->iStatus );
       
   276 		iNext->Activate( aAsyncErrorIndex );
       
   277 		IncOutstanding();
       
   278 		}
       
   279 	else
       
   280 		{
       
   281 		TInt	err = KErrNone;
       
   282 		while ( ( iCount > iCountNextEnd ) && ( err == KErrNone ) )
       
   283 			{
       
   284 			err = iFormat->Next( iCount );
       
   285 			INFO_PRINTF2( _L("iCount %d"), iCount );
       
   286 			}
       
   287 		if ( err != KErrNone )
       
   288 			{
       
   289 			ERR_PRINTF2( _L("Next() error %d"), err );
       
   290 			SetError( err );
       
   291 			}
       
   292 		}
       
   293 	}
       
   294 
       
   295 TBool CT_FormatData::GetFormatMode( const TDesC& aParameterName, const TDesC& aSection, TUint& aFormatMode )
       
   296 	{
       
   297 	aFormatMode = 0;
       
   298 
       
   299 	TPtrC	formatStr;
       
   300 	TBool	ret = GET_MANDATORY_STRING_PARAMETER( aParameterName, aSection, formatStr );
       
   301 	if ( ret )
       
   302 		{
       
   303 		if ( !ConvertToFormatMode( formatStr, aFormatMode ) )
       
   304 			{
       
   305 			TInt	intTemp;
       
   306 			ret = GET_MANDATORY_INT_PARAMETER( aParameterName, aSection, intTemp );
       
   307 			if ( ret )
       
   308 				{
       
   309 				aFormatMode = intTemp;
       
   310 				}
       
   311 			}
       
   312 		}
       
   313 
       
   314 	return ret;
       
   315 	}
       
   316 
       
   317 TBool CT_FormatData::ConvertToFormatMode( const TDesC& aFormatModeStr, TUint& aFormatMode )
       
   318 	{
       
   319 	TBool	ret = ETrue;
       
   320 	if ( aFormatModeStr == KFormatHighDensity )
       
   321 		{
       
   322 		aFormatMode = EHighDensity;
       
   323 		}
       
   324 	else if ( aFormatModeStr == KFormatLowDensity )
       
   325 		{
       
   326 		aFormatMode = ELowDensity;
       
   327 		}
       
   328 	else if ( aFormatModeStr == KFormatFullFormat )
       
   329 		{
       
   330 		aFormatMode = EFullFormat;
       
   331 		}
       
   332 	else if ( aFormatModeStr == KFormatQuickFormat )
       
   333 		{
       
   334 		aFormatMode = EQuickFormat;
       
   335 		}
       
   336 	else if ( aFormatModeStr == KFormatSpecialFormat )
       
   337 		{
       
   338 		aFormatMode = ESpecialFormat;
       
   339 		}
       
   340 	else if ( aFormatModeStr == KFormatForceErase )
       
   341 		{
       
   342 		aFormatMode = EForceErase;
       
   343 		}
       
   344 	else
       
   345 		{
       
   346 		TInt	location = aFormatModeStr.Match( _L("*|*") );
       
   347 		if( location != KErrNotFound )
       
   348 			{
       
   349 			//Converting Left part of the data
       
   350 			TPtrC		tempStr = aFormatModeStr.Left( location );
       
   351 			ret = ConvertToFormatMode( tempStr, aFormatMode );
       
   352 
       
   353 			//Converting right data can be with another "|"
       
   354 			tempStr.Set( aFormatModeStr.Mid( location + 1 ) );
       
   355 
       
   356 			TUint	formatModeTmp;
       
   357 			if ( ConvertToFormatMode( tempStr, formatModeTmp ) )
       
   358 				{
       
   359 				aFormatMode |= formatModeTmp;
       
   360 				}
       
   361 			else
       
   362 				{
       
   363 				ret = EFalse;
       
   364 				}
       
   365 			}
       
   366 		else
       
   367 			{
       
   368 			ret = EFalse;
       
   369 			}
       
   370 		}
       
   371 
       
   372 	return ret;
       
   373 	}
       
   374 
       
   375 void CT_FormatData::RunL( CActive* aActive, TInt aIndex )
       
   376 	{
       
   377 	if ( aActive == iNext )
       
   378 		{
       
   379 		TInt	err = aActive->iStatus.Int();
       
   380 		if( err != KErrNone )
       
   381 			{
       
   382 			ERR_PRINTF2( _L("DoCancel Error %d"), err );
       
   383 			SetAsyncError( aIndex, err );
       
   384 			DecOutstanding();
       
   385 			}
       
   386 		else
       
   387 			{
       
   388 			// Reset the outstanding request state
       
   389 			INFO_PRINTF2( _L("RunL iCount %d"), iCountPckg() );
       
   390 			if ( iCountPckg() > iCountNextEnd )
       
   391 				{
       
   392 				iFormat->Next( iCountPckg, iNext->iStatus );
       
   393 				iNext->Activate( aIndex );
       
   394 				}
       
   395 			else
       
   396 				{
       
   397 				DecOutstanding();
       
   398 				}
       
   399 			}
       
   400 		}
       
   401 	else
       
   402 		{
       
   403  		ERR_PRINTF1( _L("Stray RunL signal") );
       
   404  		SetBlockResult( EFail );
       
   405 		}
       
   406 	}
       
   407 
       
   408 void CT_FormatData::DoCancel( CActive* aActive, TInt aIndex )
       
   409 	{
       
   410 	if ( aActive == iNext )
       
   411 		{
       
   412 		TInt	err = aActive->iStatus.Int();
       
   413 		if( err != KErrNone )
       
   414 			{
       
   415 			ERR_PRINTF2( _L("DoCancel Error %d"), err );
       
   416 			SetAsyncError( aIndex, err );
       
   417 			}
       
   418 
       
   419 		// Reset the outstanding request state
       
   420 		DecOutstanding();
       
   421 		}
       
   422 	else
       
   423 		{
       
   424  		ERR_PRINTF1( _L("Stray RunL signal") );
       
   425  		SetBlockResult( EFail );
       
   426 		}
       
   427 	}