os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_ParseData.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_ParseData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,233 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "T_ParseData.h"
    1.23 +
    1.24 +
    1.25 +// Commands
    1.26 +_LIT( KCmdDelete,					"~" );
    1.27 +_LIT( KCmdAddDir,					"AddDir");
    1.28 +_LIT( KCmdPopDir,					"PopDir");
    1.29 +_LIT( KCmdNew,						"new" );
    1.30 +_LIT( KCmdSet,						"Set" );
    1.31 +_LIT( KCmdSetNoWild,				"SetNoWild" );
    1.32 +// Parameters
    1.33 +_LIT( KParamDefaultSpec,			"DefaultSpec" );
    1.34 +_LIT( KParamFileSpec,				"FileName" );
    1.35 +_LIT( KParamRelatedSpec,			"RelatedSpec" );
    1.36 +_LIT( KParamDirName,				"DirName" );
    1.37 +
    1.38 +
    1.39 +CT_ParseData* CT_ParseData::NewL()
    1.40 +/**
    1.41 +* Two phase constructor
    1.42 +*/
    1.43 +	{
    1.44 +	CT_ParseData* ret = new (ELeave) CT_ParseData();
    1.45 +	CleanupStack::PushL( ret );
    1.46 +	ret->ConstructL();
    1.47 +	CleanupStack::Pop( ret );
    1.48 +	return ret;
    1.49 +	}
    1.50 +
    1.51 +TParseBase* CT_ParseData::GetParse()
    1.52 +	{
    1.53 +	return iParse;
    1.54 +	}
    1.55 +	
    1.56 +
    1.57 +CT_ParseData::CT_ParseData()
    1.58 +:	iParse(NULL)
    1.59 +/**
    1.60 +* Protected constructor. First phase construction
    1.61 +*/
    1.62 +	{
    1.63 +	}
    1.64 +	
    1.65 +void CT_ParseData::ConstructL()
    1.66 +/**
    1.67 +* Protected constructor. Second phase construction
    1.68 +*/
    1.69 +	{
    1.70 +	}
    1.71 +	
    1.72 +CT_ParseData::~CT_ParseData()
    1.73 +/**
    1.74 +* Destructor.
    1.75 +*/
    1.76 +	{
    1.77 +	DoCleanup();
    1.78 +	}
    1.79 +	
    1.80 +
    1.81 +TAny* CT_ParseData::GetObject()
    1.82 +/**
    1.83 +* Return a pointer to the object that the data wraps
    1.84 +*
    1.85 +* @return pointer to the object that the data wraps
    1.86 +*/
    1.87 +	{
    1.88 +	return iParse;
    1.89 +	}
    1.90 +
    1.91 +TBool CT_ParseData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
    1.92 +/**
    1.93 +* Process a command read from the ini file
    1.94 +*
    1.95 +* @param aCommand	the command to process
    1.96 +* @param aSection		the entry in the ini file requiring the command to be processed
    1.97 +*
    1.98 +* @return ETrue if the command is processed
    1.99 +*/
   1.100 +	{
   1.101 +	TBool retVal = ETrue;
   1.102 +		
   1.103 +	if ( aCommand == KCmdDelete )
   1.104 +		{
   1.105 +		DoCleanup();
   1.106 +		}
   1.107 +	else if ( aCommand == KCmdNew )
   1.108 +		{
   1.109 +		DoCmdNew();
   1.110 +		}
   1.111 +	else if ( aCommand == KCmdSet )
   1.112 +		{
   1.113 +		DoCmdSet( aSection );
   1.114 +		}
   1.115 +	else if ( aCommand == KCmdSetNoWild )
   1.116 +		{
   1.117 +		DoCmdSetNoWild( aSection );
   1.118 +		}
   1.119 +	else if ( aCommand == KCmdPopDir )
   1.120 +		{
   1.121 +		DoCmdPopDir();
   1.122 +		}
   1.123 +	else if ( aCommand == KCmdAddDir )
   1.124 +		{
   1.125 +		DoCmdAddDir( aSection );
   1.126 +		}
   1.127 +	else
   1.128 +	    {
   1.129 +	    retVal = CT_ParseBaseData::DoCommandL(aCommand,aSection,aAsyncErrorIndex);
   1.130 +	    }
   1.131 +	
   1.132 +	return retVal;
   1.133 +	}
   1.134 +	
   1.135 +void CT_ParseData::DoCleanup()
   1.136 +/** Deletes TParse class instance */
   1.137 +    {
   1.138 +    INFO_PRINTF1( _L( "Delete TParse class instance." ) );
   1.139 +    
   1.140 +	delete iParse;
   1.141 +	iParse = NULL;
   1.142 +    }
   1.143 +
   1.144 +void CT_ParseData::DoCmdNew()
   1.145 +/** Creates new TParse class instance */
   1.146 +	{
   1.147 +	DoCleanup();
   1.148 +	
   1.149 +	INFO_PRINTF1( _L( "Create new TParse class instance." ) );
   1.150 +		
   1.151 +	TRAPD( err, iParse = new (ELeave) TParse() );
   1.152 +	if ( err != KErrNone )
   1.153 +		{
   1.154 +		ERR_PRINTF2( _L( "new TParse error=%d" ), err );
   1.155 +		SetError( err );
   1.156 +		}
   1.157 +	}
   1.158 +	
   1.159 +void CT_ParseData::DoCmdSet( const TDesC& aSection )
   1.160 +	{
   1.161 +	TPtrC fileSpec;
   1.162 +	if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSpec, aSection, fileSpec ) )
   1.163 +		{
   1.164 +		TPtrC relatedSpec(_L(""));
   1.165 +		GET_OPTIONAL_STRING_PARAMETER( KParamRelatedSpec, aSection, relatedSpec );
   1.166 +		
   1.167 +		TPtrC defaultSpec(_L(""));
   1.168 +		GET_OPTIONAL_STRING_PARAMETER( KParamDefaultSpec, aSection, defaultSpec );
   1.169 +		
   1.170 +		INFO_PRINTF4( _L( "Set(%S, %S, %S)"), &fileSpec, &relatedSpec, &defaultSpec );
   1.171 +		
   1.172 +		TInt error = iParse->Set( fileSpec, &relatedSpec, &defaultSpec );
   1.173 +		
   1.174 +		if ( error != KErrNone)
   1.175 +			{
   1.176 +			ERR_PRINTF2( _L( "Set() returned %d error"), error);
   1.177 +			SetError(error);
   1.178 +			}
   1.179 +		}
   1.180 +	}
   1.181 +	
   1.182 +void CT_ParseData::DoCmdSetNoWild( const TDesC& aSection )
   1.183 +	{
   1.184 +	TPtrC fileSpec;
   1.185 +	if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSpec, aSection, fileSpec ) )
   1.186 +		{
   1.187 +		TPtrC relatedSpec(_L(""));
   1.188 +		GET_OPTIONAL_STRING_PARAMETER( KParamRelatedSpec, aSection, relatedSpec );
   1.189 +		
   1.190 +		TPtrC defaultSpec(_L(""));
   1.191 +		GET_OPTIONAL_STRING_PARAMETER( KParamDefaultSpec, aSection, defaultSpec );
   1.192 +		
   1.193 +		INFO_PRINTF4( _L( "SetNoWild(%S, %S, %S)"), &fileSpec, &relatedSpec, &defaultSpec );
   1.194 +		
   1.195 +		TInt error = iParse->SetNoWild( fileSpec, &relatedSpec, &defaultSpec );
   1.196 +	
   1.197 +		if ( error != KErrNone)
   1.198 +			{
   1.199 +			ERR_PRINTF2( _L( "SetNoWild() returned %d error"), error);
   1.200 +			SetError(error);
   1.201 +			}
   1.202 +		}
   1.203 +	}
   1.204 +	
   1.205 +	
   1.206 +void CT_ParseData::DoCmdPopDir()
   1.207 +/** Removes the last directory from the path using PopDir(). */
   1.208 +	{
   1.209 +	INFO_PRINTF1( _L( "PopDir()" ) );
   1.210 +
   1.211 +	TInt error = iParse->PopDir();
   1.212 +	if( error != KErrNone)
   1.213 +		{
   1.214 +		ERR_PRINTF2( _L( "PopDir() returned %d error"), error);
   1.215 +		SetError(error);
   1.216 +		}
   1.217 +	}
   1.218 +	
   1.219 +    
   1.220 +void CT_ParseData::DoCmdAddDir( const TDesC& aSection )
   1.221 +/** Adds a single directory onto the end of the path using AddDir. */
   1.222 +	{
   1.223 +	TPtrC dirName;
   1.224 +	if ( GET_MANDATORY_STRING_PARAMETER( KParamDirName, aSection, dirName ) )
   1.225 +		{
   1.226 +		INFO_PRINTF2( _L( "AddDir(\"%S\")" ), &dirName );
   1.227 +		
   1.228 +		TInt error = iParse->AddDir( dirName );
   1.229 +		if(	error != KErrNone)
   1.230 +			{
   1.231 +			ERR_PRINTF2( _L( "AddDir() returned %d error"), error);
   1.232 +			SetError(error);
   1.233 +			}
   1.234 +		}
   1.235 +	}
   1.236 +