|
1 /* |
|
2 * Copyright (c) 2008 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: Handles native landmark database events |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INTERNAL INCLUDES |
|
20 #include "clapilmdatabaseeventnotifier.h" |
|
21 #include "mlapilmdatabaseobserver.h" |
|
22 #include "lapipanics.h" |
|
23 #include "logger.h" |
|
24 |
|
25 // EXTERNAL INCLUDES |
|
26 #include <EPos_CPosLandmarkDatabase.h> |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CLAPILmDatabaseEventNotifier::NewLC |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CLAPILmDatabaseEventNotifier* CLAPILmDatabaseEventNotifier::NewLC( |
|
33 CPosLandmarkDatabase& aDatabase) |
|
34 { |
|
35 JELOG2(EJavaLocation); |
|
36 CLAPILmDatabaseEventNotifier* self = |
|
37 new(ELeave) CLAPILmDatabaseEventNotifier(aDatabase); |
|
38 CleanupStack::PushL(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CLAPILmDatabaseEventNotifier::~CLAPILmDatabaseEventNotifier |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CLAPILmDatabaseEventNotifier::~CLAPILmDatabaseEventNotifier() |
|
47 { |
|
48 JELOG2(EJavaLocation); |
|
49 Cancel(); |
|
50 iEventObservers.Close(); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CLAPILmDatabaseEventNotifier::AddObserverL |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 void CLAPILmDatabaseEventNotifier::AddObserverL( |
|
58 MLAPILmDatabaseObserver* aObserver) |
|
59 { |
|
60 JELOG2(EJavaLocation); |
|
61 __ASSERT_DEBUG(aObserver, LAPIError::Panic(ELAPIPanicNullArgument)); |
|
62 iEventObservers.AppendL(aObserver); |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CLAPILmDatabaseEventNotifier::RemoveObserver |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 void CLAPILmDatabaseEventNotifier::RemoveObserver( |
|
70 MLAPILmDatabaseObserver* aObserver) |
|
71 { |
|
72 JELOG2(EJavaLocation); |
|
73 __ASSERT_DEBUG(aObserver, LAPIError::Panic(ELAPIPanicNullArgument)); |
|
74 TInt index = iEventObservers.Find(aObserver); |
|
75 if (index != KErrNotFound) |
|
76 { |
|
77 iEventObservers.Remove(index); |
|
78 } |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CLAPILmDatabaseEventNotifier::IsEventListeningSupported |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 TBool CLAPILmDatabaseEventNotifier::IsEventListeningSupported() |
|
86 { |
|
87 JELOG2(EJavaLocation); |
|
88 // Event listening is not supported if the first request has returned |
|
89 // with KErrNotSupported error code. If there are requests pending, it |
|
90 // means that the request is pending and event listening is supported |
|
91 return iStatus != KErrNotSupported; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CLAPILmDatabaseEventNotifier::RunL |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CLAPILmDatabaseEventNotifier::RunL() |
|
99 { |
|
100 JELOG2(EJavaLocation); |
|
101 LOG1(EJavaLocation, EInfo, "CLAPILmDatabaseEventNotifier::RunL - event %d", |
|
102 iEvent.iEventType); |
|
103 // Listening database events is not supported. Stop listening and return |
|
104 if (iStatus == KErrNotSupported) |
|
105 { |
|
106 return; |
|
107 } |
|
108 else |
|
109 { |
|
110 TPosLmEvent curEvent(iEvent); |
|
111 TRequestStatus curStatus(iStatus); |
|
112 // Request a new database event. The operation completes when a change |
|
113 // occurs in the native database so the callback does not occur immediately |
|
114 // Call this before notifying the observer because events may occur |
|
115 // very frequently so subsequent events will not be missed |
|
116 iDatabase.NotifyDatabaseEvent(iEvent, iStatus); |
|
117 SetActive(); |
|
118 |
|
119 // Notify observers if the change occured without any errors. All events |
|
120 // are informed to the observers which are responsible for filtering |
|
121 // incorrect events |
|
122 if (curStatus == KErrNone) |
|
123 { |
|
124 TInt observerCount = iEventObservers.Count(); |
|
125 for (TInt i = 0; i < observerCount; i++) |
|
126 { |
|
127 iEventObservers[i]->NotifyEvent(curEvent.iEventType, |
|
128 curEvent.iLandmarkItemId); |
|
129 } |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CLAPILmDatabaseEventNotifier::DoCancel |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CLAPILmDatabaseEventNotifier::DoCancel() |
|
139 { |
|
140 JELOG2(EJavaLocation); |
|
141 // Cancel listening database events |
|
142 iDatabase.CancelNotifyDatabaseEvent(); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // CLAPILmDatabaseEventNotifier::CLAPILmDatabaseEventNotifier |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 CLAPILmDatabaseEventNotifier::CLAPILmDatabaseEventNotifier( |
|
150 CPosLandmarkDatabase& aDatabase) : |
|
151 CActive(EPriorityStandard), iDatabase(aDatabase) |
|
152 { |
|
153 JELOG2(EJavaLocation); |
|
154 CActiveScheduler::Add(this); |
|
155 // Issue database change request. Note that the request completes only |
|
156 // when a change occurs in the native database |
|
157 iDatabase.NotifyDatabaseEvent(iEvent, iStatus); |
|
158 SetActive(); |
|
159 } |
|
160 |
|
161 // End of file |