|
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: CCFIfClause class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cfifclause.h" |
|
22 #include "cfscriptaction.h" |
|
23 #include "cfbasicoptrace.h" |
|
24 |
|
25 #include <gmxmlnode.h> |
|
26 |
|
27 // CONSTANTS |
|
28 _LIT( KScriptIfName16, "if" ); |
|
29 _LIT( KScriptActionsName16, "actions" ); |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CCFIfClause::CCFIfClause |
|
35 // C++ default constructor can NOT contain any code, that might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CCFIfClause::CCFIfClause( MCFOperationServices& aServices, |
|
39 CCFOperationNode* aParent ) |
|
40 : CCFClauseNode( aServices, aParent ) |
|
41 { |
|
42 FUNC_LOG; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CCFIfClause::ConstructL |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CCFIfClause::ConstructL() |
|
51 { |
|
52 FUNC_LOG; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CCFIfClause::NewL |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CCFIfClause* CCFIfClause::NewL( MCFOperationServices& aServices, |
|
61 CCFOperationNode* aParent ) |
|
62 { |
|
63 FUNC_LOG; |
|
64 |
|
65 CCFIfClause* self = NewLC( aServices, aParent ); |
|
66 CleanupStack::Pop( self ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CCFIfClause::NewLC |
|
72 // Two-phased constructor. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CCFIfClause* CCFIfClause::NewLC( MCFOperationServices& aServices, |
|
76 CCFOperationNode* aParent ) |
|
77 { |
|
78 FUNC_LOG; |
|
79 |
|
80 CCFIfClause* self = new( ELeave ) CCFIfClause( aServices, aParent ); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CCFIfClause::ParseL |
|
88 // Construction with parsing from a DOM node. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CCFIfClause* CCFIfClause::ParseL( MCFOperationServices& aServices, |
|
92 CCFOperationNode* aParent, |
|
93 CMDXMLNode& aNode ) |
|
94 { |
|
95 FUNC_LOG; |
|
96 |
|
97 if ( aNode.NodeName().CompareF( KScriptIfName16 ) != 0 ) |
|
98 { |
|
99 return NULL; // Cannot create if clause from the given node. |
|
100 } |
|
101 |
|
102 CCFIfClause* self = NewLC( aServices, aParent ); // CLEANUP<< self |
|
103 |
|
104 // Parse children. |
|
105 TBool unsupportedNode( EFalse ); |
|
106 TBool actionsParsed( EFalse ); |
|
107 CMDXMLNode* child = aNode.FirstChild(); |
|
108 while ( child ) |
|
109 { |
|
110 if ( child->NodeType() == CMDXMLNode::EElementNode ) |
|
111 { |
|
112 if ( child->NodeName().CompareF( KScriptActionsName16 ) == 0 ) |
|
113 { |
|
114 if ( actionsParsed ) |
|
115 { |
|
116 INFO( "CCFIfClause::ParseL - Redefinition not allowed, actions already parsed" ); |
|
117 unsupportedNode = ETrue; |
|
118 break; |
|
119 } |
|
120 self->ParseActionsL( *child, self->iActions ); |
|
121 actionsParsed = ETrue; |
|
122 } |
|
123 else |
|
124 { |
|
125 if ( self->iChild ) |
|
126 { |
|
127 TPtrC nodeName( child->NodeName() ); |
|
128 INFO_1( "CCFIfClause::ParseL - One child operation is allowed. [%S] is not supported", |
|
129 &nodeName ); |
|
130 unsupportedNode = ETrue; // Already parsed the child. |
|
131 break; |
|
132 } |
|
133 CCFOperationNode* op = self->iServices.ParseL( self, *child ); |
|
134 if ( op ) |
|
135 { |
|
136 self->iChild = op; |
|
137 } |
|
138 else |
|
139 { |
|
140 TPtrC nodeName( child->NodeName() ); |
|
141 INFO_1( "CCFIfClause::ParseL - Unsupported node [%S]", |
|
142 &nodeName ); |
|
143 unsupportedNode = ETrue; |
|
144 break; |
|
145 } |
|
146 } |
|
147 } |
|
148 else if ( child->NodeType() != CMDXMLNode::ECommentNode ) |
|
149 { |
|
150 TPtrC nodeName( child->NodeName() ); |
|
151 INFO_1( "CCFIfClause::ParseL - Unsupported node [%S]", |
|
152 &nodeName ); |
|
153 unsupportedNode = ETrue; |
|
154 break; |
|
155 } |
|
156 child = child->NextSibling(); |
|
157 } |
|
158 |
|
159 CleanupStack::Pop( self ); // CLEANUP>> self |
|
160 if ( !self->iChild || unsupportedNode ) |
|
161 { |
|
162 INFO( "CCFIfClause::ParseL - No child operation defined or unsupported node" ); |
|
163 delete self; // Discard unsupported if clause. |
|
164 self = NULL; |
|
165 } |
|
166 |
|
167 CREATE_DOM_INFO( self, aNode ); |
|
168 |
|
169 return self; |
|
170 } |
|
171 |
|
172 |
|
173 // Destructor |
|
174 CCFIfClause::~CCFIfClause() |
|
175 { |
|
176 FUNC_LOG; |
|
177 |
|
178 delete iChild; |
|
179 iActions.ResetAndDestroy(); |
|
180 } |
|
181 |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CCFIfClause::FireActionsL |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CCFIfClause::FireActionsL() |
|
188 { |
|
189 FUNC_LOG; |
|
190 |
|
191 ACTION_INFO_2( "Firing [%d] IF-actions for script ID=[%d]", |
|
192 iActions.Count(), |
|
193 iServices.ScriptId() ); |
|
194 |
|
195 for ( TInt i = 0; i < iActions.Count(); ++i ) |
|
196 { |
|
197 iActions[ i ]->ActL(); |
|
198 } |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CCFIfClause::ActivateL |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void CCFIfClause::ActivateL() |
|
206 { |
|
207 FUNC_LOG; |
|
208 |
|
209 if ( iChild ) |
|
210 { |
|
211 iChild->ActivateL(); |
|
212 } |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CCFIfClause::Deactivate |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void CCFIfClause::Deactivate() |
|
220 { |
|
221 FUNC_LOG; |
|
222 |
|
223 if ( iChild ) |
|
224 { |
|
225 iChild->Deactivate(); |
|
226 } |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CCFIfClause::CheckSecurity |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 TInt CCFIfClause::CheckSecurity() |
|
234 { |
|
235 FUNC_LOG; |
|
236 |
|
237 TInt err( KErrNone ); |
|
238 // Check security for context subscriptions. |
|
239 if ( iChild ) |
|
240 { |
|
241 err = iChild->CheckSecurity(); |
|
242 if ( err != KErrNone ) |
|
243 { |
|
244 ERROR( err, "CCFIfClause::CheckSecurity - Context read security check failed!" ); |
|
245 return err; |
|
246 } |
|
247 } |
|
248 |
|
249 // Check security for actions. |
|
250 for ( TInt i = 0; i < iActions.Count(); ++i ) |
|
251 { |
|
252 TSecurityPolicy securityPolicy; |
|
253 TInt err = iActions[ i ]->GetSecurityPolicy( securityPolicy ); |
|
254 if ( err != KErrNone ) |
|
255 { |
|
256 ERROR( err, "CCFIfClause::CheckSecurity - Getting action security policy failed!" ); |
|
257 return err; |
|
258 } |
|
259 |
|
260 err = iServices.CheckScriptOwnerAccess( securityPolicy ); |
|
261 if ( err != KErrNone ) |
|
262 { |
|
263 ERROR( err, "CCFIfClause::CheckSecurity - Checking action security policy failed!" ); |
|
264 return err; |
|
265 } |
|
266 } |
|
267 |
|
268 return KErrNone; |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CCFIfClause::Evaluate |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CCFIfClause::Evaluate() |
|
276 { |
|
277 FUNC_LOG; |
|
278 |
|
279 DOM_INFO( "CCFIfClause::Evaluate" ); |
|
280 |
|
281 if ( iChild ) |
|
282 { |
|
283 // If clause has a root condition. |
|
284 TCFConditionValue newValue = iChild->Value(); |
|
285 |
|
286 if ( newValue != Value() ) |
|
287 { |
|
288 INFO_1( "CCFIfClause::Evaluate - Value changed to (-1=undefined, 0=false, 1=true): %d", newValue ); |
|
289 |
|
290 iValue = newValue; |
|
291 if ( iParent ) |
|
292 { |
|
293 iParent->Evaluate(); |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 INFO_1( "CCFIfClause::Evaluate - Value still (-1=undefined, 0=false, 1=true): %d", newValue ); |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CCFIfClause::Cleanup |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 void CCFIfClause::Cleanup() |
|
308 { |
|
309 FUNC_LOG; |
|
310 |
|
311 if ( iChild ) |
|
312 { |
|
313 iChild->Cleanup(); |
|
314 } |
|
315 } |