|
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: CCFContextOperation class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <f32file.h> // for KExtDelimiter '.' and KDriveDelimiter ':' |
|
21 |
|
22 #include "cfcontextoperation.h" |
|
23 #include "cfbasicoptrace.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt KCFContextOperationNoContextLevelDelay = 0; |
|
27 const TInt KDefaultPreviousValueLength = 256; |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CCFContextOperation::CCFContextOperation |
|
33 // C++ default constructor can NOT contain any code, that might leave. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CCFContextOperation::CCFContextOperation( MCFOperationServices& aServices, |
|
37 CCFOperationNode* aParent, |
|
38 HBufC* aType, |
|
39 HBufC* aSource ) |
|
40 : CCFOperationNode( aServices, aParent ), |
|
41 iContextLevelDelay( 0 ), |
|
42 iSource( aSource ), |
|
43 iType( aType ) |
|
44 { |
|
45 FUNC_LOG; |
|
46 |
|
47 iPreviousValue = HBufC::New( KDefaultPreviousValueLength ); |
|
48 } |
|
49 |
|
50 |
|
51 // Destructor |
|
52 CCFContextOperation::~CCFContextOperation() |
|
53 { |
|
54 FUNC_LOG; |
|
55 |
|
56 delete iSource; |
|
57 delete iType; |
|
58 delete iPreviousValue; |
|
59 } |
|
60 |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CCFContextOperation::Evaluate |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 TBool CCFContextOperation::Evaluate( const CCFContextObject& aContext, |
|
67 TInt& aContextLevelDelay ) |
|
68 { |
|
69 FUNC_LOG; |
|
70 |
|
71 DOM_INFO( "CCFContextOperation::Evaluate" ); |
|
72 |
|
73 // Check that context value has changed (context is state information) |
|
74 if ( iPreviousValue && ( *iPreviousValue ).Compare( aContext.Value() ) == 0 ) |
|
75 { |
|
76 INFO_2( "CCFContextOperation::Evaluate - NOT evaluating (prev value [%S] == arg value [%S])!", |
|
77 iPreviousValue, &aContext.Value() ); |
|
78 aContextLevelDelay = KCFContextOperationNoContextLevelDelay; |
|
79 return EFalse; |
|
80 } |
|
81 TInt err = UpdatePreviousValue( aContext.Value() ); |
|
82 ERROR( err, "Previous value update failed!" ); |
|
83 |
|
84 // Ask concrete implementation if it is true |
|
85 TInt val( EFalse ); |
|
86 TRAP( err, val = IsTrueL( aContext ) ); |
|
87 |
|
88 if ( err != KErrNone ) |
|
89 { |
|
90 ERROR( err, "CCFContextOperation: IsTrueL leave occurred, evaluation cancelled" ); |
|
91 return EFalse; |
|
92 } |
|
93 |
|
94 // Evaluate parents if we have changed |
|
95 if ( val != iValue ) |
|
96 { |
|
97 INFO_1( "CCFContextOperation::Evaluate - Value changed to (-1=undefined, 0=false, 1=true): %d", val ); |
|
98 |
|
99 iValue = static_cast< TCFConditionValue >( val ); |
|
100 if ( iParent ) |
|
101 { |
|
102 iParent->Evaluate(); |
|
103 } |
|
104 } |
|
105 else |
|
106 { |
|
107 INFO_1( "CCFContextOperation::Evaluate - Value still (-1=undefined, 0=false, 1=true): %d", val ); |
|
108 } |
|
109 |
|
110 aContextLevelDelay = iContextLevelDelay; |
|
111 return ETrue; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CCFContextOperation::Source |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 TPtrC CCFContextOperation::Source() const |
|
119 { |
|
120 FUNC_LOG; |
|
121 |
|
122 return TPtrC( *iSource ); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CCFContextOperation::Type |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 TPtrC CCFContextOperation::Type() const |
|
130 { |
|
131 FUNC_LOG; |
|
132 |
|
133 return TPtrC( *iType ); |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CCFContextOperation::IsAllRequired |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 TBool CCFContextOperation::IsAllRequired() const |
|
141 { |
|
142 FUNC_LOG; |
|
143 |
|
144 return EFalse; |
|
145 } |
|
146 |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // CCFContextOperation::UpdatePreviousValue |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 TInt CCFContextOperation::UpdatePreviousValue( const TDesC& aNewValue ) |
|
153 { |
|
154 FUNC_LOG; |
|
155 |
|
156 TInt err = KErrNone; |
|
157 if( !iPreviousValue ) |
|
158 { |
|
159 iPreviousValue = HBufC::New( KDefaultPreviousValueLength ); |
|
160 } |
|
161 |
|
162 if( iPreviousValue ) |
|
163 { |
|
164 TPtr previousValuePtr = iPreviousValue->Des(); |
|
165 if( previousValuePtr.MaxLength() >= aNewValue.Length() ) |
|
166 { |
|
167 previousValuePtr.Copy( aNewValue ); |
|
168 } |
|
169 else |
|
170 { |
|
171 delete iPreviousValue; |
|
172 iPreviousValue = NULL; |
|
173 iPreviousValue = aNewValue.Alloc(); |
|
174 if( !iPreviousValue ) |
|
175 { |
|
176 err = KErrNoMemory; |
|
177 } |
|
178 } |
|
179 } |
|
180 else |
|
181 { |
|
182 err = KErrNoMemory; |
|
183 } |
|
184 |
|
185 return err; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // CCFContextOperation::PreviousValue |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 const TDesC& CCFContextOperation::PreviousValue() |
|
193 { |
|
194 if ( iPreviousValue ) |
|
195 { |
|
196 return *iPreviousValue; |
|
197 } |
|
198 return KNullDesC; |
|
199 } |
|
200 |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CCFContextOperation::ActivateL |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void CCFContextOperation::ActivateL() |
|
207 { |
|
208 FUNC_LOG; |
|
209 |
|
210 iServices.SubscribeContextL( this ); |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CCFContextOperation::Deactivate |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CCFContextOperation::Deactivate() |
|
218 { |
|
219 FUNC_LOG; |
|
220 |
|
221 iServices.RemoveSubscription( this ); |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CCFContextOperation::CheckSecurity |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 TInt CCFContextOperation::CheckSecurity() |
|
229 { |
|
230 FUNC_LOG; |
|
231 |
|
232 if ( !iSource || !iType ) |
|
233 { |
|
234 return KErrBadDescriptor; |
|
235 } |
|
236 |
|
237 return iServices.CheckContextReadSecurity( *iSource, *iType ); |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CCFContextOperation::Evaluate |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CCFContextOperation::Evaluate() |
|
245 { |
|
246 FUNC_LOG; |
|
247 } |