14 * Description: ESMR policymmanager implementation |
14 * Description: ESMR policymmanager implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include "emailtrace.h" |
|
20 #include "cesmrpolicymanager.h" |
19 #include "cesmrpolicymanager.h" |
21 //<cmail> |
|
22 #include "cesmrpolicy.h" |
20 #include "cesmrpolicy.h" |
23 #include <esmrpolicies.rsg> |
|
24 #include "esmrdef.h" |
21 #include "esmrdef.h" |
25 //</cmail> |
|
26 #include "esmrinternaluid.h" |
22 #include "esmrinternaluid.h" |
27 #include "cesmrcalimportexporter.h" |
23 #include "cesmrcalimportexporter.h" |
28 #include "tesmrentryfield.h" |
24 #include "tesmrentryfield.h" |
29 #include "cesmrpolicychecker.h" |
25 #include "cmrpolicyresolver.h" |
30 #include "cesmrpolicyextensionmanager.h" |
26 #include "esmrentryhelper.h" |
31 |
27 #include "mesmrcalentry.h" |
32 #include <coemain.h>// CCoeEnv |
28 |
33 #include <barsread.h> |
29 #include "emailtrace.h" |
|
30 |
|
31 #include <esmrpolicies.rsg> |
34 |
32 |
35 |
33 |
36 /// Unnamed namespace for local definitions |
34 /// Unnamed namespace for local definitions |
37 namespace { |
35 namespace { |
38 |
|
39 // Definition for resource id array granularity |
|
40 const TInt KESMRPolicyIdArrayGranularity = 4; |
|
41 |
|
42 /** |
|
43 * Reads ESMR policy resource id table from resource. |
|
44 * |
|
45 * @param aReader Reference to resource reader. |
|
46 * @param aResourceIdTable Reference to resource id table. |
|
47 */ |
|
48 void ReadResourceIdArrayL( |
|
49 TResourceReader& aReader, |
|
50 RArray<TInt>& aResourceIdTable ) |
|
51 { |
|
52 TInt numOfFields = aReader.ReadInt16(); |
|
53 for (TInt i(0); i < numOfFields; i++ ) |
|
54 { |
|
55 TInt resourceId= aReader.ReadInt32(); |
|
56 aResourceIdTable.AppendL(resourceId); |
|
57 } |
|
58 } |
|
59 |
|
60 |
36 |
61 #ifdef _DEBUG |
37 #ifdef _DEBUG |
62 |
38 |
63 _LIT( KESMRPolicyMgrPanic, "ESMRPolicyManager" ); |
39 _LIT( KESMRPolicyMgrPanic, "ESMRPolicyManager" ); |
64 |
40 |
125 // --------------------------------------------------------------------------- |
100 // --------------------------------------------------------------------------- |
126 // |
101 // |
127 EXPORT_C CESMRPolicyManager::~CESMRPolicyManager() |
102 EXPORT_C CESMRPolicyManager::~CESMRPolicyManager() |
128 { |
103 { |
129 FUNC_LOG; |
104 FUNC_LOG; |
130 delete iDefaultPolicyChecker; |
105 delete iResolverPlugin; |
131 delete iCurrentPolicy; |
106 delete iCurrentPolicy; |
132 delete iExtension; |
|
133 iPolicyResourceFile.Close(); |
|
134 iPolicyResourceIds.Close(); |
|
135 iPolicyStack.ResetAndDestroy(); |
107 iPolicyStack.ResetAndDestroy(); |
136 } |
108 } |
137 |
109 |
138 // --------------------------------------------------------------------------- |
110 // --------------------------------------------------------------------------- |
139 // CESMRPolicyManager::NewL |
111 // CESMRPolicyManager::NewL |
156 // --------------------------------------------------------------------------- |
128 // --------------------------------------------------------------------------- |
157 // |
129 // |
158 void CESMRPolicyManager::ConstructL() |
130 void CESMRPolicyManager::ConstructL() |
159 { |
131 { |
160 FUNC_LOG; |
132 FUNC_LOG; |
161 iDefaultPolicyChecker = CESMRPolicyChecker::NewL(); |
133 |
162 iCoeEnv = CCoeEnv::Static(); |
134 } |
163 iExtension = CESMRPolicyExtensionManager::NewL( *iCoeEnv ); |
135 |
164 } |
136 // ----------------------------------------------------------------------------- |
165 |
137 // CESMRPolicyManager::CurrentPolicy |
166 // --------------------------------------------------------------------------- |
138 // ----------------------------------------------------------------------------- |
167 // CESMRPolicyManager::ExtensionUid |
139 // |
168 // --------------------------------------------------------------------------- |
140 EXPORT_C CESMRPolicy& CESMRPolicyManager::CurrentPolicy() |
169 // |
141 { |
170 EXPORT_C TUid CESMRPolicyManager::ExtensionUid() |
142 CESMRPolicy* currentPolicy = iCurrentPolicy; |
171 { |
143 if ( !currentPolicy && iPolicyStack.Count() ) |
172 FUNC_LOG; |
144 { |
173 return TUid::Uid( KESMRPolicyMgrUid ); |
145 currentPolicy = iPolicyStack[ iPolicyStack.Count() - 1 ]; |
|
146 } |
|
147 |
|
148 ASSERT( currentPolicy ); |
|
149 return *currentPolicy; |
174 } |
150 } |
175 |
151 |
176 // --------------------------------------------------------------------------- |
152 // --------------------------------------------------------------------------- |
177 // CESMRPolicyManager::ResolvePolicyL |
153 // CESMRPolicyManager::ResolvePolicyL |
178 // --------------------------------------------------------------------------- |
154 // --------------------------------------------------------------------------- |
179 // |
155 // |
180 EXPORT_C void CESMRPolicyManager::ResolvePolicyL( |
156 EXPORT_C void CESMRPolicyManager::ResolvePolicyL( |
181 const TESMRScenarioData& aScenarioData, |
157 const TESMRScenarioData& aScenarioData, |
182 MESMRCalEntry& aESMREntry, |
158 MESMRCalEntry& aESMREntry, |
183 MESMRPolicyChecker* aPolicyChecker ) |
159 MMRPolicyResolver* aPolicyResolver ) |
184 { |
160 { |
185 FUNC_LOG; |
161 FUNC_LOG; |
186 |
162 |
187 MESMRPolicyChecker* policyChecker = iDefaultPolicyChecker; |
163 MMRPolicyResolver* policyResolver = NULL; |
188 if ( aPolicyChecker ) |
164 |
189 { |
165 if ( aPolicyResolver ) |
190 policyChecker = aPolicyChecker; |
166 { |
|
167 policyResolver = aPolicyResolver; |
|
168 } |
|
169 else |
|
170 { |
|
171 TESMRCalendarEventType type = |
|
172 ESMREntryHelper::EventTypeL( aESMREntry.Entry() ); |
|
173 |
|
174 if ( !iResolverPlugin || !iResolverPlugin->SupportsTypeL( type ) ) |
|
175 { |
|
176 // Instantiate correct resolver |
|
177 policyResolver = CMRPolicyResolver::NewL( type ); |
|
178 delete iResolverPlugin; |
|
179 iResolverPlugin = policyResolver; |
|
180 } |
|
181 else |
|
182 { |
|
183 // Use default resolver |
|
184 policyResolver = iResolverPlugin; |
|
185 } |
191 } |
186 } |
192 |
187 |
193 delete iCurrentPolicy; |
188 delete iCurrentPolicy; |
194 iCurrentPolicy = NULL; |
189 iCurrentPolicy = NULL; |
195 |
190 |
196 TInt policyCount( iPolicyResourceIds.Count() ); |
191 iCurrentPolicy = policyResolver->ResolveL( aScenarioData ); |
197 for ( TInt i( 0 ); |
|
198 ( i < policyCount) && !iCurrentPolicy; |
|
199 ++i ) |
|
200 { |
|
201 ReadPolicyL( iPolicyResourceIds[i], aESMREntry ); |
|
202 if ( !policyChecker->MatchesL( *iCurrentPolicy, aScenarioData ) ) |
|
203 { |
|
204 // Policy did not match --> Reading next |
|
205 delete iCurrentPolicy; |
|
206 iCurrentPolicy = NULL; |
|
207 } |
|
208 } |
|
209 |
192 |
210 // Matching policy not found --> Panic |
193 // Matching policy not found --> Panic |
211 __ASSERT_DEBUG( iCurrentPolicy, Panic(EESMRPolicyMgrNoPolicyFound) ); |
194 __ASSERT_DEBUG( iCurrentPolicy, Panic(EESMRPolicyMgrNoPolicyFound) ); |
212 |
195 |
213 if ( !iCurrentPolicy ) |
196 if ( !iCurrentPolicy ) |
252 |
235 |
253 return iCurrentPolicy; |
236 return iCurrentPolicy; |
254 } |
237 } |
255 |
238 |
256 // --------------------------------------------------------------------------- |
239 // --------------------------------------------------------------------------- |
257 // CESMRPolicyManager::ReadPolicyFromResourceL |
240 // CESMRPolicyManager::CurrentPolicy |
258 // --------------------------------------------------------------------------- |
241 // --------------------------------------------------------------------------- |
259 // |
242 // |
260 EXPORT_C void CESMRPolicyManager::ReadPolicyFromResourceL( |
243 const CESMRPolicy& CESMRPolicyManager::CurrentPolicy() const |
261 const TDesC& aPolicyFile, |
244 { |
262 TInt aPolicyArrayResourceId ) |
245 CESMRPolicy& policy = |
263 { |
246 const_cast< CESMRPolicyManager* >( this )->CurrentPolicy(); |
264 FUNC_LOG; |
247 |
265 |
248 return policy; |
266 |
|
267 iPolicyResourceFile.Close(); |
|
268 iPolicyResourceFile.OpenL( iCoeEnv->FsSession(), aPolicyFile ); |
|
269 iPolicyResourceFile.ConfirmSignatureL(); |
|
270 |
|
271 // R_ESMR_POLICIES |
|
272 HBufC8* resourceIdBuffer = |
|
273 iPolicyResourceFile.AllocReadLC( aPolicyArrayResourceId ); |
|
274 |
|
275 // Construct resource reader |
|
276 TResourceReader reader; |
|
277 reader.SetBuffer(resourceIdBuffer); |
|
278 |
|
279 // Read policy resource ids |
|
280 iPolicyResourceIds.Reset(); |
|
281 ReadResourceIdArrayL(reader, iPolicyResourceIds ); |
|
282 |
|
283 CleanupStack::PopAndDestroy( resourceIdBuffer ); |
|
284 |
|
285 // Load extension resources |
|
286 iExtension->ReadResourcesFromExtensionsL(); |
|
287 |
|
288 } |
|
289 |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CESMRPolicyManager::ReadPolicyL |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void CESMRPolicyManager::ReadPolicyL( |
|
296 TInt aResourceId, |
|
297 MESMRCalEntry& /*aESMREntry */) |
|
298 { |
|
299 FUNC_LOG; |
|
300 |
|
301 HBufC8* resourceBuffer = NULL; |
|
302 // First try to find policy from static policies and then from extensions |
|
303 TRAPD( error, resourceBuffer = iPolicyResourceFile.AllocReadL( aResourceId ) ); |
|
304 if ( resourceBuffer ) |
|
305 { |
|
306 CleanupStack::PushL( resourceBuffer ); |
|
307 } |
|
308 |
|
309 TResourceReader reader; |
|
310 CESMRPolicy* policy = NULL; |
|
311 if ( error == KErrNone && resourceBuffer ) |
|
312 { |
|
313 reader.SetBuffer(resourceBuffer); |
|
314 policy = CESMRPolicy::NewL( iPolicyResourceFile, reader ); |
|
315 } |
|
316 else |
|
317 { |
|
318 resourceBuffer = iExtension->ReadBufferL( aResourceId ); |
|
319 CESMRExtensionResourceFile* file = NULL; |
|
320 if ( resourceBuffer ) |
|
321 { |
|
322 CleanupStack::PushL( resourceBuffer ); |
|
323 file = iExtension->ExtensionResourceFile( aResourceId ); |
|
324 } |
|
325 |
|
326 if ( resourceBuffer && file ) |
|
327 { |
|
328 reader.SetBuffer(resourceBuffer); |
|
329 policy = CESMRPolicy::NewL( file->ResFile(), reader ); |
|
330 } |
|
331 } |
|
332 |
|
333 // Logging read policy |
|
334 LOG_POLICY( *policy ) |
|
335 |
|
336 delete iCurrentPolicy; |
|
337 iCurrentPolicy = policy; |
|
338 |
|
339 if ( resourceBuffer ) |
|
340 { |
|
341 CleanupStack::PopAndDestroy( resourceBuffer ); |
|
342 } |
|
343 |
|
344 } |
249 } |
345 |
250 |
346 // EOF |
251 // EOF |
347 |
252 |