backupandrestore/backuptest/burtestserver/TestSteps/src/t_burteststepbase.cpp
changeset 0 d0791faffa3f
child 19 0aa8cc770c8a
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @released
       
    19 */
       
    20 
       
    21 #include "t_burteststepbase.h"
       
    22 
       
    23 namespace bur_ts
       
    24 	{
       
    25 	_LIT(KTabText, "\t|");
       
    26 	_LIT(KFormatText2, "%S%S");
       
    27 	_LIT(KFormatText3, "%S%S%S");
       
    28 	_LIT(KFormatText4, "%S%S%d");
       
    29 	_LIT(KFormatText5, "%S%S%X");
       
    30 	_LIT(KFormatText6, "%S%S%s");
       
    31 	
       
    32 	const TUint8 KMaxHexLength = 8;
       
    33 	
       
    34 	CBURTestStepBase::CBURTestStepBase(CBURTestServer& aParent) 
       
    35 		/**
       
    36 		C++ Constructor
       
    37 		
       
    38 		@internalComponent
       
    39 		@released
       
    40 		
       
    41 		@param aParent - The parent CBURTestServer of this child test step.
       
    42 		*/
       
    43 		:iParentTestServer(aParent),
       
    44 		iBackupClient(NULL),
       
    45 		iBackupIncType(EBackupBase),
       
    46 	 	iIsPartial(EFalse),
       
    47 	 	iExpectStatus(1),
       
    48 	 	iExpectStatus2(1),
       
    49 		iFailures(KErrNone),
       
    50 		iStorageManager(NULL),
       
    51 		iMode(EBackupMode),
       
    52 		iWaitedForActive(EFalse)
       
    53 		{}
       
    54 	
       
    55 	CBURTestStepBase::~CBURTestStepBase()
       
    56 		/**
       
    57 		C++ Destructor
       
    58 		@internalComponent
       
    59 		@released
       
    60 		*/
       
    61 		{
       
    62 		iDataOwners.ResetAndDestroy();
       
    63 		iDataOwners.Close();
       
    64 			
       
    65 		iSidArray.Close();
       
    66 		iJidArray.Close();
       
    67 		iPublicFileNames.Close();
       
    68 		iPrivateFileNames.Close();
       
    69 		iPrivateFileSizes.Close();
       
    70 		
       
    71 		iFs.Close();
       
    72 		
       
    73 		iTransferTypes.ResetAndDestroy();
       
    74 		iTransferTypes.Close();
       
    75 		
       
    76 		delete iStorageManager;
       
    77 		delete iActiveScheduler;
       
    78 		
       
    79 		delete iBackupClient;
       
    80 		}
       
    81 	
       
    82 	// LOGGING METHODS
       
    83 	void CBURTestStepBase::Log(TUint aIndentationLevel, const TDesC& aLog)
       
    84 		/**
       
    85 		Logs the data inside the string as text string at aIndentationLevel.
       
    86 		
       
    87 		@internalComponent
       
    88 		@released
       
    89 		
       
    90 		@param aIndentationLevel - The indentation level in the TestExecute test report.
       
    91 		@param aLog - The message to be logged.
       
    92 		*/
       
    93 		{
       
    94 		HBufC* indentation = NULL;
       
    95 		indentation = GetIndentation(aIndentationLevel);
       
    96 		TPtr ptr = indentation->Des();
       
    97 		INFO_PRINTF3(KFormatText2, &ptr, &aLog);
       
    98 		delete indentation;
       
    99 		}
       
   100 	
       
   101 	void CBURTestStepBase::LogWithText(TUint aIndentationLevel, const TDesC& aLog, const TDesC& aText)
       
   102 		/**
       
   103 		Writes the message with a text string.
       
   104 		
       
   105 		@internalComponent
       
   106 		@released
       
   107 		
       
   108 		@param aIndentationLevel - The indentation level in the TestExecute test report.
       
   109 		@param aLog - The message to be logged.
       
   110 		@param aText - Textual data to be logged with the main message.
       
   111 		*/
       
   112 		{
       
   113 		HBufC* indentation = NULL;
       
   114 		indentation = GetIndentation(aIndentationLevel);
       
   115 		TPtr ptr = indentation->Des();
       
   116 		INFO_PRINTF4(KFormatText3, &ptr, &aLog, &aText);
       
   117 		delete indentation;
       
   118 		}
       
   119 	
       
   120 	void CBURTestStepBase::LogWithText8(TUint aIndentationLevel, const TDesC& aLog, const TDesC8& aText)
       
   121 		/**
       
   122 		8-bit variant of the above
       
   123 		
       
   124 		@internalComponent
       
   125 		@released
       
   126 		
       
   127 		@param aIndentationLevel - The indentation level in the TestExecute test report.
       
   128 		@param aLog - The message to be logged.
       
   129 		@param aText - 8-bit textual data to be logged with the main message.
       
   130 		*/
       
   131 		{
       
   132 		HBufC* indentation = NULL;
       
   133 		indentation = GetIndentation(aIndentationLevel);
       
   134 		TPtr ptr = indentation->Des();
       
   135 		INFO_PRINTF4(KFormatText3, &ptr, &aLog, &aText);
       
   136 		delete indentation;
       
   137 		}
       
   138 	
       
   139 	void CBURTestStepBase::LogWithNum(TUint aIndentationLevel, const TDesC& aLog, TInt aNum)
       
   140 		/**
       
   141 		Writes to the report a number along with a message.
       
   142 		
       
   143 		@internalComponent
       
   144 		@released
       
   145 		
       
   146 		@param aIndentationLevel - The indentation level in the TestExecute test report.
       
   147 		@param aLog - The message to be logged.
       
   148 		@param aNum - Number to be printed with the log.
       
   149 		*/
       
   150 		{
       
   151 		HBufC* indentation = NULL;
       
   152 		indentation = GetIndentation(aIndentationLevel);
       
   153 		TPtr ptr = indentation->Des();
       
   154 		INFO_PRINTF4(KFormatText4, &ptr, &aLog, aNum);
       
   155 		delete indentation;
       
   156 		}
       
   157 	
       
   158 	void CBURTestStepBase::LogWithSID(TUint aIndentationLevel, const TDesC& aLog, TSecureId aSecureId)
       
   159 		/**
       
   160 		Writes out a TSecureId as a hexadecimal number along with a message.
       
   161 		
       
   162 		@internalComponent
       
   163 		@released
       
   164 		
       
   165 		@param aIndentationLevel - The indentation level in the TestExecute test report.
       
   166 		@param aLog - The message to be logged.
       
   167 		@param aSecureId - A TSecureId to be printed as a hexadecimal number.
       
   168 		*/
       
   169 		{
       
   170 		HBufC* indentation = NULL;
       
   171 		indentation = GetIndentation(aIndentationLevel);
       
   172 		TPtr ptr = indentation->Des();
       
   173 		INFO_PRINTF4(KFormatText5, &ptr, &aLog, aSecureId.iId);
       
   174 		delete indentation;
       
   175 		}
       
   176 	
       
   177 	void CBURTestStepBase::LogWithChar(TUint aIndentationLevel, const TDesC& aLog, TChar aChar)
       
   178 		/**
       
   179 		@internalComponent
       
   180 		@released
       
   181 		
       
   182 		@param aIndentationLevel - The indentation level in the TestExecute test report.
       
   183 		@param aLog - The message to be logged.
       
   184 		@param aChar - A single char, appended at the end of the message.
       
   185 		*/
       
   186 		{
       
   187 		HBufC* indentation = NULL;
       
   188 		indentation = GetIndentation(aIndentationLevel);
       
   189 		TPtr ptr = indentation->Des();
       
   190 		INFO_PRINTF4(KFormatText6, &ptr, &aLog, &aChar);
       
   191 		delete indentation;
       
   192 		}
       
   193 	
       
   194 	HBufC* CBURTestStepBase::GetIndentation(TInt aLevel)
       
   195 		/**
       
   196 		Generates a string of indentation markers (based on KIndentationMarker) the 
       
   197 		level of depth specified by aLevel
       
   198 		
       
   199 		@internalComponent
       
   200 		@released
       
   201 		
       
   202 		@param aLevel - Level of depth required for indentation.
       
   203 		*/
       
   204 		{
       
   205 		HBufC* hbuf = NULL;
       
   206 		
       
   207 		// Indentation level times the length of the indentation marker, 
       
   208 		// plus room for a tab and a '|'
       
   209 		TInt indentationLength = aLevel * KIndentationMarker().Length() + 10;
       
   210 		hbuf = HBufC::NewL(indentationLength);
       
   211 		
       
   212 		hbuf->Des().Append(KTabText);
       
   213 		for(TInt i = 0; i < aLevel; ++i)
       
   214 			{
       
   215 			hbuf->Des().Append(KIndentationMarker);
       
   216 			}
       
   217 		
       
   218 		return hbuf;
       
   219 		}
       
   220 	
       
   221 	void CBURTestStepBase::CreateStorageManagerL()
       
   222 		/**
       
   223 		Must only be called after the user input has been processed.
       
   224 		@internalComponent
       
   225 		@released
       
   226 		*/
       
   227 		{
       
   228 		iStorageManager = CStorageManager::NewL(iBackupDirName, iDriveList, this);
       
   229 		}
       
   230 	
       
   231 	void CBURTestStepBase::ProcessUserOptionsL()
       
   232 		/**
       
   233 		This function uses TestExecute config file parsers to read in the user preferences
       
   234 		from ini files
       
   235 		
       
   236 		@internalComponent
       
   237 		@released
       
   238 		 */
       
   239 		{
       
   240 		TPtrC backupDir;
       
   241 		TInt isPartial = 0;
       
   242 		TInt isBase = 0;
       
   243 		TPtrC driveListText;
       
   244 		
       
   245 		// directory for archiving backup data
       
   246 		_LIT(KBackupDirText1, "BackupDir");
       
   247 		GetStringFromConfig(ConfigSection(), KBackupDirText1, backupDir);
       
   248 		
       
   249 		_LIT(KBackupDirText2, "Backup directory: ");
       
   250 		LogWithText(LOG_LEVEL3, KBackupDirText2, backupDir);
       
   251 		iBackupDirName.Copy(backupDir);
       
   252 		
       
   253 		// affected drives
       
   254 		_LIT(KDriveListText1, "DriveList");
       
   255 		GetStringFromConfig(ConfigSection(), KDriveListText1, driveListText);
       
   256 		_LIT(KDriveListText2, "Drives: ");
       
   257 		
       
   258 		LogWithText(LOG_LEVEL3, KDriveListText2, driveListText);
       
   259 		// extract all drives from the user input
       
   260 		iDriveList = CBURTestStepBase::StringToDriveListL(driveListText);
       
   261 		
       
   262 		// create the storage handler based on the drives and backup directory
       
   263 		CreateStorageManagerL();
       
   264 		
       
   265 		_LIT(KExpectStatusText1, "ExpectStatus");
       
   266 		GetIntFromConfig(ConfigSection(), KExpectStatusText1, iExpectStatus);
       
   267 		
       
   268 		_LIT(KExpectStatusText2, "ExpectStatus: ");
       
   269 		LogWithNum(LOG_LEVEL3, KExpectStatusText2, iExpectStatus);		
       
   270 		
       
   271 		_LIT(KExpectStatusText3, "ExpectStatus2");
       
   272 		GetIntFromConfig(ConfigSection(), KExpectStatusText3, iExpectStatus2);
       
   273 		
       
   274 		_LIT(KExpectStatusText4, "ExpectStatus2: ");
       
   275 		LogWithNum(LOG_LEVEL3, KExpectStatusText4, iExpectStatus2);			
       
   276 
       
   277 		// full/partial backup
       
   278 		_LIT(KPartialText1, "IsPartial");
       
   279 		GetIntFromConfig(ConfigSection(), KPartialText1, isPartial);
       
   280 		if (isPartial == 0)
       
   281 			{
       
   282 			iIsPartial = EFalse;
       
   283 			
       
   284 			_LIT(KPartialText2, "Full/Partial Type: Full");
       
   285 			Log(LOG_LEVEL3, KPartialText2);
       
   286 			} //if
       
   287 		else if (isPartial == 1)
       
   288 			{
       
   289 			iIsPartial = ETrue;
       
   290 			TSecureId sid;
       
   291 			
       
   292 			TChar ch;
       
   293 			TPtrC list;
       
   294 			
       
   295 			
       
   296 			// PARSING ID LIST //
       
   297 			
       
   298 			_LIT(KSIDList, "IDs");
       
   299 			GetStringFromConfig(ConfigSection(), KSIDList, list);
       
   300 			TLex sidLex(list);
       
   301 		
       
   302 			while (!sidLex.Eos())
       
   303 				{
       
   304         		sidLex.Mark();
       
   305 	        	ch=sidLex.Peek();
       
   306 
       
   307     	    	while(!sidLex.Eos() && ( ch=sidLex.Peek() ) != TChar(','))
       
   308         			sidLex.Inc();
       
   309  
       
   310         		if(!sidLex.TokenLength())
       
   311         			continue;
       
   312         		
       
   313         		TPtrC pToken = sidLex.MarkedToken();
       
   314         		TLex token(pToken);
       
   315         		
       
   316         		if (pToken.Length() <= KMaxHexLength && token.Val(sid.iId, EHex) == KErrNone)
       
   317         			{
       
   318         			iSidArray.Append(sid);
       
   319 					_LIT(KFound, "ID Found in ini file: ");
       
   320 					LogWithSID(LOG_LEVEL4, KFound, sid);		
       
   321         			} //if
       
   322         		else // must be a Java suite hash
       
   323         			{
       
   324         			iJidArray.Append(pToken);
       
   325         			_LIT(KJFound, "Java ID Found in ini file: ");
       
   326         			LogWithText(LOG_LEVEL4, KJFound, pToken);
       
   327         			}
       
   328 				
       
   329         		if(ch==TChar(','))
       
   330         			sidLex.Inc();
       
   331         		
       
   332         		sidLex.SkipSpace();
       
   333         
       
   334 				} //while
       
   335 				
       
   336 			
       
   337 			_LIT(KPartialText3, "Full/Partial Type: Partial");
       
   338 			Log(LOG_LEVEL3, KPartialText3);
       
   339 			} //if
       
   340 		else
       
   341 			{
       
   342 			_LIT(KPartialText4, "Full/Partial Type: UNKNOWN");
       
   343 			_LIT(KPartialText5, "** PLEASE USE 0 OR 1 ONLY **");
       
   344 			_LIT(KPartialText6, "** Using FULL as default  **");
       
   345 			Log(LOG_LEVEL4, KPartialText4);
       
   346 			Log(LOG_LEVEL4, KPartialText5);
       
   347 			Log(LOG_LEVEL4, KPartialText6);
       
   348 			}
       
   349 		
       
   350 		// base/incremental
       
   351 		_LIT(KIncrText1, "BaseOnly");
       
   352 		GetIntFromConfig(ConfigSection(), KIncrText1, isBase);
       
   353 		if (isBase == 1)
       
   354 			{
       
   355 			iBackupIncType = EBackupBase;
       
   356 			
       
   357 			_LIT(KIncrText2, "Base/Incremental Type: Base Only");
       
   358 			Log(LOG_LEVEL3, KIncrText2);
       
   359 			}
       
   360 		else if (isBase == 0)
       
   361 			{
       
   362 			iBackupIncType = EBackupIncrement;
       
   363 			
       
   364 			_LIT(KIncrText3, "Base/Incremental Type: Incremental by Default");
       
   365 			Log(LOG_LEVEL3, KIncrText3);
       
   366 			}
       
   367 		else
       
   368 			{
       
   369 			_LIT(KIncrText4, "Base/Incremental Type: UNKNOWN");
       
   370 			_LIT(KIncrText5, "** PLEASE USE 0 OR 1 ONLY **");
       
   371 			_LIT(KIncrText6, "** Using BASE as default  **");
       
   372 			Log(LOG_LEVEL4, KIncrText4);
       
   373 			Log(LOG_LEVEL4, KIncrText5);
       
   374 			Log(LOG_LEVEL4, KIncrText6);
       
   375 			}
       
   376 		
       
   377 		TChar delimiter(',');
       
   378 		
       
   379 		/** Read public files into array */
       
   380 		_LIT(KExpectPublicFiles, "ExpectPublicFiles");
       
   381 		ReadListIntoStringArray(KExpectPublicFiles, delimiter, iPublicFileNames);
       
   382 		
       
   383 		/** Read private files into array */
       
   384 		_LIT(KExpectPrivateFiles, "ExpectPrivateFiles");
       
   385 		ReadListIntoStringArray(KExpectPrivateFiles, delimiter, iPrivateFileNames);		
       
   386 		
       
   387 		/** Read private file sizes into array */
       
   388 		_LIT(KExpectPrivateFileSizes, "ExpectPrivateFileSizes");
       
   389 		ReadListIntoIntArray(KExpectPrivateFileSizes, delimiter, iPrivateFileSizes);
       
   390 		}
       
   391 		
       
   392 	void CBURTestStepBase::ReadListIntoStringArray(const TDesC& aSectionName, const TChar& aDelimiter, RArray<TPtrC>& aResultList)
       
   393 		{
       
   394 		TChar ch;
       
   395 		TPtrC list;
       
   396 		GetStringFromConfig(ConfigSection(), aSectionName, list);
       
   397 		TLex strLex(list);
       
   398 		
       
   399 		while (!strLex.Eos())
       
   400 			{
       
   401 			strLex.Mark();
       
   402         	ch=strLex.Peek();
       
   403 
       
   404 	    	while( ( !strLex.Eos() ) && 
       
   405 	    		   ((ch=strLex.Peek()) != aDelimiter) )
       
   406 	    		{
       
   407 	    		strLex.Inc();
       
   408 	    		}
       
   409 
       
   410     		if(!strLex.TokenLength())
       
   411     			continue;
       
   412     		
       
   413     		TPtrC pToken = strLex.MarkedToken();
       
   414     		aResultList.Append(pToken);
       
   415 			
       
   416     		if(ch == aDelimiter)
       
   417     			strLex.Inc();
       
   418     		
       
   419     		strLex.SkipSpace();    
       
   420 			} //while		
       
   421 		}
       
   422 	
       
   423 	void CBURTestStepBase::ReadListIntoIntArray(const TDesC& aSectionName, const TChar& aDelimiter, RArray<TInt>& aResultList)
       
   424 		{
       
   425 		RArray<TPtrC> strList;
       
   426 		CleanupClosePushL(strList);
       
   427 		ReadListIntoStringArray(aSectionName, aDelimiter, strList);
       
   428 		
       
   429 		TInt count = strList.Count();
       
   430 		for (TInt i=0; i<count; ++i)
       
   431 			{
       
   432 			TInt num = 0;
       
   433 			TLex token(strList[i]);
       
   434 			if (token.Val(num) == KErrNone)
       
   435 				{
       
   436 				aResultList.Append(num);
       
   437 				}
       
   438 			}
       
   439 		CleanupStack::PopAndDestroy(&strList); // strList
       
   440 		}	
       
   441 	
       
   442 	void CBURTestStepBase::PopulateListOfDataOwnersL()
       
   443 		/**
       
   444 		Uses CSBEClient::ListOfDataOwnersL() to extract a list of data owners that have 
       
   445 		registred for backup and restore. Populates iDataOwners.
       
   446 		
       
   447 		@internalComponent
       
   448 		@released
       
   449 		*/
       
   450 		{
       
   451 		_LIT(KTempText1, "Getting list of data owners from device");
       
   452 		Log(LOG_LEVEL2,KTempText1);
       
   453 		
       
   454 		TRAPD(err, iBackupClient->ListOfDataOwnersL(iDataOwners));
       
   455 		if (err != KErrNone)
       
   456 			{
       
   457 			_LIT(KTempText1, "Error getting list of data owners: ");
       
   458 			LogWithNum(LOG_LEVEL2,KTempText1, err);
       
   459 			iFailures++;
       
   460 			}
       
   461 
       
   462 		// Log
       
   463 		if (iDataOwners.Count() == 0)
       
   464 			{
       
   465 			_LIT(KTempText3, "No data owners found.");
       
   466 			Log(LOG_LEVEL3, KTempText3);
       
   467 			}
       
   468 		else
       
   469 			{
       
   470 			_LIT(KTempText4, "Number of data owners found on device: ");
       
   471 			LogWithNum(LOG_LEVEL3, KTempText4, iDataOwners.Count());
       
   472 			}
       
   473 		}
       
   474 		
       
   475 	void CBURTestStepBase::PopulateListOfDataOwnersAsyncL()
       
   476 		/**
       
   477 		Uses CSBEClient::ListOfDataOwnersL() to extract a list of data owners that have 
       
   478 		registred for backup and restore. Populates iDataOwners.
       
   479 		
       
   480 		@internalComponent
       
   481 		@released
       
   482 		*/
       
   483 		{
       
   484 		_LIT(KTempText1, "Getting list of data owners from device");
       
   485 		Log(LOG_LEVEL2,KTempText1);
       
   486 		CBURActiveObject* active = CBURActiveObject::NewL();
       
   487 		CleanupStack::PushL(active);
       
   488 		TRAPD(err, iBackupClient->ListOfDataOwnersL(iDataOwners, active->iStatus));
       
   489 		if (err == KErrNone)
       
   490 			{
       
   491 			active->StartL();
       
   492 			}
       
   493 			
       
   494 		if (err != KErrNone || active->Error() != KErrNone)
       
   495 			{
       
   496 			_LIT(KTempText1, "Error getting list of data owners: ");
       
   497 			LogWithNum(LOG_LEVEL2,KTempText1, err);
       
   498 			iFailures++;
       
   499 			}
       
   500 		CleanupStack::PopAndDestroy(active);
       
   501 		
       
   502 		// Log
       
   503 		if (iDataOwners.Count() == 0)
       
   504 			{
       
   505 			_LIT(KTempText3, "No data owners found.");
       
   506 			Log(LOG_LEVEL3, KTempText3);
       
   507 			}
       
   508 		else
       
   509 			{
       
   510 			_LIT(KTempText4, "Number of data owners found on device: ");
       
   511 			LogWithNum(LOG_LEVEL3, KTempText4, iDataOwners.Count());
       
   512 			}
       
   513 		}
       
   514 	
       
   515 	void CBURTestStepBase::SetBURModeL(TBURPartType aBURPartType, TBackupIncType aBackupIncType)
       
   516 		/**
       
   517 		Uses CSBEClient::SetBURModeL() to set backup and restore settings
       
   518 		
       
   519 		@internalComponent
       
   520 		@released
       
   521 		
       
   522 		@param aBURPartType - Full/Partial backup/restore.
       
   523 		@param aBackupIncType - Base/Incremental backup/restore.
       
   524 		*/
       
   525 		{
       
   526 		iBackupClient->SetBURModeL(iDriveList, aBURPartType, aBackupIncType);
       
   527 		}
       
   528 	
       
   529 	void CBURTestStepBase::SetBURModeAsyncL(TBURPartType aBURPartType, TBackupIncType aBackupIncType)
       
   530 		/**
       
   531 		Uses CSBEClient::SetBURModeL() Asyncrhonous version to set backup and restore settings
       
   532 		
       
   533 		@internalComponent
       
   534 		@released
       
   535 		
       
   536 		@param aBURPartType - Full/Partial backup/restore.
       
   537 		@param aBackupIncType - Base/Incremental backup/restore.
       
   538 		*/
       
   539 		{
       
   540 		CBURActiveObject* active = CBURActiveObject::NewL();
       
   541 		CleanupStack::PushL(active);
       
   542 		iBackupClient->SetBURModeL(iDriveList, aBURPartType, aBackupIncType, active->iStatus);
       
   543 		active->StartL();
       
   544 		User::LeaveIfError(active->Error());
       
   545 		CleanupStack::PopAndDestroy(active);
       
   546 		}
       
   547 	
       
   548 	void CBURTestStepBase::PrepareForPartialBURL()
       
   549 		/**
       
   550 		@internalComponent
       
   551 		@released
       
   552 		*/
       
   553 		{
       
   554 		TSecureId sid = NULL;
       
   555 		
       
   556 		// go through list of pids and sids
       
   557 		for (TInt index = 0; index < iDataOwners.Count(); index++)
       
   558 			{
       
   559 			TBool notFound = ETrue;
       
   560 			sid = ExtractIDL(*iDataOwners[index]);
       
   561 			
       
   562 			if (sid != NULL)
       
   563 				{
       
   564 				TInt position = iSidArray.Find(sid);
       
   565 				if (position != KErrNotFound)
       
   566 					{
       
   567 					_LIT(KTempText2, "ID found in list of data owners: ");
       
   568 					LogWithSID(LOG_LEVEL3, KTempText2, sid);
       
   569 					notFound = EFalse;
       
   570 					}
       
   571 				else if (position == KErrNotFound)
       
   572 					{
       
   573 					notFound = ETrue;
       
   574 					} // if else
       
   575 				} // if
       
   576 			else // possibly jid
       
   577 				{
       
   578 				HBufC* pSuiteHash = ExtractJavaIDL(*iDataOwners[index]);
       
   579 				TPtrC suiteHash = pSuiteHash->Des();
       
   580 				if (iJidArray.Find(suiteHash) != KErrNotFound)
       
   581 					{
       
   582 					_LIT(KTempText3, "Java ID found in list of data owners: ");
       
   583 					LogWithText(LOG_LEVEL3, KTempText3, suiteHash);
       
   584 					notFound = EFalse;
       
   585 					}
       
   586 				else // not found 
       
   587 					{
       
   588 					notFound = ETrue;
       
   589 					}
       
   590 				delete pSuiteHash;
       
   591 				pSuiteHash = NULL;
       
   592 				}
       
   593 			if (notFound)
       
   594 				{
       
   595 				delete iDataOwners[index];
       
   596 				iDataOwners[index] = NULL;
       
   597 				iDataOwners.Remove(index);
       
   598 				index--;
       
   599 				}
       
   600 			}
       
   601 		}
       
   602 		
       
   603 	void CBURTestStepBase::SetSIDListForPartialL()
       
   604 	/**
       
   605 	Set the list of active data owners for partial bur
       
   606 	
       
   607 	@param aDataOwners List of data owners for partial bur
       
   608 	*/
       
   609 		{
       
   610 		iSidArray.Reset();
       
   611 		for (TInt i=0; i< iDataOwners.Count(); i++)
       
   612 			{
       
   613 			if (iDataOwners[i]->CommonSettings() & EActiveBUR)
       
   614 				{
       
   615 				TSBDerivedType type = iDataOwners[i]->Identifier().DerivedTypeL();
       
   616 				if (type == ESIDDerivedType)
       
   617 					{
       
   618 					// means it is definately a sid
       
   619 					CSBSecureId* secureId = CSBSecureId::NewL(&(iDataOwners[i]->Identifier()));
       
   620 					CleanupStack::PushL(secureId);
       
   621 						
       
   622 					iSidArray.AppendL(secureId->SecureIdL());
       
   623 					CleanupStack::PopAndDestroy(secureId);
       
   624 					}
       
   625 				else if (type == EPackageDerivedType)
       
   626 					{
       
   627 					CSBPackageId* packageId = CSBPackageId::NewL(&(iDataOwners[i]->Identifier()));
       
   628 					CleanupStack::PushL(packageId);
       
   629 					
       
   630 					iSidArray.AppendL(packageId->SecureIdL());
       
   631 					CleanupStack::PopAndDestroy(packageId);
       
   632 					}
       
   633 				} //if
       
   634 			}// for
       
   635 		
       
   636 		// set active owners array	
       
   637 		TRAPD(err,iBackupClient->SetSIDListForPartialBURL(iSidArray));
       
   638 		if (err != KErrNone)
       
   639 			{
       
   640 			iFailures++;
       
   641 			_LIT(KSidP, "Error Setting list for partial : ");
       
   642 			LogWithNum(LOG_LEVEL3, KSidP, err);
       
   643 			}
       
   644 		}
       
   645 		
       
   646 	void CBURTestStepBase::GenerateSIDTransferTypesL(RTransferTypeArray& aTransferTypes, TTransferDataType aDataType)
       
   647 		/**
       
   648 		For each data owner in iDataOwners, this method creates CSBGenericTransferTypes
       
   649 		based on the TTransferDataType passed. One transfer type is created per drive that
       
   650 		the data owner in question has data on. Only creates transfer types supported by data owner
       
   651 		
       
   652 		@internalComponent
       
   653 		@released
       
   654 		
       
   655 		@param aTransferTypes - Array of transfer types.
       
   656 		@param aDataType - Trasnfer data type, passive base, active base, etc.
       
   657 		*/
       
   658 		{
       
   659 		TTransferDataType tempDataType = aDataType;
       
   660 		aTransferTypes.ResetAndDestroy();
       
   661 		TSecureId sid = NULL;
       
   662 		
       
   663 		TInt length = iDriveList.Length();
       
   664 		for (TInt driveCount = 0; driveCount < length; driveCount++)
       
   665 			{
       
   666 			if (iDriveList[driveCount])
       
   667 				{
       
   668 				for (TInt i = 0; i < iDataOwners.Count(); i++)
       
   669 					{
       
   670 					if ( (iDataOwners[i]->Identifier().DerivedTypeL() == ESIDDerivedType) &&
       
   671 					     (iDataOwners[i]->DriveList()[driveCount]) )
       
   672 						{
       
   673 						CSBSecureId* secureId = CSBSecureId::NewL(&(iDataOwners[i]->Identifier()));
       
   674 						CleanupStack::PushL(secureId);
       
   675 						
       
   676 						sid = secureId->SecureIdL();
       
   677 						
       
   678 						CleanupStack::PopAndDestroy(secureId);
       
   679 						}
       
   680 					else if ( (iDataOwners[i]->Identifier().DerivedTypeL() == EPackageDerivedType) &&
       
   681 					          (iDataOwners[i]->DriveList()[driveCount]) )
       
   682 						{						
       
   683 						CSBPackageId* pkgId = CSBPackageId::NewL(&(iDataOwners[i]->Identifier()));
       
   684 						CleanupStack::PushL(pkgId);
       
   685 					
       
   686 						sid = pkgId->SecureIdL();
       
   687 						
       
   688 						CleanupStack::PopAndDestroy(pkgId);	
       
   689 						} // else if
       
   690 					
       
   691 					if (sid != NULL)
       
   692 						{
       
   693 						// decides if data owner supports that data type
       
   694 						
       
   695 						TBool checkIfHaveBase = EFalse;
       
   696 						TBool baseOnly = EFalse;
       
   697 						TBool supports = EFalse;
       
   698 						switch (aDataType)
       
   699 							{
       
   700 							case ERegistrationData:
       
   701 								supports = EFalse;
       
   702 								break;
       
   703 							case EPassiveBaseData:
       
   704 								if (iDataOwners[i]->CommonSettings() & EPassiveBUR)
       
   705 									{
       
   706 									supports = ETrue;
       
   707 									}
       
   708 								break;
       
   709 							case EPassiveSnapshotData:
       
   710 								if (iDataOwners[i]->PassiveSettings() & EPassiveSupportsInc)
       
   711 									{
       
   712 									supports = ETrue;
       
   713 									}
       
   714 								break;
       
   715 							case EPassiveIncrementalData:
       
   716 								if (iDataOwners[i]->CommonSettings() & EPassiveBUR)
       
   717 									{
       
   718 									if (!(iDataOwners[i]->PassiveSettings() & EPassiveSupportsInc) && !iMode)
       
   719 										{
       
   720 										_LIT(KPsIncDt, "Base only for SID: ");
       
   721 										LogWithSID(LOG_LEVEL3, KPsIncDt, sid);
       
   722 										baseOnly = ETrue;
       
   723 										supports = ETrue;
       
   724 										aDataType = EPassiveBaseData;
       
   725 										}
       
   726 									else if (iDataOwners[i]->PassiveSettings() & EPassiveSupportsInc)
       
   727 										{
       
   728 										checkIfHaveBase = ETrue;
       
   729 										}
       
   730 									} // if
       
   731 								break;
       
   732 							case EActiveSnapshotData:
       
   733 								if (iDataOwners[i]->ActiveSettings() & EActiveSupportsInc)
       
   734 									{
       
   735 									supports = ETrue;
       
   736 									}
       
   737 								break;
       
   738 							case EActiveIncrementalData:
       
   739 								if (iDataOwners[i]->CommonSettings() & EActiveBUR)
       
   740 									{
       
   741 									if (!(iDataOwners[i]->ActiveSettings() & EActiveSupportsInc) && !iMode)
       
   742 										{
       
   743 										_LIT(KAcIncDt, "Base only for SID: ");
       
   744 										LogWithSID(LOG_LEVEL3, KAcIncDt, sid);
       
   745 										baseOnly = ETrue;
       
   746 										supports = ETrue;
       
   747 										aDataType = EActiveBaseData;
       
   748 										}
       
   749 									else if (iDataOwners[i]->ActiveSettings() & EActiveSupportsInc)
       
   750 										{
       
   751 										checkIfHaveBase = ETrue;
       
   752 										}	
       
   753 									} // if
       
   754 								break;
       
   755 							case EActiveBaseData:
       
   756 								if (iDataOwners[i]->CommonSettings() & EActiveBUR)
       
   757 									{
       
   758 									supports = ETrue;
       
   759 									}
       
   760 								break;
       
   761 							} //switch
       
   762 						
       
   763 						
       
   764 						if (checkIfHaveBase)
       
   765 							{
       
   766 							TTransferDataType dType;
       
   767 							if (aDataType == EActiveIncrementalData)
       
   768 								{
       
   769 								dType = EActiveBaseData;
       
   770 								}
       
   771 							else
       
   772 								{
       
   773 								dType = EPassiveBaseData;
       
   774 								} // if else
       
   775 								
       
   776 							CSBSIDTransferType* tType = CSBSIDTransferType::NewL(sid, TDriveNumber(driveCount), dType);
       
   777 							CleanupStack::PushL(tType);
       
   778 							TFileName fileName;
       
   779 							iStorageManager->GetFileNameL(tType, fileName, EFalse);
       
   780 							if(iStorageManager->IsFileExists(fileName))
       
   781 								{
       
   782 								supports = ETrue;
       
   783 								}
       
   784 							else 
       
   785 								{
       
   786 								_LIT(KTempText2, "No increments found use Base instead for SID: ");
       
   787 								LogWithSID(LOG_LEVEL3, KTempText2, sid);
       
   788 								supports = ETrue;
       
   789 								aDataType = dType;
       
   790 								baseOnly = ETrue;
       
   791 								}
       
   792 							CleanupStack::PopAndDestroy(tType);
       
   793 							} // if check if have base
       
   794 											
       
   795 						
       
   796 						if (supports)
       
   797 							{
       
   798 							CSBSIDTransferType* sidType = CSBSIDTransferType::NewL(sid, TDriveNumber(driveCount), aDataType);
       
   799 							CleanupStack::PushL(sidType);
       
   800 							aTransferTypes.AppendL(sidType);
       
   801 							CleanupStack::Pop(sidType);
       
   802 							} // if else
       
   803 						
       
   804 						// change to the proper dataType if base only true	
       
   805 						if (baseOnly)
       
   806 							{
       
   807 							aDataType = tempDataType;
       
   808 							}
       
   809 						sid = NULL;	
       
   810 						}// if
       
   811 					} // for		
       
   812 				} // if
       
   813 			} //for
       
   814 		}
       
   815 		
       
   816 	void CBURTestStepBase::GeneratePIDTransferTypesL(RTransferTypeArray& aTransferTypes, TPackageDataType aPkgDataType)
       
   817 		/**
       
   818 		For each data owner in iDataOwners, this method creates CSBGenericTransferTypes
       
   819 		based on the TTransferDataType passed. One transfer type is created per drive that
       
   820 		the data owner in question has data on.
       
   821 		
       
   822 		@internalComponent
       
   823 		@released
       
   824 		
       
   825 		@param aTransferTypes - Array of transfer types.
       
   826 		@param aDataType - Trasnfer data type, passive base, active base, etc.
       
   827 		*/
       
   828 		{
       
   829 		aTransferTypes.ResetAndDestroy();
       
   830 		TUid id;
       
   831 		//need array to avoid duplications
       
   832 		RArray<TUid> uidArray;
       
   833 		CleanupClosePushL(uidArray);
       
   834 		
       
   835 		TInt length = iDriveList.Length();
       
   836 		for (TInt driveCount = 0; driveCount < length; driveCount++)
       
   837 			{
       
   838 			if (iDriveList[driveCount])
       
   839 				{
       
   840 				TInt count = iDataOwners.Count();
       
   841 				for (TInt i = 0; i < count; i++)
       
   842 					{
       
   843 					if ( (iDataOwners[i]->Identifier().DerivedTypeL() == EPackageDerivedType) &&
       
   844 					     (iDataOwners[i]->DriveList()[driveCount]) )
       
   845 					    {
       
   846 					    CSBPackageId* pkgId = CSBPackageId::NewL(&(iDataOwners[i]->Identifier()));
       
   847 					    CleanupStack::PushL(pkgId);
       
   848                         
       
   849 					    id = pkgId->PackageIdL();
       
   850 					    if (uidArray.Find(id) == KErrNotFound)
       
   851 					        {
       
   852 					        CSBPackageTransferType* idType = CSBPackageTransferType::NewL(id, TDriveNumber(driveCount), aPkgDataType);
       
   853 					        CleanupStack::PushL(idType);
       
   854 					        aTransferTypes.AppendL(idType);
       
   855 					        CleanupStack::Pop(idType);
       
   856 					        //add to uid array
       
   857 					        uidArray.AppendL(id);
       
   858 					        }
       
   859 					    CleanupStack::PopAndDestroy(pkgId); 					    
       
   860 					    }
       
   861 					} //for		
       
   862 				} //if	
       
   863 			} //for
       
   864 		CleanupStack::PopAndDestroy(&uidArray);
       
   865 		}
       
   866 		
       
   867 	void CBURTestStepBase::GenerateJavaTransferTypesL(RTransferTypeArray& aTransferTypes, TJavaTransferType aJavaTransferType)
       
   868 		/**
       
   869 		For each data owner in iDataOwners, this method creates CSBGenericTransferTypes
       
   870 		based on the TTransferDataType passed. One transfer type is created per drive that
       
   871 		the data owner in question has data on.
       
   872 		
       
   873 		@internalComponent
       
   874 		@released
       
   875 		
       
   876 		@param aTransferTypes - Array of transfer types.
       
   877 		@param aJavaTransferType - Trasnfer data type
       
   878 		*/
       
   879 		{
       
   880 		aTransferTypes.ResetAndDestroy();
       
   881 		
       
   882 		TInt length = iDriveList.Length();
       
   883 		for (TInt driveCount = 0; driveCount < length; driveCount++)
       
   884 			{
       
   885 			if (iDriveList[driveCount])
       
   886 				{
       
   887 				TInt count = iDataOwners.Count();
       
   888 				for (TInt i=0; i < count; i++)
       
   889 					{
       
   890 					if ( (iDataOwners[i]->Identifier().DerivedTypeL() == EJavaDerivedType) &&
       
   891 					     (iDataOwners[i]->DriveList()[driveCount]) )
       
   892 					    {
       
   893 					    if ((aJavaTransferType == EJavaMIDlet && (iDataOwners[i]->CommonSettings() & EHasSystemFiles)) || aJavaTransferType == EJavaMIDletData)
       
   894 					        {
       
   895 					        CSBJavaId* javaId = CSBJavaId   ::NewL(&(iDataOwners[i]->Identifier()));
       
   896 					        CleanupStack::PushL(javaId);
       
   897 					        const TDesC& suiteHash = javaId->SuiteHashL();
       
   898 					        CSBJavaTransferType* javaType = CSBJavaTransferType::NewL(suiteHash, TDriveNumber(driveCount), aJavaTransferType);
       
   899 					        CleanupStack::PushL(javaType);
       
   900 					        aTransferTypes.AppendL(javaType);
       
   901 					        CleanupStack::Pop(javaType);
       
   902 					        CleanupStack::PopAndDestroy(javaId);
       
   903 					        }//if					    
       
   904 					    }
       
   905 					} //for
       
   906 				} // if
       
   907 			} // for
       
   908 		}
       
   909 		
       
   910 	
       
   911 	void CBURTestStepBase::GeneratePublicTransferTypesL(RPointerArray<CSBGenericDataType>& aTransferTypes)
       
   912 		/**
       
   913 		For each data owner in iDataOwners, this method creates CSBGenericTransferTypes
       
   914 		based on the TTransferDataType passed. One transfer type is created per drive that
       
   915 		the data owner in question has data on.
       
   916 		
       
   917 		@internalComponent
       
   918 		@released
       
   919 		
       
   920 		@param aTransferTypes - Array of transfer types.
       
   921 		@param aDataType - Trasnfer data type, passive base, active base, etc.
       
   922 		*/
       
   923 		{
       
   924 		aTransferTypes.ResetAndDestroy();
       
   925 
       
   926 		TInt count = iDataOwners.Count();
       
   927 		for (TInt i = 0; i < count; i++)
       
   928 			{
       
   929 			switch (iDataOwners[i]->Identifier().DerivedTypeL())
       
   930 				{
       
   931 				case EPackageDerivedType:
       
   932 				case ESIDDerivedType:
       
   933 					if (iDataOwners[i]->PassiveSettings() & EHasPublicFiles)
       
   934 						{
       
   935 						const TDesC8& desc = iDataOwners[i]->Identifier().Externalise();
       
   936 						CSBGenericDataType* idType = CSBGenericDataType::NewL(desc);
       
   937 						CleanupStack::PushL(idType);
       
   938 						aTransferTypes.AppendL(idType);
       
   939 						CleanupStack::Pop(idType);
       
   940 						} //if
       
   941 					break;
       
   942 				} // switch
       
   943 			}
       
   944 		}
       
   945 	
       
   946 	
       
   947 	void CBURTestStepBase::SupplyDataL(RTransferTypeArray& aTransferTypes)
       
   948 		/**
       
   949 		Retrieves data from the storage handler and supplies to the backup client for 
       
   950 		the given transfer type
       
   951 		
       
   952 		@internalComponent
       
   953 		@released
       
   954 		
       
   955 		@param aTransferTypes - Array of transfer types.
       
   956 		*/
       
   957 		{
       
   958 		TInt transferTypesCount = aTransferTypes.Count();
       
   959 		for(TInt currentIndex = 0; currentIndex < transferTypesCount; ++currentIndex)
       
   960 			{
       
   961 			TInt error;		
       
   962 			TInt increments = 0;
       
   963 			TInt incrIndex = 1;
       
   964 			
       
   965 			TSBDerivedType dataType = aTransferTypes[currentIndex]->DerivedTypeL();
       
   966 			
       
   967 			// check for incremental data
       
   968 			switch(dataType)
       
   969 				{
       
   970 				case ESIDTransferDerivedType:
       
   971 					{
       
   972 					CSBSIDTransferType* type = CSBSIDTransferType::NewL(aTransferTypes[currentIndex]);
       
   973 					CleanupStack::PushL(type);
       
   974 					
       
   975 					_LIT(KSid, "Supplying data for ID: ");
       
   976 					LogWithSID(LOG_LEVEL3, KSid, type->SecureIdL());
       
   977 					
       
   978 					if (type->DataTypeL() == EActiveIncrementalData || type->DataTypeL() == EPassiveIncrementalData)
       
   979 						{
       
   980 						increments = iStorageManager->TotalIncFiles(type);
       
   981 						if (!increments)
       
   982 							{
       
   983 							_LIT(KErrorText2, "No increments found");
       
   984 							Log(LOG_LEVEL4, KErrorText2);
       
   985 							// cleanup
       
   986 							CleanupStack::PopAndDestroy(type);
       
   987 							continue;
       
   988 							}
       
   989 						else 
       
   990 							{
       
   991 							_LIT(KIncFound, "Number of increments found: ");
       
   992 							LogWithNum(LOG_LEVEL4, KIncFound, increments);
       
   993 							} // else if
       
   994 						} // if
       
   995 					CleanupStack::PopAndDestroy(type);
       
   996 					}
       
   997 					break;
       
   998 				case EPackageTransferDerivedType:
       
   999 					{
       
  1000 					// package stuff
       
  1001 					CSBPackageTransferType* pType = CSBPackageTransferType::NewL(aTransferTypes[currentIndex]);
       
  1002 					CleanupStack::PushL(pType);
       
  1003 					_LIT(KPid, "Supplying data for Package ID: ");
       
  1004 					LogWithSID(LOG_LEVEL3, KPid, pType->PackageIdL());
       
  1005 					CleanupStack::PopAndDestroy(pType);
       
  1006 					}
       
  1007 					break;
       
  1008 				case EJavaTransferDerivedType:
       
  1009 					{
       
  1010 					// java stuff
       
  1011 					CSBJavaTransferType* jType = CSBJavaTransferType::NewL(aTransferTypes[currentIndex]);
       
  1012 					CleanupStack::PushL(jType);
       
  1013 					_LIT(KJid, "Supplying data for Java SuiteHash: ");
       
  1014 					LogWithText(LOG_LEVEL3, KJid, jType->SuiteHashL());
       
  1015 					CleanupStack::PopAndDestroy(jType);
       
  1016 					}
       
  1017 					break;
       
  1018 				
       
  1019 				} // switch
       
  1020 			TBool runAgain = ETrue;		
       
  1021 			do 
       
  1022 				{
       
  1023 				TBool finished;				
       
  1024 				TPtr8* bufferPtr = NULL;
       
  1025 				TRAP(error, bufferPtr = &iBackupClient->TransferDataAddressL());
       
  1026 				if (error != KErrNone)
       
  1027 					{
       
  1028 					_LIT(KErrTDA, "Error getting TransferDataAddress: ");
       
  1029 					LogWithNum(LOG_LEVEL4, KErrTDA, error);
       
  1030 					break;
       
  1031 					}
       
  1032 				TRAP(error, iStorageManager->RetrieveDataL(aTransferTypes[currentIndex], *bufferPtr, finished, incrIndex));
       
  1033 				if (error != KErrNone)
       
  1034 					{
       
  1035 					iStorageManager->Reset();
       
  1036 					if (error == KErrPathNotFound || error == KErrNotFound)
       
  1037 						{
       
  1038 						_LIT(KErrorText2, "Data doesn't exists");
       
  1039 						Log(LOG_LEVEL4, KErrorText2);
       
  1040 						}
       
  1041 					else
       
  1042 						{
       
  1043 						_LIT(KErrorText1, "Error reading from archive: ");
       
  1044 						LogWithNum(LOG_LEVEL4, KErrorText1, error);
       
  1045 						iFailures++;
       
  1046 						}
       
  1047 					break;
       
  1048 					} 
       
  1049 				else
       
  1050 					{
       
  1051 					_LIT(KLogBytes, "Number of bytes to send: ");
       
  1052 					LogWithNum(LOG_LEVEL4, KLogBytes, bufferPtr->Length());	
       
  1053 			
       
  1054 					TRAP(error, iBackupClient->SupplyDataL(*aTransferTypes[currentIndex], finished));
       
  1055 					if (error != KErrNone)
       
  1056 						{
       
  1057 						_LIT(KErrorText2, "Error supplying data to backup server: ");
       
  1058 						LogWithNum(LOG_LEVEL4, KErrorText2, error);
       
  1059 						if (iExpectStatus != error && iExpectStatus2 != error)
       
  1060 							{
       
  1061 							iFailures++;
       
  1062 							_LIT(KErrorText3, "Expect Error is: ");
       
  1063 							LogWithNum(LOG_LEVEL4, KErrorText3, iExpectStatus);
       
  1064 							}			
       
  1065 						break;
       
  1066 						}
       
  1067 					else
       
  1068 						{
       
  1069 						_LIT(KSuccess, "Operation finished successfully");
       
  1070 						Log(LOG_LEVEL4, KSuccess);
       
  1071 						}
       
  1072 					
       
  1073 					} // else
       
  1074 					
       
  1075 				if ((finished && !increments) || (incrIndex == increments && finished)) // if finished 
       
  1076 					{
       
  1077 					runAgain = EFalse;
       
  1078 					}
       
  1079 				else if (finished && incrIndex < increments) // is incremental data move to next increment
       
  1080 					{
       
  1081 					incrIndex++;
       
  1082 					runAgain = ETrue;
       
  1083 					}
       
  1084 				else 
       
  1085 					{
       
  1086 					runAgain = ETrue;
       
  1087 					}
       
  1088 				} // do
       
  1089 				while (runAgain);
       
  1090 			} // for
       
  1091 			
       
  1092 			if (!iFailures)
       
  1093 				{
       
  1094 				_LIT(KComp, "No errors found");
       
  1095 				Log(LOG_LEVEL3, KComp);
       
  1096 				}
       
  1097 		// Do not delete bufferPtr, as it gets deleted by the iBackupClient
       
  1098 		}
       
  1099 	
       
  1100 	TDriveList CBURTestStepBase::StringToDriveListL(TPtrC apText)
       
  1101 		/**
       
  1102 		@internalComponent
       
  1103 		@released
       
  1104 		
       
  1105 		@param apText - String that needs to be converted into a TDriveList.
       
  1106 		@return TDriveList with all the bytes set to 1 where a corresponding drive letter 
       
  1107 				was found in apText
       
  1108 		*/
       
  1109 		{
       
  1110 		TInt error;
       
  1111 		RFs fsSession;
       
  1112 		CleanupClosePushL(fsSession);
       
  1113 		error = fsSession.Connect();
       
  1114 		if (error != KErrNone)
       
  1115 			{
       
  1116 			User::Leave(error);
       
  1117 			}
       
  1118 		
       
  1119 		TUint8 str[KMaxDrives];
       
  1120 		for (TInt i = 0; i < KMaxDrives; ++i)
       
  1121 			{ 
       
  1122 			str[i] = 0; // Initialise to zero
       
  1123 			}
       
  1124 		
       
  1125 		TInt length = apText.Length();
       
  1126 		for (TInt i = 0; i < length; ++i)
       
  1127 			{
       
  1128 			TInt pos;
       
  1129 			fsSession.CharToDrive(apText.Ptr()[i], pos);
       
  1130 			str[pos] = 1;
       
  1131 			}
       
  1132 		
       
  1133 		TDriveList driveList;
       
  1134 		//driveList.FillZ(); // initialise to zeros
       
  1135 		TPtr8 ptr(&str[0], KMaxDrives, KMaxDrives);
       
  1136 		driveList.Copy(ptr);
       
  1137 		
       
  1138 		CleanupStack::PopAndDestroy();
       
  1139 		return driveList;
       
  1140 		}
       
  1141 		
       
  1142 	
       
  1143 	void CBURTestStepBase::SaveDataOwners()
       
  1144 		/**
       
  1145 		Saves data owners to storage Manager
       
  1146 		*/
       
  1147 		{
       
  1148 		TInt count = iDataOwners.Count();
       
  1149 		for (TInt i =0; i < count; i++)
       
  1150 			{
       
  1151 			TRAPD(err, iStorageManager->SaveDataOwnerL(*iDataOwners[i]));
       
  1152 			if (err != KErrNone)
       
  1153 				{
       
  1154 				_LIT(KDataOwnerErr, "Error saving Data Owner: ");
       
  1155 				LogWithNum(LOG_LEVEL2, KDataOwnerErr, err);
       
  1156 				}
       
  1157 			}
       
  1158 		}
       
  1159 	
       
  1160 	void CBURTestStepBase::CheckSIDStatusL(RTransferTypeArray& aTransferTypes, RTransferTypeArray& aReadyArray)
       
  1161 		/**
       
  1162 		Checks the readyness status for Active Data Owner. The ones are ready put into ready array and removed from the original
       
  1163 		
       
  1164 		@param aTransferTypes - TransferTypes to check for status
       
  1165 		@param aReadyArray - array of transfer types where dataowners are ready
       
  1166 		*/
       
  1167 		{
       
  1168 		aReadyArray.ResetAndDestroy();
       
  1169 		if (aTransferTypes.Count())
       
  1170 			{
       
  1171 			// used for getting statuses
       
  1172 			RSIDStatusArray statusArray;
       
  1173 			CleanupClosePushL(statusArray);
       
  1174 			// create array of sid for status request
       
  1175 			for (TInt i =0; i< aTransferTypes.Count(); i++)
       
  1176 				{
       
  1177 				TSecureId id = NULL;
       
  1178 				TSBDerivedType type = aTransferTypes[i]->DerivedTypeL();
       
  1179 				if (type == ESIDTransferDerivedType)
       
  1180 					{
       
  1181 					CSBSIDTransferType* sidType = CSBSIDTransferType::NewL(aTransferTypes[i]);
       
  1182 					CleanupStack::PushL(sidType);
       
  1183 					id = sidType->SecureIdL();
       
  1184 					CleanupStack::PopAndDestroy(sidType);
       
  1185 					statusArray.Append(TDataOwnerAndStatus(id, EUnset, KErrNone));	
       
  1186 					}
       
  1187 				} //for
       
  1188 						
       
  1189 			// get status for data owners	
       
  1190 			iBackupClient->SIDStatusL(statusArray);
       
  1191 			
       
  1192 			// check which sids ready
       
  1193 			TInt total = statusArray.Count();
       
  1194 			for (TInt j=0; j < total; j++)
       
  1195 				{
       
  1196 				TDataOwnerAndStatus test = statusArray[j];
       
  1197 				if (statusArray[j].iStatus == EDataOwnerReady)
       
  1198 					{
       
  1199 					LogWithSID(LOG_LEVEL3, _L("Data Owner ready: "),statusArray[j].iSID.iId);
       
  1200 					aReadyArray.Append(aTransferTypes[j]);
       
  1201 					statusArray.Remove(j);
       
  1202 					aTransferTypes.Remove(j);
       
  1203 					j--;
       
  1204 					total--;
       
  1205 					}
       
  1206 				else if (statusArray[j].iStatus == EDataOwnerReadyNoImpl || statusArray[j].iStatus == EDataOwnerFailed || statusArray[j].iStatus == EDataOwnerNotFound)
       
  1207 					{
       
  1208 					LogWithSID(LOG_LEVEL3, _L("Data Owner Failed, NotFound or Has No implementation : "),statusArray[j].iSID.iId);
       
  1209 					statusArray.Remove(j);
       
  1210 					delete aTransferTypes[j];
       
  1211 					aTransferTypes[j] = NULL;
       
  1212 					aTransferTypes.Remove(j);
       
  1213 					j--;
       
  1214 					total--;
       
  1215 					}
       
  1216 				else if(statusArray[j].iStatus == EDataOwnerNotConnected && EDataOwnerNotConnected == iExpectStatus)
       
  1217 					{//ignore this error
       
  1218 					LogWithSID(LOG_LEVEL3, _L("Data Owner not ready: "),statusArray[j].iSID.iId);
       
  1219 					statusArray.Remove(j);
       
  1220 					delete aTransferTypes[j];
       
  1221 					aTransferTypes[j] = NULL;
       
  1222 					aTransferTypes.Remove(j);
       
  1223 					j--;
       
  1224 					total--;
       
  1225 					}
       
  1226 				} //for	
       
  1227 			statusArray.Reset();
       
  1228 			CleanupStack::PopAndDestroy(&statusArray);
       
  1229 			} // if
       
  1230 		}
       
  1231 		
       
  1232 	TSecureId CBURTestStepBase::ExtractIDL(CDataOwnerInfo& aDataOwner)
       
  1233 		/**
       
  1234 		Gets Secure ID or UID from Data Owner
       
  1235 		
       
  1236 		@param aDataOwner Data Owner to get ID from
       
  1237 		
       
  1238 		@return TSecureId Secure ID of the data owner
       
  1239 		*/
       
  1240 		{
       
  1241 		TSecureId id = NULL;
       
  1242 		if (aDataOwner.Identifier().DerivedTypeL() == ESIDDerivedType)
       
  1243 			{
       
  1244 			CSBSecureId* secureId = CSBSecureId::NewL(&(aDataOwner.Identifier()));
       
  1245 			CleanupStack::PushL(secureId);
       
  1246 					
       
  1247 			id = secureId->SecureIdL();
       
  1248 												
       
  1249 			CleanupStack::PopAndDestroy(secureId);
       
  1250 			} // if				
       
  1251 		else if (aDataOwner.Identifier().DerivedTypeL() == EPackageDerivedType)
       
  1252 			{
       
  1253 			CSBPackageId* pkgId = CSBPackageId::NewL(&(aDataOwner.Identifier()));
       
  1254 			CleanupStack::PushL(pkgId);
       
  1255 			
       
  1256 			// package id		
       
  1257 			id = pkgId->PackageIdL();
       
  1258 				
       
  1259 			CleanupStack::PopAndDestroy(pkgId);
       
  1260 			} // else if
       
  1261 		return id;
       
  1262 		}
       
  1263 		
       
  1264 	HBufC* CBURTestStepBase::ExtractJavaIDL(CDataOwnerInfo& aDataOwner)
       
  1265 		/**
       
  1266 		Gets Suite Hash ID from the Data Owner
       
  1267 		
       
  1268 		@param aDataOwner - Data Owner to get suite hash from
       
  1269 		
       
  1270 		@return HBufC* pointe to a suite hash
       
  1271 		*/
       
  1272 		{
       
  1273 		HBufC* jid = NULL;
       
  1274 		if (aDataOwner.Identifier().DerivedTypeL() == EJavaDerivedType)
       
  1275 			{
       
  1276 			CSBJavaId* javaId = CSBJavaId::NewL(&(aDataOwner.Identifier()));
       
  1277 			CleanupStack::PushL(javaId);
       
  1278 			
       
  1279 			const TDesC& suiteHash = javaId->SuiteHashL();
       
  1280 			jid = HBufC::NewLC(suiteHash.Size());
       
  1281 			*jid = suiteHash;
       
  1282 			CleanupStack::Pop(jid);
       
  1283 			CleanupStack::PopAndDestroy(javaId);
       
  1284 			}
       
  1285 		return jid;
       
  1286 		}
       
  1287 		
       
  1288 	void CBURTestStepBase::CheckValidRegistrationL()
       
  1289 		/**
       
  1290 		Checks the list of data owners returned from the device for the validity of the registration file.
       
  1291 		If registration is invalid the data owner is removed from the list and not backed up or restored.
       
  1292 		*/
       
  1293 		{
       
  1294 		for (TInt i = 0; i < iDataOwners.Count(); i++)
       
  1295 			{
       
  1296 			switch (iDataOwners[i]->Identifier().DerivedTypeL())
       
  1297 				{
       
  1298 				case ESIDDerivedType:
       
  1299 					{
       
  1300 					_LIT(KFoundSid, "Sid in the list: ");
       
  1301 					LogWithSID(LOG_LEVEL3, KFoundSid, ExtractIDL(*iDataOwners[i]));
       
  1302 					}
       
  1303 					break;
       
  1304 		
       
  1305 				case EPackageDerivedType:
       
  1306 					{
       
  1307 					_LIT(KFoundPid, "Package in the list: ");
       
  1308 					LogWithSID(LOG_LEVEL3, KFoundPid, ExtractIDL(*iDataOwners[i]));
       
  1309 					}
       
  1310 					break;
       
  1311 				
       
  1312 				case EJavaDerivedType:
       
  1313 					{	
       
  1314 					HBufC* suiteHash = ExtractJavaIDL(*iDataOwners[i]);
       
  1315 					_LIT(KJava, "Java ID found: ");
       
  1316 					LogWithText(LOG_LEVEL3, KJava, *suiteHash);
       
  1317 					delete suiteHash;
       
  1318 					suiteHash = NULL;
       
  1319 					}
       
  1320 					break;
       
  1321 				default:
       
  1322 					_LIT(KLogErr, "Not supported type");
       
  1323 					Log(LOG_LEVEL3, KLogErr);
       
  1324 					break;
       
  1325 				}
       
  1326 			
       
  1327 			TCommonBURSettings settings = iDataOwners[i]->CommonSettings();
       
  1328 			// check if registration file was parsed correctly
       
  1329 			if (!(settings & EPassiveBUR))
       
  1330 				{
       
  1331 				if (!(settings & EActiveBUR))
       
  1332 					{
       
  1333 					if (!(settings & EHasSystemFiles))
       
  1334 						{
       
  1335 						delete iDataOwners[i];
       
  1336 						iDataOwners[i] = NULL;
       
  1337 						iDataOwners.Remove(i);
       
  1338 						i--;
       
  1339 						if (iIsPartial)
       
  1340 							{
       
  1341 							iFailures++;
       
  1342 							}
       
  1343 						_LIT(KBadReg, "*** Error: Bad Registration file for ID above ^^^");
       
  1344 						Log(LOG_LEVEL3, KBadReg);
       
  1345 						}
       
  1346 					
       
  1347 					}//if
       
  1348 				}//if
       
  1349 			}// for
       
  1350 		}
       
  1351 		
       
  1352 	void CBURTestStepBase::DoSupplyL(TTransferDataType aDataType)
       
  1353 		/**
       
  1354 		@internalComponent
       
  1355 		@released
       
  1356 		*/
       
  1357 		{
       
  1358 		GenerateSIDTransferTypesL(iTransferTypes, aDataType);
       
  1359 		if (iTransferTypes.Count())
       
  1360 			{
       
  1361 			// TODO: need to check weather we can supply snapshot without waiting
       
  1362 			if (aDataType == EActiveSnapshotData || aDataType == EActiveBaseData || aDataType == EActiveIncrementalData)
       
  1363 				{
       
  1364 			 	// used for sids which are ready
       
  1365 				RTransferTypeArray readyArray;
       
  1366 				CleanupClosePushL(readyArray);
       
  1367 					
       
  1368 				for (TInt i=0; i < KRetries;)
       
  1369 					{
       
  1370 					CheckSIDStatusL(iTransferTypes, readyArray);
       
  1371 											
       
  1372 					if (readyArray.Count()) // dataowners ready
       
  1373 						{
       
  1374 						// ========= Supply Data ================
       
  1375 						SupplyDataL(readyArray);		
       
  1376 						} 
       
  1377 					else if (iTransferTypes.Count()) // data owners not ready
       
  1378 						{
       
  1379 						User::After(KDelay);
       
  1380 						i++;
       
  1381 						}
       
  1382 					else // finished with all sids
       
  1383 						{
       
  1384 						break;
       
  1385 						}
       
  1386 					} // for
       
  1387 				if (iTransferTypes.Count())
       
  1388 					{
       
  1389 					iFailures++;
       
  1390 					_LIT(KLogNoTrans, "***Error: Some Data Owners were Not Ready or Failed to Connect");
       
  1391 					Log(LOG_LEVEL3, KLogNoTrans);
       
  1392 					}
       
  1393 				readyArray.ResetAndDestroy();
       
  1394 				CleanupStack::PopAndDestroy(&readyArray);
       
  1395 				} //if
       
  1396 			else 
       
  1397 				{
       
  1398 				SupplyDataL(iTransferTypes);
       
  1399 				}	
       
  1400 			} //if
       
  1401 		}
       
  1402 		
       
  1403 	// CBURActiveObject //
       
  1404 	
       
  1405 	/**
       
  1406 	Standard Symbian OS Constructor
       
  1407 	@return pointer to newly allocated CBURActiveObject object
       
  1408 	*/
       
  1409 	CBURActiveObject* CBURActiveObject::NewL()
       
  1410 		{
       
  1411 		CBURActiveObject* self = new(ELeave) CBURActiveObject();
       
  1412 		CleanupStack::PushL(self);
       
  1413 		self->ConstructL();
       
  1414 		CleanupStack::Pop(self);
       
  1415 		return self;
       
  1416 		}
       
  1417 		
       
  1418 	/**
       
  1419 	C++ Standard destructor
       
  1420 	*/
       
  1421 	CBURActiveObject::~CBURActiveObject()
       
  1422 		{
       
  1423 		Cancel();
       
  1424 		delete iActiveScheduler;
       
  1425 		}
       
  1426 	
       
  1427 	/**
       
  1428 	C++ Standard Constructor
       
  1429 	*/
       
  1430 	CBURActiveObject::CBURActiveObject()
       
  1431 		: CActive(EPriorityNormal), iError(KErrNone)
       
  1432 		{
       
  1433 		}
       
  1434 	
       
  1435 	/**
       
  1436 	Symbian OS 2nd phase constructor
       
  1437 	*/
       
  1438 	void CBURActiveObject::ConstructL()
       
  1439 		{
       
  1440 		iActiveScheduler = new (ELeave) CActiveSchedulerWait();
       
  1441 		CActiveScheduler::Add(this);		
       
  1442 		}
       
  1443 	
       
  1444 	/**
       
  1445 	CActive::DoCancel() implementation
       
  1446 	Stops ActiveSchedulerWait if it is Started
       
  1447 	*/
       
  1448 	void CBURActiveObject::DoCancel()
       
  1449 		{
       
  1450 		if (iActiveScheduler->IsStarted())
       
  1451 			{
       
  1452 			iActiveScheduler->AsyncStop();
       
  1453 			}
       
  1454 		}
       
  1455 	
       
  1456 	/**
       
  1457 	Waits for the Status to complete, remembers the iStatus code and calls AsyncStop
       
  1458 	*/
       
  1459 	void CBURActiveObject::RunL()
       
  1460 		{
       
  1461 		iError = iStatus.Int();
       
  1462 		iActiveScheduler->AsyncStop();
       
  1463 		}
       
  1464 	/**
       
  1465 	CActive::RunError() implementation
       
  1466 	@param aError error code
       
  1467 	@return KErrNone
       
  1468 	*/
       
  1469 	TInt CBURActiveObject::RunError(TInt aError)
       
  1470 		{
       
  1471 		iError = aError;
       
  1472 		Cancel();
       
  1473 		return KErrNone;
       
  1474 		}
       
  1475 	
       
  1476 	/**
       
  1477 	Starts and active object and Scheduler, the call will be complete when RunL is called
       
  1478 	*/
       
  1479 	void CBURActiveObject::StartL()
       
  1480 		{
       
  1481 		if (IsActive())
       
  1482 			{
       
  1483 			User::Leave(KErrInUse);
       
  1484 			}
       
  1485 		iStatus = KRequestPending;
       
  1486 		SetActive();
       
  1487 		iActiveScheduler->Start();
       
  1488 		}
       
  1489 	/**
       
  1490 	Returns an error/completing code of the iStatus
       
  1491 	*/
       
  1492 	TInt CBURActiveObject::Error()
       
  1493 		{
       
  1494 		return iError;
       
  1495 		}
       
  1496 		
       
  1497 	}	// end namespace
       
  1498