usbmgmt/usbmgr/inifile/src/inifile.cpp
changeset 29 59aa7d6e3e0f
parent 0 c9bc50fca66e
child 43 012cc2ee6408
equal deleted inserted replaced
28:f1fd07aa74c9 29:59aa7d6e3e0f
     1 /*
     1 /*
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 /**
    19 /**
    20  @file
    20  @file
    21 */
    21 */
    22 
    22 
    23 #include <f32file.h>
    23 #include <f32file.h>
       
    24 #include <usb/usblogger.h>
    24 #include "inifile.h"
    25 #include "inifile.h"
    25 #include <usb/usblogger.h>
    26 #include "OstTraceDefinitions.h"
    26 
    27 #ifdef OST_TRACE_COMPILER_IN_USE
    27 #ifdef __FLOG_ACTIVE
    28 #include "inifileTraces.h"
    28 _LIT8(KLogComponent, "IniFile");
       
    29 #endif
    29 #endif
    30 
    30 
    31 
    31 
    32 const TUint KTokenSize = 32;
    32 const TUint KTokenSize = 32;
    33 _LIT(KDefaultIniFileDir,"\\");
    33 _LIT(KDefaultIniFileDir,"\\");
    34 
    34 
    35 void CIniFile::Panic(TIniPanic aPanic)
    35 void CIniFile::Panic(TIniPanic aPanic)
    36 	{
    36 	{
    37 	_LIT(KIniData,"CIniFile");
    37 	_LIT(KIniData,"CIniFile");	
    38 	_USB_PANIC(KIniData,aPanic);
    38 	OstTrace1( TRACE_NORMAL, CINIFILE_PANIC, "CIniFile::Panic;aPanic=%d", aPanic );
       
    39 	User::Panic(KIniData,aPanic );
    39 	}
    40 	}
    40 
    41 
    41 CIniFile::CIniFile() 
    42 CIniFile::CIniFile() 
    42  :	iPtr(NULL,0)
    43  :	iPtr(NULL,0)
    43 	{
    44 	{
    44 	LOG_FUNC
    45     OstTraceFunctionEntry1( CINIFILE_CINIFILE_CONS_ENTRY, this );
    45 	}
    46 	}
    46 
    47 
    47 CIniFile::~CIniFile()
    48 CIniFile::~CIniFile()
    48 	{
    49 	{
    49 	delete (TText*)iPtr.Ptr();
    50 	delete (TText*)iPtr.Ptr();
    56  * Factory function for CIniFile.
    57  * Factory function for CIniFile.
    57  *
    58  *
    58  * @param aName The name of the ini file to be used, e.g. "GPRSBTT.INI".
    59  * @param aName The name of the ini file to be used, e.g. "GPRSBTT.INI".
    59  */
    60  */
    60 	{
    61 	{
    61 	LOG_STATIC_FUNC_ENTRY
    62     OstTraceFunctionEntry0( CINIFILE_NEWL_TDESC_ENTRY );
    62 
    63 
    63 	CIniFile* self = new(ELeave) CIniFile;
    64 	CIniFile* self = new(ELeave) CIniFile;
    64 	CleanupStack::PushL(self);
    65 	CleanupStack::PushL(self);
    65 	self->ConstructL(aName, KDefaultIniFileDir);
    66 	self->ConstructL(aName, KDefaultIniFileDir);
    66 	CleanupStack::Pop(self);
    67 	CleanupStack::Pop(self);
       
    68 	OstTraceFunctionExit0( CINIFILE_NEWL_TDESC_EXIT );
    67 	return self;
    69 	return self;
    68 	}
    70 	}
    69 
    71 
    70 CIniFile* CIniFile::NewL(const TDesC& aName, const TDesC& aPath)
    72 CIniFile* CIniFile::NewL(const TDesC& aName, const TDesC& aPath)
    71 /**
    73 /**
    74  *
    76  *
    75  * @param aName The name of the ini file to be used, e.g. "GPRSBTT.INI".
    77  * @param aName The name of the ini file to be used, e.g. "GPRSBTT.INI".
    76  * @param aPath The location of the file e.g. "\\system\\data\\".
    78  * @param aPath The location of the file e.g. "\\system\\data\\".
    77  */
    79  */
    78  {
    80  {
    79 	LOG_STATIC_FUNC_ENTRY
    81     OstTraceFunctionEntry0( CINIFILE_NEWL_TDESC_TDESC_ENTRY );
    80 
    82 
    81  	CIniFile* self = new(ELeave) CIniFile;
    83  	CIniFile* self = new(ELeave) CIniFile;
    82 	CleanupStack::PushL(self);
    84 	CleanupStack::PushL(self);
    83 	self->ConstructL(aName, aPath);
    85 	self->ConstructL(aName, aPath);
    84 	CleanupStack::Pop(self);
    86 	CleanupStack::Pop(self);
       
    87 	OstTraceFunctionExit0( CINIFILE_NEWL_TDESC_TDESC_EXIT );
    85 	return self;	 	
    88 	return self;	 	
    86  }
    89  }
    87  
    90  
    88 void CIniFile::ConstructL(const TDesC& aName, const TDesC& aPath)
    91 void CIniFile::ConstructL(const TDesC& aName, const TDesC& aPath)
    89 /**
    92 /**
    93  */
    96  */
    94 	{
    97 	{
    95     iToken = HBufC::NewL(KTokenSize+2);	// 2 extra chars for []
    98     iToken = HBufC::NewL(KTokenSize+2);	// 2 extra chars for []
    96 
    99 
    97 	RFs fs;
   100 	RFs fs;
    98 	LEAVEIFERRORL(fs.Connect());
   101 	TInt err;
       
   102 	err = fs.Connect();	
       
   103 	if(err < 0)
       
   104 	    {
       
   105         OstTrace1( TRACE_NORMAL, CINIFILE_CONSTRUCTL, "CIniFile::ConstructL;fs.Connect() with error=%d", err );
       
   106         User::Leave(err);
       
   107 	    }
    99 	CleanupClosePushL(fs);
   108 	CleanupClosePushL(fs);
   100 
   109 
   101 	TFindFile ff(fs);
   110 	TFindFile ff(fs);
   102 
   111 
   103 	LEAVEIFERRORL(ff.FindByDir(aName, aPath));
   112 	err = ff.FindByDir(aName, aPath);
       
   113 	if(err < 0)
       
   114 	    {
       
   115         OstTrace1( TRACE_NORMAL, CINIFILE_CONSTRUCTL_DUP1, "CIniFile::ConstructL;ff.FindByDir(aName, aPath) with error=%d", err );
       
   116         User::Leave(err);
       
   117 	    }
   104 
   118 
   105 	iName = ff.File().AllocL();
   119 	iName = ff.File().AllocL();
   106 	
   120 	
   107 	RFile file;
   121 	RFile file;
   108 	TInt size;
   122 	TInt size;
   109 	LEAVEIFERRORL(file.Open(fs,*iName,EFileStreamText|EFileRead|EFileShareReadersOnly));
   123 	err = file.Open(fs,*iName,EFileStreamText|EFileRead|EFileShareReadersOnly);
       
   124 	if(err < 0)
       
   125 	    {
       
   126         OstTrace1( TRACE_NORMAL, CINIFILE_CONSTRUCTL_DUP2, "CIniFile::ConstructL;file.Open(fs,*iName,EFileStreamText|EFileRead|EFileShareReadersOnly) with error=%d", err );
       
   127         User::Leave(err);
       
   128 	    }
   110 	CleanupClosePushL(file);
   129 	CleanupClosePushL(file);
   111 	
   130 	
   112 	LEAVEIFERRORL(file.Size(size));
   131 	err = file.Size(size);
       
   132 	if(err < 0)
       
   133 	    {
       
   134         OstTrace1( TRACE_NORMAL, CINIFILE_CONSTRUCTL_DUP3, "CIniFile::ConstructL;file.Size(size) with error=%d", err );
       
   135         User::Leave(err);
       
   136 	    }
   113 
   137 
   114 
   138 
   115 	TText* data = REINTERPRET_CAST(TText*, User::AllocL(size));
   139 	TText* data = REINTERPRET_CAST(TText*, User::AllocL(size));
   116 	iPtr.Set(data, size/sizeof(TText), size/sizeof(TText));
   140 	iPtr.Set(data, size/sizeof(TText), size/sizeof(TText));
   117 	TPtr8 dest(REINTERPRET_CAST(TUint8*,data), 0, size);
   141 	TPtr8 dest(REINTERPRET_CAST(TUint8*,data), 0, size);
   118 	LEAVEIFERRORL(file.Read(dest)); 
   142 	err = file.Read(dest);
       
   143 	if(err < 0)
       
   144 	    {
       
   145         OstTrace1( TRACE_NORMAL, CINIFILE_CONSTRUCTL_DUP4, "CIniFile::ConstructL;file.Read(dest) with error=%d", err );
       
   146         User::Leave(err);
       
   147 	    }
   119 
   148 
   120 	TUint8* ptr = REINTERPRET_CAST(TUint8*,data);
   149 	TUint8* ptr = REINTERPRET_CAST(TUint8*,data);
   121 
   150 
   122 	//
   151 	//
   123 	// This is orderred as FEFF assuming the processor is Little Endian
   152 	// This is orderred as FEFF assuming the processor is Little Endian