telephonyserverplugins/multimodetsy/test/gprs/tcfgfile.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // TESTUTL.CPP
       
    15 // \file TCfgFile.cpp
       
    16 // This cpp file is taken from the t_inet project.
       
    17 // It uses a ini file to store settings that can
       
    18 // be changed like IP addresses and webpage addresses.
       
    19 // The loading of the drivers has been removed from this file.
       
    20 // 
       
    21 //
       
    22 
       
    23 #include "tcfgfile.h"
       
    24 #include <f32file.h>
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 //PhilippeG 15/05/2000
       
    30 //New object to load and parse the test parameters file
       
    31 CConfigParams* CConfigParams::NewL(const TDesC &aCfgFileName)
       
    32 	{
       
    33 	CConfigParams *f;
       
    34 	f=new (ELeave) CConfigParams();
       
    35 	CleanupStack::PushL(f);
       
    36 	//A leave during the ConstrucL is not fatal, just means there's no param file
       
    37 	TRAPD(err,f->ConstructL(aCfgFileName));
       
    38 	CleanupStack::Pop();
       
    39 	return f;
       
    40 	}
       
    41 void CConfigParams::ConstructL(const TDesC &aCfgFileName)
       
    42 	{
       
    43 	//Find the config file
       
    44 	TAutoClose<RFs> fs;
       
    45 	User::LeaveIfError(fs.iObj.Connect());
       
    46 	fs.PushL();
       
    47 	//Location for the test parameter config file
       
    48 	_LIT(KTinetConfigFilePaths,"\\;\\system\\data\\");
       
    49 	TFindFile filePath(fs.iObj);
       
    50 	User::LeaveIfError(filePath.FindByPath(aCfgFileName,&KTinetConfigFilePaths));
       
    51 	//read the content of the file
       
    52 	TAutoClose<RFile> fl;
       
    53 	fl.PushL();
       
    54 	User::LeaveIfError(fl.iObj.Open(fs.iObj,filePath.File(),EFileShareExclusive));
       
    55 	User::LeaveIfError(fl.iObj.Read(iConfigParamBuf8));
       
    56 	iConfigParamBuf.Copy(iConfigParamBuf8);
       
    57 	CleanupStack::Pop(2);
       
    58 	iFileExist = ETrue;
       
    59 	}
       
    60 
       
    61 const TPtrC CConfigParams::FindAlphaVar(const TDesC &aVarName, const TDesC &aDefault)
       
    62 	{
       
    63 	if(!iFileExist)
       
    64 		return TPtrC(aDefault);
       
    65 	TInt pos=iConfigParamBuf.Find(aVarName);
       
    66 	if (pos==KErrNotFound)
       
    67 		return TPtrC(aDefault);
       
    68 	TLex lex(iConfigParamBuf.Mid(pos));
       
    69 	lex.SkipCharacters();
       
    70 	lex.SkipSpaceAndMark();		// Should be at the start of the data
       
    71 	lex.SkipCharacters();
       
    72 	return TPtrC(lex.MarkedToken().Ptr(),lex.MarkedToken().Length());
       
    73 	}
       
    74 const TInt CConfigParams::FindNumVar(const TDesC &aVarName, const TInt aDefault)
       
    75 	{
       
    76 	TInt result;
       
    77 	TPtrC ptr = FindAlphaVar(aVarName,KNullDesC);
       
    78 	if(ptr.Length())
       
    79 		{
       
    80 		TLex lex(ptr);
       
    81 		if (lex.Val(result)==KErrNone)
       
    82 			return result;
       
    83 		}
       
    84 	return aDefault;
       
    85 	}