|
1 /* |
|
2 * Copyright (c) 2005 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: location triggering server client interface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <lbtstartuptrigger.h> |
|
22 #include "lbtcontainerao.h" |
|
23 #include "lbtlisttriggerobserver.h" |
|
24 #include "lbtupdateasyncoperation.h" |
|
25 #include "lbtlistasyncoperation.h" |
|
26 #include "lbtdeleteasyncoperation.h" |
|
27 #include "lbtcreateasyncoperation.h" |
|
28 #include "lbtdbtriggersmanager.h" |
|
29 #include "lbtramtriggersmanager.h" |
|
30 #include "lbttriggerchangeobserver.h" |
|
31 #include "lbtcontainer.h" |
|
32 #include "lbttriggerconditionarea.h" |
|
33 #include "lbttriggerstoreinterface.h" |
|
34 #include "lbtcontainerextendedtriggerinfo.h" |
|
35 #include "lbtlogger.h" |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 // ================= LOCAL FUNCTIONS ======================== |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // ------------------------------------------------------------------ |
|
46 // C++ default constructor can NOT contain any code, that |
|
47 // might leave. |
|
48 // ------------------------------------------------------------------ |
|
49 // |
|
50 |
|
51 CLbtContainerAO::CLbtContainerAO(RPointerArray<MLbtTriggerStore>& aTriggerStores, |
|
52 RArray<CLbtContainer::TLbtTriggerStoreChangeObserver>& aObservers ): |
|
53 CActive(EPriorityStandard), |
|
54 iClientStatus(NULL), |
|
55 iAsyncRequest(EOpNone), |
|
56 iTriggerStores(aTriggerStores), |
|
57 iTriggerStoreCtr (0), |
|
58 iObservers(aObservers) |
|
59 |
|
60 { |
|
61 CActiveScheduler::Add(this); |
|
62 } |
|
63 |
|
64 |
|
65 // ------------------------------------------------------------------ |
|
66 // CLbtContainerAO::ConstructL. |
|
67 // ------------------------------------------------------------------ |
|
68 // |
|
69 void CLbtContainerAO::ConstructL() |
|
70 { |
|
71 for(TInt i=0;i<iTriggerStores.Count();++i) |
|
72 { |
|
73 iTriggerStores[i]->SetStoreChangeObserver(this); |
|
74 } |
|
75 } |
|
76 |
|
77 |
|
78 // ------------------------------------------------------------------ |
|
79 // CLbtContainerAO::NewL |
|
80 // ------------------------------------------------------------------ |
|
81 // |
|
82 CLbtContainerAO* CLbtContainerAO::NewL(RPointerArray<MLbtTriggerStore>& aTriggerStores, |
|
83 RArray<CLbtContainer::TLbtTriggerStoreChangeObserver>& aObservers ) |
|
84 { |
|
85 FUNC_ENTER("CLbtContainerAO::NewL"); |
|
86 CLbtContainerAO* self = new (ELeave) CLbtContainerAO(aTriggerStores,aObservers); |
|
87 CleanupStack::PushL(self); |
|
88 self->ConstructL(); |
|
89 CleanupStack::Pop(self); |
|
90 return self; |
|
91 } |
|
92 |
|
93 |
|
94 // ------------------------------------------------------------------ |
|
95 // CLbtContainerAO::~CLbtContainerAO |
|
96 // ------------------------------------------------------------------ |
|
97 // |
|
98 CLbtContainerAO::~CLbtContainerAO() |
|
99 { |
|
100 FUNC_ENTER("CLbtContainerAO::~CLbtContainerAO"); |
|
101 if(IsActive()) |
|
102 { |
|
103 Cancel(); |
|
104 } |
|
105 iAsyncOpQueue.ResetAndDestroy(); |
|
106 } |
|
107 |
|
108 // ------------------------------------------------------------------ |
|
109 // CLbtContainerAO::AddAsyncOpToQueue |
|
110 // ------------------------------------------------------------------ |
|
111 // |
|
112 void CLbtContainerAO::AddAsyncOpToQueue( CLbtContainerAOOperation* aAsyncOp) |
|
113 { |
|
114 FUNC_ENTER("CLbtContainerAO::AddAsyncOpToQueue"); |
|
115 // Append to the queue of asynchronous requests. |
|
116 if(aAsyncOp) |
|
117 { |
|
118 iAsyncOpQueue.Append(aAsyncOp); |
|
119 // if AO is not active, start serving the current request. |
|
120 StartNextAsyncOperation(); |
|
121 } |
|
122 } |
|
123 |
|
124 // ------------------------------------------------------------------ |
|
125 // CLbtContainerAO::StartNextAsyncOperation |
|
126 // ------------------------------------------------------------------ |
|
127 // |
|
128 void CLbtContainerAO::StartNextAsyncOperation() |
|
129 { |
|
130 FUNC_ENTER("CLbtContainerAO::StartNextAsyncOperation"); |
|
131 // Check if any of the trigger stores are busy |
|
132 for(TInt i=0;i<iTriggerStores.Count();++i) |
|
133 { |
|
134 if(iTriggerStores[i]->IsStoreBusy()) |
|
135 { |
|
136 return; |
|
137 } |
|
138 } |
|
139 |
|
140 if(!IsActive()) |
|
141 { |
|
142 if(iTriggerStores.Count() > 0) |
|
143 { |
|
144 iTriggerStoreCtr = -1; |
|
145 iAsyncOpQueue[0]->SetPrevReturnCode(KErrNotReady); |
|
146 iAsyncOpQueue[0]->SetCurrentReturnCode(KErrNotReady); |
|
147 iAsyncRequest = iAsyncOpQueue[0]->GetAOOperationType(); |
|
148 } |
|
149 else |
|
150 { |
|
151 TRequestStatus* status = iAsyncOpQueue[0]->GetStatus(); |
|
152 User::RequestComplete(status,KErrNotSupported); |
|
153 return; |
|
154 } |
|
155 iStatus = KRequestPending; |
|
156 TRequestStatus* status = &iStatus; |
|
157 SetActive(); |
|
158 /* Do a Self Complete so that the RunL() gets scheduled */ |
|
159 User::RequestComplete(status,KErrNone); |
|
160 } |
|
161 } |
|
162 |
|
163 // ------------------------------------------------------------------ |
|
164 // CLbtContainerAO::GetTriggersL |
|
165 // ------------------------------------------------------------------ |
|
166 // |
|
167 void CLbtContainerAO::GetTriggersL( const RArray<TLbtTriggerId>& aTriggerIds, |
|
168 RPointerArray < CLbtContainerTriggerEntry >& aTriggers, |
|
169 TInt& aOpId, |
|
170 TRequestStatus& aStatus, |
|
171 TLbtSecurityPolicy aSecurityPolicy ) |
|
172 { |
|
173 FUNC_ENTER("CLbtContainerAO::GetTriggers"); |
|
174 CLbtListAsyncOperation* listop = CLbtListAsyncOperation::NewL( aTriggerIds, |
|
175 aTriggers, |
|
176 aSecurityPolicy, |
|
177 aStatus); |
|
178 listop->SetOpCode( aOpId ); |
|
179 AddAsyncOpToQueue( listop ); |
|
180 } |
|
181 |
|
182 // ------------------------------------------------------------------ |
|
183 // CLbtContainerAO::ListTriggersL |
|
184 // ------------------------------------------------------------------ |
|
185 // |
|
186 void CLbtContainerAO::ListTriggersL( CLbtContainerListOptions* aFilter, |
|
187 RPointerArray < CLbtContainerTriggerEntry >& aTriggers, |
|
188 TInt aOpCode, |
|
189 TRequestStatus& aStatus, |
|
190 TLbtSecurityPolicy aSecurityPolicy ) |
|
191 { |
|
192 FUNC_ENTER("CLbtContainerAO::ListTriggersL"); |
|
193 iSortingOption = aFilter->ListOptions()->SortingOption(); |
|
194 CLbtListAsyncOperation* listop = CLbtListAsyncOperation::NewL( aFilter, |
|
195 aTriggers, |
|
196 aSecurityPolicy, |
|
197 aStatus); |
|
198 listop->SetOpCode(aOpCode); |
|
199 AddAsyncOpToQueue(listop); |
|
200 } |
|
201 |
|
202 // ------------------------------------------------------------------ |
|
203 // CLbtContainerAO::UpdateTriggerL |
|
204 // ------------------------------------------------------------------ |
|
205 // |
|
206 void CLbtContainerAO::UpdateTriggerL( CLbtContainerTriggerEntry& aEntry, |
|
207 TLbtTriggerDataMask aDataMask, |
|
208 TLbtTriggerAttributeFieldsMask aAttrMask, |
|
209 TInt aOpCode, |
|
210 TRequestStatus& aStatus, |
|
211 TLbtSecurityPolicy aSecurityPolicy ) |
|
212 { |
|
213 FUNC_ENTER("CLbtContainerAO::UpdateTriggerL"); |
|
214 iDataMask = aDataMask; |
|
215 iAttrMask = aAttrMask; |
|
216 CLbtUpdateAsyncOperation* updateop = CLbtUpdateAsyncOperation::NewL( aEntry, |
|
217 aDataMask, |
|
218 aAttrMask, |
|
219 aStatus, |
|
220 aSecurityPolicy, |
|
221 EOpUpdateTrigger); |
|
222 updateop->SetOpCode(aOpCode); |
|
223 AddAsyncOpToQueue(updateop); |
|
224 } |
|
225 |
|
226 // ------------------------------------------------------------------ |
|
227 // CLbtContainerAO::UpdateTriggerL |
|
228 // ------------------------------------------------------------------ |
|
229 // |
|
230 void CLbtContainerAO::UpdateTriggerFiredStateL( RArray<TLbtTriggerId>& aTriggerIds, |
|
231 TBool aFireBool, |
|
232 TInt aOpCode, |
|
233 TRequestStatus& aStatus ) |
|
234 { |
|
235 FUNC_ENTER("CLbtContainerAO::UpdateTriggerL - Filter"); |
|
236 aStatus = KRequestPending; |
|
237 CLbtUpdateAsyncOperation* updateop = CLbtUpdateAsyncOperation::NewL( aTriggerIds, |
|
238 aStatus, |
|
239 aFireBool, |
|
240 KLbtNullSecurity, |
|
241 EOpUpdateTriggersFiredState ); |
|
242 updateop->SetOpCode(aOpCode); |
|
243 AddAsyncOpToQueue(updateop); |
|
244 } |
|
245 |
|
246 // ------------------------------------------------------------------ |
|
247 // CLbtContainerAO::UpdateTriggersStateL |
|
248 // ------------------------------------------------------------------ |
|
249 // |
|
250 void CLbtContainerAO::UpdateTriggersStateL( CLbtTriggerEntry::TLbtTriggerState aState, |
|
251 CLbtContainerUpdateFilter* aFilter, |
|
252 TInt aOpCode, |
|
253 TLbtFireOnUpdate aFireOnUpdate, |
|
254 TRequestStatus& aStatus, |
|
255 TLbtSecurityPolicy aSecurityPolicy ) |
|
256 { |
|
257 FUNC_ENTER("CLbtContainerAO::UpdateTriggersStateL"); |
|
258 aStatus = KRequestPending; |
|
259 CLbtUpdateAsyncOperation* updateop = CLbtUpdateAsyncOperation::NewL( aState, |
|
260 aFilter, |
|
261 aFireOnUpdate, |
|
262 aStatus, |
|
263 aSecurityPolicy, |
|
264 EOpUpdateTriggerState); |
|
265 updateop->SetOpCode(aOpCode); |
|
266 AddAsyncOpToQueue(updateop); |
|
267 } |
|
268 |
|
269 |
|
270 // ------------------------------------------------------------------ |
|
271 // CLbtContainerAO::UpdateTriggersValidityL |
|
272 // ------------------------------------------------------------------ |
|
273 // |
|
274 void CLbtContainerAO::UpdateTriggersValidityL( TLbtTriggerDynamicInfo::TLbtTriggerValidity aValidity, |
|
275 RArray <TLbtTriggerId>& aTriggerIds, |
|
276 TInt aOpCode, |
|
277 TRequestStatus& aStatus, |
|
278 TLbtSecurityPolicy aSecurityPolicy ) |
|
279 |
|
280 { |
|
281 FUNC_ENTER("CLbtContainerAO::UpdateTriggersValidityL"); |
|
282 CLbtUpdateAsyncOperation* updateop = CLbtUpdateAsyncOperation::NewL( aValidity, |
|
283 aTriggerIds, |
|
284 aStatus, |
|
285 aSecurityPolicy, |
|
286 EOpUpdateTriggersValidity); |
|
287 updateop->SetOpCode(aOpCode); |
|
288 AddAsyncOpToQueue(updateop); |
|
289 } |
|
290 |
|
291 |
|
292 // ------------------------------------------------------------------ |
|
293 // CLbtContainerAO::DeleteTriggersL |
|
294 // ------------------------------------------------------------------ |
|
295 // |
|
296 void CLbtContainerAO::DeleteTriggersL( CLbtContainerUpdateFilter* aFilter, |
|
297 TInt aOpCode, |
|
298 TRequestStatus& aStatus, |
|
299 TLbtSecurityPolicy aSecurityPolicy ) |
|
300 { |
|
301 FUNC_ENTER("CLbtContainerAO::DeleteTriggersL"); |
|
302 CLbtDeleteAsyncOperation* deleteop = CLbtDeleteAsyncOperation::NewL(aFilter, aStatus, aSecurityPolicy); |
|
303 deleteop->SetOpCode(aOpCode); |
|
304 AddAsyncOpToQueue(deleteop); |
|
305 } |
|
306 |
|
307 // ------------------------------------------------------------------ |
|
308 // CLbtContainerAO::CreateTriggerL |
|
309 // ------------------------------------------------------------------ |
|
310 // |
|
311 void CLbtContainerAO::CreateTriggerL(CLbtContainerTriggerEntry* aEntry,TInt aOpCode,TRequestStatus& aStatus) |
|
312 { |
|
313 FUNC_ENTER("CLbtContainerAO::CreateTriggerL"); |
|
314 CLbtCreateAsyncOperation* createop = CLbtCreateAsyncOperation::NewL(aEntry,aStatus); |
|
315 createop->SetOpCode(aOpCode); |
|
316 AddAsyncOpToQueue(createop); |
|
317 } |
|
318 |
|
319 // --------------------------------------------------------- |
|
320 // CLbtContainerAO::RunL |
|
321 // |
|
322 // (other items were commented in a header). |
|
323 // --------------------------------------------------------- |
|
324 // |
|
325 void CLbtContainerAO::RunL() |
|
326 { |
|
327 FUNC_ENTER("CLbtContainerAO::RunL"); |
|
328 TInt error=iStatus.Int(); |
|
329 |
|
330 if( error == KErrCancel ) |
|
331 { |
|
332 if( iAsyncOpQueue.Count() > 0 ) |
|
333 { |
|
334 StartNextAsyncOperation(); |
|
335 } |
|
336 return; |
|
337 } |
|
338 |
|
339 if(iTriggerStoreCtr < iTriggerStores.Count() - 1) |
|
340 { |
|
341 iTriggerStoreCtr++; |
|
342 if(iTriggerStoreCtr == 0) |
|
343 { |
|
344 iAsyncOpQueue[0]->StartAOOperationL( iTriggerStores[iTriggerStoreCtr],iStatus); |
|
345 SetActive(); |
|
346 } |
|
347 else if(iTriggerStoreCtr == 1) |
|
348 { |
|
349 if(error == KErrNone || error == KErrNotFound) |
|
350 { |
|
351 iAsyncOpQueue[0]->SetCurrentReturnCode(error); |
|
352 iAsyncOpQueue[0]->StartAOOperationL( iTriggerStores[iTriggerStoreCtr],iStatus); |
|
353 SetActive(); |
|
354 } |
|
355 else |
|
356 { |
|
357 CompleteAsyncRequest(error); |
|
358 if(iAsyncOpQueue.Count()>0) |
|
359 { |
|
360 StartNextAsyncOperation(); |
|
361 } |
|
362 } |
|
363 } |
|
364 else if(iTriggerStoreCtr>1) |
|
365 { |
|
366 TInt prevError = iAsyncOpQueue[0]->GetPrevReturnCode(); |
|
367 TInt currError = iAsyncOpQueue[0]->GetCurrentReturnCode(); |
|
368 |
|
369 /* if previous error is KErrNotFound and current is KErrNone |
|
370 * then make previous as KErrNone |
|
371 * else if prev is KErrNone, that means that the operation has |
|
372 * succeeded in atleast one trigger store so, |
|
373 * let the prev code remain KErrNone |
|
374 * even if the currErr is KErrNotFound |
|
375 */ |
|
376 if((prevError == KErrNotFound || prevError == KErrNotReady) && (currError == KErrNone || currError == KErrNotReady)) |
|
377 { |
|
378 iAsyncOpQueue[0]->SetPrevReturnCode(currError); |
|
379 } |
|
380 |
|
381 /* Now once the prev code is modified, set the current code |
|
382 * to the one this operation returned. |
|
383 */ |
|
384 |
|
385 iAsyncOpQueue[0]->SetCurrentReturnCode(error); |
|
386 TInt prevCode,currCode; |
|
387 prevCode = iAsyncOpQueue[0]->GetCurrentReturnCode(); |
|
388 currCode = iAsyncOpQueue[0]->GetPrevReturnCode(); |
|
389 |
|
390 /* Start the operation with the next trigger store only if |
|
391 * both the prevCode and CurrCode are KErrNone or KErrNotFound |
|
392 * else complete the request with the error code |
|
393 */ |
|
394 if(((prevCode == KErrNotFound) ||( prevCode == KErrNone) || (prevCode == KErrNotReady))&&(currCode == KErrNotFound || currCode == KErrNone)) |
|
395 { |
|
396 if(iTriggerStoreCtr<iTriggerStores.Count()) |
|
397 { |
|
398 iAsyncOpQueue[0]->StartAOOperationL( iTriggerStores[iTriggerStoreCtr],iStatus); |
|
399 SetActive(); |
|
400 } |
|
401 else |
|
402 { |
|
403 CompleteAsyncRequest(currCode); |
|
404 if(iAsyncOpQueue.Count()>0) |
|
405 { |
|
406 StartNextAsyncOperation(); |
|
407 } |
|
408 } |
|
409 |
|
410 } |
|
411 else |
|
412 { |
|
413 CompleteAsyncRequest(currCode); |
|
414 if(iAsyncOpQueue.Count()>0) |
|
415 { |
|
416 StartNextAsyncOperation(); |
|
417 } |
|
418 } |
|
419 } |
|
420 } |
|
421 else |
|
422 { |
|
423 TInt prevCode = iAsyncOpQueue[0]->GetPrevReturnCode(); |
|
424 TInt currCode = iAsyncOpQueue[0]->GetCurrentReturnCode(); |
|
425 |
|
426 if(prevCode == KErrNone || currCode == KErrNone || error == KErrNone) |
|
427 { |
|
428 CompleteAsyncRequest(KErrNone); |
|
429 } |
|
430 else |
|
431 { |
|
432 CompleteAsyncRequest(error); |
|
433 } |
|
434 |
|
435 if(iAsyncOpQueue.Count()>0) |
|
436 { |
|
437 StartNextAsyncOperation(); |
|
438 } |
|
439 } |
|
440 } |
|
441 |
|
442 // ------------------------------------------------------------------ |
|
443 // CLbtContainerAO::CompleteAsyncRequest |
|
444 // ------------------------------------------------------------------ |
|
445 // |
|
446 void CLbtContainerAO::CompleteAsyncRequest(TInt aErr) |
|
447 { |
|
448 FUNC_ENTER("CLbtContainerAO::CompleteAsyncRequest"); |
|
449 CLbtContainerAOOperation* asyncObjPtr = iAsyncOpQueue[0]; |
|
450 |
|
451 if( (iAsyncRequest == EOpCreateTrigger) && |
|
452 (aErr == KErrNone) ) |
|
453 { |
|
454 CLbtCreateAsyncOperation* createop = static_cast <CLbtCreateAsyncOperation*> (asyncObjPtr); |
|
455 |
|
456 RArray<TLbtTriggerId> triggerIds; |
|
457 CLbtContainerTriggerEntry* entry = const_cast<CLbtContainerTriggerEntry*>(createop->ContainerTriggerEntry()); |
|
458 triggerIds.Append(entry->TriggerEntry()->Id()); |
|
459 |
|
460 |
|
461 TLbtTriggerEventMask eventMask; |
|
462 |
|
463 // Append the manager uids and owner uids into the array |
|
464 RArray<TUid> managerui; |
|
465 managerui.Append( entry->TriggerEntry()->ManagerUi() ); |
|
466 |
|
467 TUid ownerUid; |
|
468 ownerUid.iUid = (TInt)( entry->ExtendedTriggerInfo()->OwnerSid().iId); |
|
469 managerui.Append( ownerUid ); |
|
470 |
|
471 if( entry->TriggerEntry()->Type() == CLbtTriggerEntry::ETypeStartup ) |
|
472 { |
|
473 CLbtStartupTrigger* startupTrigger = static_cast<CLbtStartupTrigger*>(entry->TriggerEntry()); |
|
474 TSecureId secureId; |
|
475 TBuf16<KMaxFileName> fileName; |
|
476 startupTrigger->GetProcessId(fileName, secureId); |
|
477 TUid startupUid; |
|
478 startupUid.iUid = (TInt)(secureId.iId); |
|
479 |
|
480 if( startupUid != KNullUid ) |
|
481 { |
|
482 managerui.Append( startupUid ); |
|
483 } |
|
484 } |
|
485 |
|
486 // Give the observer callback through interface |
|
487 for( TInt i = 0; i<iObservers.Count(); i++ ) |
|
488 { |
|
489 TInt isRequested = EFalse; |
|
490 ProcessFilter(isRequested,iObservers[i].iEventMask,eventMask); |
|
491 if(isRequested) |
|
492 { |
|
493 MLbtContainerChangeEventObserver::TLbtContainerChangedAreaType changeType = |
|
494 MLbtContainerChangeEventObserver::ETypeUnKnown; |
|
495 const CLbtTriggerConditionArea* conditionBase = |
|
496 static_cast<const CLbtTriggerConditionArea*>(entry->TriggerEntry()->GetCondition()); |
|
497 if(conditionBase) |
|
498 { |
|
499 CLbtGeoAreaBase* areaBase = conditionBase->TriggerArea(); |
|
500 |
|
501 if(areaBase) |
|
502 { |
|
503 CLbtGeoAreaBase::TGeoAreaType areaType = areaBase->Type(); |
|
504 |
|
505 if(areaType == CLbtGeoAreaBase::ECircle) |
|
506 { |
|
507 changeType = MLbtContainerChangeEventObserver::ETypeCircularTriggerChange; |
|
508 } |
|
509 else if(areaType == CLbtGeoAreaBase::ECellular) |
|
510 { |
|
511 changeType = MLbtContainerChangeEventObserver::ETypeCellularTriggerChange; |
|
512 } |
|
513 else |
|
514 { |
|
515 changeType = MLbtContainerChangeEventObserver::ETypeRectangularTriggerChange; |
|
516 } |
|
517 } |
|
518 } |
|
519 |
|
520 //Ownership of triggersModified array is transferred to the client |
|
521 iObservers[i].iObserver->TriggerStoreChanged(triggerIds, CLbtContainer::ELbtConTriggerCreated, changeType, managerui); |
|
522 triggerIds.Reset(); |
|
523 } |
|
524 } |
|
525 triggerIds.Close(); |
|
526 managerui.Close(); |
|
527 } |
|
528 |
|
529 if( EOpListTriggers == iAsyncRequest ) |
|
530 { |
|
531 if( aErr == KErrNone) |
|
532 { |
|
533 RPointerArray<CLbtContainerTriggerEntry>* triggers = NULL; |
|
534 CLbtListAsyncOperation* listAsync = static_cast<CLbtListAsyncOperation*> (asyncObjPtr); |
|
535 triggers = listAsync->GetTriggerList(); |
|
536 |
|
537 // sort the list using sorting options |
|
538 if( triggers ) |
|
539 { |
|
540 SortTriggers(*triggers); |
|
541 } |
|
542 } |
|
543 else |
|
544 { |
|
545 CLbtListAsyncOperation* listOp = static_cast<CLbtListAsyncOperation*>(asyncObjPtr); |
|
546 RPointerArray<CLbtContainerTriggerEntry>* triggers = listOp->GetTriggerList(); |
|
547 triggers->ResetAndDestroy(); |
|
548 } |
|
549 } |
|
550 |
|
551 // Now,notify the trigger store change observers. |
|
552 if( EOpListTriggers != iAsyncRequest && |
|
553 EOpCreateTrigger != iAsyncRequest ) |
|
554 { |
|
555 NotifyListeners(); |
|
556 } |
|
557 |
|
558 TRequestStatus* status = asyncObjPtr->GetStatus(); |
|
559 // Sorting is completed,complete the client request. |
|
560 User::RequestComplete(status,aErr); |
|
561 |
|
562 iAsyncOpQueue.Remove(0); |
|
563 iAsyncRequest = EOpNone; |
|
564 delete asyncObjPtr; |
|
565 } |
|
566 |
|
567 // --------------------------------------------------------- |
|
568 // CLbtContainerAO::RunError |
|
569 // |
|
570 // (other items were commented in a header). |
|
571 // --------------------------------------------------------- |
|
572 // |
|
573 TInt CLbtContainerAO::RunError(TInt /*aError*/) |
|
574 { |
|
575 FUNC_ENTER("CLbtContainerAO::RunError"); |
|
576 return KErrNone; |
|
577 } |
|
578 |
|
579 // --------------------------------------------------------- |
|
580 // CLbtContainerAO::DoCancel |
|
581 // |
|
582 // (other items were commented in a header). |
|
583 // --------------------------------------------------------- |
|
584 // |
|
585 void CLbtContainerAO::DoCancel() |
|
586 { |
|
587 FUNC_ENTER("CLbtContainerAO::DoCancel"); |
|
588 CLbtContainerAOOperation* cancelObj = iAsyncOpQueue[0]; |
|
589 // Cancel current operation of trigger store |
|
590 |
|
591 TInt error = KErrCancel; |
|
592 if( iTriggerStoreCtr!= -1 ) |
|
593 { |
|
594 error = iTriggerStores[iTriggerStoreCtr]->CancelCurrentOperation(); |
|
595 } |
|
596 CompleteAsyncRequest( error ); |
|
597 if(iAsyncOpQueue.Count()>0) |
|
598 { |
|
599 StartNextAsyncOperation(); |
|
600 } |
|
601 } |
|
602 |
|
603 // --------------------------------------------------------- |
|
604 // CLbtContainerAO::NotifyListeners |
|
605 // |
|
606 // (other items were commented in a header). |
|
607 // --------------------------------------------------------- |
|
608 // |
|
609 void CLbtContainerAO::NotifyListeners() |
|
610 { |
|
611 FUNC_ENTER("CLbtContainerAO::NotifyListeners"); |
|
612 TLbtTriggerEventMask eventMask; |
|
613 |
|
614 CLbtRamTriggersManager* ramTriggerMgr = NULL; |
|
615 CLbtDbTriggersManager* dbTriggerMgr = NULL; |
|
616 |
|
617 RArray<MLbtTriggerStore::TLbtTriggerModifiedInfo> triggerInfoArray; |
|
618 |
|
619 // Get the list of triggers which were modified for a given operation |
|
620 for( TInt i = 0; i<iTriggerStores.Count(); i++ ) |
|
621 { |
|
622 if( CLbtTriggerEntry::ETypeSession == iTriggerStores[i]->SupportedTriggerTypes() ) |
|
623 { |
|
624 ramTriggerMgr = static_cast<CLbtRamTriggersManager*> (iTriggerStores[i]); |
|
625 ramTriggerMgr->TriggersModified(triggerInfoArray); |
|
626 } |
|
627 else if( CLbtTriggerEntry::ETypeStartup == iTriggerStores[i]->SupportedTriggerTypes() ) |
|
628 { |
|
629 dbTriggerMgr = static_cast<CLbtDbTriggersManager*> (iTriggerStores[i]); |
|
630 dbTriggerMgr->TriggersModified(triggerInfoArray); |
|
631 } |
|
632 } |
|
633 |
|
634 if(triggerInfoArray.Count() <= 0) |
|
635 { |
|
636 triggerInfoArray.Close(); |
|
637 // If no triggers are modified then no notification required |
|
638 return; |
|
639 } |
|
640 |
|
641 TInt changedAreaType = MLbtContainerChangeEventObserver::ETypeUnKnown; |
|
642 for(TInt i=0;i<triggerInfoArray.Count();++i) |
|
643 { |
|
644 if(triggerInfoArray[i].iAreaType == CLbtGeoAreaBase::ECircle) |
|
645 { |
|
646 changedAreaType = changedAreaType | MLbtContainerChangeEventObserver::ETypeCircularTriggerChange; |
|
647 } |
|
648 else if(triggerInfoArray[i].iAreaType == CLbtGeoAreaBase::ECellular) |
|
649 { |
|
650 changedAreaType = changedAreaType | MLbtContainerChangeEventObserver::ETypeCellularTriggerChange; |
|
651 } |
|
652 else if(triggerInfoArray[i].iAreaType == CLbtGeoAreaBase::ERectangular) |
|
653 { |
|
654 changedAreaType = changedAreaType | MLbtContainerChangeEventObserver::ETypeRectangularTriggerChange; |
|
655 } |
|
656 } |
|
657 |
|
658 RArray<TLbtTriggerId> triggersModified; |
|
659 RArray<TUid> managerUis; |
|
660 for(TInt i=0;i<triggerInfoArray.Count();++i) |
|
661 { |
|
662 triggersModified.Append(triggerInfoArray[i].iTriggerId); |
|
663 |
|
664 if( managerUis.Find(triggerInfoArray[i].iManagerUi) == KErrNotFound ) |
|
665 { |
|
666 // Appen both manager ui and owner into manager uis |
|
667 managerUis.Append(triggerInfoArray[i].iManagerUi); |
|
668 } |
|
669 |
|
670 if( managerUis.Find(triggerInfoArray[i].iOwner) == KErrNotFound ) |
|
671 { |
|
672 managerUis.Append(triggerInfoArray[i].iOwner); |
|
673 } |
|
674 |
|
675 if( managerUis.Find(triggerInfoArray[i].iStartupProcess) == KErrNotFound && |
|
676 triggerInfoArray[i].iStartupProcess != KNullUid ) |
|
677 { |
|
678 managerUis.Append(triggerInfoArray[i].iStartupProcess); |
|
679 } |
|
680 } |
|
681 |
|
682 TBool isRequested = EFalse; |
|
683 // Give the observer callback through interface |
|
684 for( TInt i = 0; i<iObservers.Count(); i++ ) |
|
685 { |
|
686 isRequested = EFalse; |
|
687 ProcessFilter(isRequested,iObservers[i].iEventMask,eventMask); |
|
688 if(isRequested) |
|
689 { |
|
690 MLbtContainerChangeEventObserver::TLbtContainerChangedAreaType areaType = |
|
691 static_cast<MLbtContainerChangeEventObserver::TLbtContainerChangedAreaType>(changedAreaType); |
|
692 //Ownership of triggersModified array is transferred to the client |
|
693 iObservers[i].iObserver->TriggerStoreChanged( triggersModified, |
|
694 eventMask, |
|
695 areaType, |
|
696 managerUis ); |
|
697 } |
|
698 } |
|
699 triggersModified.Close(); |
|
700 triggerInfoArray.Close(); |
|
701 managerUis.Close(); |
|
702 } |
|
703 |
|
704 // --------------------------------------------------------- |
|
705 // CLbtContainerAO::ProcessFilter |
|
706 // |
|
707 // (other items were commented in a header). |
|
708 // --------------------------------------------------------- |
|
709 // |
|
710 void CLbtContainerAO::ProcessFilter(TBool& aIsRequested,TLbtTriggerEventMask& aRequestedMask,TLbtTriggerEventMask& aEventMask) |
|
711 { |
|
712 FUNC_ENTER("CLbtContainerAO::ProcessFilter"); |
|
713 aEventMask = 0; |
|
714 if( EOpUpdateTrigger == iAsyncRequest ) |
|
715 { |
|
716 // Depending on the bitmask,form trigger change event |
|
717 if( iAttrMask & CLbtTriggerEntry::EAttributeName ) |
|
718 { |
|
719 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerNameFieldChanged; |
|
720 if((aRequestedMask&CLbtContainer::ELbtConTriggerNameFieldChanged) == CLbtContainer::ELbtConTriggerNameFieldChanged) |
|
721 { |
|
722 aIsRequested = ETrue; |
|
723 } |
|
724 } |
|
725 |
|
726 if( iAttrMask & CLbtTriggerEntry::EAttributeState ) |
|
727 { |
|
728 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerStateFieldChanged; |
|
729 if((aRequestedMask&CLbtContainer::ELbtConTriggerStateFieldChanged) == CLbtContainer::ELbtConTriggerStateFieldChanged) |
|
730 { |
|
731 aIsRequested = ETrue; |
|
732 } |
|
733 } |
|
734 |
|
735 if( iAttrMask & CLbtTriggerEntry::EAttributeCondition ) |
|
736 { |
|
737 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerConditionFieldChanged; |
|
738 if((aRequestedMask&CLbtContainer::ELbtConTriggerConditionFieldChanged) == CLbtContainer::ELbtConTriggerConditionFieldChanged) |
|
739 { |
|
740 aIsRequested = ETrue; |
|
741 } |
|
742 } |
|
743 |
|
744 if( iAttrMask & CLbtTriggerEntry::EAttributeStartUpProcessId ) |
|
745 { |
|
746 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerStartupFieldChanged; |
|
747 if((aRequestedMask&CLbtContainer::ELbtConTriggerStartupFieldChanged) == CLbtContainer::ELbtConTriggerStartupFieldChanged) |
|
748 { |
|
749 aIsRequested = ETrue; |
|
750 } |
|
751 } |
|
752 |
|
753 if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeRectTriggerArea ) |
|
754 { |
|
755 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerRectAreaFieldChanged; |
|
756 if((aRequestedMask&CLbtContainer::ELbtConTriggerRectAreaFieldChanged) == CLbtContainer::ELbtConTriggerRectAreaFieldChanged) |
|
757 { |
|
758 aIsRequested = ETrue; |
|
759 } |
|
760 } |
|
761 |
|
762 if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeHysteresisRadius ) |
|
763 { |
|
764 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerHysteresisFieldChanged; |
|
765 if((aRequestedMask&CLbtContainer::ELbtConTriggerHysteresisFieldChanged) == CLbtContainer::ELbtConTriggerHysteresisFieldChanged) |
|
766 { |
|
767 aIsRequested = ETrue; |
|
768 } |
|
769 } |
|
770 |
|
771 if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeIsFired ) |
|
772 { |
|
773 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerFiredFieldChanged; |
|
774 if((aRequestedMask&CLbtContainer::ELbtConTriggerFiredFieldChanged) == CLbtContainer::ELbtConTriggerFiredFieldChanged) |
|
775 { |
|
776 aIsRequested = ETrue; |
|
777 } |
|
778 } |
|
779 |
|
780 if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeStrategyData ) |
|
781 { |
|
782 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerStrategyDataFieldChanged; |
|
783 if((aRequestedMask&CLbtContainer::ELbtConTriggerStrategyDataFieldChanged) == CLbtContainer::ELbtConTriggerStrategyDataFieldChanged) |
|
784 { |
|
785 aIsRequested = ETrue; |
|
786 } |
|
787 } |
|
788 |
|
789 if( iDataMask & CLbtContainerTriggerEntry::EContainerDynInfoAttributeValidity ) |
|
790 { |
|
791 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerValidityFieldChanged; |
|
792 if((aRequestedMask&CLbtContainer::ELbtConTriggerValidityFieldChanged) == CLbtContainer::ELbtConTriggerValidityFieldChanged) |
|
793 { |
|
794 aIsRequested = ETrue; |
|
795 } |
|
796 } |
|
797 |
|
798 if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeIsTriggerFireOnCreation ) |
|
799 { |
|
800 aEventMask = aEventMask | CLbtContainer::ELbtConTriggerFireOnCreationFieldChanged; |
|
801 if((aRequestedMask&CLbtContainer::ELbtConTriggerFireOnCreationFieldChanged) == CLbtContainer::ELbtConTriggerFireOnCreationFieldChanged) |
|
802 { |
|
803 aIsRequested = ETrue; |
|
804 } |
|
805 } |
|
806 } |
|
807 else if( EOpUpdateTriggerState == iAsyncRequest ) |
|
808 { |
|
809 //form trigger change event |
|
810 aEventMask = CLbtContainer::ELbtConTriggerStateFieldChanged; |
|
811 if( aRequestedMask & CLbtContainer::ELbtConTriggerStateFieldChanged ) |
|
812 { |
|
813 aIsRequested = ETrue; |
|
814 } |
|
815 } |
|
816 else if( EOpUpdateTriggersValidity == iAsyncRequest ) |
|
817 { |
|
818 // form trigger change event |
|
819 aEventMask = CLbtContainer::ELbtConTriggerValidityFieldChanged; |
|
820 if( aRequestedMask & CLbtContainer::ELbtConTriggerValidityFieldChanged ) |
|
821 { |
|
822 aIsRequested = ETrue; |
|
823 } |
|
824 } |
|
825 else if( EOpDeleteTriggers == iAsyncRequest ) |
|
826 { |
|
827 // form trigger change event |
|
828 aEventMask = CLbtContainer::ELbtConTriggerDeleted; |
|
829 if( aRequestedMask & CLbtContainer::ELbtConTriggerDeleted ) |
|
830 { |
|
831 aIsRequested = ETrue; |
|
832 } |
|
833 } |
|
834 else if( EOpCreateTrigger == iAsyncRequest ) |
|
835 { |
|
836 if( aRequestedMask & CLbtContainer::ELbtConTriggerCreated ) |
|
837 { |
|
838 aEventMask = CLbtContainer::ELbtConTriggerCreated; |
|
839 aIsRequested = ETrue; |
|
840 } |
|
841 |
|
842 if( aRequestedMask & CLbtContainer::ELbtConTriggerEnabledAndValidCreated ) |
|
843 { |
|
844 // Get the currently running ao operation object and check if the trigger is enabled and valid |
|
845 CLbtCreateAsyncOperation* operation = static_cast<CLbtCreateAsyncOperation*>(iAsyncOpQueue[0]); |
|
846 CLbtContainerTriggerEntry* entry = const_cast<CLbtContainerTriggerEntry*>(operation->ContainerTriggerEntry()); |
|
847 |
|
848 if( entry->TriggerEntry()->State() == CLbtTriggerEntry::EStateEnabled && |
|
849 entry->DynInfo()->iValidity == TLbtTriggerDynamicInfo::EValid) |
|
850 { |
|
851 // The trigger is enabled and valid, hence notify |
|
852 aEventMask = CLbtContainer::ELbtConTriggerEnabledAndValidCreated; |
|
853 aIsRequested = ETrue; |
|
854 } |
|
855 } |
|
856 } |
|
857 } |
|
858 |
|
859 // ------------------------------------------------------------------ |
|
860 // CLbtContainerAO::SortTriggers |
|
861 // ------------------------------------------------------------------ |
|
862 // |
|
863 void CLbtContainerAO::SortTriggers(RPointerArray<CLbtContainerTriggerEntry>& aTriggers) |
|
864 { |
|
865 FUNC_ENTER("CLbtContainerAO::SortTriggers"); |
|
866 if(CLbtListTriggerOptions::ELbtNoSorting == iSortingOption) |
|
867 { |
|
868 //No sorting |
|
869 return; |
|
870 } |
|
871 else if(CLbtListTriggerOptions::ELbtTriggerNameAscending == iSortingOption) |
|
872 { |
|
873 //sort by name ascending |
|
874 SortByName(aTriggers); |
|
875 } |
|
876 else if(CLbtListTriggerOptions::ELbtTriggerNameDescending == iSortingOption) |
|
877 { |
|
878 //sort by name ascending |
|
879 // reverse the array |
|
880 SortByName(aTriggers); |
|
881 ReverseArray(aTriggers); |
|
882 } |
|
883 else if(CLbtListTriggerOptions::ELbtDistanceToLatestLocationAscending == iSortingOption) |
|
884 { |
|
885 //sort by distance ascending |
|
886 SortByDistance(aTriggers); |
|
887 } |
|
888 } |
|
889 |
|
890 // ------------------------------------------------------------------ |
|
891 // CLbtContainerAO::SortByName |
|
892 // ------------------------------------------------------------------ |
|
893 // |
|
894 void CLbtContainerAO::SortByName(RPointerArray<CLbtContainerTriggerEntry>& aTriggers) |
|
895 { |
|
896 FUNC_ENTER("CLbtContainerAO::SortByName"); |
|
897 TBool isFinished=EFalse; |
|
898 CLbtContainerTriggerEntry* temp=NULL; |
|
899 |
|
900 while(!isFinished) |
|
901 { |
|
902 isFinished=ETrue; |
|
903 for(TInt i = 1 ;i <= aTriggers.Count()-1 ; i++) |
|
904 { |
|
905 if( aTriggers[i]->TriggerEntry()->Name() < aTriggers[i-1]->TriggerEntry()->Name() ) |
|
906 { |
|
907 temp=aTriggers[i-1]; |
|
908 aTriggers[i-1]=aTriggers[i]; |
|
909 aTriggers[i]=temp; |
|
910 isFinished=EFalse; |
|
911 } |
|
912 } |
|
913 } |
|
914 } |
|
915 |
|
916 // ------------------------------------------------------------------ |
|
917 // CLbtContainerAO::SortByDistance |
|
918 // ------------------------------------------------------------------ |
|
919 // |
|
920 void CLbtContainerAO::SortByDistance(RPointerArray<CLbtContainerTriggerEntry>& aTriggers) |
|
921 { |
|
922 FUNC_ENTER("CLbtContainerAO::SortByDistance"); |
|
923 TBool isFinished=EFalse; |
|
924 CLbtContainerTriggerEntry* temp=NULL; |
|
925 |
|
926 while(!isFinished) |
|
927 { |
|
928 isFinished=ETrue; |
|
929 for(TInt i = 1 ;i <= aTriggers.Count()-1 ; i++) |
|
930 { |
|
931 if( aTriggers[i]->DynInfo()->iDistanceToLatestLocation < aTriggers[i-1]->DynInfo()->iDistanceToLatestLocation ) |
|
932 { |
|
933 temp=aTriggers[i-1]; |
|
934 aTriggers[i-1]=aTriggers[i]; |
|
935 aTriggers[i]=temp; |
|
936 isFinished=EFalse; |
|
937 } |
|
938 } |
|
939 } |
|
940 } |
|
941 |
|
942 // ------------------------------------------------------------------ |
|
943 // CLbtContainerAO::ReverseArray |
|
944 // ------------------------------------------------------------------ |
|
945 // |
|
946 void CLbtContainerAO::ReverseArray(RPointerArray<CLbtContainerTriggerEntry>& aTriggers) |
|
947 { |
|
948 FUNC_ENTER("CLbtContainerAO::ReverseArray"); |
|
949 int i=0; |
|
950 int j=aTriggers.Count()-1; |
|
951 CLbtContainerTriggerEntry* temp=NULL; |
|
952 |
|
953 while(i < j) |
|
954 { |
|
955 temp=aTriggers[i]; |
|
956 aTriggers[i]=aTriggers[j]; |
|
957 aTriggers[j]=temp; |
|
958 i++; |
|
959 j--; |
|
960 } |
|
961 } |
|
962 |
|
963 // ------------------------------------------------------------------ |
|
964 // CLbtContainerAO::CancelAsyncRequest |
|
965 // ------------------------------------------------------------------ |
|
966 // |
|
967 void CLbtContainerAO::CancelAsyncRequest(TInt aOpId) |
|
968 { |
|
969 FUNC_ENTER("CLbtContainerAO::CancelAsyncRequest"); |
|
970 |
|
971 if(iAsyncOpQueue.Count() > 0) |
|
972 { |
|
973 if(iAsyncOpQueue[0]->GetOpCode() == aOpId) |
|
974 { |
|
975 // Currently running operation |
|
976 if( IsActive() ) |
|
977 { |
|
978 Cancel(); |
|
979 } |
|
980 else |
|
981 { |
|
982 CLbtContainerAOOperation* cancelObj = iAsyncOpQueue[0]; |
|
983 iAsyncOpQueue.Remove(0); |
|
984 if( iAsyncRequest == EOpListTriggers ) |
|
985 { |
|
986 CLbtListAsyncOperation* listOp = static_cast<CLbtListAsyncOperation*> (cancelObj); |
|
987 listOp->FreeArray(); |
|
988 } |
|
989 TRequestStatus* status = cancelObj->GetStatus(); |
|
990 User::RequestComplete(status, KErrCancel); |
|
991 delete cancelObj; |
|
992 if(iAsyncOpQueue.Count()>0) |
|
993 { |
|
994 StartNextAsyncOperation(); |
|
995 } |
|
996 } |
|
997 } |
|
998 else |
|
999 { |
|
1000 for(TInt i=1;i < iAsyncOpQueue.Count(); ++i) |
|
1001 { |
|
1002 if(iAsyncOpQueue[i]->GetOpCode() == aOpId) |
|
1003 { |
|
1004 CLbtContainerAOOperation* cancelObj = iAsyncOpQueue[i]; |
|
1005 iAsyncOpQueue.Remove(i); |
|
1006 TRequestStatus* status = cancelObj->GetStatus(); |
|
1007 User::RequestComplete(status,KErrCancel); |
|
1008 delete cancelObj; |
|
1009 break; |
|
1010 } |
|
1011 } |
|
1012 } |
|
1013 } |
|
1014 } |
|
1015 |
|
1016 // ------------------------------------------------------------------ |
|
1017 // CLbtContainerAO::NotifyTriggerStoreReadyToServe |
|
1018 // ------------------------------------------------------------------ |
|
1019 // |
|
1020 void CLbtContainerAO::NotifyTriggerStoreReadyToServe() |
|
1021 { |
|
1022 FUNC_ENTER("CLbtContainerAO::NotifyTriggerStoreReadyToServe"); |
|
1023 if(iAsyncOpQueue.Count() > 0) |
|
1024 { |
|
1025 StartNextAsyncOperation(); |
|
1026 } |
|
1027 } |
|
1028 |
|
1029 // End of File |