1 /* |
1 /* |
2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2002-2009 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 "inifile.h" |
24 #include <usb/usblogger.h> |
25 #include <usb/usblogger.h> |
25 #include "inifile.h" |
26 |
26 #include "OstTraceDefinitions.h" |
27 #ifdef __FLOG_ACTIVE |
27 #ifdef OST_TRACE_COMPILER_IN_USE |
28 _LIT8(KLogComponent, "IniFile"); |
28 #include "inifileTraces.h" |
|
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 OstTrace1( TRACE_NORMAL, CINIFILE_PANIC, "CIniFile::Panic;aPanic=%d", aPanic ); |
38 _USB_PANIC(KIniData,aPanic); |
39 User::Panic(KIniData,aPanic ); |
|
40 } |
39 } |
41 |
40 |
42 CIniFile::CIniFile() |
41 CIniFile::CIniFile() |
43 : iPtr(NULL,0) |
42 : iPtr(NULL,0) |
44 { |
43 { |
45 OstTraceFunctionEntry1( CINIFILE_CINIFILE_CONS_ENTRY, this ); |
44 LOG_FUNC |
46 } |
45 } |
47 |
46 |
48 CIniFile::~CIniFile() |
47 CIniFile::~CIniFile() |
49 { |
48 { |
50 delete (TText*)iPtr.Ptr(); |
49 delete (TText*)iPtr.Ptr(); |
57 * Factory function for CIniFile. |
56 * Factory function for CIniFile. |
58 * |
57 * |
59 * @param aName The name of the ini file to be used, e.g. "GPRSBTT.INI". |
58 * @param aName The name of the ini file to be used, e.g. "GPRSBTT.INI". |
60 */ |
59 */ |
61 { |
60 { |
62 OstTraceFunctionEntry0( CINIFILE_NEWL_TDESC_ENTRY ); |
61 LOG_STATIC_FUNC_ENTRY |
63 |
62 |
64 CIniFile* self = new(ELeave) CIniFile; |
63 CIniFile* self = new(ELeave) CIniFile; |
65 CleanupStack::PushL(self); |
64 CleanupStack::PushL(self); |
66 self->ConstructL(aName, KDefaultIniFileDir); |
65 self->ConstructL(aName, KDefaultIniFileDir); |
67 CleanupStack::Pop(self); |
66 CleanupStack::Pop(self); |
68 OstTraceFunctionExit0( CINIFILE_NEWL_TDESC_EXIT ); |
|
69 return self; |
67 return self; |
70 } |
68 } |
71 |
69 |
72 CIniFile* CIniFile::NewL(const TDesC& aName, const TDesC& aPath) |
70 CIniFile* CIniFile::NewL(const TDesC& aName, const TDesC& aPath) |
73 /** |
71 /** |
76 * |
74 * |
77 * @param aName The name of the ini file to be used, e.g. "GPRSBTT.INI". |
75 * @param aName The name of the ini file to be used, e.g. "GPRSBTT.INI". |
78 * @param aPath The location of the file e.g. "\\system\\data\\". |
76 * @param aPath The location of the file e.g. "\\system\\data\\". |
79 */ |
77 */ |
80 { |
78 { |
81 OstTraceFunctionEntry0( CINIFILE_NEWL_TDESC_TDESC_ENTRY ); |
79 LOG_STATIC_FUNC_ENTRY |
82 |
80 |
83 CIniFile* self = new(ELeave) CIniFile; |
81 CIniFile* self = new(ELeave) CIniFile; |
84 CleanupStack::PushL(self); |
82 CleanupStack::PushL(self); |
85 self->ConstructL(aName, aPath); |
83 self->ConstructL(aName, aPath); |
86 CleanupStack::Pop(self); |
84 CleanupStack::Pop(self); |
87 OstTraceFunctionExit0( CINIFILE_NEWL_TDESC_TDESC_EXIT ); |
|
88 return self; |
85 return self; |
89 } |
86 } |
90 |
87 |
91 void CIniFile::ConstructL(const TDesC& aName, const TDesC& aPath) |
88 void CIniFile::ConstructL(const TDesC& aName, const TDesC& aPath) |
92 /** |
89 /** |
96 */ |
93 */ |
97 { |
94 { |
98 iToken = HBufC::NewL(KTokenSize+2); // 2 extra chars for [] |
95 iToken = HBufC::NewL(KTokenSize+2); // 2 extra chars for [] |
99 |
96 |
100 RFs fs; |
97 RFs fs; |
101 TInt err; |
98 LEAVEIFERRORL(fs.Connect()); |
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 } |
|
108 CleanupClosePushL(fs); |
99 CleanupClosePushL(fs); |
109 |
100 |
110 TFindFile ff(fs); |
101 TFindFile ff(fs); |
111 |
102 |
112 err = ff.FindByDir(aName, aPath); |
103 LEAVEIFERRORL(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 } |
|
118 |
104 |
119 iName = ff.File().AllocL(); |
105 iName = ff.File().AllocL(); |
120 |
106 |
121 RFile file; |
107 RFile file; |
122 TInt size; |
108 TInt size; |
123 err = file.Open(fs,*iName,EFileStreamText|EFileRead|EFileShareReadersOnly); |
109 LEAVEIFERRORL(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 } |
|
129 CleanupClosePushL(file); |
110 CleanupClosePushL(file); |
130 |
111 |
131 err = file.Size(size); |
112 LEAVEIFERRORL(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 } |
|
137 |
113 |
138 |
114 |
139 TText* data = REINTERPRET_CAST(TText*, User::AllocL(size)); |
115 TText* data = REINTERPRET_CAST(TText*, User::AllocL(size)); |
140 iPtr.Set(data, size/sizeof(TText), size/sizeof(TText)); |
116 iPtr.Set(data, size/sizeof(TText), size/sizeof(TText)); |
141 TPtr8 dest(REINTERPRET_CAST(TUint8*,data), 0, size); |
117 TPtr8 dest(REINTERPRET_CAST(TUint8*,data), 0, size); |
142 err = file.Read(dest); |
118 LEAVEIFERRORL(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 } |
|
148 |
119 |
149 TUint8* ptr = REINTERPRET_CAST(TUint8*,data); |
120 TUint8* ptr = REINTERPRET_CAST(TUint8*,data); |
150 |
121 |
151 // |
122 // |
152 // This is orderred as FEFF assuming the processor is Little Endian |
123 // This is orderred as FEFF assuming the processor is Little Endian |