|
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: CCFContextChanged class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "cfcontextchanged.h" |
|
22 #include "cfcontextoperationutils.h" |
|
23 #include "cfbasicoptrace.h" |
|
24 |
|
25 #include <gmxmlnode.h> |
|
26 |
|
27 // CONSTANTS |
|
28 _LIT( KScriptChangedName, "contextChanged" ); |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CCFContextChanged::CCFContextChanged |
|
34 // C++ default constructor can NOT contain any code, that might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CCFContextChanged::CCFContextChanged( 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 // CCFContextChanged::ConstructL |
|
48 // Symbian 2nd phase constructor can leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CCFContextChanged::ConstructL( const TDesC& aValue ) |
|
52 { |
|
53 FUNC_LOG; |
|
54 |
|
55 if ( aValue.Length() ) |
|
56 { |
|
57 iCmpValue = aValue.AllocL(); |
|
58 } |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CCFContextChanged::NewL |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CCFContextChanged* CCFContextChanged::NewL( MCFOperationServices& aServices, |
|
67 CCFOperationNode* aParent, |
|
68 const TDesC& aName, |
|
69 const TDesC& aSource, |
|
70 const TDesC& aValue ) |
|
71 { |
|
72 FUNC_LOG; |
|
73 |
|
74 CCFContextChanged* self |
|
75 = NewLC( aServices, aParent, aName, aSource, aValue ); |
|
76 CleanupStack::Pop( self ); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CCFContextChanged::NewLC |
|
82 // Two-phased constructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CCFContextChanged* CCFContextChanged::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 CCFContextChanged* self |
|
96 = new( ELeave ) CCFContextChanged( 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 // CCFContextChanged::ParseL |
|
111 // Construction with parsing from a DOM node. |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 CCFContextChanged* CCFContextChanged::ParseL( MCFOperationServices& aServices, |
|
115 CCFOperationNode* aParent, |
|
116 CMDXMLNode& aNode ) |
|
117 { |
|
118 FUNC_LOG; |
|
119 |
|
120 if ( aNode.NodeName().CompareF( KScriptChangedName ) != 0 ) |
|
121 { |
|
122 return NULL; // Cannot create context changed 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 CCFContextChanged* 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( "CCFContextChanged::ParseL - Unsupported arguments" ); |
|
181 } |
|
182 |
|
183 CREATE_DOM_INFO( self, aNode ); |
|
184 |
|
185 return self; |
|
186 } |
|
187 |
|
188 |
|
189 // Destructor |
|
190 CCFContextChanged::~CCFContextChanged() |
|
191 { |
|
192 FUNC_LOG; |
|
193 |
|
194 delete iCmpValue; |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // CCFContextChanged::IsAllRequired |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 TBool CCFContextChanged::IsAllRequired() const |
|
202 { |
|
203 FUNC_LOG; |
|
204 |
|
205 return ETrue; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // CCFContextChanged::Evaluate |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 TBool CCFContextChanged::Evaluate( const CCFContextObject& aContext, |
|
213 TInt& aContextLevelDelay ) |
|
214 { |
|
215 FUNC_LOG; |
|
216 |
|
217 DOM_INFO( "CCFContextChanged::Evaluate" ); |
|
218 |
|
219 // Ask concrete implementation if it is true. |
|
220 TInt val( EFalse ); |
|
221 TRAPD( err, val = IsTrueL( aContext ) ); |
|
222 |
|
223 if ( err != KErrNone ) |
|
224 { |
|
225 ERROR( err, |
|
226 "CCFContextChanged: IsTrueL leave occurred, evaluation cancelled" ); |
|
227 return EFalse; |
|
228 } |
|
229 |
|
230 // Evaluate parents if we have changed. |
|
231 if ( val != iValue ) |
|
232 { |
|
233 INFO_1( "CCFContextChanged::Evaluate - Value changed to (-1=undefined, 0=false, 1=true): %d", val ); |
|
234 |
|
235 iValue = static_cast< TCFConditionValue >( val ); |
|
236 if ( iParent ) |
|
237 { |
|
238 iParent->Evaluate(); |
|
239 } |
|
240 } |
|
241 else |
|
242 { |
|
243 INFO_1( "CCFContextChanged::Evaluate - Value still (-1=undefined, 0=false, 1=true): %d", val ); |
|
244 } |
|
245 |
|
246 if ( iPreviousTruthCheckWithReferencedContext ) |
|
247 { |
|
248 aContextLevelDelay = iContextLevelDelay; |
|
249 } |
|
250 return ETrue; |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CCFContextChanged::IsTrueL |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 TBool CCFContextChanged::IsTrueL( const CCFContextObject& aContext ) |
|
258 { |
|
259 FUNC_LOG; |
|
260 |
|
261 TBool value( EFalse ); |
|
262 if ( aContext.Source() == Source() && aContext.Type() == Type() ) |
|
263 { |
|
264 INFO_2( "CCFContextChanged::IsTrueL - Current value [%S] <> [%S] new value", |
|
265 &PreviousValue(), &aContext.Value() ); |
|
266 |
|
267 // Check if context has changed since last time. |
|
268 if ( PreviousValue() != aContext.Value() ) |
|
269 { |
|
270 if ( iCmpValue ) |
|
271 { |
|
272 if ( aContext.Value() == *iCmpValue ) |
|
273 { |
|
274 value = ETrue; |
|
275 } |
|
276 } |
|
277 else |
|
278 { |
|
279 value = ETrue; |
|
280 } |
|
281 |
|
282 TInt err = UpdatePreviousValue( aContext.Value() ); |
|
283 ERROR( err, "Previous value update failed! [CCFContextChanged]" ); |
|
284 } |
|
285 iPreviousTruthCheckWithReferencedContext = ETrue; |
|
286 } |
|
287 else |
|
288 { |
|
289 iPreviousTruthCheckWithReferencedContext = EFalse; |
|
290 } |
|
291 |
|
292 return value; |
|
293 } |