|
1 /* |
|
2 * Copyright (c) 2006 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: implementation of policy handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "alfpolicyhandler.h" |
|
21 #include "alfpolicyrequesthandler.h" |
|
22 #include <alflogger.h> |
|
23 |
|
24 // ======== HELPER CLASS ======== |
|
25 |
|
26 NONSHARABLE_CLASS(TFullScreenBlock) |
|
27 { |
|
28 public: |
|
29 TUid iFromUid; |
|
30 TUid iToUid; |
|
31 |
|
32 }; |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 CPolicyHandler* CPolicyHandler::NewL() |
|
37 { |
|
38 __ALFFXLOGSTRING("CPolicyHandler::NewL >>"); |
|
39 CPolicyHandler* self = new (ELeave) CPolicyHandler(); |
|
40 CleanupStack::PushL(self); |
|
41 self->iClientRequestHandler = new (ELeave) CPolicyClientRequestHandler(self); |
|
42 CleanupStack::Pop(self); |
|
43 __ALFFXLOGSTRING("CPolicyHandler::NewL <<"); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CPolicyHandler::~CPolicyHandler() |
|
48 { |
|
49 __ALFFXLOGSTRING("CPolicyHandler::~CPolicyHandler >>"); |
|
50 delete iClientRequestHandler; |
|
51 |
|
52 iFullscreenPolicies.ResetAndDestroy(); |
|
53 |
|
54 iControlPolicies.ResetAndDestroy(); |
|
55 |
|
56 iFullScreenBlocks.ResetAndDestroy(); |
|
57 |
|
58 iListBoxPolicies.ResetAndDestroy(); |
|
59 __ALFFXLOGSTRING("CPolicyHandler::~CPolicyHandler <<"); |
|
60 } |
|
61 |
|
62 CPolicyHandler::CPolicyHandler() |
|
63 { |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Insert the new policy in the list of existing ones. The list is kept |
|
68 // sorted according to specificity, ie. how much is specified in the policy. |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CPolicyHandler::RegisterListBoxKmlL( const TUid& aUid, |
|
72 const TThreadId& aThreadId, |
|
73 const CAlfTransitionServerClient::TListBoxType aListBoxType, |
|
74 const TDesC& aResourceDir, |
|
75 const TDesC& aBackgroundFilename, |
|
76 const TDesC& aItemFilename, |
|
77 TInt aCachePriority, |
|
78 TInt aWantedTime , TInt aMinTime ) |
|
79 { |
|
80 __ALFFXLOGSTRING2("CPolicyHandler::RegisterListBoxKmlL - aUid 0x%x, aThreadId >>", aUid, aThreadId.Id()); |
|
81 aCachePriority = 1; |
|
82 // For now, the cache priority is always 1 at registration time, and after |
|
83 // fetching the KML information from the policy, it gets set to 0. This is |
|
84 // used to trigger eviction from the KML cache. Newly registered KML:s have |
|
85 // priority over existing... |
|
86 CListBoxPolicy* policy = CListBoxPolicy::NewL( aUid, |
|
87 aThreadId, |
|
88 aListBoxType, |
|
89 aResourceDir, |
|
90 aBackgroundFilename, |
|
91 aItemFilename, |
|
92 aCachePriority, |
|
93 aWantedTime, |
|
94 aMinTime ); |
|
95 CleanupStack::PushL( policy ); |
|
96 TInt spec = policy->Specificity(); |
|
97 TInt count = iListBoxPolicies.Count(); |
|
98 TInt uid = aUid.iUid; |
|
99 TInt i; |
|
100 |
|
101 // This keeps the list with ListBox KMLs sorted after specifity, |
|
102 // High specificity is in the beginning of the list and low at the end. |
|
103 // This means that when getting a ListBox KML it will find the more specified |
|
104 // values first. A Uid counts as more specific than a TListBoxType. |
|
105 |
|
106 for ( i = 0; i < count; i++ ) |
|
107 { |
|
108 CListBoxPolicy* curr = iListBoxPolicies[i]; |
|
109 TInt currspec = curr->Specificity(); |
|
110 |
|
111 if ( uid == curr->Uid().iUid && aListBoxType == curr->ListBoxType() ) |
|
112 { |
|
113 // Duplicate policy, delete the old one. |
|
114 iListBoxPolicies.Remove( i ); |
|
115 delete curr; |
|
116 break; |
|
117 } |
|
118 else if ( spec > currspec ) |
|
119 { |
|
120 break; |
|
121 } |
|
122 } |
|
123 |
|
124 iListBoxPolicies.InsertL( policy, i ); |
|
125 |
|
126 CleanupStack::Pop(); |
|
127 __ALFFXLOGSTRING("CPolicyHandler::RegisterListBoxKmlL <<"); |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 TInt CPolicyHandler::UnregisterListBoxKml( const TUid& aUid, |
|
134 CAlfTransitionServerClient::TListBoxType aListBoxType ) |
|
135 { |
|
136 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterListBoxKml - Uid: 0x%x >>", aUid); |
|
137 for( TInt count = iListBoxPolicies.Count() - 1 ; count >= 0; count-- ) |
|
138 { |
|
139 if( iListBoxPolicies[count]->Uid() == aUid && |
|
140 iListBoxPolicies[count]->ListBoxType() == aListBoxType ) |
|
141 { |
|
142 delete iListBoxPolicies[count]; |
|
143 iListBoxPolicies.Remove( count ); |
|
144 __ALFFXLOGSTRING("CPolicyHandler::UnregisterListBoxKml - return KErrNone<<"); |
|
145 return KErrNone; |
|
146 } |
|
147 } |
|
148 __ALFFXLOGSTRING("CPolicyHandler::UnregisterListBoxKml - return KErrNotFound <<"); |
|
149 return KErrNotFound; |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CPolicyHandler::UnregisterListBoxKml( const TThreadId& aThreadId ) |
|
156 { |
|
157 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterListBoxKml - aThreadId: %d >>", aThreadId.Id()); |
|
158 TThreadId tid; |
|
159 TInt err = KErrNotFound; |
|
160 |
|
161 for( TInt count = iListBoxPolicies.Count() - 1 ; count >= 0; count-- ) |
|
162 { |
|
163 tid = iListBoxPolicies[count]->ThreadId(); |
|
164 if( tid.Id() == aThreadId.Id() ) |
|
165 { |
|
166 delete iListBoxPolicies[count]; |
|
167 iListBoxPolicies.Remove( count ); |
|
168 err = KErrNone; |
|
169 } |
|
170 } |
|
171 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterListBoxKml - return: %d <<", err); |
|
172 return err; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 TInt CPolicyHandler::GetListBoxKml( const TUid& aAppId, |
|
179 const CAlfTransitionServerClient::TListBoxType aListBoxType, |
|
180 TPtrC& aResourceDir, |
|
181 TPtrC& aBackgroundFilename, |
|
182 TPtrC& aItemFilename, |
|
183 TInt& aCachePriority, TInt& aWantedTime, |
|
184 TInt& aMinTime) |
|
185 { |
|
186 __ALFFXLOGSTRING3("CPolicyHandler::GetListBoxKml - aResourceDir: %S, aBackgroundFilename: %S, aItemFilename: %S >>", &aResourceDir, &aBackgroundFilename, &aItemFilename); |
|
187 TInt count = iListBoxPolicies.Count(); |
|
188 TBool hit = EFalse; |
|
189 TInt i; |
|
190 aResourceDir.Set( TPtrC() ); |
|
191 aBackgroundFilename.Set( TPtrC() ); |
|
192 aItemFilename.Set( TPtrC() ); |
|
193 |
|
194 for ( i = 0; i < count; i++ ) |
|
195 { |
|
196 CListBoxPolicy* curr = iListBoxPolicies[i]; |
|
197 TInt uid = curr->Uid().iUid; |
|
198 CAlfTransitionServerClient::TListBoxType listType = curr->ListBoxType(); |
|
199 |
|
200 if ( ( !uid || uid == aAppId.iUid ) && |
|
201 ( listType == CAlfTransitionServerClient::EListTypeAny || |
|
202 listType == aListBoxType ) ) |
|
203 { |
|
204 hit = ETrue; |
|
205 break; |
|
206 } |
|
207 } |
|
208 |
|
209 if ( !hit ) |
|
210 { |
|
211 __ALFFXLOGSTRING("CPolicyHandler::GetListBoxKml - return KErrNotFound <<"); |
|
212 return KErrNotFound; |
|
213 } |
|
214 |
|
215 aResourceDir.Set( iListBoxPolicies[i]->ResourceDir() ); |
|
216 aBackgroundFilename.Set( iListBoxPolicies[i]->BackgroundFilename() ); |
|
217 aItemFilename.Set( iListBoxPolicies[i]->ItemFilename() ); |
|
218 aCachePriority = iListBoxPolicies[i]->CachePriority(); |
|
219 aWantedTime = iListBoxPolicies[i]->WantedTime(); |
|
220 aMinTime = iListBoxPolicies[i]->MinTime(); |
|
221 |
|
222 // For now, this entry should have no priority over others |
|
223 iListBoxPolicies[i]->SetCachePriority( 0 ); |
|
224 __ALFFXLOGSTRING("CPolicyHandler::GetListBoxKml - return KErrNone <<"); |
|
225 return KErrNone; |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 void CPolicyHandler::RegisterFullscreenKmlL(TUint aAction, const TUid& aUid, const TThreadId& aThreadId, |
|
232 const TDesC& aResourceDir, const TDesC& aFilename, |
|
233 TInt /*aCachePriority*/, TInt aWantedTime, TInt aMinTime) |
|
234 { |
|
235 __ALFFXLOGSTRING3("CPolicyHandler::RegisterFullscreenKmlL - aAction: %d aUid: 0x%x aThread.Id : %d", aAction, aUid, aThreadId.Id() ); |
|
236 __ALFFXLOGSTRING2("CPolicyHandler::RegisterFullscreenKmlL - aResourceDir: %S, aFilename: %S", &aResourceDir, &aFilename ); |
|
237 TInt cachePriority = 1; //aCachePriority; |
|
238 // For now, the cache priority is always 1 at registration time, and after |
|
239 // fetching the KML information from the policy, it gets set to 0. This is |
|
240 // used to trigger eviction from the KML cache. Newly registered KML:s have |
|
241 // priority over existing... |
|
242 |
|
243 CFullscreenPolicy* policy = NULL; |
|
244 |
|
245 // Check if the action was already is registered and if so, delete it. |
|
246 TInt count = iFullscreenPolicies.Count()-1; |
|
247 for(; count >= 0; count--) |
|
248 { |
|
249 if( iFullscreenPolicies[count]->Action() == aAction && |
|
250 iFullscreenPolicies[count]->Uid() == aUid) |
|
251 { |
|
252 policy = iFullscreenPolicies[count]; |
|
253 iFullscreenPolicies.Remove(count); |
|
254 delete policy; |
|
255 policy = NULL; |
|
256 } |
|
257 } |
|
258 |
|
259 // create and add the new action. |
|
260 policy = CFullscreenPolicy::NewL(aAction, aUid, aThreadId, aResourceDir, aFilename, |
|
261 cachePriority, aWantedTime, aMinTime); |
|
262 CleanupStack::PushL(policy); |
|
263 iFullscreenPolicies.AppendL(policy); |
|
264 CleanupStack::Pop(policy); |
|
265 __ALFFXLOGSTRING("CPolicyHandler::RegisterFullscreenKmlL <<"); |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 TInt CPolicyHandler::UnregisterFullscreenKml(TUint aAction, const TUid& aUid) |
|
272 { |
|
273 __ALFFXLOGSTRING2("CPolicyHandler::UnregisterFullscreenKml - aAction: %d, aUid: 0x%x <<", aAction, aUid ); |
|
274 TInt count = iFullscreenPolicies.Count() -1; |
|
275 for(; count >= 0; count--) |
|
276 { |
|
277 if(iFullscreenPolicies[count]->Action() == aAction && |
|
278 iFullscreenPolicies[count]->Uid() == aUid) |
|
279 { |
|
280 CFullscreenPolicy* policy = iFullscreenPolicies[count]; |
|
281 iFullscreenPolicies.Remove(count); |
|
282 delete policy; |
|
283 policy = NULL; |
|
284 __ALFFXLOGSTRING("CPolicyHandler::UnregisterFullscreenKml - return KErrNone <<"); |
|
285 return KErrNone; |
|
286 } |
|
287 } |
|
288 __ALFFXLOGSTRING("CPolicyHandler::UnregisterFullscreenKml - return KErrNotFound <<"); |
|
289 return KErrNotFound; |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 TInt CPolicyHandler::UnregisterFullscreenKml(const TThreadId& aThreadId) |
|
296 { |
|
297 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterFullscreenKml - aThreadId: %d >>", aThreadId.Id()); |
|
298 TInt count = iFullscreenPolicies.Count() -1; |
|
299 TInt err = KErrNotFound; |
|
300 TThreadId tid; |
|
301 |
|
302 for(; count >= 0; count--) |
|
303 { |
|
304 tid = iFullscreenPolicies[count]->ThreadId(); |
|
305 if( tid.Id() == aThreadId.Id()) |
|
306 { |
|
307 CFullscreenPolicy* policy = iFullscreenPolicies[count]; |
|
308 iFullscreenPolicies.Remove(count); |
|
309 delete policy; |
|
310 policy = NULL; |
|
311 err = KErrNone; |
|
312 } |
|
313 } |
|
314 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterFullscreenKml - return: %d <<", err); |
|
315 return err; |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 TInt CPolicyHandler::UnregisterAllKml(const TThreadId& aThreadId) |
|
322 { |
|
323 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterAllKml - aThreadId: <<", aThreadId.Id()); |
|
324 TInt err = KErrNotFound; |
|
325 TInt err1 = UnregisterFullscreenKml(aThreadId); |
|
326 TInt err2 = UnregisterControlKml(aThreadId); |
|
327 |
|
328 if(err1 == KErrNone || err2 == KErrNone) |
|
329 err = KErrNone; |
|
330 |
|
331 |
|
332 TInt err3 = UnregisterListBoxKml(aThreadId); |
|
333 if(err3 == KErrNone) |
|
334 err = KErrNone; |
|
335 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterAllKml - return: %d <<", err); |
|
336 return err; |
|
337 } |
|
338 |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 TInt CPolicyHandler::GetFullscreenKml( TUint aAction, const TUid& aToUid, const TUid& aFromUid, |
|
344 TPtrC& aResourceDir, TPtrC& aFilename, |
|
345 TInt& aCachePriority, TInt& aWantedTime, TInt& aMinTime) |
|
346 { |
|
347 __ALFFXLOGSTRING3("CPolicyHandler::GetFullscreenKml - aAction: %d, aToUid: %d, aFromUid :%d", aAction, aToUid, aFromUid ); |
|
348 __ALFFXLOGSTRING2("CPolicyHandler::GetFullscreenKml - aResourceDir: %S, aFilename :%S", &aResourceDir, &aFilename ); |
|
349 |
|
350 // Checking if the UID is blocked. |
|
351 TInt blockedUids = iFullScreenBlocks.Count(); |
|
352 aResourceDir.Set( TPtrC() ); |
|
353 aFilename.Set( TPtrC() ); |
|
354 |
|
355 for( TInt i = 0 ; i < blockedUids ; i++ ) |
|
356 { |
|
357 if( iFullScreenBlocks[i]->iToUid == aToUid || |
|
358 iFullScreenBlocks[i]->iFromUid == aFromUid) |
|
359 { |
|
360 __ALFFXLOGSTRING("CPolicyHandler::GetFullscreenKml - return KErrNotSupported <<"); |
|
361 return KErrNotSupported; |
|
362 } |
|
363 } |
|
364 |
|
365 TInt count = iFullscreenPolicies.Count(); |
|
366 // try to find it using both action and uid |
|
367 for(TInt i = 0; i < count; i++) |
|
368 { |
|
369 if(iFullscreenPolicies[i]->Action() == aAction && |
|
370 iFullscreenPolicies[i]->Uid() == aToUid) |
|
371 { |
|
372 aResourceDir.Set( iFullscreenPolicies[i]->ResourceDir() ); |
|
373 aFilename.Set( iFullscreenPolicies[i]->Filename() ); |
|
374 aCachePriority = iFullscreenPolicies[i]->CachePriority(); |
|
375 aWantedTime = iFullscreenPolicies[i]->WantedTime(); |
|
376 aMinTime = iFullscreenPolicies[i]->MinTime(); |
|
377 // Check if theres a block on this UID/Action pair. |
|
378 if( aFilename.Length() == 0 ) |
|
379 { |
|
380 __ALFFXLOGSTRING("CPolicyHandler::GetFullscreenKml - return KErrNotSupported <<"); |
|
381 return KErrNotSupported; |
|
382 } |
|
383 |
|
384 // For now, this entry should have no priority over others |
|
385 iFullscreenPolicies[i]->SetCachePriority(0); |
|
386 __ALFFXLOGSTRING("CPolicyHandler::GetFullscreenKml - return KErrNone <<"); |
|
387 return KErrNone; |
|
388 } |
|
389 } |
|
390 // try to find the default (Uid == KNullUid) |
|
391 for(TInt i = 0; i < count; i++) |
|
392 { |
|
393 if(iFullscreenPolicies[i]->Action() == aAction && |
|
394 iFullscreenPolicies[i]->Uid() == KNullUid) |
|
395 { |
|
396 aResourceDir.Set( iFullscreenPolicies[i]->ResourceDir() ); |
|
397 aFilename.Set( iFullscreenPolicies[i]->Filename() ); |
|
398 aCachePriority = iFullscreenPolicies[i]->CachePriority(); |
|
399 aWantedTime = iFullscreenPolicies[i]->WantedTime(); |
|
400 aMinTime = iFullscreenPolicies[i]->MinTime(); |
|
401 |
|
402 // For now, this entry should have no priority over others |
|
403 iFullscreenPolicies[i]->SetCachePriority(0); |
|
404 __ALFFXLOGSTRING("CPolicyHandler::GetFullscreenKml - return KErrNone <<"); |
|
405 return KErrNone; |
|
406 } |
|
407 } |
|
408 __ALFFXLOGSTRING("CPolicyHandler::GetFullscreenKml - return KErrNotFound <<"); |
|
409 return KErrNotFound; |
|
410 } |
|
411 |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 TInt CPolicyHandler::BlockFullScreenUid(const TUid& aUid, TBool aBlockFrom, TBool aBlockTo) |
|
417 { |
|
418 __ALFFXLOGSTRING3("CPolicyHandler::BlockFullScreenUid - aUid: 0x%x, aBlockFrom: %d, aBlockTo: %d >>", aUid, aBlockFrom, aBlockTo ); |
|
419 TFullScreenBlock* block = NULL; |
|
420 |
|
421 TInt blockedUids = iFullScreenBlocks.Count(); |
|
422 if( blockedUids > 0) |
|
423 { |
|
424 // Looking for an existing To block. |
|
425 if(!aBlockTo && aBlockFrom ) |
|
426 { |
|
427 for(TInt i = 0; i < blockedUids; i++) |
|
428 { |
|
429 if(iFullScreenBlocks[i]->iFromUid == aUid) |
|
430 { |
|
431 __ALFFXLOGSTRING("CPolicyHandler::BlockFullScreenUid - return KErrNone <<"); |
|
432 return KErrNone; |
|
433 } |
|
434 } |
|
435 } |
|
436 // Looking for an existing From block. |
|
437 else if(aBlockTo && !aBlockFrom) |
|
438 { |
|
439 for(TInt i = 0; i < blockedUids; i++) |
|
440 { |
|
441 if(iFullScreenBlocks[i]->iToUid == aUid) |
|
442 { |
|
443 __ALFFXLOGSTRING("CPolicyHandler::BlockFullScreenUid - return KErrNone <<"); |
|
444 return KErrNone; |
|
445 } |
|
446 } |
|
447 } |
|
448 // Trying to unblock stuff. |
|
449 else if(!aBlockTo && !aBlockFrom) |
|
450 { |
|
451 for(TInt i = blockedUids -1; i >= 0; i--) |
|
452 { |
|
453 if( iFullScreenBlocks[i]->iToUid == aUid || |
|
454 iFullScreenBlocks[i]->iFromUid == aUid ) |
|
455 { |
|
456 block = iFullScreenBlocks[i]; |
|
457 iFullScreenBlocks.Remove(i); |
|
458 delete block; |
|
459 block = NULL; |
|
460 } |
|
461 } |
|
462 __ALFFXLOGSTRING("CPolicyHandler::BlockFullScreenUid - return KErrNone <<"); |
|
463 return KErrNone; |
|
464 } |
|
465 // Looking for an existing To and From block with the same UID's. |
|
466 else |
|
467 { |
|
468 for(TInt i = 0; i < blockedUids; i++) |
|
469 { |
|
470 if( iFullScreenBlocks[i]->iToUid == aUid && |
|
471 iFullScreenBlocks[i]->iFromUid == aUid ) |
|
472 { |
|
473 __ALFFXLOGSTRING("CPolicyHandler::BlockFullScreenUid - return KErrNone <<"); |
|
474 return KErrNone; |
|
475 } |
|
476 } |
|
477 } |
|
478 } |
|
479 |
|
480 // None found. Create! |
|
481 block = new TFullScreenBlock(); |
|
482 if(NULL == block) |
|
483 { |
|
484 __ALFFXLOGSTRING("CPolicyHandler::BlockFullScreenUid - return KErrNoMemory <<"); |
|
485 return KErrNoMemory; |
|
486 } |
|
487 |
|
488 if(aBlockTo) |
|
489 { |
|
490 block->iToUid = aUid; |
|
491 } |
|
492 if(aBlockFrom) |
|
493 { |
|
494 block->iFromUid = aUid; |
|
495 } |
|
496 |
|
497 TInt err = iFullScreenBlocks.Append(block); |
|
498 if(KErrNone != err) |
|
499 { |
|
500 delete block; |
|
501 block = NULL; |
|
502 } |
|
503 __ALFFXLOGSTRING1("CPolicyHandler::BlockFullScreenUid - return: %d <<", err); |
|
504 return err; |
|
505 } |
|
506 |
|
507 // --------------------------------------------------------------------------- |
|
508 // --------------------------------------------------------------------------- |
|
509 // |
|
510 TInt CPolicyHandler::RegisterControlAction(const TUid aUid, TUint aAction, const TDesC& aActionString) |
|
511 { |
|
512 __ALFFXLOGSTRING3("CPolicyHandler::RegisterControlAction - aUid: 0x%x, aAction: %d, aActionString: %S", aUid, aAction, &aActionString ); |
|
513 TInt index = 0; |
|
514 CControlPolicy* pData = NULL; |
|
515 CActionPolicy* pPolicy = NULL; |
|
516 |
|
517 // TEST!!!!!!!!!! |
|
518 // First see if we have an empty entry that means a new KML has been registered |
|
519 // Adding just a KML does not remove the old one, the old one gets removed only |
|
520 // after we add an action to the new KML |
|
521 |
|
522 // The double action of first registering a KML file and then registering the action |
|
523 // should be replaced with single call where the control file and action are defined |
|
524 // in one call |
|
525 |
|
526 TInt count = iControlPolicies.Count(); |
|
527 index = -1; // Setting index to negative value to use as check if match found. |
|
528 TInt i = 0; |
|
529 TInt j = 0; |
|
530 TInt k = 0; |
|
531 |
|
532 // We stop when we find a matching empty entry |
|
533 // But first old non-empty entries are deleted |
|
534 for( i = count - 1; i >= 0 && index == -1; i-- ) |
|
535 { |
|
536 pData = iControlPolicies[i]; |
|
537 if( pData->Uid() == aUid ) |
|
538 { |
|
539 if ( pData->iControlPolicies.Count() == 0 ) |
|
540 { |
|
541 index = i; |
|
542 // We have found an empty definition. |
|
543 // This means a new effect definition file has been added, and the new action |
|
544 // should be attached to it. |
|
545 // But first we have to remove the possible old effect file |
|
546 for ( j = count - 1; j >= 0; j-- ) |
|
547 { |
|
548 pData = iControlPolicies[j]; |
|
549 if ( pData->Uid() == aUid ) |
|
550 { |
|
551 for ( k = 0; pData && k < pData->iControlPolicies.Count(); k++ ) |
|
552 { |
|
553 pPolicy = pData->iControlPolicies[k]; |
|
554 if ( pPolicy->iAction == aAction ) |
|
555 { |
|
556 // Old definition found, remove the whole policy entry |
|
557 iControlPolicies.Remove( j ); |
|
558 count--; // this value is referred later. It must be kept up to date. |
|
559 delete pData; |
|
560 pData = NULL; |
|
561 } |
|
562 } |
|
563 } |
|
564 } |
|
565 } |
|
566 } |
|
567 } |
|
568 |
|
569 if( index >= 0 ) |
|
570 { |
|
571 index = -1; // paranoid... |
|
572 // find the empty entry again - if it exists |
|
573 // our indexes may have got messed up if we removed something |
|
574 // so we must recheck the index |
|
575 // We only accept entries with no policies, as we just checked |
|
576 // the existence of an entry with matching policy |
|
577 for( i = count - 1; i >= 0 && index == -1; i-- ) |
|
578 { |
|
579 pData = iControlPolicies[i]; |
|
580 if( pData->Uid() == aUid ) |
|
581 { |
|
582 if ( pData->iControlPolicies.Count() == 0 ) |
|
583 { |
|
584 index = i; |
|
585 } |
|
586 } |
|
587 } |
|
588 } |
|
589 // Now we have checked if we have an effect file definition that has no entries yet, |
|
590 // and if we found one, we deleted old effect file definitions for this UID. |
|
591 // Now we check if we just update an old action or add a new one to the existing entry |
|
592 |
|
593 // First checking if we need to update a policy. |
|
594 // If we have an empty entry, we must use it, not add our action to a different entry |
|
595 // even if if has the same UID. |
|
596 // So we must not try to find an existing entry if we have already decided to use an |
|
597 // empty entry |
|
598 |
|
599 if ( index < 0 ) |
|
600 { |
|
601 if(FindControlPolicy(aAction, aUid, pPolicy, index) == KErrNone) |
|
602 { |
|
603 // If we get here and pPolicy == NULL, something is really wrong outside of |
|
604 // our control. |
|
605 pPolicy->iAction = aAction; |
|
606 // Setting the action string is a leaving method. |
|
607 // Trap it here to avoid the rest of the system to become |
|
608 // leaving to. |
|
609 TRAPD(err, pPolicy->SetActionStringL(aActionString)); |
|
610 if(KErrNone != err) |
|
611 { |
|
612 __ALFFXLOGSTRING1("CPolicyHandler::RegisterControlAction - return: %d <<", err); |
|
613 return err; |
|
614 } |
|
615 pPolicy->iPolicy = ESupported; |
|
616 iClientRequestHandler->RegisterControlAction( aUid, aAction); |
|
617 __ALFFXLOGSTRING("CPolicyHandler::RegisterControlAction - return KErrNone <<"); |
|
618 return KErrNone; |
|
619 } |
|
620 } |
|
621 |
|
622 if( index < 0 ) |
|
623 { |
|
624 __ALFFXLOGSTRING("CPolicyHandler::RegisterControlAction - return KErrNotFound <<"); |
|
625 return KErrNotFound; |
|
626 } |
|
627 |
|
628 pData = iControlPolicies[index]; |
|
629 pPolicy = new CActionPolicy(); |
|
630 if(!pPolicy) |
|
631 { |
|
632 __ALFFXLOGSTRING("CPolicyHandler::RegisterControlAction - return KErrNoMemory <<"); |
|
633 return KErrNoMemory; |
|
634 } |
|
635 |
|
636 // Assign some values |
|
637 pPolicy->iAction = aAction; |
|
638 pPolicy->iPolicy = ESupported; |
|
639 TRAPD(err, pPolicy->SetActionStringL(aActionString)); |
|
640 if(KErrNone != err) |
|
641 { |
|
642 delete pPolicy; |
|
643 __ALFFXLOGSTRING1("CPolicyHandler::RegisterControlAction - return: %d <<", err); |
|
644 return err; |
|
645 } |
|
646 |
|
647 // Then add it to the list. |
|
648 err = pData->iControlPolicies.Append(pPolicy); |
|
649 if(err != KErrNone) |
|
650 { |
|
651 delete pPolicy; |
|
652 pPolicy = NULL; |
|
653 __ALFFXLOGSTRING1("CPolicyHandler::RegisterControlAction - return: %d <<", err); |
|
654 return err; |
|
655 } |
|
656 iClientRequestHandler->RegisterControlAction(aUid, aAction); |
|
657 __ALFFXLOGSTRING1("CPolicyHandler::RegisterControlAction - return: %d <<", err); |
|
658 return err; |
|
659 } |
|
660 |
|
661 |
|
662 // --------------------------------------------------------------------------- |
|
663 // --------------------------------------------------------------------------- |
|
664 // |
|
665 TInt CPolicyHandler::UnregisterControlAction(const TUid aUid, TUint aAction) |
|
666 { |
|
667 __ALFFXLOGSTRING2("CPolicyHandler::UnregisterControlAction - aUid %d, aAction: %d >>", aUid, aAction); |
|
668 CControlPolicy* pData = NULL; |
|
669 CActionPolicy* pPolicy = NULL; |
|
670 |
|
671 TInt count = iControlPolicies.Count(); |
|
672 |
|
673 // Removing policy for action. |
|
674 for(TInt counter = 0; counter < count; counter++) |
|
675 { |
|
676 pData = iControlPolicies[counter]; |
|
677 if(pData->Uid() == aUid) |
|
678 { |
|
679 TInt polActionCount = pData->iControlPolicies.Count(); |
|
680 // Iterating the list from first. No problem since we only delete one item! |
|
681 for(TInt j = 0; j < polActionCount; j++) |
|
682 { |
|
683 pPolicy = pData->iControlPolicies[j]; |
|
684 if(pPolicy->iAction == aAction) |
|
685 { |
|
686 // Call this before removing data permanently! |
|
687 iClientRequestHandler->RemoveControlPolicy( aUid, aAction); |
|
688 delete pPolicy; |
|
689 pPolicy = NULL; |
|
690 pData->iControlPolicies.Remove(j); |
|
691 __ALFFXLOGSTRING("CPolicyHandler::UnregisterControlAction - return KErrNone<<"); |
|
692 return KErrNone; |
|
693 } |
|
694 } |
|
695 } |
|
696 } |
|
697 __ALFFXLOGSTRING("CPolicyHandler::UnregisterControlAction - return KErrNotFound<<"); |
|
698 return KErrNotFound; |
|
699 } |
|
700 |
|
701 |
|
702 // --------------------------------------------------------------------------- |
|
703 // --------------------------------------------------------------------------- |
|
704 // |
|
705 void CPolicyHandler::RegisterControlKmlL(const TUid &aUid, const TThreadId &aThreadId, |
|
706 const TDesC& aResourceDir, const TDesC& aFilename, |
|
707 const TInt aWantedTime, const TInt aMinTime) |
|
708 { |
|
709 |
|
710 __ALFFXLOGSTRING2("CPolicyHandler::RegisterControlKmlL - aUid :%d aThread.Id :%d", aUid, aThreadId.Id() ); |
|
711 __ALFFXLOGSTRING2("CPolicyHandler::RegisterControlKmlL - aResourceDir: %S, aFilename :%S", &aResourceDir, &aFilename ); |
|
712 |
|
713 CControlPolicy* policy = NULL; |
|
714 TInt cachePriority = 1; //aCachePriority; |
|
715 // For now, the cache priority is always 1 at registration time, and after |
|
716 // fetching the KML information from the policy, it gets set to 0. This is |
|
717 // used to trigger eviction from the KML cache. Newly registered KML:s have |
|
718 // priority over existing... |
|
719 |
|
720 // Check if the action was already is registered and if so, delete it. |
|
721 |
|
722 // TEST!!!!!!!!!!!! Don't delete before action is added |
|
723 // Only delete if the entry has no policies, then we are replacing the xml file |
|
724 // though we have added no actions yet |
|
725 TInt count = iControlPolicies.Count()-1; |
|
726 for(; count >= 0; count--) |
|
727 { |
|
728 if( iControlPolicies[count]->Uid() == aUid) |
|
729 { |
|
730 policy = iControlPolicies[count]; |
|
731 if ( policy->iControlPolicies.Count() == 0 ) |
|
732 { |
|
733 iControlPolicies.Remove(count); |
|
734 delete policy; |
|
735 policy = NULL; |
|
736 } |
|
737 } |
|
738 } |
|
739 |
|
740 // Create the new action and add it. |
|
741 policy = CControlPolicy::NewL(aUid, aThreadId, aResourceDir, aFilename, cachePriority, aWantedTime, aMinTime); |
|
742 CleanupStack::PushL(policy); |
|
743 iControlPolicies.AppendL(policy); |
|
744 CleanupStack::Pop(policy); |
|
745 __ALFFXLOGSTRING("CPolicyHandler::RegisterControlKmlL <<"); |
|
746 } |
|
747 |
|
748 // --------------------------------------------------------------------------- |
|
749 // --------------------------------------------------------------------------- |
|
750 // |
|
751 TInt CPolicyHandler::RemoveControlKml(const TUid &aUid) |
|
752 { |
|
753 __ALFFXLOGSTRING1("CPolicyHandler::RemoveControlKml - aUid: %d ", aUid); |
|
754 |
|
755 TInt err = KErrNotFound; |
|
756 CControlPolicy* ptr = NULL; |
|
757 CActionPolicy* action = NULL; |
|
758 TInt policyCount = iControlPolicies.Count(); |
|
759 // We may remove several KMLs if different actions have different effect files |
|
760 for( TInt i = policyCount - 1; i >= 0; i--) |
|
761 { |
|
762 ptr = iControlPolicies[i]; |
|
763 if(ptr->Uid() == aUid) |
|
764 { |
|
765 // making sure that policies get removed from the running clients as well! |
|
766 TInt count = ptr->iControlPolicies.Count(); |
|
767 if( count > 0) |
|
768 { |
|
769 for(TInt j = 0; j < count; j++) |
|
770 { |
|
771 action = ptr->iControlPolicies[j]; |
|
772 iClientRequestHandler->RemoveControlPolicy(aUid, action->iAction); |
|
773 } |
|
774 } |
|
775 iControlPolicies.Remove(i); |
|
776 delete ptr; |
|
777 ptr = NULL; |
|
778 err = KErrNone; |
|
779 } |
|
780 } |
|
781 __ALFFXLOGSTRING1("CPolicyHandler::RemoveControlKml - return: %d <<", err); |
|
782 return err; |
|
783 } |
|
784 |
|
785 // --------------------------------------------------------------------------- |
|
786 // --------------------------------------------------------------------------- |
|
787 // |
|
788 TInt CPolicyHandler::UnregisterControlKml(const TThreadId &aThreadId) |
|
789 { |
|
790 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterControlKml - aThreadId: %d ", aThreadId.Id() ); |
|
791 CControlPolicy* ptr = NULL; |
|
792 CActionPolicy* action = NULL; |
|
793 TInt err = KErrNotFound; |
|
794 TThreadId tid; |
|
795 TInt policyCount = iControlPolicies.Count(); |
|
796 |
|
797 for( TInt i = policyCount - 1; i >= 0; i--) |
|
798 { |
|
799 ptr = iControlPolicies[i]; |
|
800 tid = ptr->ThreadId(); |
|
801 |
|
802 if(tid.Id() == aThreadId.Id()) |
|
803 { |
|
804 // making sure that policies get removed from the running clients as well! |
|
805 TInt count = ptr->iControlPolicies.Count(); |
|
806 if(count > 0) |
|
807 { |
|
808 for(TInt j = 0; j < count; j++) |
|
809 { |
|
810 action = ptr->iControlPolicies[j]; |
|
811 iClientRequestHandler->RemoveControlPolicy(ptr->Uid(), action->iAction); |
|
812 } |
|
813 } |
|
814 iControlPolicies.Remove(i); |
|
815 delete ptr; |
|
816 ptr = NULL; |
|
817 err = KErrNone; |
|
818 } |
|
819 } |
|
820 __ALFFXLOGSTRING1("CPolicyHandler::UnregisterControlKml - return: %d <<", err); |
|
821 return err; |
|
822 } |
|
823 |
|
824 // --------------------------------------------------------------------------- |
|
825 // --------------------------------------------------------------------------- |
|
826 // |
|
827 TInt CPolicyHandler::GetControlKml( TUid aUid, TUint aAction, TPtrC& aResourceDir, |
|
828 TPtrC& aFileName, TPtrC& aActionString, TInt& aCachePriority, |
|
829 TInt& aWantedTime, TInt& aMinTime) |
|
830 { |
|
831 __ALFFXLOGSTRING2("CPolicyHandler::GetControlKml - aAction: %d aUid :0x%x", aAction, aUid ); |
|
832 __ALFFXLOGSTRING3("CPolicyHandler::GetControlKml - aResourceDir: %S, aFilename :%S, aActionString: %S", &aResourceDir, &aFileName, &aActionString ); |
|
833 |
|
834 CControlPolicy* ptr = NULL; |
|
835 CActionPolicy* pPolicy = NULL; |
|
836 aResourceDir.Set( TPtrC() ); |
|
837 aFileName.Set( TPtrC() ); |
|
838 aActionString.Set( TPtrC() ); |
|
839 |
|
840 TInt itemCount = iControlPolicies.Count(); |
|
841 for(TInt i = 0; i < itemCount; i++) |
|
842 { |
|
843 ptr = iControlPolicies[i]; |
|
844 if( ptr->Uid() == aUid) |
|
845 { |
|
846 aResourceDir.Set( ptr->ResourceDir() ); |
|
847 aFileName.Set( ptr->Filename() ); |
|
848 aCachePriority = ptr->CachePriority(); |
|
849 aWantedTime = ptr->WantedTime(); |
|
850 aMinTime = ptr->MinTime(); |
|
851 TInt actionCount = ptr->iControlPolicies.Count(); |
|
852 for(TInt j = 0; j < actionCount; j++) |
|
853 { |
|
854 pPolicy = ptr->iControlPolicies[j]; |
|
855 if(pPolicy->iAction == aAction) |
|
856 { |
|
857 aActionString.Set( pPolicy->ActionString() ); |
|
858 // For now, this entry should have no priority over others |
|
859 ptr->SetCachePriority(0); |
|
860 __ALFFXLOGSTRING("CPolicyHandler::GetControlKml - return KErrNone <<"); |
|
861 return KErrNone; |
|
862 } |
|
863 } |
|
864 } |
|
865 } |
|
866 __ALFFXLOGSTRING("CPolicyHandler::GetControlKml - return KErrNotFound <<"); |
|
867 return KErrNotFound; |
|
868 } |
|
869 |
|
870 // --------------------------------------------------------------------------- |
|
871 // --------------------------------------------------------------------------- |
|
872 // |
|
873 TInt CPolicyHandler::GetAllControlPolicies(RPointerArray<CClientControlPolicy>& aControlPolicies) |
|
874 { |
|
875 __ALFFXLOGSTRING("CPolicyHandler::GetAllControlPolicies >>"); |
|
876 TInt err = KErrNone; |
|
877 |
|
878 TInt itemCount = iControlPolicies.Count(); |
|
879 if( 0 >= itemCount) |
|
880 { |
|
881 __ALFFXLOGSTRING("CPolicyHandler::GetAllControlPolicies - return KErrNotFound <<"); |
|
882 return KErrNotFound; |
|
883 } |
|
884 |
|
885 for(TInt i = 0; i < itemCount; i++) |
|
886 { |
|
887 CClientControlPolicy* ptr = new CClientControlPolicy(); |
|
888 if ( ptr == NULL ) |
|
889 { |
|
890 __ALFFXLOGSTRING("CPolicyHandler::GetAllControlPolicies - return KErrNoMemory <<"); |
|
891 return KErrNoMemory; |
|
892 } |
|
893 ptr->iUid = iControlPolicies[i]->Uid(); |
|
894 HBufC* fname = HBufC::New(iControlPolicies[i]->Filename().Length()); |
|
895 if ( fname == NULL ) |
|
896 { |
|
897 delete ptr; |
|
898 __ALFFXLOGSTRING("CPolicyHandler::GetAllControlPolicies - return KErrNoMemory <<"); |
|
899 return KErrNoMemory; |
|
900 } |
|
901 fname->Des().Copy(iControlPolicies[i]->Filename()); |
|
902 ptr->iFilename.Assign(fname); |
|
903 HBufC* resdir = HBufC::New(255); |
|
904 if ( resdir == NULL ) |
|
905 { |
|
906 delete ptr; |
|
907 __ALFFXLOGSTRING("CPolicyHandler::GetAllControlPolicies - return KErrNoMemory <<"); |
|
908 return KErrNoMemory; |
|
909 } |
|
910 ptr->iResourceDir.Assign(resdir); |
|
911 // In order to actually copy the pointers to the policy data, we |
|
912 // need to iterate through the entire list. |
|
913 TInt count = iControlPolicies[i]->iControlPolicies.Count(); |
|
914 if(count > 0) |
|
915 { |
|
916 for( TInt j = 0; j < count; j++) |
|
917 { |
|
918 err = ptr->iControlPolicies.Append(iControlPolicies[i]->iControlPolicies[j]); |
|
919 if(KErrNone != err) |
|
920 { |
|
921 delete ptr; |
|
922 __ALFFXLOGSTRING1("CPolicyHandler::GetAllControlPolicies - return: %d <<", err); |
|
923 return err; |
|
924 } |
|
925 } |
|
926 err = aControlPolicies.Append(ptr); |
|
927 if(KErrNone != err) |
|
928 { |
|
929 delete ptr; |
|
930 __ALFFXLOGSTRING1("CPolicyHandler::GetAllControlPolicies - return: %d <<", err); |
|
931 return err; |
|
932 } |
|
933 } |
|
934 else |
|
935 { |
|
936 delete ptr; |
|
937 ptr = NULL; |
|
938 } |
|
939 } |
|
940 __ALFFXLOGSTRING("CPolicyHandler::GetAllControlPolicies - return KErrNotFound<<"); |
|
941 return KErrNone; |
|
942 } |
|
943 |
|
944 // --------------------------------------------------------------------------- |
|
945 // --------------------------------------------------------------------------- |
|
946 // |
|
947 TInt CPolicyHandler::RequestPolicy(const RMessage2& aMessage) |
|
948 { |
|
949 return iClientRequestHandler->RequestPolicy(aMessage); |
|
950 } |
|
951 |
|
952 // --------------------------------------------------------------------------- |
|
953 // --------------------------------------------------------------------------- |
|
954 // |
|
955 TInt CPolicyHandler::GetPolicyL( TThreadId aClientId, TInt aPolicyCount, TPtr8& aOutBuf ) |
|
956 { |
|
957 return iClientRequestHandler->GetPolicyL( aClientId, aPolicyCount, aOutBuf ); |
|
958 } |
|
959 |
|
960 // --------------------------------------------------------------------------- |
|
961 // --------------------------------------------------------------------------- |
|
962 // |
|
963 void CPolicyHandler::RemoveClient( TThreadId aClientId ) |
|
964 { |
|
965 iClientRequestHandler->RemoveClient( aClientId ); |
|
966 } |
|
967 |
|
968 // --------------------------------------------------------------------------- |
|
969 // --------------------------------------------------------------------------- |
|
970 // |
|
971 /* |
|
972 void CPolicyHandler::RemoveDeadClients() |
|
973 { |
|
974 iClientRequestHandler->RemoveDeadClients(); |
|
975 } |
|
976 */ |
|
977 |
|
978 // --------------------------------------------------------------------------- |
|
979 // --------------------------------------------------------------------------- |
|
980 // |
|
981 /* |
|
982 void CPolicyHandler::DumpClientsL(RFileWriteStream& aFile) |
|
983 { |
|
984 iClientRequestHandler->DumpClientsL(aFile); |
|
985 } |
|
986 */ |
|
987 |
|
988 |
|
989 //============== PRIVATE METHODS =================/ |
|
990 |
|
991 // --------------------------------------------------------------------------- |
|
992 // --------------------------------------------------------------------------- |
|
993 // |
|
994 TInt CPolicyHandler::FindControlPolicy(TUint aAction, TUid aUid, CActionPolicy*& aPolicy, TInt& aIndex) |
|
995 { |
|
996 __ALFFXLOGSTRING3("CPolicyHandler::FindControlPolicy - aAction: %d, aUid: 0x%x, aIndex: %d", aAction, aUid, aIndex ); |
|
997 |
|
998 TInt count = iControlPolicies.Count(); |
|
999 aIndex = -1; // Setting index to low value to avoid accidental insertion. |
|
1000 |
|
1001 CControlPolicy* pData = NULL; |
|
1002 for(TInt i = 0; i < count; i++) |
|
1003 { |
|
1004 pData = iControlPolicies[i]; |
|
1005 if(pData->Uid() == aUid) |
|
1006 { |
|
1007 aIndex = i; |
|
1008 TInt j = pData->iControlPolicies.Count(); |
|
1009 CActionPolicy* pPolicy = NULL; |
|
1010 for(TInt q = 0; q < j; q++) |
|
1011 { |
|
1012 pPolicy = pData->iControlPolicies[q]; |
|
1013 if(pPolicy->iAction == aAction) |
|
1014 { |
|
1015 aPolicy = pPolicy; |
|
1016 __ALFFXLOGSTRING("CPolicyHandler::FindControlPolicy - return KErrNone <<"); |
|
1017 return KErrNone; |
|
1018 } |
|
1019 } |
|
1020 } |
|
1021 } |
|
1022 __ALFFXLOGSTRING("CPolicyHandler::FindControlPolicy - return KErrNotFound <<"); |
|
1023 return KErrNotFound; |
|
1024 } |
|
1025 |
|
1026 |
|
1027 // --- EOF --- |
|
1028 |
|
1029 |
|
1030 |
|
1031 |