|
1 /* |
|
2 * Copyright (c) 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <e32cmn.h> |
|
22 #include "GpsObserver.h" |
|
23 #include "GpsPlugin.h" |
|
24 |
|
25 // for debug #define BROWSER_GPS_PLUGIN_LOG |
|
26 |
|
27 #ifdef BROWSER_GPS_PLUGIN_LOG |
|
28 |
|
29 #include <flogger.h> |
|
30 |
|
31 // output goes in c:\Logs\gps (create this dir manually if it doesn't exist) |
|
32 |
|
33 _LIT(LOG_DIR, "gps"); |
|
34 _LIT(LOG_NAME, "gps.log"); |
|
35 |
|
36 TBuf16<256> formatBuf; |
|
37 _LIT16(formatInt,"[%d]"); |
|
38 |
|
39 #define LOG_E \ |
|
40 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("E")); \ |
|
41 formatBuf.Format(formatInt, e); \ |
|
42 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, formatBuf) |
|
43 #define LOG_CONNECT \ |
|
44 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("RPositionerServer.Connect")) |
|
45 #define LOG_NUMMODULES \ |
|
46 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("NUMMODULES")); \ |
|
47 formatBuf.Format(formatInt, numberOfModules); \ |
|
48 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, formatBuf) |
|
49 #define LOG_MODULE \ |
|
50 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("MODULE")); \ |
|
51 formatBuf.Format(formatInt, i); \ |
|
52 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, formatBuf) |
|
53 #define LOG_SATMODULE \ |
|
54 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("SATELLITE MODULE")); \ |
|
55 formatBuf.Format(formatInt, i); \ |
|
56 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, formatBuf) |
|
57 #define LOG_OPEN \ |
|
58 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("RPositioner.Open")) |
|
59 #define LOG_OPTIONS \ |
|
60 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("RPositioner.SetUpdateOptions")) |
|
61 #define LOG_REQUESTOR \ |
|
62 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("RPositioner.SetRequestor")) |
|
63 #define LOG_REQUESTFIELD \ |
|
64 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("HPositionGenericInfo.SetRequestedField")) |
|
65 #define LOG_POSITIONUPDATE \ |
|
66 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("RPositioner.NotifyPositionUpdate")) |
|
67 #define LOG_RESPONSE \ |
|
68 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("response")) |
|
69 #define LOG_GETPOSITION \ |
|
70 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, _L("HPositionGenericInfo.GetPosition")) |
|
71 #define LOG_LATLNGALT \ |
|
72 int lat = iPosition.Latitude(); \ |
|
73 int lon = iPosition.Longitude(); \ |
|
74 int alt = iPosition.Altitude(); \ |
|
75 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, formatBuf); \ |
|
76 formatBuf.Format(formatInt, lat); \ |
|
77 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, formatBuf); \ |
|
78 formatBuf.Format(formatInt, lon); \ |
|
79 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, formatBuf); \ |
|
80 formatBuf.Format(formatInt, alt); \ |
|
81 RFileLogger::Write(LOG_DIR, LOG_NAME, EFileLoggingModeAppend, formatBuf) |
|
82 |
|
83 |
|
84 #else |
|
85 |
|
86 #define LOG_E |
|
87 #define LOG_CONNECT |
|
88 #define LOG_NUMMODULES |
|
89 #define LOG_MODULE |
|
90 #define LOG_SATMODULE |
|
91 #define LOG_OPEN |
|
92 #define LOG_OPTIONS |
|
93 #define LOG_REQUESTOR |
|
94 #define LOG_REQUESTFIELD |
|
95 #define LOG_POSITIONUPDATE |
|
96 #define LOG_RESPONSE |
|
97 #define LOG_GETPOSITION |
|
98 #define LOG_LATLNGALT |
|
99 |
|
100 #endif |
|
101 |
|
102 |
|
103 // ============================ MEMBER FUNCTIONS =============================== |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CGpsObserver::NewL |
|
107 // Symbian 2-phase constructor. |
|
108 // ----------------------------------------------------------------------------- |
|
109 CGpsObserver* CGpsObserver::NewL( CGpsPlugin* aPlugin ) |
|
110 { |
|
111 CGpsObserver* self = new (ELeave) CGpsObserver( aPlugin ); |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL(); |
|
114 CleanupStack::Pop( self ); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CGpsObserver::CGpsObserver |
|
120 // C++ default constructor can NOT contain any code, that |
|
121 // might leave. |
|
122 // ----------------------------------------------------------------------------- |
|
123 CGpsObserver::CGpsObserver( CGpsPlugin* aPlugin ) |
|
124 : CActive( EPriorityStandard ), |
|
125 iGpsPlugin( aPlugin ) |
|
126 { |
|
127 CActiveScheduler::Add( this ); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CGpsObserver::ConstructL |
|
132 // 2nd-phase constructor. |
|
133 // ----------------------------------------------------------------------------- |
|
134 void CGpsObserver::ConstructL() |
|
135 { |
|
136 TInt e; // for error codes |
|
137 |
|
138 // 1. connect to the position server |
|
139 e = iServer.Connect(); |
|
140 LOG_E; |
|
141 LOG_CONNECT; |
|
142 User::LeaveIfError( e ); |
|
143 |
|
144 // 2. find the satellite module (see the BLID application source |
|
145 // code CSattelliteEng.cpp) |
|
146 TUint numberOfModules = 0; |
|
147 e = iServer.GetNumModules( numberOfModules ); |
|
148 LOG_E; |
|
149 LOG_NUMMODULES; |
|
150 User::LeaveIfError( e ); |
|
151 |
|
152 TPositionModuleInfo moduleInfo; |
|
153 TInt i; |
|
154 for ( i = 0; i < numberOfModules ; i++ ) |
|
155 { |
|
156 LOG_MODULE; |
|
157 e = iServer.GetModuleInfoByIndex( i, moduleInfo ); |
|
158 LOG_E; |
|
159 if ( ( e == KErrNone ) && |
|
160 ( moduleInfo.Capabilities() |
|
161 & TPositionModuleInfo::ECapabilitySatellite ) ) /* bit test */ |
|
162 { |
|
163 break; |
|
164 } |
|
165 } |
|
166 |
|
167 if ( i == numberOfModules ) |
|
168 { |
|
169 // leave if no GPS |
|
170 User::Leave( KErrNotFound ); |
|
171 } |
|
172 |
|
173 // 3. open the positioner with the satellite module |
|
174 LOG_SATMODULE; |
|
175 TPositionModuleId moduleId = moduleInfo.ModuleId(); |
|
176 e = iPositioner.Open( iServer, moduleId ); |
|
177 LOG_E; |
|
178 User::LeaveIfError( e ); |
|
179 LOG_OPEN; |
|
180 |
|
181 // 4. set the requestor on the positioner (something for security) |
|
182 iPositioner.SetRequestor( CRequestor::ERequestorService, |
|
183 CRequestor::EFormatApplication, |
|
184 _L("BrowserGpsPlugin")/**srvName*/ ); |
|
185 LOG_REQUESTOR; |
|
186 |
|
187 // 5. request position notification |
|
188 iPositioner.NotifyPositionUpdate( iPositionInfo, iStatus ); |
|
189 SetActive(); |
|
190 LOG_POSITIONUPDATE; |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CGpsObserver::~CGpsObserver() |
|
195 // Destructor |
|
196 // ----------------------------------------------------------------------------- |
|
197 CGpsObserver::~CGpsObserver() |
|
198 { |
|
199 Cancel(); |
|
200 iPositioner.Close(); |
|
201 iServer.Close(); |
|
202 |
|
203 delete iEventHandler; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CSystemInfoBatteryObserver::RequestNotification |
|
208 // ----------------------------------------------------------------------------- |
|
209 void CGpsObserver::RequestNotificationL( const NPString& aEvent ) |
|
210 { |
|
211 // remove and free current handler |
|
212 HBufC8* handler = iEventHandler; |
|
213 iEventHandler = NULL; |
|
214 delete handler; |
|
215 |
|
216 //store the event handler function name |
|
217 TInt length = aEvent.UTF8Length; |
|
218 handler = HBufC8::NewL( length+1 ); |
|
219 |
|
220 TPtr8 tptr = handler->Des(); |
|
221 tptr.Copy( (const TUint8 *)aEvent.UTF8Characters, length ); |
|
222 |
|
223 //Remove any arguments passed in the with the function name |
|
224 TInt pos = handler->LocateReverse( TChar('(') ); |
|
225 if ( pos != KErrNotFound ) |
|
226 { |
|
227 length = pos; |
|
228 } |
|
229 |
|
230 tptr.SetLength( length ); |
|
231 tptr.ZeroTerminate(); |
|
232 |
|
233 iEventHandler = handler; |
|
234 |
|
235 // monitoring is already active |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CSystemInfoBatteryObserver::RunL |
|
240 // ----------------------------------------------------------------------------- |
|
241 void CGpsObserver::RunL() |
|
242 { |
|
243 // if status ok and exists, update values and invoke callback |
|
244 if ( iStatus == KErrNone ) |
|
245 { |
|
246 // update saved values |
|
247 iPositionInfo.GetPosition( iPosition ); |
|
248 LOG_GETPOSITION; |
|
249 LOG_LATLNGALT; |
|
250 |
|
251 iTickCount++; |
|
252 if ( iEventHandler ) |
|
253 { |
|
254 iGpsPlugin->InvokeCallback( *iEventHandler, NULL, 0 ); |
|
255 } |
|
256 } |
|
257 |
|
258 // request next update |
|
259 iPositioner.NotifyPositionUpdate( iPositionInfo, iStatus ); |
|
260 SetActive(); |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CGpsObserver::RunError |
|
265 // ----------------------------------------------------------------------------- |
|
266 TInt CGpsObserver::RunError( TInt /*aError*/ ) |
|
267 { |
|
268 return KErrNone; |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CGpsObserver::DoCancel |
|
273 // ----------------------------------------------------------------------------- |
|
274 void CGpsObserver::DoCancel() |
|
275 { |
|
276 iPositioner.CancelRequest( EPositionerNotifyPositionUpdate ); |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CGpsObserver::Latitude |
|
281 // ----------------------------------------------------------------------------- |
|
282 TReal CGpsObserver::Latitude() const |
|
283 { |
|
284 return iPosition.Latitude(); |
|
285 } |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CGpsObserver::Longitude |
|
289 // ----------------------------------------------------------------------------- |
|
290 TReal CGpsObserver::Longitude() const |
|
291 { |
|
292 return iPosition.Longitude(); |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CGpsObserver::Altitude |
|
297 // ----------------------------------------------------------------------------- |
|
298 TReal CGpsObserver::Altitude() const |
|
299 { |
|
300 return iPosition.Altitude(); |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CGpsObserver::HorizontalAccuracy |
|
305 // ----------------------------------------------------------------------------- |
|
306 TReal CGpsObserver::HorizontalAccuracy() const |
|
307 { |
|
308 return iPosition.HorizontalAccuracy(); |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CGpsObserver::VerticalAccuracy |
|
313 // ----------------------------------------------------------------------------- |
|
314 TReal CGpsObserver::VerticalAccuracy() const |
|
315 { |
|
316 return iPosition.VerticalAccuracy(); |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CGpsObserver::TIckCount |
|
321 // ----------------------------------------------------------------------------- |
|
322 TInt CGpsObserver::TickCount() const |
|
323 { |
|
324 return iTickCount; |
|
325 } |
|
326 |
|
327 // End of File |