|
1 /* |
|
2 * Copyright (c) 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: Implementation of ChspsLiwDump. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "hspsbytebuffer.h" |
|
20 #include "hspsliwdump.h" |
|
21 #include "hspslogbus.h" |
|
22 #include <s32mem.h> |
|
23 #include <liwcommon.h> |
|
24 |
|
25 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
26 // indentation delimiter |
|
27 _LIT8 (KDelim8, "\t" ); |
|
28 _LIT( KDelim, "\t" ); |
|
29 _LIT( KCPlusPlusArrayStart, "const TUint8 liwDump[] = {" ); |
|
30 _LIT( KCPlusPlusArrayEnd, "};" ); |
|
31 const TInt KCPlusPlusArraySanityLimit = 16384; // 16kb. |
|
32 _LIT( KByteFormat, "0x%02x" ); |
|
33 _LIT( KLiwListBinaryDumpStartTag, "#LIW LIST BINARY DUMP START" ); |
|
34 _LIT( KLiwListBinaryDumpEndTag, "#LIW LIST BINARY DUMP END" ); |
|
35 _LIT( KLiwListTextDumpStartTag, "#LIW LIST TEXT DUMP START" ); |
|
36 _LIT( KLiwListTextDumpEndTag, "#LIW LIST TEXT DUMP END" ); |
|
37 #endif |
|
38 |
|
39 //------------------------------------------------------------------------------ |
|
40 // ChspsLiwDump::~ChspsLiwDump |
|
41 //------------------------------------------------------------------------------ |
|
42 EXPORT_C ChspsLiwDump::~ChspsLiwDump() |
|
43 { |
|
44 } |
|
45 |
|
46 //------------------------------------------------------------------------------ |
|
47 // ChspsLiwDump::NewLC |
|
48 //------------------------------------------------------------------------------ |
|
49 EXPORT_C ChspsLiwDump* ChspsLiwDump::NewLC( ChspsLogBus& aLogBus ) |
|
50 { |
|
51 ChspsLiwDump* self = new (ELeave)ChspsLiwDump( aLogBus ); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 //------------------------------------------------------------------------------ |
|
58 // ChspsLiwDump::NewL |
|
59 //------------------------------------------------------------------------------ |
|
60 EXPORT_C ChspsLiwDump* ChspsLiwDump::NewL( ChspsLogBus& aLogBus ) |
|
61 { |
|
62 ChspsLiwDump* self = ChspsLiwDump::NewLC( aLogBus ); |
|
63 CleanupStack::Pop( self ); // self; |
|
64 return self; |
|
65 } |
|
66 |
|
67 //------------------------------------------------------------------------------ |
|
68 // ChspsLiwDump::LogLiwListAsText |
|
69 //------------------------------------------------------------------------------ |
|
70 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
71 EXPORT_C void ChspsLiwDump::LogLiwListAsText( CLiwGenericParamList& aLiwList ) |
|
72 { |
|
73 TRAP_IGNORE( LogLiwListAsTextL( aLiwList ); ); |
|
74 } |
|
75 #else |
|
76 EXPORT_C void ChspsLiwDump::LogLiwListAsText( CLiwGenericParamList& /*aLiwList*/ ) |
|
77 { |
|
78 } |
|
79 #endif |
|
80 |
|
81 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
82 //------------------------------------------------------------------------------ |
|
83 // ChspsLiwDump::LogLiwListAsBinary |
|
84 //------------------------------------------------------------------------------ |
|
85 EXPORT_C void ChspsLiwDump::LogLiwListAsBinary( CLiwGenericParamList& aLiwList ) |
|
86 { |
|
87 TRAP_IGNORE( LogLiwListAsBinaryL( aLiwList ); ); |
|
88 } |
|
89 #else |
|
90 EXPORT_C void ChspsLiwDump::LogLiwListAsBinary( CLiwGenericParamList& /*aLiwList*/ ) |
|
91 { |
|
92 } |
|
93 #endif |
|
94 |
|
95 //------------------------------------------------------------------------------ |
|
96 // ChspsLiwDump::ChspsLiwDump |
|
97 //------------------------------------------------------------------------------ |
|
98 ChspsLiwDump::ChspsLiwDump( ChspsLogBus& aLogBus ) : iLogBus( aLogBus ) |
|
99 { |
|
100 iDepth = 0; |
|
101 } |
|
102 |
|
103 //------------------------------------------------------------------------------ |
|
104 // ChspsLiwDump::ConstructL |
|
105 //------------------------------------------------------------------------------ |
|
106 void ChspsLiwDump::ConstructL() |
|
107 { |
|
108 } |
|
109 |
|
110 //------------------------------------------------------------------------------ |
|
111 // ChspsLiwDump::LogLiwListAsTextL |
|
112 //------------------------------------------------------------------------------ |
|
113 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
114 void ChspsLiwDump::LogLiwListAsTextL( CLiwGenericParamList& aLiwList ) |
|
115 { |
|
116 iLogBus.LogText( KLiwListTextDumpStartTag ); |
|
117 |
|
118 // implementation for GetActiveAppConf and GetPluginConf that has map |
|
119 // as base root. |
|
120 iDepth = 0; |
|
121 TInt count = aLiwList.Count(); |
|
122 for( TInt i = 0; i < count; i++ ) |
|
123 { |
|
124 //get Generic param and check for param id and name. |
|
125 TLiwGenericParam param = aLiwList[i]; |
|
126 //Check for the param identifier: |
|
127 LIW::TGenericParamId identifier = param.SemanticId(); |
|
128 //print semanticId: |
|
129 iLogBus.LogText( _L8(" SemanticId: %d"), identifier ); |
|
130 if( identifier == LIW::EGenericParamError ) |
|
131 { |
|
132 iLogBus.LogText( _L8(" ERROR: EGenericParamError") ); |
|
133 } |
|
134 //get generic param name. |
|
135 //print name. |
|
136 iLogBus.LogText( param.Name() ); |
|
137 //get Variant |
|
138 TLiwVariant value = param.Value(); |
|
139 //get variant type. |
|
140 PrintVariantL( value ); |
|
141 } |
|
142 |
|
143 iLogBus.LogText( KLiwListTextDumpEndTag ); |
|
144 } |
|
145 #else |
|
146 void ChspsLiwDump::LogLiwListAsTextL( CLiwGenericParamList& /*aLiwList*/ ) |
|
147 { |
|
148 } |
|
149 #endif |
|
150 |
|
151 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
152 //------------------------------------------------------------------------------ |
|
153 // ChspsLiwDump::LogLiwListAsBinaryL |
|
154 //------------------------------------------------------------------------------ |
|
155 void ChspsLiwDump::LogLiwListAsBinaryL( CLiwGenericParamList& aLiwList ) |
|
156 { |
|
157 iLogBus.LogText( KLiwListBinaryDumpStartTag ); |
|
158 |
|
159 const TInt byteSize = aLiwList.Size(); |
|
160 if( byteSize <= 0 ) |
|
161 { |
|
162 User::Leave( KErrArgument ); |
|
163 } |
|
164 |
|
165 // Create memory buffer. |
|
166 ChspsByteBuffer* buffer = ChspsByteBuffer::NewL( byteSize ); |
|
167 CleanupStack::PushL( buffer ); |
|
168 |
|
169 // Wrap buffer using memory stream. |
|
170 RMemWriteStream stream; |
|
171 stream.Open( buffer->Buffer(), byteSize ); |
|
172 stream.PushL(); |
|
173 |
|
174 // Use stream that wraps buffer to enable direct-to-RAM |
|
175 // streaming from CLiwGenericParamList. |
|
176 aLiwList.ExternalizeL( stream ); |
|
177 stream.CommitL(); |
|
178 |
|
179 // Clean stream wrapper. |
|
180 stream.Release(); |
|
181 stream.Close(); |
|
182 stream.Pop(); |
|
183 |
|
184 // Create C++ array and print it. |
|
185 HBufC* cplusplusDump = CreateCPlusPlusDumpL( *buffer ); |
|
186 iLogBus.LogText( *cplusplusDump ); |
|
187 delete cplusplusDump; |
|
188 cplusplusDump = NULL; |
|
189 |
|
190 // Clean memory buffer |
|
191 CleanupStack::PopAndDestroy( buffer ); |
|
192 |
|
193 iLogBus.LogText( KLiwListBinaryDumpEndTag ); |
|
194 } |
|
195 #else |
|
196 void ChspsLiwDump::LogLiwListAsBinaryL( CLiwGenericParamList& /*aLiwList*/ ) |
|
197 { |
|
198 } |
|
199 #endif |
|
200 |
|
201 //------------------------------------------------------------------------------ |
|
202 // ChspsLiwDump::PrintVariantL |
|
203 //------------------------------------------------------------------------------ |
|
204 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
205 void ChspsLiwDump::PrintVariantL( TLiwVariant value ) |
|
206 { |
|
207 LIW::TVariantTypeId variantId = value.TypeId(); |
|
208 if( variantId == LIW::EVariantTypeDesC8 ) |
|
209 { |
|
210 PrintString8L( value ); |
|
211 } |
|
212 else if( variantId == LIW::EVariantTypeDesC ) |
|
213 { |
|
214 PrintStringL( value ); |
|
215 } |
|
216 else if ( variantId == LIW::EVariantTypeMap ) |
|
217 { |
|
218 HBufC* text = GetFixedTextLC( _L("<Map>"), iDepth, KDelim ); |
|
219 iLogBus.LogText( *text ); |
|
220 CleanupStack::PopAndDestroy( text ); |
|
221 PrintMapL( value ); |
|
222 } |
|
223 else if ( variantId == LIW::EVariantTypeList ) |
|
224 { |
|
225 HBufC* text = GetFixedTextLC( _L("<List>"), iDepth, KDelim ); |
|
226 iLogBus.LogText( *text ); |
|
227 CleanupStack::PopAndDestroy( text ); |
|
228 PrintListL( value ); |
|
229 } |
|
230 else |
|
231 { |
|
232 iLogBus.LogText( _L8("--- TODO: Unknown --- ")); |
|
233 } |
|
234 } |
|
235 #else |
|
236 void ChspsLiwDump::PrintVariantL( TLiwVariant /*value*/ ) |
|
237 { |
|
238 } |
|
239 #endif |
|
240 |
|
241 //------------------------------------------------------------------------------ |
|
242 // ChspsLiwDump::PrintMapL |
|
243 //------------------------------------------------------------------------------ |
|
244 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
245 void ChspsLiwDump::PrintMapL( TLiwVariant value ) |
|
246 { |
|
247 //get map from the variant. |
|
248 //get map values. |
|
249 const CLiwMap* map = value.AsMap(); |
|
250 TInt count = map->Count(); |
|
251 for( TInt i = 0; i < count; i++ ) |
|
252 { |
|
253 HBufC* index = GetFixedTextLC( _L("---"), iDepth, KDelim ); |
|
254 iLogBus.LogText( *index ); |
|
255 CleanupStack::PopAndDestroy( index ); |
|
256 TBuf8<100> buf; |
|
257 map->AtL( i, buf); |
|
258 HBufC8* text = GetFixedText8LC( buf, iDepth, KDelim8 ); |
|
259 iLogBus.LogText( *text ); |
|
260 CleanupStack::PopAndDestroy( text ); |
|
261 TLiwVariant value; |
|
262 map->FindL( buf, value ); |
|
263 PrintVariantL( value ); |
|
264 value.Reset(); |
|
265 } |
|
266 } |
|
267 #else |
|
268 void ChspsLiwDump::PrintMapL( TLiwVariant /*value*/ ) |
|
269 { |
|
270 } |
|
271 #endif |
|
272 |
|
273 //------------------------------------------------------------------------------ |
|
274 // ChspsLiwDump::PrintStringL |
|
275 //------------------------------------------------------------------------------ |
|
276 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
277 void ChspsLiwDump::PrintStringL( TLiwVariant value ) |
|
278 { |
|
279 TPtrC textValue = value.AsDes(); |
|
280 HBufC* text = GetFixedTextLC( textValue, iDepth, KDelim ); |
|
281 iLogBus.LogText( *text ); |
|
282 CleanupStack::PopAndDestroy( text ); |
|
283 } |
|
284 #else |
|
285 void ChspsLiwDump::PrintStringL( TLiwVariant /*value*/ ) |
|
286 { |
|
287 } |
|
288 #endif |
|
289 |
|
290 //------------------------------------------------------------------------------ |
|
291 // ChspsLiwDump::PrintString8L |
|
292 //------------------------------------------------------------------------------ |
|
293 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
294 void ChspsLiwDump::PrintString8L( TLiwVariant value ) |
|
295 { |
|
296 TPtrC8 textValue = value.AsData(); |
|
297 HBufC8* text = GetFixedText8LC( textValue, iDepth, KDelim8 ); |
|
298 iLogBus.LogText( *text ); |
|
299 CleanupStack::PopAndDestroy( text ); |
|
300 } |
|
301 #else |
|
302 void ChspsLiwDump::PrintString8L( TLiwVariant /*value*/ ) |
|
303 { |
|
304 } |
|
305 #endif |
|
306 |
|
307 //------------------------------------------------------------------------------ |
|
308 // ChspsLiwDump::PrintListL |
|
309 //------------------------------------------------------------------------------ |
|
310 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
311 void ChspsLiwDump::PrintListL( TLiwVariant value ) |
|
312 { |
|
313 iDepth++; |
|
314 const CLiwList* list = value.AsList(); |
|
315 TInt count = list->Count(); |
|
316 for( TInt i = 0; i < count; i++ ) |
|
317 { |
|
318 HBufC* index = GetFixedTextLC( _L("---"), iDepth, KDelim ); |
|
319 iLogBus.LogText( *index ); |
|
320 CleanupStack::PopAndDestroy( index ); |
|
321 TLiwVariant value; |
|
322 list->AtL( i, value ); |
|
323 PrintVariantL( value ); |
|
324 value.Reset(); |
|
325 } |
|
326 iDepth--; |
|
327 } |
|
328 #else |
|
329 void ChspsLiwDump::PrintListL( TLiwVariant /*value*/ ) |
|
330 { |
|
331 } |
|
332 #endif |
|
333 |
|
334 //------------------------------------------------------------------------------ |
|
335 // ChspsLiwDump::GetFixedText8LC |
|
336 //------------------------------------------------------------------------------ |
|
337 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
338 HBufC8* ChspsLiwDump::GetFixedText8LC( const TDesC8& aText, |
|
339 const TInt aDepth, |
|
340 const TDesC8& aDelim ) |
|
341 { |
|
342 HBufC8 *buf = HBufC8::NewLC( aDepth * aDelim.Length() + aText.Length() + 1 ); |
|
343 TInt i = 0; |
|
344 for( ; i < aDepth; i++ ) |
|
345 { |
|
346 buf->Des().Append( aDelim ); |
|
347 } |
|
348 buf->Des().Append( aText ); |
|
349 return buf; |
|
350 } |
|
351 #else |
|
352 HBufC8* ChspsLiwDump::GetFixedText8LC( const TDesC8& /*aText*/, |
|
353 const TInt /*aDepth*/, |
|
354 const TDesC8& /*aDelim*/ ) |
|
355 { |
|
356 return NULL; |
|
357 } |
|
358 #endif |
|
359 |
|
360 //------------------------------------------------------------------------------ |
|
361 // ChspsLiwDump::GetFixedTextLC |
|
362 //------------------------------------------------------------------------------ |
|
363 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
364 HBufC* ChspsLiwDump::GetFixedTextLC( const TDesC& aText, |
|
365 const TInt aDepth, |
|
366 const TDesC& aDelim ) |
|
367 { |
|
368 HBufC *buf = HBufC::NewLC( aDepth * aDelim.Length() + aText.Length() + 1 ); |
|
369 TInt i = 0; |
|
370 for( ; i < aDepth; i++ ) |
|
371 { |
|
372 buf->Des().Append( aDelim ); |
|
373 } |
|
374 buf->Des().Append( aText ); |
|
375 return buf; |
|
376 } |
|
377 #else |
|
378 HBufC* ChspsLiwDump::GetFixedTextLC( const TDesC& /*aText*/, |
|
379 const TInt /*aDepth*/, |
|
380 const TDesC& /*aDelim*/ ) |
|
381 { |
|
382 return NULL; |
|
383 } |
|
384 #endif |
|
385 |
|
386 //------------------------------------------------------------------------------ |
|
387 // ChspsLiwDump::CreateCPlusPlusDumpL |
|
388 //------------------------------------------------------------------------------ |
|
389 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION |
|
390 HBufC* ChspsLiwDump::CreateCPlusPlusDumpL( ChspsByteBuffer& aBuffer ) const |
|
391 { |
|
392 if( aBuffer.Size() <= 0 ) |
|
393 { |
|
394 User::Leave( KErrArgument ); |
|
395 } |
|
396 |
|
397 if( aBuffer.Size() > KCPlusPlusArraySanityLimit ) |
|
398 { |
|
399 User::Leave( KErrArgument ); |
|
400 } |
|
401 |
|
402 // Calcute required space. |
|
403 const TInt KOneByteFootprint = 5; // hex is like 0x00 = 4 bytes, then trailing ',' for each one. |
|
404 const TInt KRequiredSpace = KCPlusPlusArrayStart().Length() + |
|
405 ( aBuffer.Size() * KOneByteFootprint ) + |
|
406 KCPlusPlusArrayEnd().Length(); |
|
407 |
|
408 // Create descriptor. |
|
409 HBufC* descriptor = HBufC::NewLC( KRequiredSpace ); |
|
410 TPtr16 pointer = descriptor->Des(); |
|
411 pointer.Append( KCPlusPlusArrayStart ); |
|
412 for( TInt i = 0; i < aBuffer.Size(); i++ ) |
|
413 { |
|
414 TUint byte = ( TUint ) ( ( aBuffer.Buffer() )[i] ); |
|
415 pointer.AppendFormat( KByteFormat, byte ); |
|
416 |
|
417 // Add ',' for all but the last element. |
|
418 if( i != ( aBuffer.Size() - 1 ) ) |
|
419 { |
|
420 pointer.Append( TChar( ',' ) ); |
|
421 } |
|
422 } |
|
423 pointer.Append( KCPlusPlusArrayEnd ); |
|
424 |
|
425 CleanupStack::Pop( descriptor ); |
|
426 return descriptor; |
|
427 } |
|
428 #else |
|
429 HBufC* ChspsLiwDump::CreateCPlusPlusDumpL( ChspsByteBuffer& /*aBuffer*/ ) const |
|
430 { |
|
431 return NULL; |
|
432 } |
|
433 #endif |