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