|
1 /* |
|
2 * Copyright (c) 2007 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 "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 _LIT(KFormatEntryField, "%S_%S"); |
|
31 |
|
32 _LIT(KTagFontSpecName, "name"); |
|
33 _LIT(KTagFontSpecHeight, "height"); |
|
34 |
|
35 _LIT(KTagPointX, "x"); |
|
36 _LIT(KTagPointY, "y"); |
|
37 |
|
38 _LIT(KTagRectTop, "top"); |
|
39 _LIT(KTagRectLeft, "left"); |
|
40 _LIT(KTagRectBottom, "bottom"); |
|
41 _LIT(KTagRectRight, "right"); |
|
42 |
|
43 _LIT(KTagRgbRed, "red"); |
|
44 _LIT(KTagRgbGreen, "green"); |
|
45 _LIT(KTagRgbBlue, "blue"); |
|
46 _LIT(KTagRgbAlpha, "alpha"); |
|
47 |
|
48 _LIT(KTagSizeWidth, "width"); |
|
49 _LIT(KTagSizeHeight, "height"); |
|
50 |
|
51 _LIT(KTagWsGraphicIdUid, "uid"); |
|
52 _LIT(KTagWsGraphicIdId, "id"); |
|
53 _LIT(KTagWsGraphicIdName, "name"); |
|
54 |
|
55 _LIT(KFormatFieldNumber, "%S%d"); |
|
56 |
|
57 /// Logging |
|
58 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
59 _LIT(KLogRegion, "Region '%S'"); |
|
60 _LIT(KLogEmpty, "Empty"); |
|
61 _LIT(KLogRegionsRect, "Rect[%d] tl=(%d,%d) br=(%d,%d)"); |
|
62 _LIT(KLogRect, "%S tl=(%d,%d) br=(%d,%d)"); |
|
63 /*@}*/ |
|
64 |
|
65 CDataWrapperBase::CDataWrapperBase() |
|
66 : CDataWrapper() |
|
67 , iHandle(0) |
|
68 { |
|
69 } |
|
70 |
|
71 CDataWrapperBase::~CDataWrapperBase() |
|
72 /** |
|
73 * Public destructor |
|
74 */ |
|
75 { |
|
76 iInclude.ResetAndDestroy(); |
|
77 iBuffer.ResetAndDestroy(); |
|
78 iFs.Close(); |
|
79 } |
|
80 |
|
81 void CDataWrapperBase::InitialiseL() |
|
82 { |
|
83 CDataWrapper::InitialiseL(); |
|
84 |
|
85 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
86 TPtrC fileName; |
|
87 TBool moreData=ETrue; |
|
88 TBool index=0; |
|
89 while ( moreData ) |
|
90 { |
|
91 tempStore.Format(KFile(), ++index); |
|
92 moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName); |
|
93 |
|
94 if (moreData) |
|
95 { |
|
96 CIniData* iniData=CIniData::NewL(fileName); |
|
97 CleanupStack::PushL(iniData); |
|
98 iInclude.Append(iniData); |
|
99 CleanupStack::Pop(iniData); |
|
100 } |
|
101 } |
|
102 User::LeaveIfError(iFs.Connect()); |
|
103 } |
|
104 |
|
105 TBool CDataWrapperBase::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult) |
|
106 { |
|
107 TBool ret=EFalse; |
|
108 TPtrC result; |
|
109 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result)); |
|
110 if ( err != KErrNone ) |
|
111 { |
|
112 ret=EFalse; |
|
113 } |
|
114 if ( ret ) |
|
115 { |
|
116 _LIT(KTrue,"true"); |
|
117 aResult=(result.FindF(KTrue) != KErrNotFound); |
|
118 } |
|
119 |
|
120 return ret; |
|
121 } |
|
122 |
|
123 TBool CDataWrapperBase::GetFontSpecFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TFontSpec& aResult) |
|
124 { |
|
125 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
126 |
|
127 |
|
128 TPtrC name; |
|
129 tempStore.Format(KFormatEntryField, &aKeyName, &KTagFontSpecName); |
|
130 TBool ret=GetStringFromConfig(aSectName, tempStore, name); |
|
131 |
|
132 TInt height; |
|
133 tempStore.Format(KFormatEntryField, &aKeyName, &KTagFontSpecHeight); |
|
134 if ( !GetIntFromConfig(aSectName, tempStore, height) ) |
|
135 { |
|
136 ret=EFalse; |
|
137 } |
|
138 |
|
139 if ( ret ) |
|
140 { |
|
141 aResult=TFontSpec(name, height); |
|
142 } |
|
143 |
|
144 return ret; |
|
145 } |
|
146 |
|
147 TBool CDataWrapperBase::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult) |
|
148 { |
|
149 TPtrC result; |
|
150 TBool ret=EFalse; |
|
151 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result)); |
|
152 if ( err != KErrNone ) |
|
153 { |
|
154 ret=EFalse; |
|
155 } |
|
156 if ( ret ) |
|
157 { |
|
158 TLex lex(result); |
|
159 ret=(lex.Val(aResult)==KErrNone); |
|
160 } |
|
161 |
|
162 return ret; |
|
163 } |
|
164 |
|
165 TBool CDataWrapperBase::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult) |
|
166 { |
|
167 TBool ret=EFalse; |
|
168 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult)); |
|
169 if ( err != KErrNone ) |
|
170 { |
|
171 ret=EFalse; |
|
172 } |
|
173 return ret; |
|
174 } |
|
175 |
|
176 TBool CDataWrapperBase::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult) |
|
177 { |
|
178 TPtrC result; |
|
179 TBool ret=EFalse; |
|
180 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result)); |
|
181 if ( err != KErrNone ) |
|
182 { |
|
183 ret=EFalse; |
|
184 } |
|
185 if ( ret ) |
|
186 { |
|
187 TLex lex(result); |
|
188 ret=(lex.Val((TUint &)aResult, EHex)==KErrNone); |
|
189 } |
|
190 |
|
191 return ret; |
|
192 } |
|
193 |
|
194 TBool CDataWrapperBase::GetPointFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPoint& aResult) |
|
195 { |
|
196 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
197 |
|
198 TInt x; |
|
199 tempStore.Format(KFormatEntryField, &aKeyName, &KTagPointX); |
|
200 TBool ret=GetIntFromConfig(aSectName, tempStore, x); |
|
201 |
|
202 TInt y; |
|
203 tempStore.Format(KFormatEntryField, &aKeyName, &KTagPointY); |
|
204 if ( !GetIntFromConfig(aSectName, tempStore, y) ) |
|
205 { |
|
206 ret=EFalse; |
|
207 } |
|
208 |
|
209 if ( ret ) |
|
210 { |
|
211 aResult.SetXY(x, y); |
|
212 } |
|
213 |
|
214 return ret; |
|
215 } |
|
216 |
|
217 TBool CDataWrapperBase::GetRectFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TRect& aResult) |
|
218 { |
|
219 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
220 |
|
221 TInt top; |
|
222 tempStore.Format(KFormatEntryField, &aKeyName, &KTagRectTop); |
|
223 TBool ret=GetIntFromConfig(aSectName, tempStore, top); |
|
224 |
|
225 TInt left; |
|
226 tempStore.Format(KFormatEntryField, &aKeyName, &KTagRectLeft); |
|
227 if ( !GetIntFromConfig(aSectName, tempStore, left) ) |
|
228 { |
|
229 ret=EFalse; |
|
230 } |
|
231 |
|
232 TInt bottom; |
|
233 tempStore.Format(KFormatEntryField, &aKeyName, &KTagRectBottom); |
|
234 if ( !GetIntFromConfig(aSectName, tempStore, bottom) ) |
|
235 { |
|
236 ret=EFalse; |
|
237 } |
|
238 |
|
239 TInt right; |
|
240 tempStore.Format(KFormatEntryField, &aKeyName, &KTagRectRight); |
|
241 if ( !GetIntFromConfig(aSectName, tempStore, right) ) |
|
242 { |
|
243 ret=EFalse; |
|
244 } |
|
245 |
|
246 if ( ret ) |
|
247 { |
|
248 aResult.SetRect(left, top, right, bottom); |
|
249 } |
|
250 |
|
251 return ret; |
|
252 } |
|
253 |
|
254 TBool CDataWrapperBase::GetRegionFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TRegion& aResult) |
|
255 { |
|
256 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
257 TRect rect; |
|
258 |
|
259 aResult.Clear(); |
|
260 TBool moreData=ETrue; |
|
261 for ( TInt index=0; moreData; ) |
|
262 { |
|
263 tempStore.Format(KFormatFieldNumber, &aKeyName, ++index); |
|
264 moreData=GetRectFromConfig(aSectName, tempStore, rect); |
|
265 if ( moreData ) |
|
266 { |
|
267 aResult.AddRect(rect); |
|
268 } |
|
269 } |
|
270 |
|
271 return aResult.Count()>0; |
|
272 } |
|
273 |
|
274 TBool CDataWrapperBase::GetRgbFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TRgb& aResult) |
|
275 { |
|
276 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
277 |
|
278 TInt red; |
|
279 tempStore.Format(KFormatEntryField, &aKeyName, &KTagRgbRed); |
|
280 TBool ret=GetIntFromConfig(aSectName, tempStore, red); |
|
281 |
|
282 TInt green; |
|
283 tempStore.Format(KFormatEntryField, &aKeyName, &KTagRgbGreen); |
|
284 if ( !GetIntFromConfig(aSectName, tempStore, green) ) |
|
285 { |
|
286 ret=EFalse; |
|
287 } |
|
288 |
|
289 TInt blue; |
|
290 tempStore.Format(KFormatEntryField, &aKeyName, &KTagRgbBlue); |
|
291 if ( !GetIntFromConfig(aSectName, tempStore, blue) ) |
|
292 { |
|
293 ret=EFalse; |
|
294 } |
|
295 |
|
296 if ( ret ) |
|
297 { |
|
298 aResult.SetRed(red); |
|
299 aResult.SetGreen(green); |
|
300 aResult.SetBlue(blue); |
|
301 |
|
302 TInt alpha; |
|
303 tempStore.Format(KFormatEntryField, &aKeyName, &KTagRgbAlpha); |
|
304 if ( GetIntFromConfig(aSectName, tempStore, alpha) ) |
|
305 { |
|
306 aResult.SetAlpha(alpha); |
|
307 } |
|
308 } |
|
309 |
|
310 return ret; |
|
311 } |
|
312 |
|
313 TBool CDataWrapperBase::GetSizeFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TSize& aResult) |
|
314 { |
|
315 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
316 |
|
317 TInt width; |
|
318 tempStore.Format(KFormatEntryField, &aKeyName, &KTagSizeWidth); |
|
319 TBool ret=GetIntFromConfig(aSectName, tempStore, width); |
|
320 |
|
321 TInt height; |
|
322 tempStore.Format(KFormatEntryField, &aKeyName, &KTagSizeHeight); |
|
323 if ( !GetIntFromConfig(aSectName, tempStore, height) ) |
|
324 { |
|
325 ret=EFalse; |
|
326 } |
|
327 |
|
328 if ( ret ) |
|
329 { |
|
330 aResult.SetSize(width, height); |
|
331 } |
|
332 |
|
333 return ret; |
|
334 } |
|
335 |
|
336 TBool CDataWrapperBase::GetRgbListFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt aSize, TRgb*& aResult) |
|
337 { |
|
338 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
339 |
|
340 TBool ok=ETrue; |
|
341 for ( TInt index=0; (index<aSize) && (ok); ) |
|
342 { |
|
343 tempStore.Format(KFormatFieldNumber, &aKeyName, ++index); |
|
344 ok=GetRgbFromConfig(aSectName, tempStore, aResult[index-1]); |
|
345 if ( !ok ) |
|
346 { |
|
347 ERR_PRINTF2(KLogMissingParameter, &tempStore); |
|
348 SetBlockResult(EFail); |
|
349 } |
|
350 } |
|
351 |
|
352 return ok; |
|
353 } |
|
354 |
|
355 TBool CDataWrapperBase::GetPointListFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt aSize, TPoint*& aResult) |
|
356 { |
|
357 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
358 |
|
359 TBool ok=ETrue; |
|
360 for ( TInt index=0; (index<aSize) && (ok); ) |
|
361 { |
|
362 tempStore.Format(KFormatFieldNumber, &aKeyName, ++index); |
|
363 ok=GetPointFromConfig(aSectName, tempStore, aResult[index-1]); |
|
364 if ( !ok ) |
|
365 { |
|
366 ERR_PRINTF2(KLogMissingParameter, &tempStore); |
|
367 SetBlockResult(EFail); |
|
368 } |
|
369 } |
|
370 |
|
371 return ok; |
|
372 } |
|
373 |
|
374 TBool CDataWrapperBase::GetPointListFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, CArrayFix<TPoint>& aResult) |
|
375 { |
|
376 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
377 TPoint point; |
|
378 |
|
379 aResult.Reset(); |
|
380 TBool ok=ETrue; |
|
381 for ( TInt index=0; ok; ) |
|
382 { |
|
383 tempStore.Format(KFormatFieldNumber, &aKeyName, ++index); |
|
384 ok=GetPointFromConfig(aSectName, tempStore, point); |
|
385 if ( ok ) |
|
386 { |
|
387 aResult.AppendL(point); |
|
388 } |
|
389 } |
|
390 |
|
391 return aResult.Count()>0; |
|
392 } |
|
393 |
|
394 TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult) |
|
395 { |
|
396 TBool ret=EFalse; |
|
397 |
|
398 if ( aSectName.Length()!=0 ) |
|
399 { |
|
400 ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult); |
|
401 |
|
402 for ( TInt index=iInclude.Count(); (index>0) && (!ret); ) |
|
403 { |
|
404 ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult); |
|
405 } |
|
406 } |
|
407 |
|
408 if ( ret ) |
|
409 { |
|
410 if ( aResult.Match(KMatch)!=KErrNotFound ) |
|
411 { |
|
412 // We have an entry of the format |
|
413 // entry =*{section,entry}* |
|
414 // where * is one or more characters |
|
415 // We need to construct this from other data in the ini file replacing {*,*} |
|
416 // with the data from |
|
417 // [section] |
|
418 // entry =some_value |
|
419 HBufC* buffer=HBufC::NewLC(aResult.Length()); |
|
420 buffer->Des().Copy(aResult); |
|
421 |
|
422 TInt startLength=KStart().Length(); |
|
423 TInt sparatorLength=KSeparator().Length(); |
|
424 TInt endLength=KEnd().Length(); |
|
425 TInt bufferLength; |
|
426 TInt start; |
|
427 TInt sparator; |
|
428 TInt end; |
|
429 TPtrC remaining; |
|
430 TLex lex; |
|
431 do |
|
432 { |
|
433 bufferLength=buffer->Length(); |
|
434 start=buffer->Find(KStart); |
|
435 |
|
436 remaining.Set(buffer->Des().Right(bufferLength-start-startLength)); |
|
437 sparator=remaining.Find(KSeparator); |
|
438 remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength)); |
|
439 sparator += (start + startLength); |
|
440 |
|
441 end=remaining.Find(KEnd) + sparator + sparatorLength; |
|
442 |
|
443 TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength); |
|
444 TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength); |
|
445 sectionName.Set(TLex(sectionName).NextToken()); |
|
446 keyName.Set(TLex(keyName).NextToken()); |
|
447 |
|
448 TInt entrySize=0; |
|
449 TPtrC entryData; |
|
450 TBool found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData); |
|
451 for ( TInt index=iInclude.Count(); (index>0) && (!found); ) |
|
452 { |
|
453 found=iInclude[--index]->FindVar(sectionName, keyName, entryData); |
|
454 } |
|
455 if ( found ) |
|
456 { |
|
457 entrySize=entryData.Length(); |
|
458 } |
|
459 |
|
460 TInt newLength=start + bufferLength - end - endLength + entrySize; |
|
461 HBufC* bufferNew=HBufC::NewLC(newLength); |
|
462 bufferNew->Des().Copy(buffer->Ptr(), start); |
|
463 if ( entrySize>0 ) |
|
464 { |
|
465 bufferNew->Des().Append(entryData); |
|
466 } |
|
467 bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength); |
|
468 CleanupStack::Pop(bufferNew); |
|
469 CleanupStack::PopAndDestroy(buffer); |
|
470 buffer=bufferNew; |
|
471 CleanupStack::PushL(buffer); |
|
472 } |
|
473 while ( buffer->Match(KMatch)!=KErrNotFound ); |
|
474 iBuffer.Append(buffer); |
|
475 CleanupStack::Pop(buffer); |
|
476 aResult.Set(*buffer); |
|
477 INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult); |
|
478 } |
|
479 } |
|
480 |
|
481 return ret; |
|
482 } |
|
483 |
|
484 void CDataWrapperBase::LogRegion(const TDesC& aMessage, const TRegion& aRegion) |
|
485 { |
|
486 INFO_PRINTF2(KLogRegion, &aMessage); |
|
487 TInt indCount = aRegion.Count(); |
|
488 if ( indCount==0 ) |
|
489 { |
|
490 INFO_PRINTF1(KLogEmpty); |
|
491 } |
|
492 else |
|
493 { |
|
494 const TRect* rect=aRegion.RectangleList(); |
|
495 for ( TInt index=0; index<indCount; ++index ) |
|
496 { |
|
497 INFO_PRINTF6(KLogRegionsRect, index, rect[index].iTl.iX, rect[index].iTl.iY, rect[index].iBr.iX, rect[index].iBr.iY); |
|
498 } |
|
499 } |
|
500 } |
|
501 |
|
502 void CDataWrapperBase::LogRect(const TDesC& aMessage, const TRect& aRect) |
|
503 { |
|
504 INFO_PRINTF6(KLogRect, &aMessage, aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY); |
|
505 } |