|
1 /* |
|
2 * Copyright (c) 2002-2006 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: CFContextSourceSettingsManagerImpl class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "cfcontextsourcesettingsmanagerimpl.h" |
|
22 |
|
23 #include <gmxmldocument.h> |
|
24 #include <gmxmlelement.h> |
|
25 |
|
26 #include "cfcontextsourcesettingimpl.h" |
|
27 #include "cfcontextsourcesettingparameterimpl.h" |
|
28 #include "cfcontextsourcesettingarrayimpl.h" |
|
29 #include "cftrace.h" |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 // Root node name |
|
34 _LIT( KRootNode, "ContextSourceSettings" ); |
|
35 |
|
36 // MEMBER FUNCTIONS |
|
37 |
|
38 EXPORT_C CCFContextSourceSettingsManagerImpl* CCFContextSourceSettingsManagerImpl::NewL( |
|
39 RFs& aFs ) |
|
40 { |
|
41 FUNC_LOG; |
|
42 |
|
43 CCFContextSourceSettingsManagerImpl* self = |
|
44 CCFContextSourceSettingsManagerImpl::NewLC( aFs ); |
|
45 CleanupStack::Pop( self ); |
|
46 |
|
47 return self; |
|
48 } |
|
49 |
|
50 EXPORT_C CCFContextSourceSettingsManagerImpl* CCFContextSourceSettingsManagerImpl::NewLC( |
|
51 RFs& aFs ) |
|
52 { |
|
53 FUNC_LOG; |
|
54 |
|
55 CCFContextSourceSettingsManagerImpl* self = |
|
56 new( ELeave ) CCFContextSourceSettingsManagerImpl( aFs ); |
|
57 |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 |
|
61 return self; |
|
62 } |
|
63 |
|
64 EXPORT_C CCFContextSourceSettingsManagerImpl::~CCFContextSourceSettingsManagerImpl() |
|
65 { |
|
66 FUNC_LOG; |
|
67 |
|
68 if( iWait ) |
|
69 { |
|
70 if( iWait->IsStarted() ) |
|
71 { |
|
72 iWait->AsyncStop(); |
|
73 } |
|
74 delete iWait; |
|
75 } |
|
76 delete iParser; |
|
77 } |
|
78 |
|
79 CCFContextSourceSettingsManagerImpl::CCFContextSourceSettingsManagerImpl( |
|
80 RFs& aFs ): |
|
81 iFs( aFs ) |
|
82 { |
|
83 FUNC_LOG; |
|
84 } |
|
85 |
|
86 void CCFContextSourceSettingsManagerImpl::ConstructL() |
|
87 { |
|
88 FUNC_LOG; |
|
89 |
|
90 iParser = CMDXMLParser::NewL( this ); |
|
91 iWait = new( ELeave ) CActiveSchedulerWait; |
|
92 } |
|
93 |
|
94 // METHODS |
|
95 |
|
96 //---------------------------------------------------------------------------- |
|
97 // CCFContextSourceSettingsManagerImpl::ParseSettingsL |
|
98 //---------------------------------------------------------------------------- |
|
99 // |
|
100 void CCFContextSourceSettingsManagerImpl::ParseSettingsL( |
|
101 const TDesC& aSettingsFile, |
|
102 CCFContextSourceSettingArray& aSettings ) |
|
103 { |
|
104 FUNC_LOG; |
|
105 |
|
106 INFO_1( "Started parsing context source setting file: %S", |
|
107 &aSettingsFile ); |
|
108 TIMESTAMP( "Context source setting file parse start" ); |
|
109 |
|
110 TInt err = iParser->ParseFile( iFs, aSettingsFile ); |
|
111 if( err == KErrNone ) |
|
112 { |
|
113 iSettings = |
|
114 static_cast<CCFContextSourceSettingArrayImpl*>( &aSettings ); |
|
115 iWait->Start(); |
|
116 } |
|
117 } |
|
118 |
|
119 //---------------------------------------------------------------------------- |
|
120 // CCFContextSourceSettingsManagerImpl::ParseSettingsL |
|
121 //---------------------------------------------------------------------------- |
|
122 // |
|
123 void CCFContextSourceSettingsManagerImpl::ParseSettingsL( RFile& aSettingsFile, |
|
124 CCFContextSourceSettingArray& aSettings ) |
|
125 { |
|
126 FUNC_LOG; |
|
127 |
|
128 INFO( "Started parsing context source setting file from open file handle" ); |
|
129 TIMESTAMP( "Context source setting file parse start" ); |
|
130 |
|
131 TInt err = iParser->ParseFile( aSettingsFile ); |
|
132 if( err == KErrNone ) |
|
133 { |
|
134 iSettings = |
|
135 static_cast<CCFContextSourceSettingArrayImpl*>( &aSettings ); |
|
136 iWait->Start(); |
|
137 } |
|
138 } |
|
139 |
|
140 //---------------------------------------------------------------------------- |
|
141 // CCFContextSourceSettingsManagerImpl::ParseFileCompleteL |
|
142 //---------------------------------------------------------------------------- |
|
143 // |
|
144 void CCFContextSourceSettingsManagerImpl::ParseFileCompleteL() |
|
145 { |
|
146 FUNC_LOG; |
|
147 |
|
148 TIMESTAMP( "Context source setting file parse stop" ); |
|
149 |
|
150 CMDXMLDocument* document = iParser->DetachXMLDoc(); |
|
151 if( document ) |
|
152 { |
|
153 CMDXMLElement* documentElement = document->DocumentElement(); |
|
154 if( documentElement ) |
|
155 { |
|
156 // Get first node |
|
157 CMDXMLNode* root = documentElement->FirstChild(); |
|
158 if( root ) |
|
159 { |
|
160 // Check that we have a correct root |
|
161 if( root->NodeName().CompareF( KRootNode ) == KErrNone ) |
|
162 { |
|
163 // Start parsing setting blocks |
|
164 CMDXMLNode* child = root->FirstChild(); |
|
165 while( child ) |
|
166 { |
|
167 // Parse current child and check if we have more |
|
168 // settings defined |
|
169 if( child->NodeType() == CMDXMLNode::EElementNode ) |
|
170 { |
|
171 CMDXMLElement* element = |
|
172 static_cast<CMDXMLElement*>( child ); |
|
173 // Trap possible leaves so that we can still |
|
174 // stop wait |
|
175 TRAP_IGNORE( ParseSettingBlockL( *element ) ); |
|
176 } |
|
177 child = child->NextSibling(); |
|
178 } |
|
179 } |
|
180 } |
|
181 } |
|
182 } |
|
183 delete document; |
|
184 |
|
185 // We have completed, stop wait and continue |
|
186 iWait->AsyncStop(); |
|
187 } |
|
188 |
|
189 //---------------------------------------------------------------------------- |
|
190 // CCFContextSourceSettingsManagerImpl::ParseSettingBlockL |
|
191 //---------------------------------------------------------------------------- |
|
192 // |
|
193 void CCFContextSourceSettingsManagerImpl::ParseSettingBlockL( |
|
194 CMDXMLElement& aElement ) |
|
195 { |
|
196 FUNC_LOG; |
|
197 |
|
198 TPtrC nodeName( aElement.NodeName() ); |
|
199 INFO_1( "Found setting item: [%S]", &nodeName ); |
|
200 |
|
201 // Check that we really have an element |
|
202 CCFContextSourceSettingImpl* setting = |
|
203 CCFContextSourceSettingImpl::NewLC(); |
|
204 |
|
205 // Set plug-in name |
|
206 setting->SetNameL( nodeName ); |
|
207 |
|
208 // Set attributes |
|
209 ParseAttributesL( aElement, *setting ); |
|
210 |
|
211 // Set parameters |
|
212 CMDXMLNode* child = aElement.FirstChild(); |
|
213 while( child ) |
|
214 { |
|
215 // Parse current child and check if we have more |
|
216 // settings defined |
|
217 if( child->NodeType() == CMDXMLNode::EElementNode ) |
|
218 { |
|
219 CMDXMLElement* element = |
|
220 static_cast<CMDXMLElement*>( child ); |
|
221 ParseParametersL( *element, *setting ); |
|
222 } |
|
223 child = child->NextSibling(); |
|
224 } |
|
225 |
|
226 // Save setting |
|
227 iSettings->AppendItemL( setting ); |
|
228 CleanupStack::Pop( setting ); |
|
229 } |
|
230 |
|
231 //---------------------------------------------------------------------------- |
|
232 // CCFContextSourceSettingsManagerImpl::ParseAttributesL |
|
233 //---------------------------------------------------------------------------- |
|
234 // |
|
235 void CCFContextSourceSettingsManagerImpl::ParseAttributesL( |
|
236 CMDXMLElement& aElement, |
|
237 CCFContextSourceSettingImpl& aSetting ) |
|
238 { |
|
239 FUNC_LOG; |
|
240 |
|
241 TInt numOfAttributes = aElement.NumAttributes(); |
|
242 TPtrC attributeName( KNullDesC ); |
|
243 TPtrC attributeValue( KNullDesC ); |
|
244 for( TInt i = 0; i < numOfAttributes; i++ ) |
|
245 { |
|
246 if( aElement.AttributeDetails( |
|
247 i, attributeName, attributeValue ) == KErrNone ) |
|
248 { |
|
249 INFO_2( "Found attribute: '%S'='%S'", |
|
250 &attributeName, |
|
251 &attributeValue ); |
|
252 |
|
253 CCFKeyValuePair* keyValue = CCFKeyValuePair::NewLC( |
|
254 attributeName, |
|
255 attributeValue ); |
|
256 aSetting.AddAttributeL( keyValue ); |
|
257 CleanupStack::Pop( keyValue ); |
|
258 } |
|
259 } |
|
260 } |
|
261 |
|
262 //---------------------------------------------------------------------------- |
|
263 // CCFContextSourceSettingsManagerImpl::ParseParametersL |
|
264 //---------------------------------------------------------------------------- |
|
265 // |
|
266 void CCFContextSourceSettingsManagerImpl::ParseParametersL( |
|
267 CMDXMLElement& aElement, |
|
268 CCFContextSourceSettingImpl& aSetting ) |
|
269 { |
|
270 FUNC_LOG; |
|
271 |
|
272 TPtrC nodeName( aElement.NodeName() ); |
|
273 INFO_1( "Found parameter item: [%S]", &nodeName ); |
|
274 |
|
275 CCFContextSourceSettingParameterImpl* param = |
|
276 CCFContextSourceSettingParameterImpl::NewLC(); |
|
277 |
|
278 // Set parameter block name |
|
279 param->SetNameL( nodeName ); |
|
280 |
|
281 // Set attributes for the parameter block |
|
282 TInt numOfAttributes = aElement.NumAttributes(); |
|
283 TPtrC attributeName( KNullDesC ); |
|
284 TPtrC attributeValue( KNullDesC ); |
|
285 for( TInt i = 0; i < numOfAttributes; i++ ) |
|
286 { |
|
287 if( aElement.AttributeDetails( |
|
288 i, attributeName, attributeValue ) == KErrNone ) |
|
289 { |
|
290 INFO_2( "Found parameter attribute: '%S'='%S'", |
|
291 &attributeName, |
|
292 &attributeValue ); |
|
293 |
|
294 CCFKeyValuePair* keyValue = CCFKeyValuePair::NewLC( |
|
295 attributeName, |
|
296 attributeValue ); |
|
297 param->AddAttributeL( keyValue ); |
|
298 CleanupStack::Pop( keyValue ); |
|
299 } |
|
300 } |
|
301 aSetting.AddParameterL( param ); |
|
302 CleanupStack::Pop( param ); |
|
303 } |