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