|
1 /* |
|
2 * Copyright (c) 2006, 2007 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 Trigger View |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <lbtlisttriggeroptions.h> |
|
21 |
|
22 #include "lbtlogger.h" |
|
23 #include "lbttriggerview.h" |
|
24 #include "lbttriggerconditionarea.h" |
|
25 #include "lbtgeohybrid.h" |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CLbtTriggerView::NewL |
|
32 // |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CLbtTriggerView* CLbtTriggerView::NewL( MLbtTriggerViewObserver* aObserver ) |
|
36 { |
|
37 FUNC_ENTER("CLbtTriggerView::NewL"); |
|
38 |
|
39 CLbtTriggerView* self = new ( ELeave ) CLbtTriggerView; |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL( aObserver ); |
|
42 CleanupStack::Pop(); |
|
43 return self; |
|
44 |
|
45 } |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CLbtTriggerView::CheckRefreshRequests |
|
50 // |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CLbtTriggerView::CheckRefreshRequests() |
|
54 { |
|
55 FUNC_ENTER("CLbtTriggerView::CheckRefreshRequests"); |
|
56 if( iRefRequestList.Count() > 0 ) |
|
57 { |
|
58 iState = ERefreshView; |
|
59 SetEvent(); |
|
60 } |
|
61 else |
|
62 { |
|
63 // switch back to idle state |
|
64 iState = EIdle; |
|
65 } |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CLbtTriggerView::Refresh |
|
70 // |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void CLbtTriggerView::Refresh( TPositionInfo& aPosInfo, |
|
74 TLbtTriggerEventMask aEventMask, |
|
75 RArray<TLbtTriggerId>& aTriggerID ) |
|
76 { |
|
77 FUNC_ENTER("CLbtTriggerView::Refresh"); |
|
78 |
|
79 // Append refresh requests to the queue to be processed by trigger view |
|
80 if( aTriggerID.Count() != 0 ) |
|
81 { |
|
82 TRefRequestParam req; |
|
83 req.posInfo = aPosInfo; |
|
84 req.eventMask = aEventMask; |
|
85 |
|
86 RArray< TLbtTriggerId >* triggerID = NULL; |
|
87 TRAPD( err, triggerID = |
|
88 new( ELeave ) RArray< TLbtTriggerId > ); |
|
89 if( KErrNone == err ) |
|
90 { |
|
91 for( TInt i = 0; i < aTriggerID.Count(); i++ ) |
|
92 { |
|
93 triggerID->Append( aTriggerID[i] ); |
|
94 } |
|
95 req.triggerID = triggerID; |
|
96 } |
|
97 else |
|
98 { |
|
99 // Memory allocation failure |
|
100 LOG1("Mem Error: %d", err); |
|
101 // ToDo: Initiate termination |
|
102 return; |
|
103 } |
|
104 |
|
105 iRefRequestList.Append( req ); |
|
106 } |
|
107 |
|
108 LOG1( "View State is %d", iState ); |
|
109 // Initiate processing of request queue only if the current state is |
|
110 // idle. Processing of subsequent requests is automatically handled |
|
111 // by the ProcessRefreshRequests() method when state is ERefreshView |
|
112 if( EIdle == iState ) |
|
113 { |
|
114 LOG("Resetting modified trigger list"); |
|
115 iModifiedTrgList.Reset(); |
|
116 iState = ERefreshView; |
|
117 SetEvent(); |
|
118 } |
|
119 } |
|
120 |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CLbtTriggerView::GetModifiedTriggers |
|
124 // |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CLbtTriggerView::GetModifiedTriggers( RArray< TLbtTriggerId >& aList ) |
|
128 { |
|
129 FUNC_ENTER("CLbtTriggerView::GetModifiedTriggers"); |
|
130 |
|
131 for( TInt index = 0; index < iModifiedTrgList.Count(); index++ ) |
|
132 { |
|
133 aList.Append( iModifiedTrgList[index] ); |
|
134 } |
|
135 |
|
136 // This is done here because strategy engine invokes this method and evaluates all modified triggers |
|
137 iModifiedTrgList.Reset(); |
|
138 |
|
139 } |
|
140 |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CLbtTriggerView::GetTriggerByID |
|
144 // |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 TBool CLbtTriggerView::GetTriggerByID( TLbtTriggerId aID, |
|
148 CLbtContainerTriggerEntry*& aTriggerInfo ) |
|
149 { |
|
150 FUNC_ENTER("CLbtTriggerView::GetTriggerByID"); |
|
151 |
|
152 TBtreePos pos; |
|
153 TBool found = EFalse; |
|
154 TRAPD( err, |
|
155 found = iTriggerList->FindL( pos, aID ); |
|
156 if( found ) |
|
157 { |
|
158 TTrigger tEntry; |
|
159 iTriggerList->ExtractAtL( pos, tEntry ); |
|
160 aTriggerInfo = tEntry.info; |
|
161 } |
|
162 ); |
|
163 if( KErrNone != err ) |
|
164 { |
|
165 found = EFalse; |
|
166 } |
|
167 |
|
168 return found; |
|
169 |
|
170 } |
|
171 |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CLbtTriggerView::IsEmpty |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TBool CLbtTriggerView::IsEmpty() |
|
179 { |
|
180 return iTriggerList->IsEmpty(); |
|
181 } |
|
182 |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CLbtTriggerView::SetContainerObserver |
|
186 // |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CLbtTriggerView::SetContainerObserver( |
|
190 MLbtContainerChangeEventObserver* aObserver ) |
|
191 { |
|
192 FUNC_ENTER("CLbtTriggerView::SetContainerObserver"); |
|
193 |
|
194 // Set observer for trigger change notifications from container |
|
195 TLbtTriggerEventMask event = CLbtContainer::ELbtConTriggerEnabledAndValidCreated | |
|
196 CLbtContainer::ELbtConTriggerDeleted | |
|
197 CLbtContainer::ELbtConTriggerStateFieldChanged | |
|
198 CLbtContainer::ELbtConTriggerConditionFieldChanged | |
|
199 CLbtContainer::ELbtConTriggerValidityFieldChanged; |
|
200 |
|
201 iTrgContainer->SetChangeObserver( aObserver, event ); |
|
202 iContainerObserver = aObserver; |
|
203 } |
|
204 |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CLbtTriggerView::SetTriggerStatusObserver |
|
208 // |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CLbtTriggerView::SetTriggerStatusObserver( |
|
212 MLbtTriggerStatusObsrvr* aObserver ) |
|
213 { |
|
214 FUNC_ENTER("CLbtTriggerView::SetTriggerStatusObserver"); |
|
215 |
|
216 iTriggerStatusObserver = aObserver; |
|
217 |
|
218 } |
|
219 |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CLbtTriggerView::UpdateTriggerInfo |
|
223 // |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 void CLbtTriggerView::UpdateTriggerInfo( CLbtGeoAreaBase::TGeoAreaType aAreaType, |
|
227 TPositionInfo aPosInfo, |
|
228 CLbtContainerTriggerEntry* aTrigger, |
|
229 TLbtTriggerDataMask aDataMask ) |
|
230 { |
|
231 FUNC_ENTER("CLbtTriggerView::UpdateTriggerInfo"); |
|
232 |
|
233 TUpdateRequestParam reqParam; |
|
234 reqParam.areaType = aAreaType; |
|
235 reqParam.posInfo = aPosInfo; |
|
236 reqParam.trigger = aTrigger; |
|
237 reqParam.dataMask = aDataMask; |
|
238 iUpdateRequestList.Append( reqParam ); |
|
239 if( EIdle == iState ) |
|
240 { |
|
241 iState = ERefreshContainer; |
|
242 SetEvent(); |
|
243 } |
|
244 |
|
245 } |
|
246 |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CLbtTriggerView::RemContainerObserver |
|
250 // |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CLbtTriggerView::DetermineNearestTriggerChanges( RArray< TNearestTrigger >* aNearestTriggers ) |
|
254 { |
|
255 FUNC_ENTER("CLbtTriggerView::DetermineNearestTriggerChanges"); |
|
256 TLinearOrder< TLbtTriggerId > byTriggerID( CompareByID ); |
|
257 TInt pos = 0; |
|
258 TInt count = aNearestTriggers->Count(); |
|
259 for( TInt index = count - 1; index >= 0; index-- ) |
|
260 { |
|
261 pos = iModifiedTrgList.FindInOrder( ( *aNearestTriggers )[0].id, byTriggerID ); |
|
262 if( KErrNotFound != pos ) |
|
263 { |
|
264 aNearestTriggers->Remove( index ); |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CLbtTriggerView::RemContainerObserver |
|
272 // |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CLbtTriggerView::RemContainerObserver() |
|
276 { |
|
277 FUNC_ENTER("CLbtTriggerView::RemContainerObserver"); |
|
278 |
|
279 iTrgContainer->RemoveObserver( iContainerObserver ); |
|
280 |
|
281 } |
|
282 |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CLbtTriggerView::InvalidateTrigger |
|
286 // |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 void CLbtTriggerView::InvalidateTrigger( TLbtTriggerId aKey ) |
|
290 { |
|
291 FUNC_ENTER("CLbtTriggerView::InvalidateTrigger"); |
|
292 |
|
293 TBtreePos pos; |
|
294 TBool found = EFalse; |
|
295 TRAPD( err, |
|
296 found = iTriggerList->FindL( pos, aKey ); |
|
297 if( found ) |
|
298 { |
|
299 TTrigger tEntry; |
|
300 iTriggerList->ExtractAtL( pos, tEntry ); |
|
301 tEntry.validity = EFalse; |
|
302 |
|
303 // Remove entry from tree and re-insert the modified entry |
|
304 iTriggerList->DeleteL( aKey ); |
|
305 iTriggerList->InsertL( pos, tEntry ); |
|
306 } |
|
307 ); |
|
308 if( KErrNone != err ) |
|
309 { |
|
310 LOG1("Invalidation of trigger %d failed",aKey ); |
|
311 LOG1("Reason: %d", err); |
|
312 } |
|
313 else |
|
314 { |
|
315 LOG1("Trigger %d will no longer be supervised as it is invalidated", aKey); |
|
316 } |
|
317 } |
|
318 |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CLbtTriggerView::BeginL |
|
322 // |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 CLbtTriggerView::TTriggerViewIter CLbtTriggerView::BeginL(CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea) |
|
326 { |
|
327 FUNC_ENTER("CLbtTriggerView::BeginL"); |
|
328 |
|
329 TTriggerViewIter iter = TTriggerViewIter( iTriggerList,aPrimaryTriggerArea ); |
|
330 TInt err = iter.Reset(); |
|
331 if( KErrNone != err && KErrNotFound != err ) |
|
332 { |
|
333 User::Leave( err ); |
|
334 } |
|
335 return iter; |
|
336 |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CLbtTriggerView::BeginL |
|
341 // |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 CLbtTriggerView::TTriggerViewIter CLbtTriggerView::BeginL(CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea, |
|
345 CLbtGeoAreaBase::TGeoAreaType aSecondaryTriggerArea) |
|
346 { |
|
347 FUNC_ENTER("CLbtTriggerView::BeginL"); |
|
348 |
|
349 TTriggerViewIter iter = TTriggerViewIter( iTriggerList,aPrimaryTriggerArea, |
|
350 aSecondaryTriggerArea); |
|
351 TInt err = iter.Reset(); |
|
352 if( KErrNone != err && KErrNotFound != err ) |
|
353 { |
|
354 User::Leave( err ); |
|
355 } |
|
356 return iter; |
|
357 |
|
358 } |
|
359 |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CLbtTriggerView::Begin |
|
363 // |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 CLbtTriggerView::TTriggerViewIter CLbtTriggerView::Begin( |
|
367 RArray< TLbtTriggerId >* aID, |
|
368 CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea) |
|
369 { |
|
370 FUNC_ENTER("CLbtTriggerView::CLbtTriggerView::Begin"); |
|
371 |
|
372 TTriggerViewIter iter = TTriggerViewIter( iTriggerList, aID ,aPrimaryTriggerArea ); |
|
373 ( void )iter.Reset(); |
|
374 return iter; |
|
375 |
|
376 } |
|
377 |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CLbtTriggerView::~CLbtTriggerView |
|
381 // |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 CLbtTriggerView::~CLbtTriggerView() |
|
385 { |
|
386 FUNC_ENTER("CLbtTriggerView::~CLbtTriggerView"); |
|
387 |
|
388 TBtreeMark index; |
|
389 TBool next = EFalse; |
|
390 |
|
391 if (IsActive()) |
|
392 { |
|
393 Cancel(); |
|
394 } |
|
395 |
|
396 if( NULL != iTriggerList ) |
|
397 { |
|
398 TRAPD( err, |
|
399 next = iTriggerList->ResetL( index ); |
|
400 TTrigger tEntry; |
|
401 while( next ) |
|
402 { |
|
403 iTriggerList->ExtractAtL( index, tEntry ); |
|
404 delete tEntry.info; |
|
405 iTriggerList->DeleteL( tEntry.key ); |
|
406 next = iTriggerList->ResetL( index ); |
|
407 } ); |
|
408 if( KErrNone != err ) |
|
409 { |
|
410 // TODO: Log warning message that entries could not be deleted |
|
411 } |
|
412 } |
|
413 |
|
414 iList.ResetAndDestroy(); |
|
415 delete iTriggerList; |
|
416 delete iPool; |
|
417 if( NULL != iTrgContainer ) |
|
418 { |
|
419 iTrgContainer->Destroy(); |
|
420 } |
|
421 iModifiedTrgList.Close(); |
|
422 iUpdateRequestList.Close(); |
|
423 |
|
424 for(TInt i=0;i<iRefRequestList.Count();++i) |
|
425 { |
|
426 if( iRefRequestList[i].triggerID != NULL ) |
|
427 { |
|
428 iRefRequestList[i].triggerID->Close(); |
|
429 delete (iRefRequestList[i].triggerID); |
|
430 } |
|
431 } |
|
432 iRefRequestList.Close(); |
|
433 } |
|
434 |
|
435 |
|
436 // ----------------------------------------------------------------------------- |
|
437 // CLbtTriggerView::TTriggerViewIter::TTriggerViewIter |
|
438 // |
|
439 // ----------------------------------------------------------------------------- |
|
440 // |
|
441 CLbtTriggerView::TTriggerViewIter::TTriggerViewIter() |
|
442 { |
|
443 |
|
444 } |
|
445 |
|
446 |
|
447 // ----------------------------------------------------------------------------- |
|
448 // CLbtTriggerView::TTriggerViewIter::TTriggerViewIter |
|
449 // |
|
450 // ----------------------------------------------------------------------------- |
|
451 // |
|
452 CLbtTriggerView::TTriggerViewIter::TTriggerViewIter( |
|
453 TBtreeFix< TTrigger, TLbtTriggerId >* aTriggerList, |
|
454 CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea ) |
|
455 { |
|
456 FUNC_ENTER("CLbtTriggerView::TTriggerViewIter"); |
|
457 iTrgArray = NULL; |
|
458 iLast = ETrue; |
|
459 iTree = aTriggerList; |
|
460 iPrimaryAreaType = aPrimaryTriggerArea; |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CLbtTriggerView::TTriggerViewIter::TTriggerViewIter |
|
465 // |
|
466 // ----------------------------------------------------------------------------- |
|
467 // |
|
468 CLbtTriggerView::TTriggerViewIter::TTriggerViewIter( |
|
469 TBtreeFix< TTrigger, TLbtTriggerId >* aTriggerList, |
|
470 CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea, |
|
471 CLbtGeoAreaBase::TGeoAreaType aSecondaryTriggerArea) |
|
472 { |
|
473 FUNC_ENTER("CLbtTriggerView::TTriggerViewIter"); |
|
474 iTrgArray = NULL; |
|
475 iLast = ETrue; |
|
476 iTree = aTriggerList; |
|
477 iPrimaryAreaType = aPrimaryTriggerArea; |
|
478 iSecondaryAreaType = aSecondaryTriggerArea; |
|
479 } |
|
480 |
|
481 |
|
482 // ----------------------------------------------------------------------------- |
|
483 // CLbtTriggerView::TTriggerViewIter::TTriggerViewIter |
|
484 // |
|
485 // ----------------------------------------------------------------------------- |
|
486 // |
|
487 CLbtTriggerView::TTriggerViewIter::TTriggerViewIter( |
|
488 TBtreeFix< TTrigger, TLbtTriggerId >* aTriggerList, |
|
489 RArray< TLbtTriggerId >* aTriggerIDs, |
|
490 CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea ) |
|
491 { |
|
492 FUNC_ENTER("CLbtTriggerView::TTriggerViewIter"); |
|
493 iTrgArray = aTriggerIDs; |
|
494 iLast = ETrue; |
|
495 iTree = aTriggerList; |
|
496 iPrimaryAreaType = aPrimaryTriggerArea; |
|
497 } |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // CLbtTriggerView::TTriggerViewIter::TTriggerViewIter |
|
501 // |
|
502 // ----------------------------------------------------------------------------- |
|
503 // |
|
504 CLbtTriggerView::TTriggerViewIter::TTriggerViewIter( |
|
505 TBtreeFix< TTrigger, TLbtTriggerId >* aTriggerList, |
|
506 RArray< TLbtTriggerId >* aTriggerIDs, |
|
507 CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea, |
|
508 CLbtGeoAreaBase::TGeoAreaType aSecondaryTriggerArea) |
|
509 { |
|
510 FUNC_ENTER("CLbtTriggerView::TTriggerViewIter"); |
|
511 iTrgArray = aTriggerIDs; |
|
512 iLast = ETrue; |
|
513 iTree = aTriggerList; |
|
514 iPrimaryAreaType = aPrimaryTriggerArea; |
|
515 iSecondaryAreaType = aSecondaryTriggerArea; |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CLbtTriggerView::TTriggerViewIter::ResetL |
|
520 // |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 TInt CLbtTriggerView::TTriggerViewIter::Reset() |
|
524 { |
|
525 FUNC_ENTER("CLbtTriggerView::Reset"); |
|
526 |
|
527 if( iTrgArray && iTrgArray->Count() ) |
|
528 { |
|
529 iIndex = 0; |
|
530 } |
|
531 else |
|
532 { |
|
533 TBool exist = EFalse; |
|
534 TRAPD( err, exist = iTree->ResetL( iPos ) ); |
|
535 if( KErrNone != err ) |
|
536 { |
|
537 return err; |
|
538 } |
|
539 else if( !exist ) |
|
540 { |
|
541 return KErrNotFound; |
|
542 } |
|
543 } |
|
544 iLast = EFalse; |
|
545 return KErrNone; |
|
546 |
|
547 } |
|
548 |
|
549 |
|
550 // ----------------------------------------------------------------------------- |
|
551 // CLbtTriggerView::TTriggerViewIter::NextL |
|
552 // |
|
553 // ----------------------------------------------------------------------------- |
|
554 // |
|
555 TBool CLbtTriggerView::TTriggerViewIter::NextL( |
|
556 CLbtContainerTriggerEntry*& aTriggerInfo ) |
|
557 { |
|
558 FUNC_ENTER("CLbtTriggerView::NextL"); |
|
559 TInt err; |
|
560 TInt count = 0; |
|
561 if( iTrgArray ) |
|
562 { |
|
563 count = iTrgArray->Count(); |
|
564 } |
|
565 |
|
566 // This section of code is for triggers whose IDs are specified. This |
|
567 // section is executed only when there are trigger changes ( addition / |
|
568 // modification / deletion ) in the system |
|
569 if( count ) |
|
570 { |
|
571 while( iIndex < count ) |
|
572 { |
|
573 TBtreePos pos; |
|
574 TBool found = EFalse; |
|
575 |
|
576 TRAP( err, |
|
577 found = iTree->FindL( pos, ( *iTrgArray )[iIndex] ) ); |
|
578 if( KErrNone == err ) |
|
579 { |
|
580 if( found ) |
|
581 { |
|
582 CLbtTriggerView::TTrigger tEntry; |
|
583 TRAP( err, iTree->ExtractAtL( pos, tEntry ) ); |
|
584 if( KErrNone == err && tEntry.validity && |
|
585 ( tEntry.type == iPrimaryAreaType || tEntry.type == iSecondaryAreaType ) ) |
|
586 { |
|
587 aTriggerInfo = tEntry.info; |
|
588 ++iIndex; |
|
589 return ETrue; |
|
590 } |
|
591 } |
|
592 } |
|
593 LOG1("TTriggerViewIter::NextL - trigger %d not found in repository",( *iTrgArray )[iIndex]); |
|
594 // This step only ignores missing trigger information and proceeds |
|
595 // with the next entry |
|
596 ++iIndex; |
|
597 continue; |
|
598 } // end of while |
|
599 |
|
600 return EFalse; |
|
601 } |
|
602 |
|
603 // This section is for all triggers in the BTree |
|
604 else |
|
605 { |
|
606 while( ETrue ) |
|
607 { |
|
608 if( !iLast ) |
|
609 { |
|
610 CLbtTriggerView::TTrigger tEntry; |
|
611 iTree->ExtractAtL( iPos, tEntry ); |
|
612 if( tEntry.validity && |
|
613 ( tEntry.type == iPrimaryAreaType || tEntry.type == iSecondaryAreaType ) ) |
|
614 { |
|
615 aTriggerInfo = tEntry.info; |
|
616 } |
|
617 else |
|
618 { |
|
619 if( iTree->NextL( iPos ) ) |
|
620 { |
|
621 continue; |
|
622 } |
|
623 else |
|
624 { |
|
625 aTriggerInfo = NULL; |
|
626 iLast = ETrue; |
|
627 return !iLast; |
|
628 } |
|
629 } |
|
630 |
|
631 if( iTree->NextL( iPos ) ) |
|
632 { |
|
633 return !iLast; |
|
634 } |
|
635 else |
|
636 { |
|
637 iLast = ETrue; |
|
638 return iLast; |
|
639 } |
|
640 } |
|
641 else |
|
642 { |
|
643 return !iLast; |
|
644 } |
|
645 } |
|
646 } |
|
647 } |
|
648 |
|
649 |
|
650 // ----------------------------------------------------------------------------- |
|
651 // CLbtTriggerView::CLbtTriggerView |
|
652 // |
|
653 // ----------------------------------------------------------------------------- |
|
654 // |
|
655 CLbtTriggerView::CLbtTriggerView() : |
|
656 CActive( EPriorityStandard ) |
|
657 { |
|
658 CActiveScheduler::Add( this ); |
|
659 } |
|
660 |
|
661 |
|
662 // ----------------------------------------------------------------------------- |
|
663 // CLbtTriggerView::ConstructL |
|
664 // |
|
665 // ----------------------------------------------------------------------------- |
|
666 // |
|
667 void CLbtTriggerView::ConstructL( MLbtTriggerViewObserver* aObserver ) |
|
668 { |
|
669 FUNC_ENTER("CLbtTriggerView::ConstructL"); |
|
670 iObserver = aObserver; |
|
671 iRefReqCounter = 0; |
|
672 iUpdateReqCounter = 0; |
|
673 iCellTriggerCount = 0; |
|
674 iCoordTriggerCount = 0; |
|
675 iRequestInitiated = EFalse; |
|
676 iDelayedInitialization = EFalse; |
|
677 |
|
678 |
|
679 iTriggerList = new ( ELeave ) |
|
680 TBtreeFix< TTrigger, TLbtTriggerId >( EBtreeFast ); |
|
681 iPool = CMemPagePool::NewL(); |
|
682 iTriggerList->Connect( iPool, &iKey ); |
|
683 |
|
684 iTrgContainer = CLbtContainer::NewL(); |
|
685 iState = EInitialize; |
|
686 // Retrieve triggers from container |
|
687 ListEnabledAndValidTriggersL(); |
|
688 } |
|
689 |
|
690 |
|
691 // ----------------------------------------------------------------------------- |
|
692 // CLbtTriggerView::InitializeList |
|
693 // |
|
694 // ----------------------------------------------------------------------------- |
|
695 // |
|
696 void CLbtTriggerView::InitializeList() |
|
697 { |
|
698 FUNC_ENTER("CLbtTriggerView::InitializeList"); |
|
699 |
|
700 TInt err; |
|
701 TInt count = iList.Count(); |
|
702 for( TInt index = count - 1; index >= 0; index-- ) |
|
703 { |
|
704 TRAP( err, AddToTreeL( ( iList[index] )->TriggerEntry()->Id(), |
|
705 iList[index] ) ); |
|
706 if( KErrNone != err ) |
|
707 { |
|
708 LOG1("Initializing trigger repository failed. Reason: %d", err ); |
|
709 iObserver->OperationComplete( |
|
710 MLbtTriggerViewObserver::EOperationError ); |
|
711 iList.ResetAndDestroy(); |
|
712 return; |
|
713 } |
|
714 |
|
715 iList.Remove( index ); |
|
716 } |
|
717 |
|
718 // Reset the trigger list as this would be used later to retrieve |
|
719 // trigger information from container during refresh operations |
|
720 iList.Reset(); |
|
721 |
|
722 // Check if there have been any refresh requests queued while view was |
|
723 // being initialized. Process these requests and delay notification to |
|
724 // strategy engine. |
|
725 if( iRefRequestList.Count() ) |
|
726 { |
|
727 iDelayedInitialization = ETrue; |
|
728 iState = ERefreshView; |
|
729 SetEvent(); |
|
730 } |
|
731 else |
|
732 { |
|
733 iState = EIdle; |
|
734 iObserver->OperationComplete( MLbtTriggerViewObserver::EViewInitialized ); |
|
735 } |
|
736 } |
|
737 |
|
738 |
|
739 // ----------------------------------------------------------------------------- |
|
740 // CLbtTriggerView::ProcessRefreshRequests |
|
741 // |
|
742 // ----------------------------------------------------------------------------- |
|
743 // |
|
744 void CLbtTriggerView::ProcessRefreshRequests() |
|
745 { |
|
746 FUNC_ENTER("CLbtTriggerView::ProcessRefreshRequests"); |
|
747 |
|
748 // TODO: Implement relevance here! Currently the list contains |
|
749 // all enabled and valid triggers in the system |
|
750 while( iRefRequestList.Count() > 0 ) |
|
751 { |
|
752 TRefRequestParam req = iRefRequestList[iRefReqCounter]; |
|
753 if( !req.eventMask ) |
|
754 { |
|
755 // This is a special case when strategy engine requests refresh of |
|
756 // trigger view based on position info |
|
757 // Current implementation only removes request from queue and |
|
758 // notifies strategy engine |
|
759 req.triggerID->Close(); |
|
760 delete (req.triggerID); |
|
761 iRefRequestList.Remove( iRefReqCounter ); |
|
762 |
|
763 LOG("Event mask absent for process refresh requests"); |
|
764 continue; |
|
765 } |
|
766 |
|
767 if( req.eventMask & CLbtContainer::ELbtConTriggerDeleted ) |
|
768 { |
|
769 LOG("Event Mask : Trigger Deleted"); |
|
770 // Trigger(s) deleted - remove entry from tree |
|
771 iRefRequestList.Remove( iRefReqCounter ); |
|
772 HandleTriggerDeletionEvent( req.triggerID ); |
|
773 ( req.triggerID )->Reset(); |
|
774 delete (req.triggerID); |
|
775 } |
|
776 else |
|
777 { |
|
778 // Trigger(s) created or modified |
|
779 if( !iRequestInitiated && iList.Count() == 0 ) |
|
780 { |
|
781 iRequestInitiated = ETrue; |
|
782 // Retrieve modified triggers from container |
|
783 TRAPD( err, GetTriggers( req.triggerID ) ); |
|
784 if( KErrNone != err ) |
|
785 { |
|
786 iRefRequestList.Remove( iRefReqCounter ); |
|
787 // Invalidate triggers that have been modified |
|
788 if( !( req.eventMask & CLbtContainer::ELbtConTriggerEnabledAndValidCreated ) && |
|
789 !( req.eventMask & CLbtContainer:: ELbtConTriggerDeleted) ) |
|
790 { |
|
791 TInt index = 0; |
|
792 while ( index < ( req.triggerID )->Count() ) |
|
793 { |
|
794 InvalidateTrigger( ( *req.triggerID )[index] ); |
|
795 index++; |
|
796 } |
|
797 } |
|
798 ( req.triggerID )->Reset(); |
|
799 delete req.triggerID; |
|
800 |
|
801 continue; |
|
802 } |
|
803 |
|
804 break; |
|
805 } |
|
806 else |
|
807 { |
|
808 iRequestInitiated = EFalse; |
|
809 |
|
810 // Triggers with the specified IDs were not found in container |
|
811 if( iList.Count() == 0 ) |
|
812 { |
|
813 LOG("Zombie Triggers!!"); |
|
814 iRefRequestList.Remove( iRefReqCounter ); |
|
815 ( req.triggerID )->Reset(); |
|
816 delete req.triggerID; |
|
817 } |
|
818 |
|
819 // Update tree with triggers retrieved from container |
|
820 else if( req.eventMask & CLbtContainer::ELbtConTriggerEnabledAndValidCreated ) |
|
821 { |
|
822 LOG("Event Mask : Trigger Created"); |
|
823 // Add new triggers to view |
|
824 iRefRequestList.Remove( iRefReqCounter ); |
|
825 HandleTriggerCreationEvent(); |
|
826 ( req.triggerID )->Reset(); |
|
827 delete req.triggerID; |
|
828 } |
|
829 else |
|
830 { |
|
831 LOG("Event Mask : Trigger Modified"); |
|
832 // Check for trigger modifications |
|
833 iRefRequestList.Remove( iRefReqCounter ); |
|
834 HandleTriggerModificationEvent(); |
|
835 ( req.triggerID )->Reset(); |
|
836 delete req.triggerID; |
|
837 } |
|
838 } |
|
839 } |
|
840 |
|
841 continue; |
|
842 }// end while |
|
843 |
|
844 if( iRefRequestList.Count() <= 0 ) |
|
845 { |
|
846 LOG("End of ProcessRefreshReqs"); |
|
847 |
|
848 // Reset request list to be reused |
|
849 iRefRequestList.Reset(); |
|
850 iState = EIdle; |
|
851 |
|
852 // If a result of delayed initialization caused by triggers being created |
|
853 // before the initialization process is complete, notify initialization |
|
854 // operation complete now. |
|
855 if( iDelayedInitialization ) |
|
856 { |
|
857 iDelayedInitialization = EFalse; |
|
858 iObserver->OperationComplete( MLbtTriggerViewObserver::EViewInitialized ); |
|
859 } |
|
860 else |
|
861 { |
|
862 iObserver->OperationComplete( MLbtTriggerViewObserver::EViewRefreshed ); |
|
863 } |
|
864 |
|
865 |
|
866 // Check if there are any update requests pending. If so, switch to |
|
867 // processing of updates |
|
868 if( iUpdateRequestList.Count() > 0 ) |
|
869 { |
|
870 LOG("ERefreshContainer"); |
|
871 iState = ERefreshContainer; |
|
872 SetEvent(); |
|
873 } |
|
874 else |
|
875 { |
|
876 iState = EIdle; |
|
877 } |
|
878 } |
|
879 } |
|
880 |
|
881 |
|
882 // ----------------------------------------------------------------------------- |
|
883 // CLbtTriggerView::ProcessUpdateRequests |
|
884 // |
|
885 // ----------------------------------------------------------------------------- |
|
886 // |
|
887 void CLbtTriggerView::ProcessUpdateRequests() |
|
888 { |
|
889 FUNC_ENTER("CLbtTriggerView::ProcessUpdateRequests"); |
|
890 |
|
891 if( iUpdateReqCounter ) |
|
892 { |
|
893 if( KErrNone != iStatus.Int() ) |
|
894 { |
|
895 LOG1("Updating information of trigger %d in the container failed.", |
|
896 iUpdateRequestList[iUpdateReqCounter - 1].trigger->TriggerEntry()->Id()); |
|
897 LOG1("Reason: %d", iStatus.Int() ); |
|
898 // Error in updating container |
|
899 } |
|
900 else if( iUpdateRequestList[iUpdateReqCounter - 1].dataMask & |
|
901 CLbtContainerTriggerEntry::EContainerAttributeIsFired ) |
|
902 { |
|
903 iTriggerStatusObserver->TriggerFired( |
|
904 iUpdateRequestList[iUpdateReqCounter - 1].areaType, |
|
905 iUpdateRequestList[iUpdateReqCounter - 1].trigger->TriggerEntry()->Id(), |
|
906 iUpdateRequestList[iUpdateReqCounter - 1].posInfo ); |
|
907 } |
|
908 } |
|
909 |
|
910 if( iUpdateReqCounter < iUpdateRequestList.Count() ) |
|
911 { |
|
912 // Update trigger information in container. |
|
913 // TODO: May need to revisit this TRAP_IGNORE part if container decides |
|
914 // to leave. Current implementation, there aint no leave! |
|
915 TRAP_IGNORE( iTrgContainer->UpdateTriggerL( |
|
916 *( iUpdateRequestList[iUpdateReqCounter].trigger ), |
|
917 iUpdateRequestList[iUpdateReqCounter].dataMask, 0, |
|
918 iRequestID, iStatus ) ); |
|
919 SetActive(); |
|
920 iUpdateReqCounter++; |
|
921 } |
|
922 else |
|
923 { |
|
924 // Reset request list to be reused |
|
925 iUpdateRequestList.Reset(); |
|
926 iUpdateReqCounter = 0; |
|
927 |
|
928 // Check for any refresh requests from container |
|
929 CheckRefreshRequests(); |
|
930 } |
|
931 } |
|
932 |
|
933 |
|
934 // ----------------------------------------------------------------------------- |
|
935 // CLbtTriggerView::HandleTriggerCreationEvent |
|
936 // |
|
937 // ----------------------------------------------------------------------------- |
|
938 // |
|
939 void CLbtTriggerView::HandleTriggerCreationEvent() |
|
940 { |
|
941 FUNC_ENTER("CLbtTriggerView::HandleTriggerCreationEvent"); |
|
942 TInt count = iList.Count(); |
|
943 for( TInt index = count - 1; index >= 0; index-- ) |
|
944 { |
|
945 TRAPD( err, AddToTreeL( ( iList[index] )->TriggerEntry()->Id(), |
|
946 iList[index] ) ); |
|
947 if( KErrNone == err ) |
|
948 { |
|
949 LOG1("Added Trigger to tree: %d", ( iList[index] )->TriggerEntry()->Id() ); |
|
950 TLinearOrder< TLbtTriggerId > byTriggerID( CompareByID ); |
|
951 iModifiedTrgList.InsertInOrder( ( iList[index] )->TriggerEntry()->Id(), byTriggerID ); |
|
952 } |
|
953 else |
|
954 { |
|
955 LOG1("Including trigger %d in view failed.",( iList[index] )->TriggerEntry()->Id()); |
|
956 LOG1("Reason:%d",err); |
|
957 continue; |
|
958 } |
|
959 |
|
960 iList.Remove( index ); |
|
961 } |
|
962 |
|
963 // Reset list to be reused for subsequent refresh operations |
|
964 iList.ResetAndDestroy(); |
|
965 } |
|
966 |
|
967 |
|
968 // ----------------------------------------------------------------------------- |
|
969 // CLbtTriggerView::HandleTriggerModificationEvent |
|
970 // |
|
971 // ----------------------------------------------------------------------------- |
|
972 // |
|
973 void CLbtTriggerView::HandleTriggerModificationEvent() |
|
974 { |
|
975 FUNC_ENTER("CLbtTriggerView::HandleTriggerModificationEvent"); |
|
976 TInt count = iList.Count(); |
|
977 TBool found = EFalse; |
|
978 for( TInt index = count - 1; index >= 0; index-- ) |
|
979 { |
|
980 // Check for triggers that have been rendered invalid or disabled and |
|
981 // remove them from view |
|
982 if( ( iList[index] )->TriggerEntry()->State() == |
|
983 CLbtTriggerEntry::EStateDisabled || |
|
984 ( iList[index] )->DynInfo()->iValidity == |
|
985 TLbtTriggerDynamicInfo::EInvalid ) |
|
986 { |
|
987 TLbtTriggerId id = ( iList[index] )->TriggerEntry()->Id(); |
|
988 |
|
989 LOG1("Trigger deleted / set invalid: %d", id ); |
|
990 TRAPD( err, found = DeleteFromTreeL( id ) ); |
|
991 if( found ) |
|
992 { |
|
993 if( KErrNone == err ) |
|
994 { |
|
995 TLinearOrder< TLbtTriggerId > byTriggerID( CompareByID ); |
|
996 iModifiedTrgList.InsertInOrder( id, byTriggerID ); |
|
997 } |
|
998 else |
|
999 { |
|
1000 LOG1("Excluding trigger %d from view failed.",id); |
|
1001 LOG1("This trigger is invalidated and shall not be supervised. Reason: %d",err); |
|
1002 InvalidateTrigger( id ); |
|
1003 } |
|
1004 } |
|
1005 } |
|
1006 else |
|
1007 { |
|
1008 TLbtTriggerId id = ( iList[index] )->TriggerEntry()->Id(); |
|
1009 TTrigger trigger; |
|
1010 |
|
1011 // Find trigger information from tree if it exists |
|
1012 TRAPD( err, found = FindInTreeL( id, trigger ) ); |
|
1013 if( found && (KErrNone == err) ) |
|
1014 { |
|
1015 TBool copyStrategyData = ETrue; |
|
1016 |
|
1017 CLbtTriggerConditionArea* cond = |
|
1018 static_cast<CLbtTriggerConditionArea*>(iList[index]->TriggerEntry()->GetCondition()); |
|
1019 CLbtTriggerConditionArea::TDirection oldDirection = |
|
1020 cond->Direction(); |
|
1021 |
|
1022 CLbtContainerTriggerEntry* triggerEntry = trigger.info; |
|
1023 cond = static_cast<CLbtTriggerConditionArea*>(triggerEntry->TriggerEntry()->GetCondition()); |
|
1024 CLbtTriggerConditionArea::TDirection newDirection = |
|
1025 cond->Direction(); |
|
1026 |
|
1027 if( triggerEntry->ExtendedTriggerInfo()->IsTriggerFireOnCreation() ) |
|
1028 { |
|
1029 copyStrategyData = EFalse; |
|
1030 } |
|
1031 else if( newDirection != oldDirection ) |
|
1032 { |
|
1033 copyStrategyData = EFalse; |
|
1034 } |
|
1035 |
|
1036 if( copyStrategyData ) |
|
1037 { |
|
1038 // The trigger is already present in the tree. Save the strategy information |
|
1039 // since it is required for regular supervision |
|
1040 TStrategyData strategyData = triggerEntry->StrategyData(); |
|
1041 iList[index]->SetStrategyData( strategyData ); |
|
1042 } |
|
1043 } |
|
1044 |
|
1045 found = EFalse; |
|
1046 |
|
1047 // Remove trigger information from tree if it exists |
|
1048 TRAP( err, found = DeleteFromTreeL( id ) ); |
|
1049 if( found && KErrNone != err ) |
|
1050 { |
|
1051 InvalidateTrigger( id ); |
|
1052 } |
|
1053 else |
|
1054 { |
|
1055 LOG1("Added modified trigger to tree: %d", id ); |
|
1056 |
|
1057 // Add modified trigger information to tree |
|
1058 TRAP( err, AddToTreeL( id, iList[index] ) ); |
|
1059 if( KErrNone == err ) |
|
1060 { |
|
1061 TLinearOrder< TLbtTriggerId > byTriggerID( CompareByID ); |
|
1062 iModifiedTrgList.InsertInOrder( id, byTriggerID ); |
|
1063 } |
|
1064 else |
|
1065 { |
|
1066 LOG1("Excluding trigger %d from view failed.",id); |
|
1067 LOG1("This trigger is invalidated and shall not be supervised. Reason: %d",err); |
|
1068 InvalidateTrigger( id ); |
|
1069 } |
|
1070 } |
|
1071 } |
|
1072 |
|
1073 iList.Remove( index ); |
|
1074 } |
|
1075 |
|
1076 // Reset list to be reused for subsequent refresh operations |
|
1077 iList.ResetAndDestroy(); |
|
1078 } |
|
1079 |
|
1080 |
|
1081 // ----------------------------------------------------------------------------- |
|
1082 // CLbtTriggerView::HandleTriggerDeletionEvent |
|
1083 // |
|
1084 // ----------------------------------------------------------------------------- |
|
1085 // |
|
1086 void CLbtTriggerView::HandleTriggerDeletionEvent( |
|
1087 RArray< TLbtTriggerId >* aIDs ) |
|
1088 { |
|
1089 FUNC_ENTER("CLbtTriggerView::HandleTriggerDeletionEvent"); |
|
1090 TBool found = EFalse; |
|
1091 for( TInt index = 0; index < aIDs->Count(); index++ ) |
|
1092 { |
|
1093 TRAPD( err, found = DeleteFromTreeL( ( *aIDs )[index] ) ); |
|
1094 if( found ) |
|
1095 { |
|
1096 if( KErrNone == err ) |
|
1097 { |
|
1098 TLinearOrder< TLbtTriggerId > byTriggerID( CompareByID ); |
|
1099 iModifiedTrgList.InsertInOrder( ( *aIDs )[index], byTriggerID ); |
|
1100 } |
|
1101 else |
|
1102 { |
|
1103 // TODO: Log error message mentioning the trigger ID |
|
1104 InvalidateTrigger( ( *aIDs )[index] ); |
|
1105 } |
|
1106 } |
|
1107 } |
|
1108 } |
|
1109 |
|
1110 |
|
1111 // ----------------------------------------------------------------------------- |
|
1112 // CLbtTriggerView::CompareByID |
|
1113 // |
|
1114 // ----------------------------------------------------------------------------- |
|
1115 // |
|
1116 TInt CLbtTriggerView::CompareByID( const TLbtTriggerId& src, const TLbtTriggerId& dst ) |
|
1117 { |
|
1118 if( src > dst ) |
|
1119 { |
|
1120 return 1; |
|
1121 } |
|
1122 else if( src < dst ) |
|
1123 { |
|
1124 return -1; |
|
1125 } |
|
1126 return 0; |
|
1127 } |
|
1128 |
|
1129 |
|
1130 // ----------------------------------------------------------------------------- |
|
1131 // CLbtTriggerView::ListEnabledAndValidTriggersL |
|
1132 // |
|
1133 // ----------------------------------------------------------------------------- |
|
1134 // |
|
1135 void CLbtTriggerView::ListEnabledAndValidTriggersL() |
|
1136 { |
|
1137 FUNC_ENTER("CLbtTriggerView::ListEnabledAndValidTriggersL"); |
|
1138 |
|
1139 CLbtTriggerFilterByAttribute* filter = |
|
1140 CLbtTriggerFilterByAttribute::NewL(); |
|
1141 CleanupStack::PushL( filter ); |
|
1142 |
|
1143 filter->AddTriggerTypeL( CLbtTriggerEntry::ETypeSession ); |
|
1144 filter->AddTriggerTypeL( CLbtTriggerEntry::ETypeStartup ); |
|
1145 filter->AddTriggerStateL( CLbtTriggerEntry::EStateEnabled ); |
|
1146 filter->AddTriggerValidityL( TLbtTriggerDynamicInfo::EValid ); |
|
1147 |
|
1148 // Set fields to retrieve |
|
1149 TLbtTriggerDataMask dataMask = |
|
1150 CLbtContainerTriggerEntry::EContainerAttributeHysteresisRadius | |
|
1151 CLbtContainerTriggerEntry::EContainerAttributeRectTriggerArea | |
|
1152 CLbtContainerTriggerEntry::EContainerAttributeIsFired | |
|
1153 CLbtContainerTriggerEntry::EContainerAttributeStrategyData | |
|
1154 CLbtContainerTriggerEntry::EContainerAttributeIsTriggerFireOnCreation; |
|
1155 |
|
1156 |
|
1157 TLbtTriggerAttributeFieldsMask attribMask = CLbtTriggerEntry::EAttributeId | |
|
1158 CLbtTriggerEntry::EAttributeCondition | |
|
1159 CLbtTriggerEntry::EAttributeState | |
|
1160 CLbtTriggerEntry::EAttributeName; |
|
1161 |
|
1162 TLbtTriggerDynamicInfoFieldsMask dynInfoMask = |
|
1163 TLbtTriggerDynamicInfo::EValidityStatus; |
|
1164 |
|
1165 CLbtListTriggerOptions* listOpt = CLbtListTriggerOptions::NewL(); |
|
1166 listOpt->SetRetrievedFields( attribMask, dynInfoMask ); |
|
1167 listOpt->SetFilter( filter ); |
|
1168 CleanupStack::PushL( listOpt ); |
|
1169 |
|
1170 CLbtContainerListOptions* conOpt = CLbtContainerListOptions::NewL( |
|
1171 listOpt, NULL ); |
|
1172 conOpt->SetDataMask( dataMask ); |
|
1173 |
|
1174 CleanupStack::Pop(); // listOpt |
|
1175 CleanupStack::Pop(); // filter |
|
1176 |
|
1177 iTrgContainer->ListTriggers( conOpt, iList, iRequestID, iStatus ); |
|
1178 SetActive(); |
|
1179 } |
|
1180 |
|
1181 |
|
1182 |
|
1183 // ----------------------------------------------------------------------------- |
|
1184 // CLbtTriggerView::GetTriggers |
|
1185 // |
|
1186 // ----------------------------------------------------------------------------- |
|
1187 // |
|
1188 void CLbtTriggerView::GetTriggers( RArray< TLbtTriggerId >* aIDs ) |
|
1189 { |
|
1190 FUNC_ENTER("CLbtTriggerView::GetTriggers"); |
|
1191 iTrgContainer->GetTriggers( *aIDs, |
|
1192 iList, |
|
1193 iRequestID, |
|
1194 iStatus ); |
|
1195 SetActive(); |
|
1196 } |
|
1197 |
|
1198 |
|
1199 // ----------------------------------------------------------------------------- |
|
1200 // CLbtTriggerView::AddToTreeL |
|
1201 // |
|
1202 // ----------------------------------------------------------------------------- |
|
1203 // |
|
1204 void CLbtTriggerView::AddToTreeL( TLbtTriggerId aKey, |
|
1205 CLbtContainerTriggerEntry* aEntry ) |
|
1206 { |
|
1207 FUNC_ENTER("CLbtTriggerView::AddToTreeL"); |
|
1208 TBtreePos pos; |
|
1209 TTrigger tEntry; |
|
1210 tEntry.info = aEntry; |
|
1211 tEntry.key = aKey; |
|
1212 |
|
1213 CLbtTriggerEntry* trgEntry = aEntry->TriggerEntry(); |
|
1214 CLbtTriggerConditionBase* conditionBase = trgEntry->GetCondition(); |
|
1215 CLbtTriggerConditionArea* conditionArea = |
|
1216 static_cast< CLbtTriggerConditionArea* >( conditionBase ); |
|
1217 CLbtGeoAreaBase* areaBase = conditionArea->TriggerArea(); |
|
1218 |
|
1219 tEntry.type = areaBase->Type(); |
|
1220 tEntry.validity = ETrue; |
|
1221 |
|
1222 iTriggerList->InsertL( pos, tEntry ); |
|
1223 |
|
1224 if( CLbtGeoAreaBase::ECellular == tEntry.type ) |
|
1225 { |
|
1226 ++iCellTriggerCount; |
|
1227 } |
|
1228 else if( CLbtGeoAreaBase::ECircle == tEntry.type ) |
|
1229 { |
|
1230 ++iCoordTriggerCount; |
|
1231 } |
|
1232 else if( CLbtGeoAreaBase::EHybrid == tEntry.type ) |
|
1233 { |
|
1234 CLbtGeoHybrid* hybridArea = static_cast<CLbtGeoHybrid*> ( areaBase ); |
|
1235 RPointerArray<CLbtGeoAreaBase> hybridAreaArray = hybridArea->HybridArea(); |
|
1236 |
|
1237 if( hybridAreaArray.Count() ) |
|
1238 { |
|
1239 // Since hybrid area can hold similar area types, it is enough to |
|
1240 // check the first element in the array |
|
1241 if( hybridAreaArray[0]->Type() == CLbtGeoAreaBase::ECircle ) |
|
1242 { |
|
1243 ++iCoordTriggerCount; |
|
1244 } |
|
1245 else if( hybridAreaArray[0]->Type() == CLbtGeoAreaBase::ECellular ) |
|
1246 { |
|
1247 ++iCellTriggerCount; |
|
1248 } |
|
1249 } |
|
1250 } |
|
1251 } |
|
1252 |
|
1253 |
|
1254 // ----------------------------------------------------------------------------- |
|
1255 // CLbtTriggerView::FindInTreeL |
|
1256 // |
|
1257 // ----------------------------------------------------------------------------- |
|
1258 // |
|
1259 TBool CLbtTriggerView::FindInTreeL( TLbtTriggerId aKey, TTrigger& aEntry ) |
|
1260 { |
|
1261 FUNC_ENTER("CLbtTriggerView::FindInTreeL"); |
|
1262 TBtreePos pos; |
|
1263 TBool found = EFalse; |
|
1264 found = iTriggerList->FindL( pos, aKey ); |
|
1265 if( found ) |
|
1266 { |
|
1267 iTriggerList->ExtractAtL( pos, aEntry ); |
|
1268 } |
|
1269 return found; |
|
1270 } |
|
1271 |
|
1272 // ----------------------------------------------------------------------------- |
|
1273 // CLbtTriggerView::DeleteFromTreeL |
|
1274 // |
|
1275 // ----------------------------------------------------------------------------- |
|
1276 // |
|
1277 TBool CLbtTriggerView::DeleteFromTreeL( TLbtTriggerId aKey ) |
|
1278 { |
|
1279 FUNC_ENTER("CLbtTriggerView::DeleteFromTreeL"); |
|
1280 TBtreePos pos; |
|
1281 TBool found = EFalse; |
|
1282 found = iTriggerList->FindL( pos, aKey ); |
|
1283 if( found ) |
|
1284 { |
|
1285 TTrigger tEntry; |
|
1286 iTriggerList->ExtractAtL( pos, tEntry ); |
|
1287 |
|
1288 if( CLbtGeoAreaBase::ECellular == tEntry.type && iCellTriggerCount != 0 ) |
|
1289 { |
|
1290 --iCellTriggerCount; |
|
1291 } |
|
1292 else if( CLbtGeoAreaBase::ECircle == tEntry.type && iCoordTriggerCount != 0 ) |
|
1293 { |
|
1294 --iCoordTriggerCount; |
|
1295 } |
|
1296 else if( CLbtGeoAreaBase::EHybrid == tEntry.type ) |
|
1297 { |
|
1298 CLbtTriggerEntry* trgEntry = tEntry.info->TriggerEntry(); |
|
1299 CLbtTriggerConditionBase* conditionBase = trgEntry->GetCondition(); |
|
1300 CLbtTriggerConditionArea* conditionArea = |
|
1301 static_cast< CLbtTriggerConditionArea* >( conditionBase ); |
|
1302 CLbtGeoAreaBase* areaBase = conditionArea->TriggerArea(); |
|
1303 |
|
1304 CLbtGeoHybrid* hybridArea = static_cast<CLbtGeoHybrid*> ( areaBase ); |
|
1305 RPointerArray<CLbtGeoAreaBase> hybridAreaArray = hybridArea->HybridArea(); |
|
1306 |
|
1307 if( hybridAreaArray.Count() ) |
|
1308 { |
|
1309 // Since hybrid area can hold similar area types, it is enough to |
|
1310 // check the first element in the array |
|
1311 if( hybridAreaArray[0]->Type() == CLbtGeoAreaBase::ECircle && iCoordTriggerCount != 0) |
|
1312 { |
|
1313 --iCoordTriggerCount; |
|
1314 } |
|
1315 else if( hybridAreaArray[0]->Type() == CLbtGeoAreaBase::ECellular && iCellTriggerCount != 0 ) |
|
1316 { |
|
1317 --iCellTriggerCount; |
|
1318 } |
|
1319 } |
|
1320 } |
|
1321 delete tEntry.info; |
|
1322 iTriggerList->DeleteL( aKey ); |
|
1323 } |
|
1324 return found; |
|
1325 } |
|
1326 |
|
1327 |
|
1328 // ----------------------------------------------------------------------------- |
|
1329 // CLbtTriggerView::SetEvent |
|
1330 // |
|
1331 // ----------------------------------------------------------------------------- |
|
1332 // |
|
1333 void CLbtTriggerView::SetEvent() |
|
1334 { |
|
1335 FUNC_ENTER("CLbtTriggerView::SetEvent"); |
|
1336 if ( !IsActive() ) |
|
1337 { |
|
1338 TRequestStatus* lStatus = &iStatus; |
|
1339 User::RequestComplete( lStatus, KErrNone ); |
|
1340 LOG("Calling Set Active !!"); |
|
1341 SetActive(); |
|
1342 } |
|
1343 } |
|
1344 |
|
1345 |
|
1346 // ----------------------------------------------------------------------------- |
|
1347 // CLbtTriggerView::RunL |
|
1348 // |
|
1349 // ----------------------------------------------------------------------------- |
|
1350 // |
|
1351 void CLbtTriggerView::RunL() |
|
1352 { |
|
1353 FUNC_ENTER("CLbtTriggerView::RunL"); |
|
1354 if( KErrNone != iStatus.Int() ) |
|
1355 { |
|
1356 // TODO: Log error here |
|
1357 // TODO: Check if error needs to be reported through the |
|
1358 // observer interface |
|
1359 } |
|
1360 |
|
1361 switch( iState ) |
|
1362 { |
|
1363 |
|
1364 case EInitialize: |
|
1365 InitializeList(); |
|
1366 break; |
|
1367 |
|
1368 case ERefreshView: |
|
1369 ProcessRefreshRequests(); |
|
1370 break; |
|
1371 |
|
1372 case ERefreshContainer: |
|
1373 ProcessUpdateRequests(); |
|
1374 break; |
|
1375 |
|
1376 default: |
|
1377 break; |
|
1378 |
|
1379 } |
|
1380 } |
|
1381 |
|
1382 |
|
1383 // ----------------------------------------------------------------------------- |
|
1384 // CLbtTriggerView::DoCancel |
|
1385 // |
|
1386 // ----------------------------------------------------------------------------- |
|
1387 // |
|
1388 void CLbtTriggerView::DoCancel() |
|
1389 { |
|
1390 FUNC_ENTER("CLbtTriggerView::DoCancel"); |
|
1391 if( IsActive() ) |
|
1392 { |
|
1393 iTrgContainer->CancelAsyncOperation( iRequestID ); |
|
1394 } |
|
1395 |
|
1396 // Reset the state the idle |
|
1397 iState = EIdle; |
|
1398 } |
|
1399 |
|
1400 // end of file |
|
1401 |