|
1 /* |
|
2 * Copyright (c) 2007-2008 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 |
|
19 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
20 #include <liwservicehandler.h> |
|
21 #include <f32fsys.h> |
|
22 #include "hnmdbasekey.h" |
|
23 #include "hnglobals.h" |
|
24 #include "hnliwutils.h" |
|
25 #include "hnconvutils.h" |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 EXPORT_C void HnLiwUtils::SetGenericParamListL( |
|
35 const RPointerArray<CHnMdBaseKey> & aKeys, |
|
36 CLiwGenericParamList & aInParam ) |
|
37 { |
|
38 // for each key |
|
39 for ( TInt i( 0 ); i < aKeys.Count(); i++ ) |
|
40 { |
|
41 CHnMdBaseKey* key = aKeys[i]; |
|
42 const TDesC8& keyName = key->KeyName(); |
|
43 TLiwVariant value; |
|
44 value.PushL(); |
|
45 key->ToVariantL( value ); |
|
46 aInParam.AppendL( TLiwGenericParam( keyName, value ) ); |
|
47 CleanupStack::PopAndDestroy( &value ); |
|
48 } |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C TBool HnLiwUtils::VariantToStringL( |
|
56 TLiwVariant& aVariant, |
|
57 RBuf& aBuf ) |
|
58 { |
|
59 TBool accepted( ETrue ); |
|
60 switch ( aVariant.TypeId() ) |
|
61 { |
|
62 case LIW::EVariantTypeDesC: |
|
63 { |
|
64 aBuf.CreateL( aVariant.AsDes() ); |
|
65 break; |
|
66 } |
|
67 case LIW::EVariantTypeDesC8: |
|
68 { |
|
69 HBufC* tmp = HnConvUtils::Str8ToStr( aVariant.AsData() ); |
|
70 if ( !tmp ) |
|
71 { |
|
72 User::Leave( KErrNoMemory ); |
|
73 } |
|
74 aBuf.Assign( tmp ); |
|
75 break; |
|
76 } |
|
77 case LIW::EVariantTypeTUid: |
|
78 { |
|
79 aBuf.CreateL( KMaxLength ); |
|
80 aBuf.AppendNum( aVariant.AsTUid().iUid, EHex ); |
|
81 break; |
|
82 } |
|
83 case LIW::EVariantTypeTInt32: |
|
84 { |
|
85 aBuf.CreateL( KMaxLength ); |
|
86 aBuf.AppendNum( aVariant.AsTInt32() ); |
|
87 break; |
|
88 } |
|
89 case LIW::EVariantTypeTInt64: |
|
90 { |
|
91 aBuf.CreateL( KMaxLength ); |
|
92 aBuf.AppendNum( aVariant.AsTInt64() ); |
|
93 break; |
|
94 } |
|
95 case LIW::EVariantTypeTUint: |
|
96 { |
|
97 aBuf.CreateL( KMaxLength ); |
|
98 aBuf.AppendNum( aVariant.AsTUint() ); |
|
99 break; |
|
100 } |
|
101 case LIW::EVariantTypeTBool: |
|
102 { |
|
103 aBuf.CreateL( KMaxLength ); |
|
104 aBuf.AppendNum( aVariant.AsTBool() ); |
|
105 break; |
|
106 } |
|
107 default: |
|
108 { |
|
109 accepted = EFalse; |
|
110 } |
|
111 } |
|
112 return accepted; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C TBool HnLiwUtils::VariantToStringL( |
|
120 TLiwVariant& aVariant, |
|
121 RBuf8& aBuf ) |
|
122 { |
|
123 TBool accepted( ETrue ); |
|
124 switch ( aVariant.TypeId() ) |
|
125 { |
|
126 case LIW::EVariantTypeDesC: |
|
127 { |
|
128 aBuf.Assign( HnConvUtils::StrToStr8L( aVariant.AsDes() ) ); |
|
129 break; |
|
130 } |
|
131 case LIW::EVariantTypeDesC8: |
|
132 { |
|
133 aBuf.CreateL( aVariant.AsData() ); |
|
134 break; |
|
135 } |
|
136 case LIW::EVariantTypeTUid: |
|
137 { |
|
138 aBuf.CreateL( KMaxLength ); |
|
139 aBuf.AppendNum( aVariant.AsTUid().iUid, EHex ); |
|
140 break; |
|
141 } |
|
142 case LIW::EVariantTypeTInt32: |
|
143 { |
|
144 aBuf.CreateL( KMaxLength ); |
|
145 aBuf.AppendNum( aVariant.AsTInt32() ); |
|
146 break; |
|
147 } |
|
148 case LIW::EVariantTypeTInt64: |
|
149 { |
|
150 aBuf.CreateL( KMaxLength ); |
|
151 aBuf.AppendNum( aVariant.AsTInt64() ); |
|
152 break; |
|
153 } |
|
154 case LIW::EVariantTypeTUint: |
|
155 { |
|
156 aBuf.CreateL( KMaxLength ); |
|
157 aBuf.AppendNum( aVariant.AsTUint() ); |
|
158 break; |
|
159 } |
|
160 case LIW::EVariantTypeTBool: |
|
161 { |
|
162 aBuf.CreateL( KMaxLength ); |
|
163 aBuf.AppendNum( aVariant.AsTBool() ); |
|
164 break; |
|
165 } |
|
166 default: |
|
167 { |
|
168 accepted = EFalse; |
|
169 } |
|
170 } |
|
171 return accepted; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C TInt HnLiwUtils::GetIterableItemCountL( CLiwIterable& aIterable ) |
|
179 { |
|
180 TInt count = 0; |
|
181 TLiwVariant variant; |
|
182 variant.PushL(); |
|
183 aIterable.Reset(); |
|
184 while( aIterable.NextL(variant)) |
|
185 { |
|
186 ++count; |
|
187 } |
|
188 CleanupStack::PopAndDestroy( &variant ); |
|
189 return count; |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C TInt HnLiwUtils::GetStringL( |
|
197 const CLiwGenericParamList& aParam, |
|
198 const TDesC8& aPath, |
|
199 RBuf& aRet ) |
|
200 { |
|
201 TInt ret( KErrNone ); |
|
202 TLiwVariant value; |
|
203 value.PushL(); |
|
204 |
|
205 ret = GetVariantL( aParam, aPath, value ); |
|
206 if ( ret == KErrNone && !VariantToStringL( value, aRet ) ) |
|
207 { |
|
208 ret = KErrBadDescriptor; |
|
209 } |
|
210 |
|
211 CleanupStack::PopAndDestroy( &value ); |
|
212 return ret; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 EXPORT_C TInt HnLiwUtils::GetStringL( |
|
220 const CLiwGenericParamList& aParam, |
|
221 const TDesC8& aPath, |
|
222 RBuf8& aRet ) |
|
223 { |
|
224 TInt ret( KErrNone ); |
|
225 TLiwVariant value; |
|
226 value.PushL(); |
|
227 |
|
228 ret = GetVariantL( aParam, aPath, value ); |
|
229 if ( ret == KErrNone && !VariantToStringL( value, aRet ) ) |
|
230 { |
|
231 ret = KErrBadDescriptor; |
|
232 } |
|
233 |
|
234 CleanupStack::PopAndDestroy( &value ); |
|
235 return ret; |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C TInt HnLiwUtils::GetStringL( const CLiwGenericParamList& aParam, |
|
243 const TDesC8& aPath, TInt aPos, RBuf& aRet ) |
|
244 { |
|
245 TInt ret( KErrNone ); |
|
246 TLiwVariant value; |
|
247 value.PushL(); |
|
248 |
|
249 ret = GetVariantL( aParam, aPath, aPos, value ); |
|
250 if ( ret == KErrNone && !VariantToStringL( value, aRet ) ) |
|
251 { |
|
252 ret = KErrBadDescriptor; |
|
253 } |
|
254 |
|
255 CleanupStack::PopAndDestroy( &value ); |
|
256 return ret; |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 EXPORT_C TInt HnLiwUtils::GetStringL( const CLiwGenericParamList& aParam, |
|
264 const TDesC8& aPath, TInt aPos, RBuf8& aRet ) |
|
265 { |
|
266 TInt ret( KErrNone ); |
|
267 TLiwVariant value; |
|
268 value.PushL(); |
|
269 |
|
270 ret = GetVariantL( aParam, aPath, aPos, value ); |
|
271 if ( ret == KErrNone && !VariantToStringL( value, aRet ) ) |
|
272 { |
|
273 ret = KErrBadDescriptor; |
|
274 } |
|
275 |
|
276 CleanupStack::PopAndDestroy( &value ); |
|
277 return ret; |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 EXPORT_C TInt HnLiwUtils::GetInt64L( const CLiwGenericParamList& aParam, |
|
285 const TDesC8& aPath, TInt aPos, TInt64& aRet ) |
|
286 { |
|
287 RBuf8 buf; |
|
288 TInt err = HnLiwUtils::GetStringL( aParam, aPath, aPos, buf ); |
|
289 |
|
290 if ( KErrNone == err ) |
|
291 { |
|
292 TInt64 value( KErrNotFound ); |
|
293 TLex8 lex( buf ); |
|
294 |
|
295 if ( KErrNone == lex.Val( value ) ) |
|
296 { |
|
297 aRet = value; |
|
298 err = KErrNone; |
|
299 } |
|
300 } |
|
301 |
|
302 buf.Close(); |
|
303 |
|
304 return err; |
|
305 } |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 EXPORT_C TInt HnLiwUtils::GetVariantL( |
|
312 const CLiwGenericParamList& aParam, |
|
313 const TDesC8& aPath, |
|
314 TInt aPos, |
|
315 TLiwVariant& aRet ) |
|
316 { |
|
317 TInt ret( KErrNone ); |
|
318 RBuf8 path; |
|
319 CleanupClosePushL( path ); |
|
320 path.CreateL( aPath ); |
|
321 // replace index if exist in the path |
|
322 HnLiwUtils::ReplaceIndexL( path, aPos ); |
|
323 // fetch variant |
|
324 ret = HnLiwUtils::GetVariantL( aParam, path, aRet ); |
|
325 if ( ret == KErrNotFound ) |
|
326 { |
|
327 TInt colonFound( aPath.Find( KColon8 ) ); |
|
328 if ( KErrNotFound != colonFound ) |
|
329 { |
|
330 /*TInt pos( 0 ); |
|
331 TInt rest( aPos ); |
|
332 while ( ( rest = rest / 10 ) != 0 ) |
|
333 { |
|
334 pos++; |
|
335 }*/ |
|
336 |
|
337 path.SetLength( colonFound ); |
|
338 TLiwVariant tempVariant; |
|
339 tempVariant.PushL(); |
|
340 if ( KErrNotFound != HnLiwUtils::GetVariantL( aParam, path, aRet ) ) |
|
341 { |
|
342 ret = KErrHidden; |
|
343 } |
|
344 else |
|
345 { |
|
346 ret = KErrNotFound; |
|
347 } |
|
348 CleanupStack::PopAndDestroy( &tempVariant ); |
|
349 } |
|
350 } |
|
351 CleanupStack::PopAndDestroy( &path ); |
|
352 return ret; |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 TInt HnLiwUtils::ExtractNameSpaceL( |
|
360 const CLiwGenericParamList& aParam, |
|
361 const TDesC8& aNameSpace, |
|
362 TLiwVariant& aRet ) |
|
363 { |
|
364 TInt pos( 0 ); |
|
365 const TLiwGenericParam* param; |
|
366 |
|
367 if ( &aParam != NULL ) |
|
368 { |
|
369 param = aParam.FindFirst( pos, aNameSpace ); |
|
370 if ( pos >= 0 ) |
|
371 { |
|
372 aRet.SetL( param->Value() ); |
|
373 } |
|
374 } |
|
375 else |
|
376 { |
|
377 pos = KErrNotFound; |
|
378 } |
|
379 |
|
380 return pos; |
|
381 } |
|
382 |
|
383 |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 // --------------------------------------------------------------------------- |
|
387 // |
|
388 EXPORT_C TInt HnLiwUtils::GetVariantL( |
|
389 const CLiwGenericParamList& aParam, |
|
390 const TDesC8& aPath, |
|
391 TLiwVariant& aRet ) |
|
392 { |
|
393 RArray< TPtrC8 > path; |
|
394 CleanupClosePushL( path ); |
|
395 TInt ret( KErrNone ); |
|
396 TLiwVariant variant; |
|
397 TLiwVariant lastVariant; |
|
398 variant.PushL(); |
|
399 lastVariant.PushL(); |
|
400 |
|
401 aRet.SetL( TLiwVariant( aPath ) ); |
|
402 |
|
403 ParsePathL( aPath, path ); |
|
404 |
|
405 if ( path.Count() > 0 |
|
406 && ExtractNameSpaceL( aParam, path[0], lastVariant ) != KErrNotFound ) |
|
407 { |
|
408 TBool found( ETrue ); |
|
409 for ( TInt i( 1 ); i < path.Count() && found; i++ ) |
|
410 { |
|
411 TPtrC8 name = path[ i ]; |
|
412 LIW::TVariantTypeId typeId = lastVariant.TypeId(); |
|
413 // LIW::Type ID 7 |
|
414 if ( typeId == LIW::EVariantTypeList ) |
|
415 { |
|
416 TInt pos( GetPosition( name ) ); |
|
417 found = (pos != KErrNotFound) ? lastVariant.AsList()->AtL( pos, variant ) : EFalse; |
|
418 } |
|
419 // LIW::Type ID 8 |
|
420 else if ( typeId == LIW::EVariantTypeMap ) |
|
421 { |
|
422 found = lastVariant.AsMap()->FindL( name, variant ); |
|
423 } |
|
424 // LIW::Type ID 9 |
|
425 else if ( typeId == LIW::EVariantTypeIterable ) |
|
426 { |
|
427 TInt pos( GetPosition( name ) ); |
|
428 found = GetIterableByPositionL( *lastVariant.AsIterable(), pos, variant ); |
|
429 } |
|
430 lastVariant.SetL( variant ); |
|
431 } |
|
432 ret = found ? KErrNone : KErrNotFound; |
|
433 //aRet.SetL( ( ret != KErrNotFound ) ? variant : TLiwVariant( aPath ) ); |
|
434 if ( found == 0 ) |
|
435 { |
|
436 aRet.SetL( TLiwVariant( KNullDesC8 ) ); |
|
437 } |
|
438 else |
|
439 { |
|
440 aRet.SetL( variant ); |
|
441 } |
|
442 } |
|
443 |
|
444 CleanupStack::PopAndDestroy( &lastVariant ); |
|
445 CleanupStack::PopAndDestroy( &variant ); |
|
446 CleanupStack::PopAndDestroy( &path ); |
|
447 return ret; |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------------------------- |
|
451 // |
|
452 // --------------------------------------------------------------------------- |
|
453 // |
|
454 void HnLiwUtils::ParsePathL( |
|
455 const TDesC8& aPath, |
|
456 RArray< TPtrC8 >& aPathParts ) |
|
457 { |
|
458 TChar ch; // token separator |
|
459 |
|
460 TInt colonPos = aPath.Find( KColon8 ); |
|
461 |
|
462 if ( colonPos > 0 ) |
|
463 { |
|
464 TLex8 lex( aPath ); |
|
465 |
|
466 while ( !lex.Eos() ) |
|
467 { |
|
468 ch = lex.Get(); |
|
469 |
|
470 // namespace |
|
471 if ( ch == KColon()[0] ) |
|
472 { |
|
473 lex.UnGet(); |
|
474 TPtrC8 nextToken = lex.MarkedToken(); |
|
475 lex.SkipAndMark( 1 ); |
|
476 aPathParts.AppendL( nextToken ); |
|
477 } |
|
478 // list or map |
|
479 else if ( ch == KSlash()[0] ) |
|
480 { |
|
481 lex.UnGet(); |
|
482 TPtrC8 nextToken = lex.MarkedToken(); |
|
483 lex.SkipAndMark( 1 ); |
|
484 aPathParts.AppendL( nextToken ); |
|
485 } |
|
486 // last token |
|
487 else if ( lex.Eos() ) |
|
488 { |
|
489 TPtrC8 nextToken = lex.MarkedToken(); |
|
490 aPathParts.AppendL( nextToken ); |
|
491 break; |
|
492 } |
|
493 } |
|
494 } |
|
495 } |
|
496 |
|
497 // --------------------------------------------------------------------------- |
|
498 // |
|
499 // --------------------------------------------------------------------------- |
|
500 // |
|
501 TBool HnLiwUtils::GetIterableByPositionL( CLiwIterable & aIterable, TInt pos, |
|
502 TLiwVariant & aVariant ) |
|
503 { |
|
504 TBool ret(EFalse); |
|
505 if ( pos >= 0 ) |
|
506 { |
|
507 TInt counter = 0; |
|
508 aIterable.Reset(); |
|
509 ret = aIterable.NextL( aVariant ); |
|
510 while ( ret ) |
|
511 { |
|
512 if (counter == pos) |
|
513 { |
|
514 break; |
|
515 } |
|
516 counter++; |
|
517 ret = aIterable.NextL( aVariant ); |
|
518 } |
|
519 } |
|
520 return ret; |
|
521 } |
|
522 |
|
523 // --------------------------------------------------------------------------- |
|
524 // |
|
525 // --------------------------------------------------------------------------- |
|
526 // |
|
527 TInt HnLiwUtils::GetPosition( const TDesC8& aPosition ) |
|
528 { |
|
529 TInt ret( KErrNotFound ); |
|
530 TInt pos1 = aPosition.Find( KOpenSquareBracket ); |
|
531 |
|
532 if ( pos1 >= 0 ) |
|
533 { |
|
534 TInt pos2 = aPosition.Find( KCloseSquareBracket ); |
|
535 // extract string number ( +1 a character after "[", |
|
536 // -1 a character before "]" |
|
537 TPtrC8 num = aPosition.Mid( pos1 + 1, pos2 - 1 ); |
|
538 // extract number value |
|
539 TLex8 lex( num ); |
|
540 lex.Val( ret ); |
|
541 } |
|
542 return ret; |
|
543 } |
|
544 |
|
545 // --------------------------------------------------------------------------- |
|
546 // |
|
547 // --------------------------------------------------------------------------- |
|
548 // |
|
549 TInt HnLiwUtils::ReplaceIndexL( RBuf8& aPath8, TInt aPos ) |
|
550 { |
|
551 TInt ret(KErrNotFound); |
|
552 TInt indexFound( aPath8.Find( KIndex8 ) ); |
|
553 |
|
554 if ( !aPath8.Compare( KIndexWithBrackets8 ) ) |
|
555 { |
|
556 aPath8.Close(); |
|
557 aPath8.CreateL( KMaxLength ); |
|
558 aPath8.AppendNum( aPos ); |
|
559 ret = aPath8.Length(); |
|
560 } |
|
561 else if ( KErrNotFound != indexFound ) |
|
562 { |
|
563 RBuf8 indexNum; |
|
564 CleanupClosePushL( indexNum ); |
|
565 indexNum.CreateL( KMaxLength ); |
|
566 indexNum.AppendNum( aPos ); |
|
567 |
|
568 TInt indexPos = ret = aPath8.Find( KIndex8 ); |
|
569 TInt indexLength = KIndex().Length(); |
|
570 |
|
571 aPath8.Replace( indexPos, indexLength, indexNum ); |
|
572 ret += indexNum.Length(); |
|
573 |
|
574 CleanupStack::PopAndDestroy( &indexNum ); |
|
575 } |
|
576 |
|
577 return ret; |
|
578 } |
|
579 |