|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qgeoareamonitor_s60_p.h" |
|
43 #include "qgeopositioninfo.h" |
|
44 #include "qmlbackendmonitorinfo_s60_p.h" |
|
45 #include "qmlbackendmonitorcreatetriggerao_s60_p.h" |
|
46 |
|
47 QTM_BEGIN_NAMESPACE |
|
48 |
|
49 TInt QGeoAreaMonitorS60::refCount = 0; |
|
50 |
|
51 QGeoAreaMonitorS60* QGeoAreaMonitorS60::NewL(QObject *aParent) |
|
52 { |
|
53 QGeoAreaMonitorS60 *self = QGeoAreaMonitorS60::NewLC(aParent); |
|
54 CleanupStack::Pop(); |
|
55 if (!self->isValid()) { |
|
56 delete self; |
|
57 self = NULL; |
|
58 } |
|
59 return self; |
|
60 } |
|
61 |
|
62 //creates an entry and exit trigger based on the aCoordinate and |
|
63 //aRadius values passed as argument |
|
64 void QGeoAreaMonitorS60::setMonitoredArea(const QGeoCoordinate & aCoordinate, qreal aRadius) |
|
65 { |
|
66 TCoordinate coord; |
|
67 |
|
68 TInt ret1 = QCoordinateToTCoordinate(aCoordinate, coord); |
|
69 |
|
70 TInt ret2 = iTriggerCreateAO->getRadius(aRadius); |
|
71 |
|
72 if (ret2 == KErrNone) |
|
73 QGeoAreaMonitor::setRadius(aRadius); |
|
74 |
|
75 if ((ret1 != KErrNone) || (ret2 != KErrNone)) |
|
76 return; |
|
77 |
|
78 //Intialize the trigger and enable the trigger if atleast one slot is connected to the areaEntered |
|
79 //signal |
|
80 if ((iTriggerCreateAO->InitializeTrigger(this, EntryTrigger, coord, aRadius)) && |
|
81 (receivers(SIGNAL(areaEntered(const QGeoPositionInfo&))) > 0)) { |
|
82 iTriggerCreateAO->SetTriggerState(this, EntryTrigger, true); |
|
83 iTriggerAO->NotifyFiredEvent(); |
|
84 } |
|
85 |
|
86 //Intialize the trigger and enable the trigger if atleast one slot is connected to the areaExited |
|
87 //signal |
|
88 if ((iTriggerCreateAO->InitializeTrigger(this, ExitTrigger, coord, aRadius)) && |
|
89 (receivers(SIGNAL(areaExited(const QGeoPositionInfo&))) > 0)) { |
|
90 iTriggerCreateAO->SetTriggerState(this, ExitTrigger, true); |
|
91 iTriggerAO->NotifyFiredEvent(); |
|
92 } |
|
93 |
|
94 //request for the trigger change notification events |
|
95 iNotifyTriggerAO->NotifyChangeEvent(); |
|
96 } |
|
97 |
|
98 //virtual function sets the Center of the monitoring area to coordinate |
|
99 void QGeoAreaMonitorS60::setCenter(const QGeoCoordinate& coordinate) |
|
100 { |
|
101 if (coordinate.isValid()) |
|
102 QGeoAreaMonitor::setCenter(coordinate); |
|
103 else |
|
104 return; |
|
105 |
|
106 if (QGeoAreaMonitor::radius() != 0) //if radius is not initialised |
|
107 setMonitoredArea(coordinate, QGeoAreaMonitor::radius()); |
|
108 } |
|
109 |
|
110 //virtual fucntion sets the radius of the monitorijng area to the radius |
|
111 void QGeoAreaMonitorS60::setRadius(qreal radius) |
|
112 { |
|
113 setMonitoredArea(QGeoAreaMonitor::center(), radius); |
|
114 } |
|
115 |
|
116 //callback from the QMLBackendMonitorAO object for the entry/exit event |
|
117 void QGeoAreaMonitorS60::handleTriggerEvent(TPositionInfo aPosInfo, enTriggerType aStatus) |
|
118 { |
|
119 QGeoPositionInfo posInfo; |
|
120 |
|
121 TPositionInfoToQGeoPositionInfo(aPosInfo, posInfo); |
|
122 |
|
123 if (!posInfo.isValid()) |
|
124 return; |
|
125 |
|
126 switch (aStatus) { |
|
127 case EntryTrigger : //emit areaEntered trigger |
|
128 emit areaEntered(posInfo); |
|
129 break; |
|
130 case ExitTrigger : //emit areaExited trigger |
|
131 emit areaExited(posInfo); |
|
132 break; |
|
133 case NotifyChangesTrigger: |
|
134 case InvalidTrigger: |
|
135 break; |
|
136 } |
|
137 |
|
138 } |
|
139 |
|
140 |
|
141 |
|
142 //destructor cleaning up the resources |
|
143 QGeoAreaMonitorS60::~QGeoAreaMonitorS60() |
|
144 { |
|
145 |
|
146 if (iTriggerAO || iNotifyTriggerAO || iTriggerCreateAO) { |
|
147 QMLBackendMonitorAO::DeleteAO(this); |
|
148 iTriggerAO = NULL; |
|
149 QMLBackendTriggerChangeAO::DeleteAO(); |
|
150 iNotifyTriggerAO = NULL; |
|
151 delete iTriggerCreateAO; |
|
152 iTriggerCreateAO = NULL; |
|
153 } |
|
154 if (connectedLbt) { |
|
155 --refCount; |
|
156 if (refCount == 0) { |
|
157 lbtServ.Close(); |
|
158 } |
|
159 } |
|
160 } |
|
161 |
|
162 QGeoAreaMonitorS60* QGeoAreaMonitorS60::NewLC(QObject* aParent) |
|
163 { |
|
164 QGeoAreaMonitorS60 *self = new(ELeave) QGeoAreaMonitorS60(aParent); |
|
165 CleanupStack::PushL(self); |
|
166 self->ConstructL(); |
|
167 return self; |
|
168 } |
|
169 |
|
170 //second level construction : creating the QMLBackendMonitorAO : for |
|
171 //monitoring the trigger fired event,QMLBackendMonitorCreateTriggerAO: |
|
172 //instance object for creating the trigger and QMLBackendTriggerChangeAO : |
|
173 //for monitoring the changes to the trigger properties |
|
174 void QGeoAreaMonitorS60::ConstructL() |
|
175 { |
|
176 if (lbtServ.Connect() == KErrNone) { |
|
177 CleanupClosePushL(lbtServ); |
|
178 |
|
179 connectedLbt = true; |
|
180 ++refCount; |
|
181 |
|
182 iTriggerAO = QMLBackendMonitorAO::NewL(lbtServ); |
|
183 |
|
184 if (!iTriggerAO) |
|
185 return; |
|
186 |
|
187 iTriggerCreateAO = QMLBackendMonitorCreateTriggerAO::NewL(this, lbtServ); |
|
188 |
|
189 if (!iTriggerCreateAO) |
|
190 return; |
|
191 |
|
192 iNotifyTriggerAO = QMLBackendTriggerChangeAO::NewL(lbtServ); |
|
193 |
|
194 CleanupStack::Pop(1); |
|
195 } else { |
|
196 connectedLbt = false; |
|
197 } |
|
198 } |
|
199 |
|
200 //constructor initializing the default values |
|
201 QGeoAreaMonitorS60::QGeoAreaMonitorS60(QObject* aParent) : QGeoAreaMonitor(aParent), |
|
202 iTriggerAO(NULL), iNotifyTriggerAO(NULL) |
|
203 { |
|
204 |
|
205 } |
|
206 |
|
207 //convert a symbian-TPositionInfo value to corresponding QT-QGeoPositionInfo |
|
208 void QGeoAreaMonitorS60::TPositionInfoToQGeoPositionInfo(TPositionInfo& aPosInfo, QGeoPositionInfo& aQInfo) |
|
209 { |
|
210 QGeoCoordinate coord; |
|
211 TPosition pos; |
|
212 aPosInfo.GetPosition(pos); |
|
213 |
|
214 coord.setLatitude(pos.Latitude()); |
|
215 coord.setLongitude(pos.Longitude()); |
|
216 coord.setAltitude(pos.Altitude()); |
|
217 |
|
218 //store the QGeoCoordinate values |
|
219 aQInfo.setCoordinate(coord); |
|
220 |
|
221 TDateTime datetime = pos.Time().DateTime(); |
|
222 QDateTime dt(QDate(datetime.Year(), datetime.Month() + 1, datetime.Day() + 1), |
|
223 QTime(datetime.Hour(), datetime.Minute(), datetime.Second(), |
|
224 datetime.MicroSecond() / 1000), |
|
225 Qt::UTC); |
|
226 |
|
227 //store the time stamp |
|
228 aQInfo.setTimestamp(dt); |
|
229 |
|
230 //store the horizontal accuracy |
|
231 aQInfo.setAttribute(QGeoPositionInfo::HorizontalAccuracy, pos.HorizontalAccuracy()); |
|
232 |
|
233 //store the vertical accuracy |
|
234 aQInfo.setAttribute(QGeoPositionInfo::VerticalAccuracy, pos.VerticalAccuracy()); |
|
235 |
|
236 } |
|
237 |
|
238 |
|
239 //convert QT-QCoordinate value to Symbian-TCoordinate value |
|
240 int QGeoAreaMonitorS60::QCoordinateToTCoordinate(const QGeoCoordinate& aQCoord, TCoordinate& aTCoord) |
|
241 { |
|
242 if (!aQCoord.isValid()) |
|
243 return KErrGeneral; |
|
244 |
|
245 QGeoAreaMonitor::setCenter(aQCoord); |
|
246 aTCoord.SetCoordinate(aQCoord.latitude(), aQCoord.longitude(), aQCoord.altitude()); |
|
247 return KErrNone; |
|
248 } |
|
249 |
|
250 //Notification called when a sot is connected to the areaEntered or |
|
251 //areaExited signal |
|
252 void QGeoAreaMonitorS60::connectNotify(const char* signal) |
|
253 { |
|
254 if ((iTriggerCreateAO->isTriggerInitialized(this, EntryTrigger)) && (QLatin1String(signal) == SIGNAL(areaEntered(QGeoPositionInfo))) && (receivers(SIGNAL(areaEntered(const QGeoPositionInfo&))) <= 1)) { |
|
255 iTriggerCreateAO->SetTriggerState(this, EntryTrigger, true); |
|
256 iTriggerAO-> NotifyFiredEvent(); |
|
257 } |
|
258 |
|
259 if ((iTriggerCreateAO->isTriggerInitialized(this, ExitTrigger)) && (QLatin1String(signal) == SIGNAL(areaExited(QGeoPositionInfo))) && (receivers(SIGNAL(areaExited(const QGeoPositionInfo&))) <= 1)) { |
|
260 iTriggerCreateAO->SetTriggerState(this, ExitTrigger, true); |
|
261 iTriggerAO-> NotifyFiredEvent(); |
|
262 } |
|
263 } |
|
264 |
|
265 //Notification called when a sot is disconnected from the areaEntered or |
|
266 //areaExited signal |
|
267 void QGeoAreaMonitorS60::disconnectNotify(const char* signal) |
|
268 { |
|
269 // Disable the trigger, if no slot connected to signal |
|
270 if ((iTriggerCreateAO->isTriggerInitialized(this, EntryTrigger)) && (QLatin1String(signal) == SIGNAL(areaEntered(QGeoPositionInfo))) && (receivers(SIGNAL(areaEntered(const QGeoPositionInfo&))) == 0)) { |
|
271 // iEnterTrigger->NotifyFiredEvent (FALSE); |
|
272 iTriggerCreateAO->SetTriggerState(this, EntryTrigger, FALSE); |
|
273 } |
|
274 |
|
275 if ((iTriggerCreateAO->isTriggerInitialized(this, ExitTrigger)) && (QLatin1String(signal) == SIGNAL(areaExited(QGeoPositionInfo))) && (receivers(SIGNAL(areaExited(const QGeoPositionInfo&))) == 0)) { |
|
276 // iExitTrigger->NotifyFiredEvent (FALSE); |
|
277 iTriggerCreateAO->SetTriggerState(this, ExitTrigger, FALSE); |
|
278 } |
|
279 } |
|
280 |
|
281 QTM_END_NAMESPACE |
|
282 |