telephonyserverplugins/multimodetsy/test/gprs/tcfgfile.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 02 Feb 2010 01:41:59 +0200
changeset 0 3553901f7fa8
permissions -rw-r--r--
Revision: 201005 Kit: 201005

// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// TESTUTL.CPP
// \file TCfgFile.cpp
// This cpp file is taken from the t_inet project.
// It uses a ini file to store settings that can
// be changed like IP addresses and webpage addresses.
// The loading of the drivers has been removed from this file.
// 
//

#include "tcfgfile.h"
#include <f32file.h>




//PhilippeG 15/05/2000
//New object to load and parse the test parameters file
CConfigParams* CConfigParams::NewL(const TDesC &aCfgFileName)
	{
	CConfigParams *f;
	f=new (ELeave) CConfigParams();
	CleanupStack::PushL(f);
	//A leave during the ConstrucL is not fatal, just means there's no param file
	TRAPD(err,f->ConstructL(aCfgFileName));
	CleanupStack::Pop();
	return f;
	}
void CConfigParams::ConstructL(const TDesC &aCfgFileName)
	{
	//Find the config file
	TAutoClose<RFs> fs;
	User::LeaveIfError(fs.iObj.Connect());
	fs.PushL();
	//Location for the test parameter config file
	_LIT(KTinetConfigFilePaths,"\\;\\system\\data\\");
	TFindFile filePath(fs.iObj);
	User::LeaveIfError(filePath.FindByPath(aCfgFileName,&KTinetConfigFilePaths));
	//read the content of the file
	TAutoClose<RFile> fl;
	fl.PushL();
	User::LeaveIfError(fl.iObj.Open(fs.iObj,filePath.File(),EFileShareExclusive));
	User::LeaveIfError(fl.iObj.Read(iConfigParamBuf8));
	iConfigParamBuf.Copy(iConfigParamBuf8);
	CleanupStack::Pop(2);
	iFileExist = ETrue;
	}

const TPtrC CConfigParams::FindAlphaVar(const TDesC &aVarName, const TDesC &aDefault)
	{
	if(!iFileExist)
		return TPtrC(aDefault);
	TInt pos=iConfigParamBuf.Find(aVarName);
	if (pos==KErrNotFound)
		return TPtrC(aDefault);
	TLex lex(iConfigParamBuf.Mid(pos));
	lex.SkipCharacters();
	lex.SkipSpaceAndMark();		// Should be at the start of the data
	lex.SkipCharacters();
	return TPtrC(lex.MarkedToken().Ptr(),lex.MarkedToken().Length());
	}
const TInt CConfigParams::FindNumVar(const TDesC &aVarName, const TInt aDefault)
	{
	TInt result;
	TPtrC ptr = FindAlphaVar(aVarName,KNullDesC);
	if(ptr.Length())
		{
		TLex lex(ptr);
		if (lex.Val(result)==KErrNone)
			return result;
		}
	return aDefault;
	}