|
1 /* |
|
2 * Copyright (c) 2008-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: CCFCountOneShot class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "cfcountoneshot.h" |
|
22 #include "cfcontextoperationutils.h" |
|
23 #include "cfbasicoptrace.h" |
|
24 |
|
25 #include <cfcontextobject.h> |
|
26 #include <gmxmlelement.h> |
|
27 |
|
28 // CONSTANTS |
|
29 _LIT( KScriptCountName, "count" ); |
|
30 _LIT( KScriptOneShotAtAttribute, "oneShotAt" ); |
|
31 _LIT( KScriptTypeAttribute, "type" ); |
|
32 _LIT( KScriptCountTypeRemainName, "remain" ); |
|
33 _LIT( KScriptCountTypeChangeName, "change" ); |
|
34 _LIT( KScriptCountTypeTriggerName, "trigger" ); |
|
35 _LIT( KScriptContextRefName, "contextRef" ); |
|
36 _LIT( KScriptPersistencyFileAttribute, "persistencyFile" ); |
|
37 |
|
38 static const TInt KCountMinAttributes = 1; |
|
39 static const TUint KInitialCount = 0; |
|
40 |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CCFCountOneShot::CCFCountOneShot |
|
46 // C++ default constructor can NOT contain any code, that might leave. |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CCFCountOneShot::CCFCountOneShot( MCFOperationServices& aServices, |
|
50 CCFOperationNode* aParent, |
|
51 HBufC* aName, |
|
52 HBufC* aSource, |
|
53 const CCFContextOperation::TCmpType aType, |
|
54 const TUint aCount, |
|
55 const TCountType aCountType ) |
|
56 : CCFCount( aServices, aParent, aName, aSource, aType, aCount, |
|
57 aCountType ) |
|
58 { |
|
59 FUNC_LOG; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CCFCountOneShot::ConstructL |
|
64 // Symbian 2nd phase constructor can leave. |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CCFCountOneShot::ConstructL( const TDesC& aCmpVal ) |
|
68 { |
|
69 FUNC_LOG; |
|
70 |
|
71 CCFCount::ConstructL( aCmpVal ); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CCFCountOneShot::NewL |
|
76 // Two-phased constructor. |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CCFCountOneShot* CCFCountOneShot::NewL( MCFOperationServices& aServices, |
|
80 CCFOperationNode* aParent, |
|
81 TDesC& aName, |
|
82 TDesC& aSource, |
|
83 const CCFContextOperation::TCmpType aType, |
|
84 const TDesC& aCmpVal, |
|
85 const TUint aCount, |
|
86 const TCountType aCountType ) |
|
87 { |
|
88 FUNC_LOG; |
|
89 |
|
90 CCFCountOneShot* self = NewLC( aServices, |
|
91 aParent, |
|
92 aName, |
|
93 aSource, |
|
94 aType, |
|
95 aCmpVal, |
|
96 aCount, |
|
97 aCountType ); |
|
98 CleanupStack::Pop( self ); |
|
99 return self; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CCFCountOneShot::NewLC |
|
104 // Two-phased constructor. |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 CCFCountOneShot* CCFCountOneShot::NewLC( MCFOperationServices& aServices, |
|
108 CCFOperationNode* aParent, |
|
109 TDesC& aName, |
|
110 TDesC& aSource, |
|
111 const CCFContextOperation::TCmpType aType, |
|
112 const TDesC& aCmpVal, |
|
113 const TUint aCount, |
|
114 const TCountType aCountType ) |
|
115 { |
|
116 FUNC_LOG; |
|
117 |
|
118 HBufC* name = aName.AllocLC(); |
|
119 HBufC* source = aSource.AllocLC(); |
|
120 CCFCountOneShot* self = new( ELeave ) CCFCountOneShot( aServices, |
|
121 aParent, |
|
122 name, |
|
123 source, |
|
124 aType, |
|
125 aCount, |
|
126 aCountType ); |
|
127 CleanupStack::PushL( self ); |
|
128 self->ConstructL( aCmpVal ); |
|
129 |
|
130 // Cleanup |
|
131 CleanupStack::Pop( self ); |
|
132 CleanupStack::Pop( source ); |
|
133 CleanupStack::Pop( name ); |
|
134 |
|
135 CleanupStack::PushL( self ); |
|
136 return self; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CCFCountOneShot::ParseL |
|
141 // Construction with parsing from a DOM node. |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 CCFCountOneShot* CCFCountOneShot::ParseL( MCFOperationServices& aServices, |
|
145 CCFOperationNode* aParent, |
|
146 CMDXMLNode& aNode ) |
|
147 { |
|
148 FUNC_LOG; |
|
149 |
|
150 if ( aNode.NodeName().CompareF( KScriptCountName ) != 0 |
|
151 || aNode.NodeType() != CMDXMLNode::EElementNode ) |
|
152 { |
|
153 return NULL; // Cannot create count operation from the given node. |
|
154 } |
|
155 |
|
156 // Check & get count attributes. |
|
157 CMDXMLElement& element = static_cast< CMDXMLElement& >( aNode ); |
|
158 TPtrC countAttributeValue; |
|
159 if ( KErrNone != element.GetAttribute( KScriptOneShotAtAttribute, |
|
160 countAttributeValue ) ) |
|
161 { |
|
162 INFO( "CCFCountOneShot::ParseL - count missing required attribute" ); |
|
163 return NULL; |
|
164 } |
|
165 |
|
166 TInt expectedAttributeCount = KCountMinAttributes; |
|
167 // Check optional persistency file. |
|
168 TPtrC persistencyFileAttributeValue; |
|
169 if ( KErrNone == element.GetAttribute( KScriptPersistencyFileAttribute, |
|
170 persistencyFileAttributeValue ) ) |
|
171 { |
|
172 if ( persistencyFileAttributeValue.Length() == 0 ) |
|
173 { |
|
174 ERROR_GEN( "CCFCountOneShot::ParseL - Persistency File attribute length is zero!" ); |
|
175 return NULL; |
|
176 } |
|
177 expectedAttributeCount++; |
|
178 } |
|
179 |
|
180 CCFCount::TCountType countType( CCFCount::ECountTypeRemain ); |
|
181 TPtrC countTypeValue; |
|
182 element.GetAttribute( KScriptTypeAttribute, countTypeValue ); |
|
183 if ( countTypeValue.Length() ) |
|
184 { |
|
185 expectedAttributeCount++; |
|
186 if ( element.NumAttributes() != expectedAttributeCount ) |
|
187 { |
|
188 INFO_1( "CCFCountOneShot::ParseL - count attributes != %d", |
|
189 expectedAttributeCount ); |
|
190 return NULL; |
|
191 } |
|
192 |
|
193 if ( countTypeValue.CompareF( KScriptCountTypeRemainName ) == 0 ) |
|
194 { |
|
195 // Default value, already set. |
|
196 } |
|
197 else if ( countTypeValue.CompareF( KScriptCountTypeChangeName ) == 0 ) |
|
198 { |
|
199 countType = CCFCount::ECountTypeChange; |
|
200 } |
|
201 else if ( countTypeValue.CompareF( KScriptCountTypeTriggerName ) == 0 ) |
|
202 { |
|
203 countType = CCFCount::ECountTypeTrigger; |
|
204 } |
|
205 else |
|
206 { |
|
207 INFO_1( "CCFCountOneShot::ParseL - unknown attribute value [%S] for type", |
|
208 &countTypeValue ); |
|
209 return NULL; |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 if ( element.NumAttributes() != expectedAttributeCount ) |
|
215 { |
|
216 INFO_1( "CCFCountOneShot::ParseL - count attributes != %d", |
|
217 expectedAttributeCount ); |
|
218 return NULL; |
|
219 } |
|
220 } |
|
221 // Convert the attribute value to TUint. |
|
222 TUint countValue( 0 ); |
|
223 TLex lex( countAttributeValue ); |
|
224 TInt err = lex.Val( countValue ); |
|
225 ERROR_1( err, |
|
226 "CCFCountOneShot::ParseL - Extracting count value from string [%S] failed!", |
|
227 &countAttributeValue ); |
|
228 if ( err != KErrNone ) |
|
229 { |
|
230 User::Leave( KErrArgument ); |
|
231 } |
|
232 |
|
233 TPtrC contextSource; |
|
234 TPtrC contextType; |
|
235 TPtrC contextValue; |
|
236 TCmpType compareType( CCFContextOperation::EInvalidCmpType ); |
|
237 TPtrC compareValue; |
|
238 TInt contextLevelDelay( 0 ); |
|
239 |
|
240 TBool contextRefOK( EFalse ); |
|
241 TBool comparisonTypeValueOK( EFalse ); |
|
242 TBool argsOK( ETrue ); // Will be set to false if unknown nodes detected. |
|
243 CMDXMLNode* child = aNode.FirstChild(); |
|
244 while ( child ) |
|
245 { |
|
246 if ( child->NodeType() == CMDXMLNode::EElementNode ) |
|
247 { |
|
248 if ( child->NodeName().CompareF( KScriptContextRefName ) == 0 ) |
|
249 { |
|
250 if ( !contextRefOK ) |
|
251 { |
|
252 contextRefOK = CFContextOperationUtils::ParseContextRef( |
|
253 *child, |
|
254 contextSource, |
|
255 contextType, |
|
256 contextValue, |
|
257 contextLevelDelay ); |
|
258 if ( !contextRefOK ) |
|
259 { |
|
260 argsOK = EFalse; |
|
261 break; |
|
262 } |
|
263 } |
|
264 else |
|
265 { |
|
266 argsOK = EFalse; |
|
267 break; |
|
268 } |
|
269 } |
|
270 else |
|
271 { |
|
272 if ( !comparisonTypeValueOK ) |
|
273 { |
|
274 comparisonTypeValueOK |
|
275 = CFContextOperationUtils::ParseComparisonTypeValue( |
|
276 *child, |
|
277 compareType, |
|
278 compareValue ); |
|
279 if ( !comparisonTypeValueOK ) |
|
280 { |
|
281 argsOK = EFalse; |
|
282 break; |
|
283 } |
|
284 } |
|
285 else |
|
286 { |
|
287 argsOK = EFalse; |
|
288 break; |
|
289 } |
|
290 } |
|
291 } |
|
292 else if ( child->NodeType() != CMDXMLNode::ECommentNode ) |
|
293 { |
|
294 argsOK = EFalse; |
|
295 break; |
|
296 } |
|
297 child = child->NextSibling(); |
|
298 } |
|
299 |
|
300 TBool parsed( EFalse ); |
|
301 if ( argsOK && contextRefOK ) |
|
302 { |
|
303 if ( ( comparisonTypeValueOK && !contextValue.Length() ) |
|
304 || ( !comparisonTypeValueOK && contextValue.Length() ) ) |
|
305 { |
|
306 if ( !comparisonTypeValueOK ) |
|
307 { |
|
308 compareType = CCFContextOperation::EStringCmp; |
|
309 compareValue.Set( contextValue ); |
|
310 } |
|
311 } |
|
312 else if ( comparisonTypeValueOK && contextValue.Length() ) |
|
313 { |
|
314 INFO( "CCFCountOneShot::ParseL - Ambiguous definition for comparison value" ); |
|
315 return NULL; |
|
316 } |
|
317 parsed = ETrue; |
|
318 } |
|
319 |
|
320 CCFCountOneShot* self = NULL; |
|
321 if ( parsed ) |
|
322 { |
|
323 // Below // CLEANUP<< self |
|
324 self = NewLC( aServices, |
|
325 aParent, |
|
326 contextType, |
|
327 contextSource, |
|
328 compareType, |
|
329 compareValue, |
|
330 countValue, |
|
331 countType ); |
|
332 if ( contextLevelDelay ) |
|
333 { |
|
334 self->iContextLevelDelay = contextLevelDelay; |
|
335 } |
|
336 if ( persistencyFileAttributeValue.Length() > 0 ) |
|
337 { |
|
338 self->iPersistencyFile = persistencyFileAttributeValue.AllocL(); |
|
339 } |
|
340 CleanupStack::Pop( self ); // CLEANUP>> self |
|
341 } |
|
342 else |
|
343 { |
|
344 INFO( "CCFCountOneShot::ParseL - Unsupported arguments" ); |
|
345 } |
|
346 |
|
347 return self; |
|
348 } |
|
349 |
|
350 |
|
351 // Destructor |
|
352 CCFCountOneShot::~CCFCountOneShot() |
|
353 { |
|
354 FUNC_LOG; |
|
355 } |
|
356 |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 // CCFCountOneShot::IsTrueL |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 TBool CCFCountOneShot::IsTrueL( const CCFContextObject& /*aContext*/ ) |
|
363 { |
|
364 FUNC_LOG; |
|
365 |
|
366 TBool value( EFalse ); |
|
367 if ( iCurrentCount == iCmpCount ) |
|
368 { |
|
369 value = ETrue; |
|
370 |
|
371 if ( iCountType == CCFCount::ECountTypeRemain ) |
|
372 { |
|
373 Finished(); |
|
374 } |
|
375 } |
|
376 else if ( iCurrentCount > iCmpCount ) |
|
377 { |
|
378 if ( iCmpCount == KInitialCount |
|
379 || iCountType != CCFCount::ECountTypeRemain ) |
|
380 { |
|
381 Finished(); |
|
382 } |
|
383 } |
|
384 |
|
385 return value; |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // CCFCountOneShot::Finished |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 void CCFCountOneShot::Finished() |
|
393 { |
|
394 FUNC_LOG; |
|
395 |
|
396 iFinished = ETrue; |
|
397 Deactivate(); |
|
398 } |