wlanapitest/wlanhaitest/wlan/src/T_RFileData.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     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 #include "t_rfiledata.h"
       
    21 
       
    22 /*@{*/
       
    23 //LIT for the command DoCmdGenerateFile
       
    24 _LIT(KCmdGenerateFile,				"GenerateFile");
       
    25 /*@}*/
       
    26 
       
    27 /*@{*/
       
    28 //LITs for param reads from the ini file
       
    29 _LIT(KFile,						"File");
       
    30 _LIT(KSize,						"Size");
       
    31 /*@}*/
       
    32 
       
    33 
       
    34 /**
       
    35  * Two phase constructor
       
    36  *
       
    37  * @leave	system wide error
       
    38  */
       
    39 CT_RFileData* CT_RFileData::NewL()
       
    40 	{
       
    41 	CT_RFileData* ret = new (ELeave) CT_RFileData();
       
    42 	CleanupStack::PushL(ret);
       
    43 	ret->ConstructL();
       
    44 	CleanupStack::Pop(ret);
       
    45 	return ret;
       
    46 	}
       
    47 
       
    48 /**
       
    49  * Public destructor
       
    50  */
       
    51 CT_RFileData::~CT_RFileData() 
       
    52 	{
       
    53 	iFs.Close();
       
    54 	
       
    55 	if (iFile)
       
    56 		{
       
    57 		delete iFile;
       
    58 		iFile = NULL;
       
    59 		}
       
    60 	}
       
    61 
       
    62 /**
       
    63  * Private constructor. First phase construction
       
    64  */
       
    65 CT_RFileData::CT_RFileData()
       
    66 :	iFile(NULL),
       
    67 	iFs()
       
    68 	{
       
    69 	}
       
    70 
       
    71 /**
       
    72  * Second phase construction
       
    73  *
       
    74  * @internalComponent
       
    75  *
       
    76  * @return	N/A
       
    77  *
       
    78  * @pre		None
       
    79  * @post	None
       
    80  *
       
    81  * @leave	system wide error
       
    82  */
       
    83 void CT_RFileData::ConstructL()
       
    84 	{
       
    85 	iFile = new (ELeave)RFile();
       
    86 	}
       
    87 
       
    88 /**
       
    89  * Return a pointer to the object that the data wraps
       
    90  *
       
    91  * @return	pointer to the object that the data wraps
       
    92  */
       
    93 TAny* CT_RFileData::GetObject()
       
    94 	{
       
    95 	return iFile;
       
    96 	}
       
    97 
       
    98 /**
       
    99  * Process a command read from the Ini file
       
   100  * @param aCommand 			The command to process
       
   101  * @param aSection			The section get from the *.ini file of the project T_Wlan
       
   102  * @param aAsyncErrorIndex	Command index dor async calls to returns errors to
       
   103  * @return TBool			ETrue if the command is process
       
   104  * @leave					system wide error
       
   105  */
       
   106 
       
   107 TBool CT_RFileData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   108 	{
       
   109 	TBool ret =ETrue;
       
   110 	if(aCommand == KCmdGenerateFile())
       
   111 		{
       
   112 		 DoCmdGenerateFile(aSection);
       
   113 		}
       
   114 	else
       
   115 		{
       
   116 		ERR_PRINTF1(_L("Unknown command."));
       
   117 		ret = EFalse;
       
   118 		}
       
   119 	return ret;
       
   120 	}
       
   121 
       
   122 
       
   123 /**
       
   124  * Command to generate a file for uploading in a host. If there are errors, SetBlockResult() and SetError() 
       
   125  * are used for management.
       
   126  * @param aSection				Section in the ini file for this command
       
   127  * @return
       
   128  */
       
   129 void CT_RFileData::DoCmdGenerateFile(const TTEFSectionName& aSection)
       
   130 	{
       
   131 	INFO_PRINTF1(_L("*START* CT_RFileData::DoCmdGenerateFile"));
       
   132 	
       
   133 	TBool dataOk = ETrue;
       
   134 	
       
   135 	TPtrC file;
       
   136 	if(!GetStringFromConfig(aSection, KFile, file))
       
   137 		{
       
   138         ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KFile);       
       
   139         SetBlockResult(EFail);
       
   140         dataOk = EFalse;
       
   141 		}
       
   142 
       
   143 	TInt size;
       
   144 	if(!GetIntFromConfig(aSection, KSize, size))
       
   145 		{
       
   146         ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSize);
       
   147         SetBlockResult(EFail);
       
   148         dataOk = EFalse;
       
   149 		}
       
   150 
       
   151 	if (dataOk)
       
   152 		{
       
   153 		INFO_PRINTF1(_L("Connect RFs"));
       
   154 
       
   155 		CleanupClosePushL( iFs );
       
   156 		CleanupClosePushL( *iFile );
       
   157 		
       
   158 		TInt err = iFs.Connect();
       
   159 		if(err == KErrNone)
       
   160 			{
       
   161 			INFO_PRINTF1(_L("Replace file"));
       
   162 			err = iFile->Replace( iFs, file, EFileShareAny|EFileWrite );
       
   163 			if(err == KErrNone)
       
   164 				{
       
   165 				INFO_PRINTF1(_L("Set file size"));
       
   166 				err = iFile->SetSize( size );
       
   167 				if(err != KErrNone)
       
   168 					{
       
   169 					ERR_PRINTF2(_L("CT_RFileData::DoCmdGenerateFile: file.SetSize(...) Failed with error %d"), err);
       
   170 					SetError(err);
       
   171 					}
       
   172 				}
       
   173 			else
       
   174 				{
       
   175 				ERR_PRINTF2(_L("CT_RFileData::DoCmdGenerateFile: file.Replace(...) Failed with error %d"), err);
       
   176 				SetError(err);
       
   177 				}
       
   178 			}
       
   179 		else
       
   180 			{
       
   181 			ERR_PRINTF2(_L("CT_RFileData::DoCmdGenerateFile: fs.Connect() Failed with error %d"), err);
       
   182 			SetError(err);
       
   183 			}
       
   184 		
       
   185 		INFO_PRINTF1(_L("Close RFile handle"));
       
   186 		CleanupStack::PopAndDestroy( iFile );
       
   187 		INFO_PRINTF1(_L("Close RFs handle"));	
       
   188 		CleanupStack::PopAndDestroy( &iFs );	
       
   189 		}
       
   190 	
       
   191 	INFO_PRINTF1(_L("*END* CT_RFileData::DoCmdGenerateFile"));
       
   192 	}