os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_DirScanData.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20 @test
    21 @internalComponent
    22 v
    23 This contains CT_DirScanData
    24 */
    25 
    26 //	User includes
    27 #include "T_DirScanData.h"
    28 #include "T_SfSrvServer.h"
    29 
    30 /*@{*/
    31 ///	Parameters
    32 _LIT(KAttMask,							"attmask" );
    33 _LIT(KRfsObject,						"rfsObject");
    34 _LIT(KDirObject,						"dirObject");
    35 _LIT(KExpected,							"expected");
    36 _LIT(KPath,								"path");
    37 _LIT(KEntrySortKey,						"sortkey");
    38 _LIT(KScanDirection,					"scandirection");
    39 
    40 ///Commands
    41 _LIT(KCmdNewL,							"NewL");
    42 _LIT(KCmdNewLC,							"NewLC");
    43 _LIT(KCmdSetScanDataL,					"SetScanDataL");
    44 _LIT(KCmdFullPath,						"FullPath");
    45 _LIT(KCmdAbbreviatedPath,				"AbbreviatedPath");
    46 _LIT(KCmdNextL,							"NextL");
    47 _LIT(KCmdDestructor,					"~");
    48 
    49 //	Sort key
    50 _LIT(KESortNone,						"ESortNone");
    51 _LIT(KESortByName,						"ESortByName");
    52 _LIT(KESortByExt,						"ESortByExt");
    53 _LIT(KESortBySize,						"ESortBySize");
    54 _LIT(KESortByDate,						"ESortByDate");
    55 _LIT(KESortByUid,						"ESortByUid");
    56 _LIT(KEDirsAnyOrder,					"EDirsAnyOrder");
    57 _LIT(KEDirsFirst,						"EDirsFirst");
    58 _LIT(KEDirsLast,						"EDirsLast");
    59 _LIT(KEAscending,						"EAscending");
    60 _LIT(KEDescending,						"EDescending");
    61 _LIT(KEDirDescending,					"EDirDescending");
    62 
    63 // Scan directions
    64 _LIT(KEScanUpTree,	 					"EScanUpTree");
    65 _LIT(KEScanDownTree,	 				"EScanDownTree");
    66 
    67 
    68 CT_DirScanData* CT_DirScanData::NewL()
    69 /**
    70 * Two phase constructor
    71 */
    72 	{
    73 	CT_DirScanData* ret = new (ELeave) CT_DirScanData();
    74 	CleanupStack::PushL(ret);
    75 	ret->ConstructL();
    76 	CleanupStack::Pop(ret);
    77 	return ret;
    78 	}
    79 	
    80 
    81 CT_DirScanData::CT_DirScanData()
    82 :	iDirScan(NULL)
    83 /**
    84 * Protected constructor. First phase construction
    85 */
    86 	{
    87 	}
    88 
    89 
    90 void CT_DirScanData::ConstructL()
    91 /**
    92 * Protected constructor. Second phase construction
    93 */
    94 	{
    95 	}
    96 
    97 
    98 CT_DirScanData::~CT_DirScanData()
    99 /**
   100 * Destructor.
   101 */
   102 	{
   103 	DoCleanup();
   104 	}
   105 
   106 
   107 TAny* CT_DirScanData::GetObject()
   108 	{
   109 	return iDirScan;
   110 	}
   111 
   112 
   113 TBool	CT_DirScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   114 /**
   115 * Process a command read from the ini file
   116 *
   117 * @param aCommand	the command to process
   118 * @param aSection	the section in the ini file requiring the command to be processed
   119 *
   120 * @return ETrue if the command is processed
   121 */
   122 	{
   123 	TBool	retVal = ETrue;
   124 
   125 	if (aCommand == KCmdNewL)
   126 		{
   127 		DoCmdNewL(aSection);
   128 		}
   129 	else if (aCommand == KCmdDestructor)
   130 		{
   131 		DoCleanup();
   132 		}
   133 	else if (aCommand == KCmdNewLC)
   134 		{
   135 		DoCmdNewLC(aSection);
   136 		}
   137 	else if (aCommand == KCmdSetScanDataL)
   138 		{
   139 		DoCmdSetScanDataL(aSection);
   140 		}
   141 	else if (aCommand == KCmdNextL)
   142 		{
   143 		DoCmdNextL(aSection);
   144 		}
   145 	else if (aCommand == KCmdAbbreviatedPath)
   146 		{
   147 		DoCmdAbbreviatedPath(aSection);
   148 		}
   149 	else if (aCommand == KCmdFullPath)
   150 		{
   151 		DoCmdFullPath(aSection);
   152 		}
   153 	else
   154 		{
   155 		retVal = EFalse;
   156 		}
   157 	return retVal;
   158 	}
   159 
   160 void CT_DirScanData::DoCleanup()
   161 	{
   162 	INFO_PRINTF1(_L("Doing cleanup!"));
   163 	
   164 	if (iDirScan)
   165 		{
   166 		delete iDirScan;
   167 		iDirScan = NULL;
   168 		}
   169 	}
   170 		
   171 void CT_DirScanData::DoCmdNewL(const TDesC& aSection)
   172 	{
   173 	INFO_PRINTF1(_L("Constructing CDirScan object!"));
   174 	
   175 	RFs*	rfsObject = NULL;
   176 	TPtrC	rfsObjectName;
   177 	if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName))
   178 		{
   179 		rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
   180 		}
   181 	
   182 	DoCleanup();
   183 	TRAPD (error, iDirScan = CDirScan::NewL(*rfsObject));
   184 	if (error == KErrNone)
   185 		{
   186 		INFO_PRINTF1(_L("CDirScan object has been created with NewL constructor!"));			
   187 		}
   188 	else
   189 		{
   190 		ERR_PRINTF2(_L("CDirScan object is not created with NewL constructor! Error code: %d"), error);
   191 		SetError(error);
   192 		}
   193 	}
   194 	
   195 void CT_DirScanData::DoCmdNewLC(const TDesC& aSection)
   196 	{
   197 	INFO_PRINTF1(_L("Constructing CDirScan object!"));
   198 	
   199 	RFs*	rfsObject = NULL;
   200 	TPtrC	rfsObjectName;
   201 	if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName))
   202 		{
   203 		rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
   204 		}
   205 	
   206 	DoCleanup();
   207 	TRAPD (error, iDirScan = CDirScan::NewLC(*rfsObject); CleanupStack::Pop(iDirScan) );
   208 	if (error == KErrNone)
   209 		{
   210 		INFO_PRINTF1(_L("CDirScan object has been created with NewLC constructor!"));
   211 		}
   212 	else
   213 		{
   214 		ERR_PRINTF2(_L("CDirScan object is not created with NewLC constructor! Error code: %d"), error);
   215 		SetError(error);
   216 		}
   217 	}
   218 
   219 void CT_DirScanData::DoCmdSetScanDataL(const TDesC& aSection)
   220 	{
   221 	INFO_PRINTF1(_L("Setting data scanning!"));
   222 	
   223 	TBool	dataOk = ETrue;
   224 	
   225 	TPtrC	path;
   226 	if (!GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path))
   227 		{
   228 		dataOk = EFalse;
   229 		}
   230 
   231 	TUint	attMask = KEntryAttHidden;
   232 	if ( !FileserverUtil::GetAttMask(*this, aSection, KAttMask(), attMask))
   233         {
   234        	dataOk = EFalse;
   235        	}
   236 
   237 	TPtrC	entrySortKey;
   238 	TUint	sortKey = ESortNone;
   239 	
   240 	if (GET_OPTIONAL_STRING_PARAMETER(KEntrySortKey(), aSection, entrySortKey))
   241 		{
   242 		if ( !ConvertToSortKey(entrySortKey, sortKey) )
   243 			{
   244 			TInt	intTemp;
   245 			if ( GET_MANDATORY_INT_PARAMETER(KEntrySortKey(), aSection, intTemp) )
   246 				{
   247 				sortKey=intTemp;
   248 				}
   249 			else
   250 				{
   251 				dataOk = EFalse;
   252 				}
   253 			}
   254 		}
   255 		
   256 	TPtrC						entryScanDirection;
   257 	CDirScan::TScanDirection	scanDirection = CDirScan::EScanDownTree;
   258 	
   259 	if (GET_OPTIONAL_STRING_PARAMETER(KScanDirection(), aSection, entryScanDirection))
   260 		{
   261 		if ( !ConvertToScanDirection(entryScanDirection, scanDirection))
   262             {
   263            	dataOk = EFalse;
   264            	}
   265 		}
   266 		
   267 	
   268 	if (dataOk)
   269 		{
   270 		TRAPD (err, iDirScan->SetScanDataL(path, attMask, sortKey, scanDirection));
   271 		if(err == KErrNone)
   272 			{
   273 			INFO_PRINTF1(_L("SetScanDataL complete!"));
   274 			}
   275 		else
   276 			{
   277 			ERR_PRINTF2(_L("SetScanDataL() Error: %d"), err);
   278 			SetError(err);
   279 			}
   280 		}
   281 	}	
   282 
   283 void CT_DirScanData::DoCmdNextL(const TDesC& aSection)
   284 	{
   285 	INFO_PRINTF1(_L("Scanning next directory entries!"));
   286 	
   287 	CDir*		dirObject = NULL;
   288 	CT_DirData* dirWrapperObject = NULL;
   289 	TPtrC		dirObjectName;
   290 	
   291 	if (GET_MANDATORY_STRING_PARAMETER(KDirObject, aSection, dirObjectName))
   292 		{
   293 		dirWrapperObject = static_cast<CT_DirData*>(GetDataWrapperL(dirObjectName));
   294 		}
   295 	TRAPD (err, iDirScan->NextL(dirObject));
   296 	if (err == KErrNone)
   297 		{
   298 		if (dirObject == NULL)
   299 			{
   300 			INFO_PRINTF1(_L("CDir instance is NULL, there is no directory left to go."));
   301 			}
   302 		else
   303 			{
   304 			INFO_PRINTF1(_L("Scanning the next directory entry completed successfully!"));
   305 			}
   306 		}
   307 	else
   308 		{
   309 		ERR_PRINTF2(_L("Can't scan the next directory entry in the structure Error code: %d"), err);
   310 		SetError(err);
   311 		}
   312 		
   313 	if (dirObject)
   314 		{
   315 		if(dirWrapperObject)
   316 			{
   317 			dirWrapperObject->SetObjectL(dirObject);
   318 			}
   319 		else
   320 		    {
   321 		    delete dirObject;
   322 		    dirObject = NULL;			        
   323 		    }
   324 		}	
   325 	}
   326 	
   327 void CT_DirScanData::DoCmdAbbreviatedPath(const TDesC& aSection)
   328 	{
   329 	INFO_PRINTF1(_L("Getting directory abbreviated path!"));
   330 	
   331 	TPtrC	expected;
   332 	if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected))
   333 		{
   334 		TPtrC	abbPath;
   335 		abbPath.Set(iDirScan->AbbreviatedPath());
   336 		
   337 		if (abbPath != expected)
   338 			{
   339 			ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &abbPath, &expected);
   340 			SetBlockResult(EFail);
   341 			}
   342 		else 
   343 			{
   344 			INFO_PRINTF2(_L("Result (%S) match with expected result!"), &abbPath);
   345 			}
   346 		}
   347 	}
   348 
   349 void CT_DirScanData::DoCmdFullPath(const TDesC& aSection)
   350 	{
   351 	INFO_PRINTF1(_L("Getting directory full path!"));
   352 	
   353 	TPtrC	expected;
   354 	if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected))
   355 		{
   356 		TPtrC	fullPath;
   357 		fullPath.Set(iDirScan->FullPath());
   358 		
   359 		if (fullPath != expected)
   360 			{
   361 			ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &fullPath, &expected);
   362 			SetBlockResult(EFail);
   363 			}
   364 		else 
   365 			{
   366 			INFO_PRINTF2(_L("Result (%S) match with expected result!"), &fullPath);
   367 			}
   368 		}
   369 	}
   370 	
   371 	
   372 TBool CT_DirScanData::ConvertToSortKey(const TDesC& aSortKeyStr, TUint& aSortKey)
   373 	{
   374 	TBool ret = ETrue;
   375 
   376 	if (aSortKeyStr == KESortNone)
   377 		{
   378 		aSortKey = ESortNone;
   379 		}
   380 	else if (aSortKeyStr == KESortByName)
   381 		{
   382 		aSortKey = ESortByName;
   383 		}
   384 	else if (aSortKeyStr == KESortByExt)
   385 		{
   386 		aSortKey = ESortByExt;
   387 		}
   388 	else if (aSortKeyStr == KESortBySize)
   389 		{
   390 		aSortKey = ESortBySize;
   391 		}
   392 	else if (aSortKeyStr == KESortByDate)
   393 		{
   394 		aSortKey = ESortByDate;
   395 		}
   396 	else if (aSortKeyStr == KESortByUid)
   397 		{
   398 		aSortKey = ESortByUid;
   399 		}
   400 	else if (aSortKeyStr == KEDirsAnyOrder)
   401 		{
   402 		aSortKey = EDirsAnyOrder;
   403 		}
   404 	else if (aSortKeyStr == KEDirsFirst)
   405 		{
   406 		aSortKey = EDirsFirst;
   407 		}
   408 	else if (aSortKeyStr == KEDirsLast)
   409 		{
   410 		aSortKey = EDirsLast;
   411 		}
   412 	else if (aSortKeyStr == KEAscending)
   413 		{
   414 		aSortKey = EAscending;
   415 		}
   416 	else if (aSortKeyStr == KEDescending)
   417 		{
   418 		aSortKey = EDescending;
   419 		}
   420 	else if (aSortKeyStr == KEDirDescending)
   421 		{
   422 		aSortKey = EDirDescending;
   423 		}
   424 	else if (aSortKeyStr.Match((_L("*|*"))) != KErrNotFound)
   425 		{
   426 		TUint tmpSortKey;
   427 
   428 		TInt location = aSortKeyStr.Match(_L("*|*"));
   429 		//Converting Left part of the data
   430 		TPtrC left = aSortKeyStr.Left(location);
   431 		if (ConvertToSortKey(left, tmpSortKey))
   432 			{
   433 			aSortKey = tmpSortKey;
   434 			}
   435 		else
   436 			{
   437 			ret = EFalse;
   438 			}
   439 
   440 		//Converting right data can be with another "|"
   441 		TPtrC right = aSortKeyStr.Mid(location + 1);
   442 
   443 		if (ConvertToSortKey(right, tmpSortKey))
   444 			{
   445 			aSortKey = aSortKey | tmpSortKey;
   446 			}
   447 		else
   448 			{
   449 			ret = EFalse;
   450 			}
   451 		}
   452 	else
   453 		{
   454 		ret = EFalse;
   455 		}
   456 
   457 	return ret;
   458 	}
   459 
   460 
   461 	
   462 TBool CT_DirScanData::ConvertToScanDirection(const TDesC& aScanDirectionStr, CDirScan::TScanDirection& aScanDirection)
   463 	{
   464 	TBool ret = ETrue;
   465 
   466 	if (aScanDirectionStr == KEScanUpTree)
   467 		{
   468 		aScanDirection = CDirScan::EScanUpTree;
   469 		}
   470 	else if (aScanDirectionStr == KEScanDownTree)
   471 		{
   472 		aScanDirection = CDirScan::EScanDownTree;
   473 		}
   474 	else
   475 		{
   476 		ret = EFalse;
   477 		}
   478 
   479 	return ret;
   480 	}