0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "DataWrapperBase.h"
|
|
19 |
|
|
20 |
/*@{*/
|
|
21 |
/// Constant Literals used.
|
|
22 |
_LIT(KIncludeSection, "include");
|
|
23 |
_LIT(KFile, "file%d");
|
|
24 |
_LIT(KMatch, "*{*,*}*");
|
|
25 |
_LIT(KStart, "{");
|
|
26 |
_LIT(KSeparator, ",");
|
|
27 |
_LIT(KEnd, "}");
|
|
28 |
_LIT(KDataRead, "INI READ : %S %S %S");
|
|
29 |
/*@}*/
|
|
30 |
|
|
31 |
CDataWrapperBase::CDataWrapperBase()
|
|
32 |
: CDataWrapper()
|
|
33 |
{
|
|
34 |
}
|
|
35 |
|
|
36 |
CDataWrapperBase::~CDataWrapperBase()
|
|
37 |
/**
|
|
38 |
* Public destructor
|
|
39 |
*/
|
|
40 |
{
|
|
41 |
iInclude.ResetAndDestroy();
|
|
42 |
iBuffer.ResetAndDestroy();
|
|
43 |
}
|
|
44 |
|
|
45 |
void CDataWrapperBase::InitialiseL()
|
|
46 |
{
|
|
47 |
CDataWrapper::InitialiseL();
|
|
48 |
|
|
49 |
TBuf<KMaxTestExecuteCommandLength> tempStore;
|
|
50 |
TPtrC fileName;
|
|
51 |
TBool moreData=ETrue;
|
|
52 |
TBool index=0;
|
|
53 |
while ( moreData )
|
|
54 |
{
|
|
55 |
tempStore.Format(KFile(), ++index);
|
|
56 |
moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
|
|
57 |
|
|
58 |
if (moreData)
|
|
59 |
{
|
|
60 |
CIniData* iniData=CIniData::NewL(fileName);
|
|
61 |
CleanupStack::PushL(iniData);
|
|
62 |
iInclude.Append(iniData);
|
|
63 |
CleanupStack::Pop(iniData);
|
|
64 |
}
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
TBool CDataWrapperBase::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
|
|
69 |
{
|
|
70 |
TBool ret=EFalse;
|
|
71 |
TPtrC result;
|
|
72 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
|
73 |
if ( err != KErrNone )
|
|
74 |
{
|
|
75 |
ret=EFalse;
|
|
76 |
}
|
|
77 |
if ( ret )
|
|
78 |
{
|
|
79 |
_LIT(KTrue,"true");
|
|
80 |
aResult=(result.FindF(KTrue) != KErrNotFound);
|
|
81 |
}
|
|
82 |
|
|
83 |
return ret;
|
|
84 |
}
|
|
85 |
|
|
86 |
TBool CDataWrapperBase::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
|
|
87 |
{
|
|
88 |
TPtrC result;
|
|
89 |
TBool ret=EFalse;
|
|
90 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
|
91 |
if ( err != KErrNone )
|
|
92 |
{
|
|
93 |
ret=EFalse;
|
|
94 |
}
|
|
95 |
if ( ret )
|
|
96 |
{
|
|
97 |
TLex lex(result);
|
|
98 |
ret=(lex.Val(aResult)==KErrNone);
|
|
99 |
}
|
|
100 |
|
|
101 |
return ret;
|
|
102 |
}
|
|
103 |
|
|
104 |
TBool CDataWrapperBase::GetInt64FromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt64& aResult)
|
|
105 |
{
|
|
106 |
TPtrC result;
|
|
107 |
TBool ret=EFalse;
|
|
108 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
|
109 |
if ( err != KErrNone )
|
|
110 |
{
|
|
111 |
ret=EFalse;
|
|
112 |
}
|
|
113 |
if ( ret )
|
|
114 |
{
|
|
115 |
TLex lex(result);
|
|
116 |
ret=(lex.Val(aResult)==KErrNone);
|
|
117 |
}
|
|
118 |
|
|
119 |
return ret;
|
|
120 |
}
|
|
121 |
|
|
122 |
TBool CDataWrapperBase::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
|
|
123 |
{
|
|
124 |
TBool ret=EFalse;
|
|
125 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
|
|
126 |
if ( err != KErrNone )
|
|
127 |
{
|
|
128 |
ret=EFalse;
|
|
129 |
}
|
|
130 |
return ret;
|
|
131 |
}
|
|
132 |
|
|
133 |
TBool CDataWrapperBase::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
|
|
134 |
{
|
|
135 |
TPtrC result;
|
|
136 |
TBool ret=EFalse;
|
|
137 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
|
138 |
if ( err != KErrNone )
|
|
139 |
{
|
|
140 |
ret=EFalse;
|
|
141 |
}
|
|
142 |
if ( ret )
|
|
143 |
{
|
|
144 |
TLex lex(result);
|
|
145 |
ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
|
|
146 |
}
|
|
147 |
|
|
148 |
return ret;
|
|
149 |
}
|
|
150 |
|
|
151 |
TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
|
|
152 |
{
|
|
153 |
TBool ret=EFalse;
|
|
154 |
|
|
155 |
if ( aSectName.Length()!=0 )
|
|
156 |
{
|
|
157 |
ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult);
|
|
158 |
|
|
159 |
for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
|
|
160 |
{
|
|
161 |
ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
if ( ret )
|
|
166 |
{
|
|
167 |
if ( aResult.Match(KMatch)!=KErrNotFound )
|
|
168 |
{
|
|
169 |
// We have an entry of the format
|
|
170 |
// entry =*{section,entry}*
|
|
171 |
// where * is one or more characters
|
|
172 |
// We need to construct this from other data in the ini file replacing {*,*}
|
|
173 |
// with the data from
|
|
174 |
// [section]
|
|
175 |
// entry =some_value
|
|
176 |
HBufC* buffer=HBufC::NewLC(aResult.Length());
|
|
177 |
buffer->Des().Copy(aResult);
|
|
178 |
|
|
179 |
TInt startLength=KStart().Length();
|
|
180 |
TInt sparatorLength=KSeparator().Length();
|
|
181 |
TInt endLength=KEnd().Length();
|
|
182 |
TInt bufferLength;
|
|
183 |
TInt start;
|
|
184 |
TInt sparator;
|
|
185 |
TInt end;
|
|
186 |
TPtrC remaining;
|
|
187 |
TLex lex;
|
|
188 |
do
|
|
189 |
{
|
|
190 |
bufferLength=buffer->Length();
|
|
191 |
start=buffer->Find(KStart);
|
|
192 |
|
|
193 |
remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
|
|
194 |
sparator=remaining.Find(KSeparator);
|
|
195 |
remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
|
|
196 |
sparator += (start + startLength);
|
|
197 |
|
|
198 |
end=remaining.Find(KEnd) + sparator + sparatorLength;
|
|
199 |
|
|
200 |
TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
|
|
201 |
TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
|
|
202 |
sectionName.Set(TLex(sectionName).NextToken());
|
|
203 |
keyName.Set(TLex(keyName).NextToken());
|
|
204 |
|
|
205 |
TInt entrySize=0;
|
|
206 |
TPtrC entryData;
|
|
207 |
TBool found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData);
|
|
208 |
for ( TInt index=iInclude.Count(); (index>0) && (!found); )
|
|
209 |
{
|
|
210 |
found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
|
|
211 |
}
|
|
212 |
if ( found )
|
|
213 |
{
|
|
214 |
entrySize=entryData.Length();
|
|
215 |
}
|
|
216 |
|
|
217 |
TInt newLength=start + bufferLength - end - endLength + entrySize;
|
|
218 |
HBufC* bufferNew=HBufC::NewLC(newLength);
|
|
219 |
bufferNew->Des().Copy(buffer->Ptr(), start);
|
|
220 |
if ( entrySize>0 )
|
|
221 |
{
|
|
222 |
bufferNew->Des().Append(entryData);
|
|
223 |
}
|
|
224 |
bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
|
|
225 |
CleanupStack::Pop(bufferNew);
|
|
226 |
CleanupStack::PopAndDestroy(buffer);
|
|
227 |
buffer=bufferNew;
|
|
228 |
CleanupStack::PushL(buffer);
|
|
229 |
}
|
|
230 |
while ( buffer->Match(KMatch)!=KErrNotFound );
|
|
231 |
iBuffer.Append(buffer);
|
|
232 |
CleanupStack::Pop(buffer);
|
|
233 |
aResult.Set(*buffer);
|
|
234 |
INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult);
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
return ret;
|
|
239 |
}
|
|
240 |
|
|
241 |
TBool CDataWrapperBase::GetCommandStringParameter(const TDesC& aParameterName, const TDesC& aSection, TPtrC& aResult, TText8 *aFileName, TInt aLine, TBool aMandatory)
|
|
242 |
{
|
|
243 |
TBool ret = GetStringFromConfig(aSection, aParameterName, aResult);
|
|
244 |
if (aMandatory && !ret)
|
|
245 |
{
|
|
246 |
Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
|
|
247 |
SetBlockResult(EFail);
|
|
248 |
}
|
|
249 |
return ret;
|
|
250 |
}
|
|
251 |
|
|
252 |
TBool CDataWrapperBase::GetCommandIntParameter(const TDesC& aParameterName, const TDesC& aSection, TInt& aResult, TText8* aFileName, TInt aLine, TBool aMandatory)
|
|
253 |
{
|
|
254 |
TBool ret = GetIntFromConfig(aSection, aParameterName, aResult);
|
|
255 |
if (aMandatory && !ret)
|
|
256 |
{
|
|
257 |
Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
|
|
258 |
SetBlockResult(EFail);
|
|
259 |
}
|
|
260 |
return ret;
|
|
261 |
}
|
|
262 |
|
|
263 |
TBool CDataWrapperBase::GetCommandInt64Parameter(const TDesC& aParameterName, const TDesC& aSection, TInt64& aResult, TText8* aFileName, TInt aLine, TBool aMandatory)
|
|
264 |
{
|
|
265 |
TBool ret = GetInt64FromConfig(aSection, aParameterName, aResult);
|
|
266 |
if (aMandatory && !ret)
|
|
267 |
{
|
|
268 |
Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
|
|
269 |
SetBlockResult(EFail);
|
|
270 |
}
|
|
271 |
return ret;
|
|
272 |
}
|
|
273 |
|
|
274 |
TBool CDataWrapperBase::GetCommandBoolParameter(const TDesC& aParameterName, const TDesC& aSection, TBool& aResult, TText8 *aFileName, TInt aLine, TBool aMandatory)
|
|
275 |
{
|
|
276 |
TBool ret = GetBoolFromConfig(aSection, aParameterName, aResult);
|
|
277 |
if (aMandatory && !ret)
|
|
278 |
{
|
|
279 |
Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
|
|
280 |
SetBlockResult(EFail);
|
|
281 |
}
|
|
282 |
return ret;
|
|
283 |
}
|