|
1 /* |
|
2 * Copyright (c) 2002-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: CCFContextUpdated class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "cfcontextupdated.h" |
|
22 #include "cfcontextoperationutils.h" |
|
23 #include "cfbasicoptrace.h" |
|
24 |
|
25 #include <gmxmlnode.h> |
|
26 |
|
27 // CONSTANTS |
|
28 _LIT( KScriptUpdatedName, "contextUpdated" ); |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CCFContextUpdated::CCFContextUpdated |
|
34 // C++ default constructor can NOT contain any code, that might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CCFContextUpdated::CCFContextUpdated( MCFOperationServices& aServices, |
|
38 CCFOperationNode* aParent, |
|
39 HBufC* aName, |
|
40 HBufC* aSource ) |
|
41 : CCFContextOperation( aServices, aParent, aName, aSource ) |
|
42 { |
|
43 FUNC_LOG; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CCFContextUpdated::ConstructL |
|
48 // Symbian 2nd phase constructor can leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CCFContextUpdated::ConstructL( const TDesC& aValue ) |
|
52 { |
|
53 FUNC_LOG; |
|
54 |
|
55 if ( aValue.Length() ) |
|
56 { |
|
57 iCmpValue = aValue.AllocL(); |
|
58 } |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CCFContextUpdated::NewL |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CCFContextUpdated* CCFContextUpdated::NewL( MCFOperationServices& aServices, |
|
67 CCFOperationNode* aParent, |
|
68 const TDesC& aName, |
|
69 const TDesC& aSource, |
|
70 const TDesC& aValue ) |
|
71 { |
|
72 FUNC_LOG; |
|
73 |
|
74 CCFContextUpdated* self |
|
75 = NewLC( aServices, aParent, aName, aSource, aValue ); |
|
76 CleanupStack::Pop( self ); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CCFContextUpdated::NewLC |
|
82 // Two-phased constructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CCFContextUpdated* CCFContextUpdated::NewLC( MCFOperationServices& aServices, |
|
86 CCFOperationNode* aParent, |
|
87 const TDesC& aName, |
|
88 const TDesC& aSource, |
|
89 const TDesC& aValue ) |
|
90 { |
|
91 FUNC_LOG; |
|
92 |
|
93 HBufC* name = aName.AllocLC(); |
|
94 HBufC* source = aSource.AllocLC(); |
|
95 CCFContextUpdated* self |
|
96 = new( ELeave ) CCFContextUpdated( aServices, aParent, name, source ); |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL( aValue ); |
|
99 |
|
100 // Cleanup |
|
101 CleanupStack::Pop( self ); |
|
102 CleanupStack::Pop( source ); |
|
103 CleanupStack::Pop( name ); |
|
104 |
|
105 CleanupStack::PushL( self ); |
|
106 return self; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CCFContextUpdated::ParseL |
|
111 // Construction with parsing from a DOM node. |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 CCFContextUpdated* CCFContextUpdated::ParseL( MCFOperationServices& aServices, |
|
115 CCFOperationNode* aParent, |
|
116 CMDXMLNode& aNode ) |
|
117 { |
|
118 FUNC_LOG; |
|
119 |
|
120 if ( aNode.NodeName().CompareF( KScriptUpdatedName ) != 0 ) |
|
121 { |
|
122 return NULL; // Cannot create context updated operation from the node. |
|
123 } |
|
124 |
|
125 TPtrC contextSource; |
|
126 TPtrC contextType; |
|
127 TPtrC contextValue; |
|
128 TInt contextLevelDelay( 0 ); |
|
129 |
|
130 TBool argsOK( ETrue ); |
|
131 TBool contextRefOK( EFalse ); |
|
132 CMDXMLNode* child = aNode.FirstChild(); |
|
133 while ( child ) |
|
134 { |
|
135 if ( child->NodeType() == CMDXMLNode::EElementNode ) |
|
136 { |
|
137 if ( !contextRefOK ) |
|
138 { |
|
139 contextRefOK = CFContextOperationUtils::ParseContextRef( |
|
140 *child, |
|
141 contextSource, |
|
142 contextType, |
|
143 contextValue, |
|
144 contextLevelDelay ); |
|
145 if ( !contextRefOK ) |
|
146 { |
|
147 argsOK = EFalse; |
|
148 break; |
|
149 } |
|
150 } |
|
151 else |
|
152 { |
|
153 argsOK = EFalse; |
|
154 break; |
|
155 } |
|
156 } |
|
157 else if ( child->NodeType() != CMDXMLNode::ECommentNode ) |
|
158 { |
|
159 argsOK = EFalse; // Unsupported node encountered. |
|
160 break; |
|
161 } |
|
162 child = child->NextSibling(); |
|
163 } |
|
164 |
|
165 CCFContextUpdated* self = NULL; |
|
166 if ( argsOK && contextRefOK ) |
|
167 { |
|
168 self = NewL( aServices, |
|
169 aParent, |
|
170 contextType, |
|
171 contextSource, |
|
172 contextValue ); |
|
173 if ( contextLevelDelay ) |
|
174 { |
|
175 self->iContextLevelDelay = contextLevelDelay; |
|
176 } |
|
177 } |
|
178 else |
|
179 { |
|
180 INFO( "CCFContextUpdated::ParseL - Unsupported arguments" ); |
|
181 } |
|
182 |
|
183 CREATE_DOM_INFO( self, aNode ); |
|
184 |
|
185 return self; |
|
186 } |
|
187 |
|
188 |
|
189 // Destructor |
|
190 CCFContextUpdated::~CCFContextUpdated() |
|
191 { |
|
192 FUNC_LOG; |
|
193 |
|
194 delete iCmpValue; |
|
195 } |
|
196 |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // CCFContextUpdated::IsAllRequired |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 TBool CCFContextUpdated::IsAllRequired() const |
|
203 { |
|
204 FUNC_LOG; |
|
205 |
|
206 return ETrue; |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CCFContextUpdated::Evaluate |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 TBool CCFContextUpdated::Evaluate( const CCFContextObject& aContext, |
|
214 TInt& aContextLevelDelay ) |
|
215 { |
|
216 FUNC_LOG; |
|
217 |
|
218 DOM_INFO( "CCFContextUpdated::Evaluate" ); |
|
219 |
|
220 // Ask concrete implementation if it is true. |
|
221 TInt val( EFalse ); |
|
222 TRAPD( err, val = IsTrueL( aContext ) ); |
|
223 |
|
224 if ( err != KErrNone ) |
|
225 { |
|
226 ERROR( err, |
|
227 "CCFContextUpdated: IsTrueL leave occurred, evaluation cancelled" ); |
|
228 return EFalse; |
|
229 } |
|
230 |
|
231 // Evaluate parents if we have changed. |
|
232 if ( val != iValue ) |
|
233 { |
|
234 INFO_1( "CCFContextUpdated::Evaluate - Value changed to (-1=undefined, 0=false, 1=true): %d", val ); |
|
235 |
|
236 iValue = static_cast< TCFConditionValue >( val ); |
|
237 if ( iParent ) |
|
238 { |
|
239 iParent->Evaluate(); |
|
240 } |
|
241 } |
|
242 else |
|
243 { |
|
244 INFO_1( "CCFContextUpdated::Evaluate - Value still (-1=undefined, 0=false, 1=true): %d", val ); |
|
245 } |
|
246 |
|
247 if ( iPreviousTruthCheckWithReferencedContext ) |
|
248 { |
|
249 aContextLevelDelay = iContextLevelDelay; |
|
250 } |
|
251 return ETrue; |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CCFContextUpdated::IsTrueL |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 TBool CCFContextUpdated::IsTrueL( const CCFContextObject& aContext ) |
|
259 { |
|
260 FUNC_LOG; |
|
261 |
|
262 TBool value( EFalse ); |
|
263 if ( aContext.Source() == Source() && aContext.Type() == Type() ) |
|
264 { |
|
265 // Context was updated, no need to check for change. |
|
266 if ( iCmpValue ) |
|
267 { |
|
268 if ( aContext.Value() == *iCmpValue ) |
|
269 { |
|
270 value = ETrue; |
|
271 } |
|
272 } |
|
273 else |
|
274 { |
|
275 value = ETrue; |
|
276 } |
|
277 iPreviousTruthCheckWithReferencedContext = ETrue; |
|
278 } |
|
279 else |
|
280 { |
|
281 iPreviousTruthCheckWithReferencedContext = EFalse; |
|
282 } |
|
283 |
|
284 return value; |
|
285 } |