|
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: This file implements the Location triggering container |
|
15 * interface |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <lbtlisttriggeroptions.h> |
|
21 #include <e32math.h> |
|
22 |
|
23 #include "lbtcontainer.h" |
|
24 #include "lbttriggerstoreinterface.h" |
|
25 #include "lbttriggerstorerepository.h" |
|
26 #include "lbttriggeridgenerator.h" |
|
27 #include "lbtcontainerao.h" |
|
28 #include "lbtcontainerupdatefilter.h" |
|
29 #include "lbttriggerchangeobserver.h" |
|
30 #include "lbtlogger.h" |
|
31 |
|
32 // ========= Static member variable initialization ================= |
|
33 |
|
34 // Initalize the member variable for shared Container instance. |
|
35 CLbtContainer* CLbtContainer::iContainerInstance = NULL; |
|
36 |
|
37 // Initialize the reference count for the container instance. |
|
38 TInt CLbtContainer::iRefCount = 0; |
|
39 |
|
40 |
|
41 // ======== LOCAL FUNCTIONS ======== |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // Comparison Algorithm for 2 objects of type TLbtTriggerStoreChangeObserver |
|
45 // The idea is that the 2 TLbtTriggerStoreChangeObserver structures are same |
|
46 // if they have the same observer object. |
|
47 // The event mask is not required in the comparison. |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 TBool ObserverCompare( |
|
51 const CLbtContainer::TLbtTriggerStoreChangeObserver& lhs, |
|
52 const CLbtContainer::TLbtTriggerStoreChangeObserver& rhs) |
|
53 { |
|
54 if ( lhs.iObserver == rhs.iObserver ) |
|
55 { |
|
56 return ETrue; |
|
57 } |
|
58 return EFalse; |
|
59 } |
|
60 |
|
61 // ======== MEMBER FUNCTIONS ======== |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // The Symbian 2 phase constructor |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C CLbtContainer* CLbtContainer::NewL() |
|
69 { |
|
70 FUNC_ENTER("CLbtContainer::NewL"); |
|
71 // If an instance doesn't exist then create the Container object. |
|
72 if ( !iContainerInstance ) |
|
73 { |
|
74 CLbtContainer* container = new( ELeave ) CLbtContainer(); |
|
75 |
|
76 CleanupStack::PushL( container ); |
|
77 container->ConstructL(); |
|
78 CleanupStack::Pop( container ); |
|
79 iContainerInstance = container; |
|
80 } |
|
81 |
|
82 // Increment the reference count |
|
83 iRefCount++; |
|
84 return iContainerInstance; |
|
85 } |
|
86 |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Destroys the Container Instance |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C void CLbtContainer::Destroy() |
|
93 { |
|
94 FUNC_ENTER("CLbtContainer::Destroy"); |
|
95 // Check that the Container Instance exists |
|
96 if ( iContainerInstance ) |
|
97 { |
|
98 iRefCount--; |
|
99 // If the Reference Count is 0 then delete the container Instance. |
|
100 if ( !iRefCount ) |
|
101 { |
|
102 delete iContainerInstance; |
|
103 iContainerInstance = NULL; |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // Create a Trigger |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C void CLbtContainer::CreateTrigger( |
|
114 CLbtContainerTriggerEntry& aEntry, |
|
115 TInt& aOpId, |
|
116 TRequestStatus& aStatus, |
|
117 TLbtSecurityPolicy /*aSecurityPolicy*/) |
|
118 { |
|
119 FUNC_ENTER("CLbtContainer::CreateTrigger"); |
|
120 |
|
121 // Allocate the Trigger ID First |
|
122 CLbtTriggerEntry* trigger = aEntry.TriggerEntry(); |
|
123 |
|
124 if(iTrigId == 0) |
|
125 { |
|
126 iTrigId=iTrigIdGenerator->GetTriggerId(); |
|
127 } |
|
128 |
|
129 trigger->SetId(++iTrigId); |
|
130 iTrigIdGenerator->SetTriggerId(iTrigId); |
|
131 aOpId = GenerateRandomOpCode(); |
|
132 aStatus=KRequestPending; |
|
133 TRAPD(err, iContainerAO->CreateTriggerL(&aEntry,aOpId,aStatus) ) ; |
|
134 |
|
135 if(err != KErrNone && aStatus == KRequestPending) |
|
136 { |
|
137 TRequestStatus* status = &aStatus; |
|
138 User::RequestComplete( status, err ); |
|
139 } |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CancelAsyncOperation |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 EXPORT_C void CLbtContainer::CancelAsyncOperation(TInt aOpId) |
|
147 { |
|
148 iContainerAO->CancelAsyncRequest(aOpId); |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // CLbtContainer::GetTriggers |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C void CLbtContainer::GetTriggers( const RArray<TLbtTriggerId>& aTriggerIds, |
|
156 RPointerArray < CLbtContainerTriggerEntry >& aTriggers, |
|
157 TInt& aOpId, |
|
158 TRequestStatus& aStatus, |
|
159 TLbtSecurityPolicy aSecurityPolicy ) |
|
160 { |
|
161 FUNC_ENTER("CLbtContainer::GetTriggers"); |
|
162 aOpId = GenerateRandomOpCode(); |
|
163 aStatus=KRequestPending; |
|
164 |
|
165 TRAPD(err,iContainerAO->GetTriggersL( aTriggerIds, |
|
166 aTriggers, |
|
167 aOpId, |
|
168 aStatus, |
|
169 aSecurityPolicy )); |
|
170 if(err != KErrNone && aStatus == KRequestPending) |
|
171 { |
|
172 TRequestStatus* status = &aStatus; |
|
173 User::RequestComplete( status, err ); |
|
174 } |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CLbtContainer::UpdateTriggerFiredState |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 EXPORT_C void CLbtContainer::UpdateTriggerFiredState( RArray<TLbtTriggerId>& aTriggerIds, |
|
182 TInt& aOpId, |
|
183 TBool aFireBool, |
|
184 TRequestStatus& aStatus ) |
|
185 { |
|
186 FUNC_ENTER("CLbtContainer::UpdateTriggerFiredState"); |
|
187 aOpId = GenerateRandomOpCode(); |
|
188 aStatus=KRequestPending; |
|
189 |
|
190 TRAPD(err,iContainerAO->UpdateTriggerFiredStateL(aTriggerIds, aFireBool, aOpId, aStatus)); |
|
191 if(err != KErrNone && aStatus == KRequestPending) |
|
192 { |
|
193 TRequestStatus* status = &aStatus; |
|
194 User::RequestComplete( status, err ); |
|
195 } |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // UpdateTriggerL |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C void CLbtContainer::UpdateTriggerL( CLbtContainerTriggerEntry& aEntry, |
|
203 TLbtTriggerDataMask aDataMask, |
|
204 TLbtTriggerAttributeFieldsMask aAttrMask, |
|
205 TInt& aOpId, |
|
206 TRequestStatus& aStatus, |
|
207 TLbtSecurityPolicy aSecurityPolicy ) |
|
208 { |
|
209 FUNC_ENTER("CLbtContainer::UpdateTriggerL"); |
|
210 aOpId = GenerateRandomOpCode(); |
|
211 aStatus=KRequestPending; |
|
212 |
|
213 TRAPD( err, iContainerAO->UpdateTriggerL( aEntry, |
|
214 aDataMask, |
|
215 aAttrMask, |
|
216 aOpId, |
|
217 aStatus, |
|
218 aSecurityPolicy) ); |
|
219 if(err != KErrNone && aStatus == KRequestPending) |
|
220 { |
|
221 TRequestStatus* status = &aStatus; |
|
222 User::RequestComplete( status, err ); |
|
223 } |
|
224 } |
|
225 |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // UpdateTriggersState |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C void CLbtContainer::UpdateTriggersState( CLbtTriggerEntry::TLbtTriggerState aState, |
|
232 CLbtContainerUpdateFilter* aFilter, |
|
233 TInt& aOpId, |
|
234 TLbtFireOnUpdate aFireOnUpdate, |
|
235 TRequestStatus& aStatus, |
|
236 TLbtSecurityPolicy aSecurityPolicy ) |
|
237 { |
|
238 FUNC_ENTER("CLbtContainer::UpdateTriggersState"); |
|
239 aOpId = GenerateRandomOpCode(); |
|
240 aStatus=KRequestPending; |
|
241 |
|
242 TRAPD(err, iContainerAO->UpdateTriggersStateL( aState, |
|
243 aFilter, |
|
244 aOpId, |
|
245 aFireOnUpdate, |
|
246 aStatus, |
|
247 aSecurityPolicy )); |
|
248 if(err != KErrNone && aStatus == KRequestPending) |
|
249 { |
|
250 TRequestStatus* status = &aStatus; |
|
251 User::RequestComplete( status, err ); |
|
252 } |
|
253 } |
|
254 |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // UpdateTriggersValidity |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C void CLbtContainer::UpdateTriggersValidity( TLbtTriggerDynamicInfo::TLbtTriggerValidity aValidity, |
|
261 RArray <TLbtTriggerId>& aTriggerIds, |
|
262 TInt& aOpId, |
|
263 TRequestStatus& aStatus, |
|
264 TLbtSecurityPolicy aSecurityPolicy ) |
|
265 { |
|
266 FUNC_ENTER("CLbtContainer::UpdateTriggersValidity"); |
|
267 aOpId = GenerateRandomOpCode(); |
|
268 aStatus=KRequestPending; |
|
269 |
|
270 TRAPD(err, iContainerAO->UpdateTriggersValidityL( aValidity, |
|
271 aTriggerIds, |
|
272 aOpId, |
|
273 aStatus, |
|
274 aSecurityPolicy )); |
|
275 if(err != KErrNone && aStatus == KRequestPending) |
|
276 { |
|
277 TRequestStatus* status = &aStatus; |
|
278 User::RequestComplete( status, err ); |
|
279 } |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // DeleteTriggers |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 EXPORT_C void CLbtContainer::DeleteTriggers( |
|
287 CLbtContainerUpdateFilter* aFilter, |
|
288 TInt& aOpId, |
|
289 TRequestStatus& aStatus, |
|
290 TLbtSecurityPolicy aSecurityPolicy) |
|
291 { |
|
292 FUNC_ENTER("CLbtContainer::DeleteTriggers") |
|
293 aOpId = GenerateRandomOpCode(); |
|
294 aStatus=KRequestPending; |
|
295 |
|
296 TRAPD(err, iContainerAO->DeleteTriggersL( aFilter, |
|
297 aOpId, |
|
298 aStatus, |
|
299 aSecurityPolicy )); |
|
300 if(err != KErrNone && aStatus == KRequestPending) |
|
301 { |
|
302 TRequestStatus* status = &aStatus; |
|
303 User::RequestComplete( status, err ); |
|
304 } |
|
305 } |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // CLbtContainer::ListTriggers |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 EXPORT_C void CLbtContainer::ListTriggers( |
|
312 CLbtContainerListOptions* aListOptions, |
|
313 RPointerArray < CLbtContainerTriggerEntry >& aTriggers, |
|
314 TInt& aOpId, |
|
315 TRequestStatus& aStatus, |
|
316 TLbtSecurityPolicy aSecurityPolicy) |
|
317 { |
|
318 FUNC_ENTER("CLbtContainer::ListTriggers"); |
|
319 aOpId = GenerateRandomOpCode(); |
|
320 aStatus=KRequestPending; |
|
321 |
|
322 TRAPD(err, iContainerAO->ListTriggersL( aListOptions, |
|
323 aTriggers, |
|
324 aOpId, |
|
325 aStatus, |
|
326 aSecurityPolicy )); |
|
327 if(err != KErrNone && aStatus == KRequestPending) |
|
328 { |
|
329 TRequestStatus* status = &aStatus; |
|
330 User::RequestComplete( status, err ); |
|
331 } |
|
332 } |
|
333 |
|
334 |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // SetChangeObserver |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 EXPORT_C void CLbtContainer::SetChangeObserver( |
|
341 MLbtContainerChangeEventObserver* aObserver, |
|
342 TLbtTriggerEventMask aEventMask) |
|
343 { |
|
344 FUNC_ENTER("CLbtContainer::SetChangeObserver"); |
|
345 TLbtTriggerStoreChangeObserver obsvr; |
|
346 obsvr.iObserver = aObserver; |
|
347 obsvr.iEventMask = aEventMask; |
|
348 |
|
349 TIdentityRelation<TLbtTriggerStoreChangeObserver> compareAlgoirthm(ObserverCompare); |
|
350 |
|
351 if ( KErrNotFound == iObservers.Find(obsvr, compareAlgoirthm) ) |
|
352 { |
|
353 iObservers.Append( obsvr ); |
|
354 } |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------------------------- |
|
358 // RemoveObserver |
|
359 // --------------------------------------------------------------------------- |
|
360 // |
|
361 |
|
362 EXPORT_C void CLbtContainer::RemoveObserver(MLbtContainerChangeEventObserver* aObserver) |
|
363 { |
|
364 FUNC_ENTER("CLbtContainer::RemoveObserver"); |
|
365 TLbtTriggerStoreChangeObserver obsvr; |
|
366 obsvr.iObserver = aObserver; |
|
367 |
|
368 TIdentityRelation<TLbtTriggerStoreChangeObserver> compareAlgoirthm(ObserverCompare); |
|
369 |
|
370 TInt index = iObservers.Find( obsvr, compareAlgoirthm ); |
|
371 if ( KErrNotFound != index ) |
|
372 { |
|
373 iObservers.Remove( index ); |
|
374 } |
|
375 } |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // GetCountOfEnabledAndValidTriggers |
|
379 // --------------------------------------------------------------------------- |
|
380 // |
|
381 |
|
382 EXPORT_C TInt CLbtContainer::GetCountOfEnabledAndValidTriggers() |
|
383 { |
|
384 TInt count=0; |
|
385 count = iTriggerStores[0]->GetCountOfEnabledAndValidTriggers() + |
|
386 iTriggerStores[1]->GetCountOfEnabledAndValidTriggers(); |
|
387 return count; |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // CLbtContainer::SetTimeTillCompaction |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 EXPORT_C void CLbtContainer::SetTimeTillCompaction(TTime aTime) |
|
395 { |
|
396 for(TInt i=0;i<iTriggerStores.Count();++i) |
|
397 { |
|
398 iTriggerStores[i]->SetTimeTillCompaction(aTime); |
|
399 } |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------------------------- |
|
403 // Constructor |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 CLbtContainer::CLbtContainer() |
|
407 { |
|
408 // Nothing to do here |
|
409 } |
|
410 |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // The 2nd phase Symbian Constructor |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 void CLbtContainer::ConstructL() |
|
417 { |
|
418 FUNC_ENTER("CLbtContainer::ConstructL"); |
|
419 LbtTriggerStoreFactory::CreateTriggerStoresL(iTriggerStores); |
|
420 iTrigIdGenerator = CLbtTriggerIdGenerator::NewL(); |
|
421 iTrigId=0; |
|
422 iContainerAO = CLbtContainerAO::NewL(iTriggerStores,iObservers); |
|
423 iRandNumRef = 100; |
|
424 } |
|
425 |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 // Destructor |
|
429 // --------------------------------------------------------------------------- |
|
430 // |
|
431 CLbtContainer::~CLbtContainer() |
|
432 { |
|
433 FUNC_ENTER("CLbtContainer::~CLbtContainer"); |
|
434 iTriggerStores.ResetAndDestroy(); |
|
435 |
|
436 // We don't take ownership of the observers. Hence we just need to release |
|
437 // the resources of the array. |
|
438 iObservers.Close(); |
|
439 |
|
440 delete iContainerAO; |
|
441 delete iTrigIdGenerator; |
|
442 } |
|
443 |
|
444 // --------------------------------------------------------------------------- |
|
445 // CLbtContainer::GenerateRandomOpCode |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 TInt CLbtContainer::GenerateRandomOpCode() |
|
449 { |
|
450 TInt num = Math::Rand(iRandNumRef); |
|
451 return num; |
|
452 } |