|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // client side exmaple of how to use the abstract server framework |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <e32debug.h> |
|
20 #include <lbs/lbslocclasstypes.h> |
|
21 #include "lbsdevloggermacros.h" |
|
22 #include "lbsprivacycontrollerimpl.h" |
|
23 #include "lbsprocessuiddefs.h" |
|
24 #include "messageutils.h" |
|
25 #include "lbsnrhserverdata.h" |
|
26 #include "lbsnrhmessageenums.h" |
|
27 #include "lbssatellite.h" |
|
28 #include <lbs/lbsgpsmeasurement.h> |
|
29 |
|
30 /* The Privacy Controller Implementation hides the details of the |
|
31 * Privacy Controller from the class CLbsPrivacyController, which uses only the |
|
32 * published API. |
|
33 * |
|
34 * The privacy comntroller is implemented here as a client of the Network |
|
35 * Request Handler, which includes a server to handle requests from this |
|
36 * component. |
|
37 * |
|
38 * Generic operation on thet client side is implemented by the |
|
39 * code in lbsloccommon\serverframework. |
|
40 */ |
|
41 RNrhServer::RNrhServer() |
|
42 { |
|
43 // nothing to do |
|
44 } |
|
45 |
|
46 |
|
47 RNrhServer::~RNrhServer() |
|
48 { |
|
49 // nothing to do |
|
50 } |
|
51 |
|
52 TVersion RNrhServer::Version() |
|
53 { |
|
54 return TVersion(KNrhServerMajorVersionNumber, |
|
55 KNrhServerMinorVersionNumber, |
|
56 KNrhServerBuildVersionNumber); |
|
57 } |
|
58 |
|
59 TInt RNrhServer::StartServer(TServerStartParams& /*aParams*/) |
|
60 { |
|
61 // Start LBS from LbsRoot |
|
62 TRAPD(err, StartLbsL()); |
|
63 return (err); |
|
64 } |
|
65 |
|
66 void RNrhServer::StartLbsL() |
|
67 { |
|
68 RLbsSystemController systemController; |
|
69 RProcess process; |
|
70 CleanupClosePushL(process); |
|
71 systemController.OpenL(process.SecureId()); |
|
72 CleanupClosePushL(systemController); |
|
73 |
|
74 TInt startErr = systemController.RequestSystemStartup(); |
|
75 if (startErr != ELbsStartupSuccess) |
|
76 { |
|
77 User::Leave(KErrCouldNotConnect); |
|
78 } |
|
79 |
|
80 CleanupStack::PopAndDestroy(2, &process); |
|
81 } |
|
82 |
|
83 //------------------------------------------------------------ |
|
84 |
|
85 RNrhSession::RNrhSession() |
|
86 { |
|
87 // nothing to do |
|
88 } |
|
89 |
|
90 RNrhSession::~RNrhSession() |
|
91 { |
|
92 // nothing to do |
|
93 } |
|
94 |
|
95 |
|
96 /** |
|
97 * Transmits to the server a response to a privacy query. |
|
98 * The message is synchronous, as no response is expected. |
|
99 * |
|
100 * @param aSessionId identified the session to the network request handler to |
|
101 * allow matching of request and response. |
|
102 * @param aResult indicates whether the request is accepted or rejected |
|
103 * @return KErrNone or an error code as for SendReceived |
|
104 */ |
|
105 TInt RNrhSession::SendPrivacyResponse(TLbsNetSessionIdInt aSessionId, |
|
106 CLbsPrivacyController::TRequestVerificationResult aResult) |
|
107 { |
|
108 TInt err; |
|
109 |
|
110 TPrivacyResponseParams privacyResponseParams; |
|
111 privacyResponseParams.iSessionId = aSessionId; |
|
112 privacyResponseParams.iResult = aResult; |
|
113 |
|
114 TPckgBuf<TPrivacyResponseParams> privacyResponseParamsBuf(privacyResponseParams); |
|
115 TIpcArgs args(&privacyResponseParamsBuf); |
|
116 |
|
117 err = SendReceive(ENrhPrivacyControllerResponse, args); |
|
118 |
|
119 return(err); |
|
120 } |
|
121 |
|
122 /** |
|
123 * Transmits to the server a cancel to a privacy query. |
|
124 * The message is synchronous, as no response is expected. |
|
125 * |
|
126 * @param aSessionId identified the session to the network request handler to |
|
127 * allow matching of request and response. |
|
128 * @return KErrNone or an error code as for SendReceived |
|
129 */ |
|
130 TInt RNrhSession::SendPrivacyCancel(TLbsNetSessionIdInt aSessionId) |
|
131 { |
|
132 // Synchronous - we don't expect a response |
|
133 |
|
134 TInt err; |
|
135 |
|
136 TPrivacyCancelParams privacyCancelParams; |
|
137 privacyCancelParams.iSessionId = aSessionId; |
|
138 |
|
139 TPckgBuf<TPrivacyCancelParams> privacyCancelParamsBuf(privacyCancelParams); |
|
140 TIpcArgs args(&privacyCancelParamsBuf); |
|
141 |
|
142 err = SendReceive(ENrhPrivacyControllerCancel, args); |
|
143 |
|
144 return(err); |
|
145 } |
|
146 /** |
|
147 * Issues an uotstanding request to the server, which is completed |
|
148 * when there is a message for the Pribvacy Controller (Request, Location Update |
|
149 * or Complete). |
|
150 * With the message, pointers to a buffer for each of the types of message |
|
151 * data is passed. The appropraite one is filled when a message is |
|
152 * available, and the relevant one is indicated by the completion code for the |
|
153 * status parameter. |
|
154 * |
|
155 * @param aTrs TRequestStatus |
|
156 */ |
|
157 void RNrhSession::RegisterForServerMessages(TRequestStatus& aTrs) |
|
158 { |
|
159 // Have to send it with space for whatever data the server wants to send |
|
160 // back - could be privacy request, location update or session complete |
|
161 TIpcArgs args( &iPrivacyRequestParamsBuf, |
|
162 &iLocationUpdateParamsBuf, |
|
163 &iLbsSessionCompleteParamsBuf); |
|
164 |
|
165 SendReceive(ENrhPrivacyControllerRegister, args, aTrs); |
|
166 } |
|
167 |
|
168 /** |
|
169 * Cancels the outstanding request issued by RegisterForServerMessages() |
|
170 * |
|
171 */ |
|
172 TInt RNrhSession::CancelRequest() |
|
173 { |
|
174 TInt err; |
|
175 TIpcArgs args(TIpcArgs::ENothing); |
|
176 err = SendReceive(ENrhPrivacyControllerCancelRegister, args); |
|
177 return err; |
|
178 } |
|
179 |
|
180 //----------------------------------------------------------- |
|
181 |
|
182 CLbsPrivacyControllerImpl::CLbsPrivacyControllerImpl (MLbsPrivacyObserver* aObserver) |
|
183 : CActive(EPriorityStandard), |
|
184 iObserver(aObserver) |
|
185 { |
|
186 |
|
187 } |
|
188 |
|
189 CLbsPrivacyControllerImpl* CLbsPrivacyControllerImpl::NewL(MLbsPrivacyObserver* aObserver) |
|
190 { |
|
191 CLbsPrivacyControllerImpl* self = new (ELeave) CLbsPrivacyControllerImpl(aObserver); |
|
192 CleanupStack::PushL(self); |
|
193 self->ConstructL(); |
|
194 CleanupStack::Pop(self); |
|
195 return(self); |
|
196 } |
|
197 |
|
198 CLbsPrivacyControllerImpl::~CLbsPrivacyControllerImpl () |
|
199 { |
|
200 if(iSession.SubSessionHandle() != 0) |
|
201 { |
|
202 if(IsActive()) |
|
203 { |
|
204 iSession.CancelRequest(); |
|
205 } |
|
206 iSession.Close(); |
|
207 } |
|
208 if(iServer.Handle() != 0) |
|
209 { |
|
210 iServer.Close(); |
|
211 } |
|
212 if(IsActive()) |
|
213 { |
|
214 Cancel(); |
|
215 } |
|
216 |
|
217 #if defined(SYMBIAN_LOCATION_PRIVACY_V2) |
|
218 delete iCloseDownRequestor; |
|
219 #endif // SYMBIAN_LOCATION_PRIVACY_V2 |
|
220 } |
|
221 |
|
222 void CLbsPrivacyControllerImpl ::ConstructL() |
|
223 { |
|
224 CActiveScheduler::Add(this); |
|
225 |
|
226 /** |
|
227 * See the ServerFramework code for the meaning of this code |
|
228 */ |
|
229 iParams.SetServerFileName(KNrhServerFileName); |
|
230 iParams.SetServerName(KNrhServerName); |
|
231 iParams.SetNumberOfServerSlots(-1); // Use messages from global pool |
|
232 iParams.SetServerUids(KNullUid, KNullUid, KLbsNetRequestHandlerUid); |
|
233 |
|
234 TInt err; |
|
235 err = iServer.Connect(iParams); |
|
236 User::LeaveIfError(err); |
|
237 |
|
238 TNrhPrivacyControllerData data; |
|
239 data.iVersion = iObserver->Version(); |
|
240 TNrhSubSessionType type(ENrhSubSessionPrivacyController); |
|
241 err = iSession.Open<TNrhSubSessionType, TNrhPrivacyControllerData>( |
|
242 iServer, |
|
243 type, |
|
244 data); |
|
245 User::LeaveIfError(err); |
|
246 |
|
247 // Issue an outstanding request to be told of a privacy query. |
|
248 iSession.RegisterForServerMessages(iStatus); |
|
249 SetActive(); |
|
250 |
|
251 #if defined(SYMBIAN_LOCATION_PRIVACY_V2) |
|
252 // If the privacy controller application is using the |
|
253 // MLbsPrivacyObserver2 observer, then register for |
|
254 // close down events from LbsRoot. |
|
255 if (iObserver->Version().iMajor == KLbsPrivacyObserverVersion2Major) |
|
256 { |
|
257 iCloseDownRequestor = CLbsCloseDownRequestDetector::NewL( |
|
258 this, |
|
259 RProcess().SecureId()); |
|
260 } |
|
261 #endif // SYMBIAN_LOCATION_PRIVACY_V2 |
|
262 } |
|
263 |
|
264 |
|
265 /** |
|
266 * Respond to a privacy query |
|
267 */ |
|
268 void CLbsPrivacyControllerImpl::RespondNetworkLocationRequest(TUint aRequestId, |
|
269 CLbsPrivacyController::TRequestVerificationResult aResult) |
|
270 { |
|
271 // Send the data to the server. |
|
272 |
|
273 // Set the session number even if it's not the one we received. |
|
274 // The NRH will detect any discrepancy. |
|
275 // |
|
276 // This does though take away most of the point of changing the session Id |
|
277 // from being a TUint to a TLbsNetSessionIdInt where it also has the UID of |
|
278 // the originator - due to the privacy controller API being published, |
|
279 // the UID gets lost, and it has to be assumed when a response is received that |
|
280 // it is the same as when we sent it. |
|
281 iSessionId.SetSessionNum(aRequestId); |
|
282 |
|
283 iSession.SendPrivacyResponse(iSessionId,aResult); |
|
284 } |
|
285 /** |
|
286 * Rejects a privacy query |
|
287 */ |
|
288 void CLbsPrivacyControllerImpl::CancelNetworkLocationRequest(TUint aRequestId) |
|
289 { |
|
290 iSessionId.SetSessionNum(aRequestId); |
|
291 |
|
292 iSession.SendPrivacyCancel(iSessionId); |
|
293 } |
|
294 |
|
295 /** |
|
296 * Called when the outstanding request is completed. |
|
297 * This indicates that a message has been received from the server, |
|
298 * so the type is identified and the data interpreted and |
|
299 * handled accordingly. |
|
300 * The request is then reisuued. |
|
301 */ |
|
302 void CLbsPrivacyControllerImpl::RunL() |
|
303 { |
|
304 |
|
305 TInt serverResponseType = iStatus.Int(); |
|
306 |
|
307 switch(serverResponseType) |
|
308 { |
|
309 case ENrhServerMessageAck: |
|
310 // Do nothing - just acknowledges a request. |
|
311 { |
|
312 break; |
|
313 } |
|
314 |
|
315 case ENrhServerPrivacyRequest: |
|
316 { |
|
317 HandlePrivacyRequest(); |
|
318 break; |
|
319 } |
|
320 |
|
321 case ENrhServerLocationUpdate: |
|
322 { |
|
323 HandleLocationUpdate(); |
|
324 break; |
|
325 } |
|
326 |
|
327 case ENrhServerLbsSessionComplete: |
|
328 { |
|
329 HandleLbsSessionComplete(); |
|
330 break; |
|
331 } |
|
332 } |
|
333 |
|
334 |
|
335 // Wait for another request |
|
336 // Unless the error is KErrServerTerminated, which |
|
337 // means the NRH has shut down. |
|
338 if (serverResponseType != KErrServerTerminated) |
|
339 { |
|
340 iSession.RegisterForServerMessages(iStatus); |
|
341 SetActive(); |
|
342 } |
|
343 } |
|
344 |
|
345 void CLbsPrivacyControllerImpl::DoCancel() |
|
346 { |
|
347 } |
|
348 |
|
349 /** |
|
350 * Called when a privacy request has been received. |
|
351 * Find out what sort of request it is, extract the data |
|
352 * which specifies how to inform the user, and pass it on to the observer |
|
353 */ |
|
354 void CLbsPrivacyControllerImpl::HandlePrivacyRequest() |
|
355 { |
|
356 |
|
357 |
|
358 TPrivacyRequestParams privacyRequestParams; |
|
359 privacyRequestParams = iSession.iPrivacyRequestParamsBuf(); |
|
360 iSessionId = privacyRequestParams.iSessionId; |
|
361 |
|
362 /* |
|
363 * Need to translate the notification and timeout parameters from TLbsNetPosRequestPrivacyInt |
|
364 * values to a TNotificationType value. |
|
365 */ |
|
366 MLbsPrivacyObserver::TNotificationType notificationType; |
|
367 TLbsNetPosRequestPrivacyInt::TLbsRequestAdviceInt requestAdvice = |
|
368 privacyRequestParams.iRequestPrivacy.RequestAdvice(); |
|
369 TLbsNetPosRequestPrivacyInt::TLbsRequestActionInt requestAction = |
|
370 privacyRequestParams.iRequestPrivacy.RequestAction(); |
|
371 |
|
372 |
|
373 switch(requestAdvice) |
|
374 { |
|
375 case TLbsNetPosRequestPrivacyInt::ERequestAdviceNotify: |
|
376 case TLbsNetPosRequestPrivacyInt::ERequestAdviceSilent: |
|
377 { |
|
378 if(requestAction == TLbsNetPosRequestPrivacyInt::ERequestActionAllow) |
|
379 { |
|
380 notificationType = MLbsPrivacyObserver::ENotifyLocationAccepted; |
|
381 } |
|
382 else |
|
383 { |
|
384 // Covers the 'unused' option as well, though that should never |
|
385 // get this far |
|
386 notificationType = MLbsPrivacyObserver::ENotifyLocationRejected; |
|
387 } |
|
388 break; |
|
389 } |
|
390 |
|
391 case TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify: |
|
392 { |
|
393 if(requestAction == TLbsNetPosRequestPrivacyInt::ERequestActionAllow) |
|
394 { |
|
395 notificationType = MLbsPrivacyObserver::ENotifyAndVerifyLocationAcceptedIfNoReponse; |
|
396 } |
|
397 else |
|
398 { |
|
399 // Covers the 'unused' option as well, though that should never |
|
400 // get this far |
|
401 notificationType = MLbsPrivacyObserver::ENotifyAndVerifyLocationRejectedIfNoReponse; |
|
402 } |
|
403 break; |
|
404 } |
|
405 |
|
406 default: |
|
407 { |
|
408 // No other value should get this far. |
|
409 User::Invariant(); |
|
410 break; |
|
411 } |
|
412 } |
|
413 |
|
414 LBSLOG(ELogP9, "<-A MLbsPrivacyObserver::ProcessNetworkLocationRequest() lbsnetworkrequesthandler.exe\n"); |
|
415 LBSLOG2(ELogP9, " > TUint iSessionId.SessionNum() = %u\n", iSessionId.SessionNum()); |
|
416 LBSLOG2(ELogP9, " > TNotificationType notificationType = %d\n", notificationType); |
|
417 LBSLOG(ELogP9, " > TLbsExternalRequestInfo privacyRequestParams.iRequestInfo =\n"); |
|
418 LBSLOG_TLBSEXTERNALREQ(privacyRequestParams.iRequestInfo); |
|
419 iObserver->ProcessNetworkLocationRequest(iSessionId.SessionNum(), |
|
420 privacyRequestParams.iRequestInfo, |
|
421 notificationType); |
|
422 } |
|
423 |
|
424 /** |
|
425 * Called when a location update has been received. |
|
426 * Extract the position data, and pass it on to the observer |
|
427 */ |
|
428 void CLbsPrivacyControllerImpl::HandleLocationUpdate() |
|
429 { |
|
430 TLocationUpdateParams locationUpdateParams; |
|
431 locationUpdateParams = iSession.iLocationUpdateParamsBuf(); |
|
432 |
|
433 LBSLOG(ELogP9, "<-A MLbsPrivacyObserver::ProcessNetworkPositionUpdate() lbsnetworkrequesthandler.exe\n"); |
|
434 LBSLOG2(ELogP9, " > TUint locationUpdateParams.iSessionId.SessionNum() = %u\n", locationUpdateParams.iSessionId.SessionNum()); |
|
435 LBSLOG(ELogP9, " > TPositionInfo locationUpdateParams.iPositionInfo = \n"); |
|
436 LBSLOG_TPOSITIONINFOBASE(locationUpdateParams.iPositionInfo); |
|
437 iObserver->ProcessNetworkPositionUpdate( |
|
438 locationUpdateParams.iSessionId.SessionNum(), |
|
439 locationUpdateParams.iPositionInfo); |
|
440 } |
|
441 |
|
442 /** |
|
443 * Called when a session complete message has been received. |
|
444 * Extract the data, which consists of the session id and the |
|
445 * reason for completing the session, and pass it on to the observer |
|
446 */ |
|
447 void CLbsPrivacyControllerImpl::HandleLbsSessionComplete() |
|
448 { |
|
449 TLbsSessionCompleteParams sessionCompleteParams; |
|
450 sessionCompleteParams = iSession.iLbsSessionCompleteParamsBuf(); |
|
451 |
|
452 LBSLOG(ELogP9, "<-A MLbsPrivacyObserver::ProcessRequestComplete() lbsnetworkrequesthandler.exe\n"); |
|
453 LBSLOG2(ELogP9, " > TUint sessionCompleteParams.iSessionId.SessionNum() = %u\n", sessionCompleteParams.iSessionId.SessionNum()); |
|
454 LBSLOG2(ELogP9, " > TInt sessionCompleteParams.iReason = %d\n", sessionCompleteParams.iReason); |
|
455 iObserver->ProcessRequestComplete( |
|
456 sessionCompleteParams.iSessionId.SessionNum(), |
|
457 sessionCompleteParams.iReason); |
|
458 } |
|
459 |
|
460 /** Callback from LbsRoot to tell this process to stop. |
|
461 |
|
462 CLbsPrivacyControllerImpl should only register for this shutdown callback |
|
463 if the MLbsPrivacyObserver2 version of the privacy controller observer |
|
464 was used. |
|
465 |
|
466 This callback will be triggered by LbsRoot when it is shutting down the |
|
467 LBS system. We must call ProcessCloseDownNotification to tell the |
|
468 privacy controller application to shutdown. |
|
469 */ |
|
470 void CLbsPrivacyControllerImpl::OnProcessCloseDown() |
|
471 { |
|
472 #if defined(SYMBIAN_LOCATION_PRIVACY_V2) |
|
473 MLbsPrivacyObserver2* observer = static_cast<MLbsPrivacyObserver2*>(iObserver); |
|
474 observer->ProcessCloseDownNotification(KErrNone); |
|
475 #endif // SYMBIAN_LOCATION_PRIVACY_V2 |
|
476 } |
|
477 |