|
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: Prints liw list to a file. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwcommon.h> |
|
20 #include <flogger.h> |
|
21 |
|
22 #include "mt_hspsliwlistprinter.h" |
|
23 |
|
24 |
|
25 // File logging macros |
|
26 // filename |
|
27 _LIT(KLog,"printliw.log"); |
|
28 // additional path |
|
29 _LIT(KLogFolder,"hspsprintdom"); |
|
30 #define _LOGT(aDescription) RFileLogger::Write( KLogFolder, KLog, EFileLoggingModeOverwrite, aDescription ); |
|
31 #define _LOGTFRM1(a,b) RFileLogger::WriteFormat( KLogFolder, KLog, EFileLoggingModeOverwrite, (a), (b) ) |
|
32 #define _LOGTFRM2(a,b,c) RFileLogger::WriteFormat( KLogFolder, KLog, EFileLoggingModeOverwrite, (a),(b),(c) ); |
|
33 #define _LOGTFRM3(a,b,c,d) RFileLogger::WriteFormat( KLogFolder, KLog, EFileLoggingModeOverwrite, (a),(b),(c),(d) ); |
|
34 // indentation delimiter |
|
35 _LIT8(KDelim8, "\t" ); |
|
36 _LIT(KDelim, "\t" ); |
|
37 |
|
38 //------------------------------------------------------------------------------ |
|
39 // Constuctor |
|
40 //------------------------------------------------------------------------------ |
|
41 CHspsLiwListPrinter::CHspsLiwListPrinter() |
|
42 { |
|
43 iDepth = 0; |
|
44 } |
|
45 |
|
46 //------------------------------------------------------------------------------ |
|
47 // Destructor |
|
48 //------------------------------------------------------------------------------ |
|
49 CHspsLiwListPrinter::~CHspsLiwListPrinter() |
|
50 { |
|
51 } |
|
52 |
|
53 //------------------------------------------------------------------------------ |
|
54 // Symbian constructor |
|
55 //------------------------------------------------------------------------------ |
|
56 CHspsLiwListPrinter* CHspsLiwListPrinter::NewLC() |
|
57 { |
|
58 CHspsLiwListPrinter* self = new (ELeave)CHspsLiwListPrinter(); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 //------------------------------------------------------------------------------ |
|
65 // Symbian constructor |
|
66 //------------------------------------------------------------------------------ |
|
67 CHspsLiwListPrinter* CHspsLiwListPrinter::NewL() |
|
68 { |
|
69 CHspsLiwListPrinter* self=CHspsLiwListPrinter::NewLC(); |
|
70 CleanupStack::Pop( self ); // self; |
|
71 return self; |
|
72 } |
|
73 |
|
74 //------------------------------------------------------------------------------ |
|
75 // 2nd tier constructor |
|
76 //------------------------------------------------------------------------------ |
|
77 void CHspsLiwListPrinter::ConstructL() |
|
78 { |
|
79 } |
|
80 |
|
81 //------------------------------------------------------------------------------ |
|
82 // Prints liw list to a file. |
|
83 //------------------------------------------------------------------------------ |
|
84 void CHspsLiwListPrinter::PrintLiwListL( CLiwGenericParamList& aLiwList ) |
|
85 { |
|
86 // implementation for GetActiveAppConf and GetPluginConf that has map |
|
87 // as base root. |
|
88 iDepth = 0; |
|
89 TInt count = aLiwList.Count(); |
|
90 for( TInt i = 0; i < count; i++ ) |
|
91 { |
|
92 //get Generic param and check for param id and name. |
|
93 TLiwGenericParam param = aLiwList[i]; |
|
94 //Check for the param identifier: |
|
95 LIW::TGenericParamId identifier = param.SemanticId(); |
|
96 //print semanticId: |
|
97 _LOGTFRM1(_L8(" SemanticId: %d"), identifier ); |
|
98 if( identifier == LIW::EGenericParamError ) |
|
99 { |
|
100 _LOGT(_L8(" ERROR: EGenericParamError") ); |
|
101 } |
|
102 //get generic param name. |
|
103 //print name. |
|
104 _LOGT( param.Name() ); |
|
105 //get Variant |
|
106 TLiwVariant value = param.Value(); |
|
107 //get variant type. |
|
108 PrintVariantL( value ); |
|
109 } |
|
110 } |
|
111 |
|
112 //------------------------------------------------------------------------------ |
|
113 // Parses variant type for printing. |
|
114 //------------------------------------------------------------------------------ |
|
115 void CHspsLiwListPrinter::PrintVariantL( TLiwVariant value ) |
|
116 { |
|
117 LIW::TVariantTypeId variantId = value.TypeId(); |
|
118 if( variantId == LIW::EVariantTypeDesC8 ) |
|
119 { |
|
120 PrintString8L( value ); |
|
121 } |
|
122 else if( variantId == LIW::EVariantTypeDesC ) |
|
123 { |
|
124 PrintStringL( value ); |
|
125 } |
|
126 else if ( variantId == LIW::EVariantTypeMap ) |
|
127 { |
|
128 HBufC* text = GetFixedTextLC( _L("<Map>"), iDepth, KDelim ); |
|
129 _LOGT( *text ); |
|
130 CleanupStack::PopAndDestroy( text ); |
|
131 PrintMapL( value ); |
|
132 } |
|
133 else if ( variantId == LIW::EVariantTypeList ) |
|
134 { |
|
135 HBufC* text = GetFixedTextLC( _L("<List>"), iDepth, KDelim ); |
|
136 _LOGT( *text ); |
|
137 CleanupStack::PopAndDestroy( text ); |
|
138 PrintListL( value ); |
|
139 } |
|
140 else |
|
141 { |
|
142 _LOGT(_L8("--- TODO: Unknown --- ")); |
|
143 } |
|
144 } |
|
145 |
|
146 //------------------------------------------------------------------------------ |
|
147 // Prints map type variant. |
|
148 //------------------------------------------------------------------------------ |
|
149 void CHspsLiwListPrinter::PrintMapL( TLiwVariant value ) |
|
150 { |
|
151 //get map from the variant. |
|
152 //get map values. |
|
153 const CLiwMap* map = value.AsMap(); |
|
154 TInt count = map->Count(); |
|
155 for( TInt i = 0; i < count; i++ ) |
|
156 { |
|
157 HBufC* index = GetFixedTextLC( _L("---"), iDepth, KDelim ); |
|
158 _LOGT( *index ); |
|
159 CleanupStack::PopAndDestroy( index ); |
|
160 TBuf8<100> buf; //TODO: bad solution... |
|
161 map->AtL( i, buf); |
|
162 HBufC8* text = GetFixedText8LC( buf, iDepth, KDelim8 ); |
|
163 _LOGT( *text ); |
|
164 CleanupStack::PopAndDestroy( text ); |
|
165 TLiwVariant value; |
|
166 map->FindL( buf, value ); |
|
167 PrintVariantL( value ); |
|
168 value.Reset(); |
|
169 } |
|
170 } |
|
171 |
|
172 //------------------------------------------------------------------------------ |
|
173 // Prints string type variant. |
|
174 //------------------------------------------------------------------------------ |
|
175 void CHspsLiwListPrinter::PrintStringL( TLiwVariant value ) |
|
176 { |
|
177 TPtrC textValue = value.AsDes(); |
|
178 HBufC* text = GetFixedTextLC( textValue, iDepth, KDelim ); |
|
179 _LOGT( *text ); |
|
180 CleanupStack::PopAndDestroy( text ); |
|
181 } |
|
182 |
|
183 //------------------------------------------------------------------------------ |
|
184 // Prints string type variant. |
|
185 //------------------------------------------------------------------------------ |
|
186 void CHspsLiwListPrinter::PrintString8L( TLiwVariant value ) |
|
187 { |
|
188 TPtrC8 textValue = value.AsData(); |
|
189 HBufC8* text = GetFixedText8LC( textValue, iDepth, KDelim8 ); |
|
190 _LOGT( *text ); |
|
191 CleanupStack::PopAndDestroy( text ); |
|
192 } |
|
193 |
|
194 //------------------------------------------------------------------------------ |
|
195 // Prints list type variant. |
|
196 //------------------------------------------------------------------------------ |
|
197 void CHspsLiwListPrinter::PrintListL( TLiwVariant value ) |
|
198 { |
|
199 iDepth++; |
|
200 const CLiwList* list = value.AsList(); |
|
201 TInt count = list->Count(); |
|
202 for( TInt i = 0; i < count; i++ ) |
|
203 { |
|
204 HBufC* index = GetFixedTextLC( _L("---"), iDepth, KDelim ); |
|
205 _LOGT( *index ); |
|
206 CleanupStack::PopAndDestroy( index ); |
|
207 TLiwVariant value; |
|
208 list->AtL( i, value ); |
|
209 PrintVariantL( value ); |
|
210 value.Reset(); |
|
211 } |
|
212 iDepth--; |
|
213 } |
|
214 |
|
215 //------------------------------------------------------------------------------ |
|
216 // Utility method for generating a custom text descriptor. |
|
217 // Adds indentation to a text string. 8 bit variant. |
|
218 //------------------------------------------------------------------------------ |
|
219 HBufC8* CHspsLiwListPrinter::GetFixedText8LC( const TDesC8& aText, |
|
220 const TInt aDepth, |
|
221 const TDesC8& aDelim ) |
|
222 { |
|
223 HBufC8 *buf = HBufC8::NewLC( aDepth * aDelim.Length() + aText.Length() + 1 ); |
|
224 TInt i = 0; |
|
225 for( ; i < aDepth; i++ ) |
|
226 { |
|
227 buf->Des().Append( aDelim ); |
|
228 } |
|
229 buf->Des().Append( aText ); |
|
230 return buf; |
|
231 } |
|
232 |
|
233 //------------------------------------------------------------------------------ |
|
234 // Debug utility for generating a custom text descriptor. |
|
235 // Adds indentation to a text string. 8 bit variant. |
|
236 //------------------------------------------------------------------------------ |
|
237 HBufC* CHspsLiwListPrinter::GetFixedTextLC( const TDesC& aText, |
|
238 const TInt aDepth, |
|
239 const TDesC& aDelim ) |
|
240 { |
|
241 HBufC *buf = HBufC::NewLC( aDepth * aDelim.Length() + aText.Length() + 1 ); |
|
242 TInt i = 0; |
|
243 for( ; i < aDepth; i++ ) |
|
244 { |
|
245 buf->Des().Append( aDelim ); |
|
246 } |
|
247 buf->Des().Append( aText ); |
|
248 return buf; |
|
249 } |