multimediacommsengine/tsrc/MMCTestDriver/MCETester/src/TCmdFileHandler.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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:    Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <flogger.h>
       
    22 #include "TCmdFileHandler.h"
       
    23 #include "MCEConstants.h"
       
    24 
       
    25 
       
    26 /**
       
    27  * INPUT:
       
    28  *   Headers:		-
       
    29  *   Parameters:	-
       
    30  *   IDs:			-
       
    31  *
       
    32  * OUTPUT:
       
    33  *   Parameters:	-
       
    34  *   IDs:			-
       
    35  */
       
    36 
       
    37 
       
    38 void TCmdFileHandler::ExecuteL()
       
    39 	{
       
    40 	// -- Setup ---------------------------------------------------------------
       
    41 	TPtrC8 fileName_GetInfo = ExtractTextL( KParamGetFileInfo, EFalse );
       
    42 	
       
    43 	TPtrC8 fileName_Delete = ExtractTextL( KParamDeleteFile, EFalse );
       
    44 	
       
    45 	TPtrC8 fileName_Exists = ExtractTextL( KParamCheckFileExists, EFalse );
       
    46 	
       
    47 	TPtrC8 dirName = ExtractTextL( KParamGetFilesFromFolder, EFalse );
       
    48 
       
    49 	// -- Execution -----------------------------------------------------------
       
    50 	iHandler = CTcMCEFileHandler::NewL();
       
    51 	
       
    52 	//delete the file	
       
    53 	if( fileName_Delete.Compare( KNullDesC8 ) != 0 ) 
       
    54 		{
       
    55 		TFileName filename;
       
    56 		filename.Copy(fileName_Delete);
       
    57 		if(iHandler->Delete(filename) == EFalse) User::LeaveIfError(KErrNotFound);
       
    58 		}
       
    59 	
       
    60 	//check if file exists
       
    61 	if( fileName_Exists.Compare( KNullDesC8 ) != 0 ) 
       
    62 		{
       
    63 		TFileName filename;
       
    64 		filename.Copy(fileName_Exists);
       
    65 		
       
    66 		if(iHandler->CheckFileExists(filename))
       
    67 			{
       
    68 			AddBooleanResponseL(_L8("FileExists"), ETrue);
       
    69 			}
       
    70 		else
       
    71 			{
       
    72 			AddBooleanResponseL(_L8("FileExists"), EFalse);
       
    73 			}
       
    74 		}
       
    75 	
       
    76 	//get file info
       
    77 	if( fileName_GetInfo.Compare( KNullDesC8 ) != 0 ) 
       
    78 		{
       
    79 		TFileName filename;
       
    80 		filename.Copy(fileName_GetInfo);
       
    81 		
       
    82 		CDesC8Array* fileInfo = new(ELeave)CDesC8ArraySeg(1);
       
    83 		CleanupStack::PushL(fileInfo);
       
    84 		iHandler->GetFileInfoL(filename, fileInfo);
       
    85 		
       
    86 		AddArrayResponseL( _L8("FileInfo"), *fileInfo );
       
    87 		
       
    88 		CleanupStack::PopAndDestroy(fileInfo);
       
    89 		}
       
    90 	
       
    91 	//get files from folder
       
    92 	if( dirName.Compare( KNullDesC8 ) != 0 ) 
       
    93 		{
       
    94 		TFileName folderName;
       
    95 		folderName.Copy(dirName);
       
    96 		
       
    97 		CDesC8Array* files = new(ELeave)CDesC8ArraySeg(1);
       
    98 		CleanupStack::PushL(files);
       
    99 		iHandler->GetFilesFromFolderL(folderName, files);
       
   100 		
       
   101 		AddArrayResponseL( _L8("FilesFromFolder"), *files );
       
   102 		
       
   103 		CleanupStack::PopAndDestroy(files);
       
   104 		}
       
   105 	
       
   106 	//find file
       
   107 	CTcStructure* structure;
       
   108 	//get the folder name and file name from the structure
       
   109 	do
       
   110 		{
       
   111 		structure = FindStructureL( KParamFindFile, EFalse );
       
   112 		if( structure )
       
   113 			{
       
   114 			CTcNameValue* item;
       
   115 			//structure contains a list of name-value pairs
       
   116 			for (int i=0; i < structure->Count(); i++)
       
   117 				{
       
   118 				item = structure->ItemL( i );
       
   119 				if( item )break;
       
   120 				}			
       
   121 			if( item )
       
   122 				{
       
   123 				//get the folder name
       
   124 				TFileName folderName;
       
   125 				folderName.Copy(item->Name());
       
   126 				//name of the file or wildcard
       
   127 				TFileName fileName;
       
   128 				fileName.Copy(item->Value());
       
   129 				
       
   130 				CDesC8Array* fileList = new(ELeave)CDesC8ArraySeg(1);
       
   131 				CleanupStack::PushL(fileList);
       
   132 				iHandler->FindFile(folderName, fileName, fileList);
       
   133 					
       
   134 				AddArrayResponseL( _L8("FileList"), *fileList );
       
   135 					
       
   136 				CleanupStack::PopAndDestroy(fileList);
       
   137 				
       
   138 				iContext.List().RemoveParameter( KParamFindFile );
       
   139 				break;
       
   140 				}
       
   141 			}
       
   142 	} while( structure );
       
   143 	
       
   144 	// -- Response creation ---------------------------------------------------
       
   145 	delete iHandler;
       
   146 	}
       
   147 
       
   148 TBool TCmdFileHandler::Match( const TTcIdentifier& aId )
       
   149 	{
       
   150 	return TTcMceCommandBase::Match( aId, _L8("FileHandler") );
       
   151 	}
       
   152 
       
   153 TTcCommandBase* TCmdFileHandler::CreateL( MTcTestContext& aContext )
       
   154 	{
       
   155 	return new( ELeave ) TCmdFileHandler( aContext );
       
   156 	}