os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_ParseData.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 #include "T_ParseData.h"
    20 
    21 
    22 // Commands
    23 _LIT( KCmdDelete,					"~" );
    24 _LIT( KCmdAddDir,					"AddDir");
    25 _LIT( KCmdPopDir,					"PopDir");
    26 _LIT( KCmdNew,						"new" );
    27 _LIT( KCmdSet,						"Set" );
    28 _LIT( KCmdSetNoWild,				"SetNoWild" );
    29 // Parameters
    30 _LIT( KParamDefaultSpec,			"DefaultSpec" );
    31 _LIT( KParamFileSpec,				"FileName" );
    32 _LIT( KParamRelatedSpec,			"RelatedSpec" );
    33 _LIT( KParamDirName,				"DirName" );
    34 
    35 
    36 CT_ParseData* CT_ParseData::NewL()
    37 /**
    38 * Two phase constructor
    39 */
    40 	{
    41 	CT_ParseData* ret = new (ELeave) CT_ParseData();
    42 	CleanupStack::PushL( ret );
    43 	ret->ConstructL();
    44 	CleanupStack::Pop( ret );
    45 	return ret;
    46 	}
    47 
    48 TParseBase* CT_ParseData::GetParse()
    49 	{
    50 	return iParse;
    51 	}
    52 	
    53 
    54 CT_ParseData::CT_ParseData()
    55 :	iParse(NULL)
    56 /**
    57 * Protected constructor. First phase construction
    58 */
    59 	{
    60 	}
    61 	
    62 void CT_ParseData::ConstructL()
    63 /**
    64 * Protected constructor. Second phase construction
    65 */
    66 	{
    67 	}
    68 	
    69 CT_ParseData::~CT_ParseData()
    70 /**
    71 * Destructor.
    72 */
    73 	{
    74 	DoCleanup();
    75 	}
    76 	
    77 
    78 TAny* CT_ParseData::GetObject()
    79 /**
    80 * Return a pointer to the object that the data wraps
    81 *
    82 * @return pointer to the object that the data wraps
    83 */
    84 	{
    85 	return iParse;
    86 	}
    87 
    88 TBool CT_ParseData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
    89 /**
    90 * Process a command read from the ini file
    91 *
    92 * @param aCommand	the command to process
    93 * @param aSection		the entry in the ini file requiring the command to be processed
    94 *
    95 * @return ETrue if the command is processed
    96 */
    97 	{
    98 	TBool retVal = ETrue;
    99 		
   100 	if ( aCommand == KCmdDelete )
   101 		{
   102 		DoCleanup();
   103 		}
   104 	else if ( aCommand == KCmdNew )
   105 		{
   106 		DoCmdNew();
   107 		}
   108 	else if ( aCommand == KCmdSet )
   109 		{
   110 		DoCmdSet( aSection );
   111 		}
   112 	else if ( aCommand == KCmdSetNoWild )
   113 		{
   114 		DoCmdSetNoWild( aSection );
   115 		}
   116 	else if ( aCommand == KCmdPopDir )
   117 		{
   118 		DoCmdPopDir();
   119 		}
   120 	else if ( aCommand == KCmdAddDir )
   121 		{
   122 		DoCmdAddDir( aSection );
   123 		}
   124 	else
   125 	    {
   126 	    retVal = CT_ParseBaseData::DoCommandL(aCommand,aSection,aAsyncErrorIndex);
   127 	    }
   128 	
   129 	return retVal;
   130 	}
   131 	
   132 void CT_ParseData::DoCleanup()
   133 /** Deletes TParse class instance */
   134     {
   135     INFO_PRINTF1( _L( "Delete TParse class instance." ) );
   136     
   137 	delete iParse;
   138 	iParse = NULL;
   139     }
   140 
   141 void CT_ParseData::DoCmdNew()
   142 /** Creates new TParse class instance */
   143 	{
   144 	DoCleanup();
   145 	
   146 	INFO_PRINTF1( _L( "Create new TParse class instance." ) );
   147 		
   148 	TRAPD( err, iParse = new (ELeave) TParse() );
   149 	if ( err != KErrNone )
   150 		{
   151 		ERR_PRINTF2( _L( "new TParse error=%d" ), err );
   152 		SetError( err );
   153 		}
   154 	}
   155 	
   156 void CT_ParseData::DoCmdSet( const TDesC& aSection )
   157 	{
   158 	TPtrC fileSpec;
   159 	if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSpec, aSection, fileSpec ) )
   160 		{
   161 		TPtrC relatedSpec(_L(""));
   162 		GET_OPTIONAL_STRING_PARAMETER( KParamRelatedSpec, aSection, relatedSpec );
   163 		
   164 		TPtrC defaultSpec(_L(""));
   165 		GET_OPTIONAL_STRING_PARAMETER( KParamDefaultSpec, aSection, defaultSpec );
   166 		
   167 		INFO_PRINTF4( _L( "Set(%S, %S, %S)"), &fileSpec, &relatedSpec, &defaultSpec );
   168 		
   169 		TInt error = iParse->Set( fileSpec, &relatedSpec, &defaultSpec );
   170 		
   171 		if ( error != KErrNone)
   172 			{
   173 			ERR_PRINTF2( _L( "Set() returned %d error"), error);
   174 			SetError(error);
   175 			}
   176 		}
   177 	}
   178 	
   179 void CT_ParseData::DoCmdSetNoWild( const TDesC& aSection )
   180 	{
   181 	TPtrC fileSpec;
   182 	if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSpec, aSection, fileSpec ) )
   183 		{
   184 		TPtrC relatedSpec(_L(""));
   185 		GET_OPTIONAL_STRING_PARAMETER( KParamRelatedSpec, aSection, relatedSpec );
   186 		
   187 		TPtrC defaultSpec(_L(""));
   188 		GET_OPTIONAL_STRING_PARAMETER( KParamDefaultSpec, aSection, defaultSpec );
   189 		
   190 		INFO_PRINTF4( _L( "SetNoWild(%S, %S, %S)"), &fileSpec, &relatedSpec, &defaultSpec );
   191 		
   192 		TInt error = iParse->SetNoWild( fileSpec, &relatedSpec, &defaultSpec );
   193 	
   194 		if ( error != KErrNone)
   195 			{
   196 			ERR_PRINTF2( _L( "SetNoWild() returned %d error"), error);
   197 			SetError(error);
   198 			}
   199 		}
   200 	}
   201 	
   202 	
   203 void CT_ParseData::DoCmdPopDir()
   204 /** Removes the last directory from the path using PopDir(). */
   205 	{
   206 	INFO_PRINTF1( _L( "PopDir()" ) );
   207 
   208 	TInt error = iParse->PopDir();
   209 	if( error != KErrNone)
   210 		{
   211 		ERR_PRINTF2( _L( "PopDir() returned %d error"), error);
   212 		SetError(error);
   213 		}
   214 	}
   215 	
   216     
   217 void CT_ParseData::DoCmdAddDir( const TDesC& aSection )
   218 /** Adds a single directory onto the end of the path using AddDir. */
   219 	{
   220 	TPtrC dirName;
   221 	if ( GET_MANDATORY_STRING_PARAMETER( KParamDirName, aSection, dirName ) )
   222 		{
   223 		INFO_PRINTF2( _L( "AddDir(\"%S\")" ), &dirName );
   224 		
   225 		TInt error = iParse->AddDir( dirName );
   226 		if(	error != KErrNone)
   227 			{
   228 			ERR_PRINTF2( _L( "AddDir() returned %d error"), error);
   229 			SetError(error);
   230 			}
   231 		}
   232 	}
   233