|
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 // lbsnrhserver.cpp |
|
15 // server side exmaple of how to use the abstract server framework |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32debug.h> |
|
20 #include <lbs/lbslocclasstypes.h> |
|
21 #include "lbsnrhprivacycontrollerserver.h" |
|
22 #include "opensessionparams.h" |
|
23 #include "lbsnrhmessageenums.h" |
|
24 #include "lbsnrhserverdata.h" |
|
25 #include "nrhpanic.h" |
|
26 |
|
27 TPositionInfoClassTypeFixer::TPositionInfoClassTypeFixer(const TPositionInfo& aPositionInfo) : |
|
28 TPositionInfo(aPositionInfo) |
|
29 { |
|
30 iPosClassType = EPositionInfoClass; |
|
31 iPosClassSize = sizeof(TPositionInfo); |
|
32 } |
|
33 |
|
34 CNrhPrivacyServerSubsession::CNrhPrivacyServerSubsession() : |
|
35 iPendingPrivacyRequests(1) |
|
36 { |
|
37 } |
|
38 |
|
39 CNrhPrivacyServerSubsession::~CNrhPrivacyServerSubsession() |
|
40 { |
|
41 // cancel ANY outstanding requests with KErrServerTerminated |
|
42 // or some other error code to indicate that the session has been closed |
|
43 // early |
|
44 if(!iPrivacyControllerMessage.IsNull()) |
|
45 { |
|
46 iPrivacyControllerMessage.Complete(KErrServerTerminated); |
|
47 } |
|
48 |
|
49 iPendingMessage.Reset(); |
|
50 iPendingPrivacyRequests.Reset(); |
|
51 iPendingLocationUpdates.Reset(); |
|
52 iPendingSessionCompletes.Reset(); |
|
53 CloseSubSession(); |
|
54 } |
|
55 |
|
56 CNrhPrivacyServerSubsession* CNrhPrivacyServerSubsession::NewL() |
|
57 { |
|
58 CNrhPrivacyServerSubsession* self = new (ELeave) CNrhPrivacyServerSubsession; |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(self); |
|
62 return self; |
|
63 } |
|
64 |
|
65 void CNrhPrivacyServerSubsession::ConstructL() |
|
66 { |
|
67 } |
|
68 |
|
69 void CNrhPrivacyServerSubsession::DispatchL(const RMessage2& aMessage) |
|
70 { |
|
71 switch(aMessage.Function()) |
|
72 { |
|
73 case ENrhPrivacyControllerRegister: |
|
74 SetClientReady(aMessage); |
|
75 break; |
|
76 |
|
77 case ENrhPrivacyControllerCancelRegister: |
|
78 CancelClientReady(aMessage); |
|
79 break; |
|
80 |
|
81 case ENrhPrivacyControllerResponse: |
|
82 HandlePrivacyResponse(aMessage); |
|
83 break; |
|
84 |
|
85 case ENrhPrivacyControllerCancel: |
|
86 HandlePrivacyCancel(aMessage); |
|
87 break; |
|
88 } |
|
89 } |
|
90 |
|
91 void CNrhPrivacyServerSubsession::DispatchError(const RMessage2& /*aMessage*/, TInt /*aError*/) |
|
92 { |
|
93 // errors from DispatchL end up in here |
|
94 } |
|
95 |
|
96 void CNrhPrivacyServerSubsession::CreateSubSessionL(const RMessage2& aMessage, |
|
97 const CSecureServerBase* aServer) |
|
98 { |
|
99 // Get hold of something for this subsession |
|
100 // to pass on its messages (respond/cancel privacy request) to |
|
101 iNrhServer = reinterpret_cast<const CNrhServer*>(aServer); |
|
102 |
|
103 // Check the version of the MLbsPrivacyObserver is supported |
|
104 User::LeaveIfError(CheckPrivacyObserverVersion(aMessage)); |
|
105 |
|
106 // Let the privacyhandler know where it should be passing its messages |
|
107 // (privacy request, location update, session complete) to. |
|
108 iNrhServer->PrivacyObserver()->SetServerObserver(this); |
|
109 } |
|
110 |
|
111 void CNrhPrivacyServerSubsession::CloseSubSession() |
|
112 { |
|
113 if (iNrhServer->PrivacyObserver() != NULL) |
|
114 { |
|
115 iNrhServer->PrivacyObserver()->SetServerObserver(NULL); |
|
116 } |
|
117 } |
|
118 |
|
119 void CNrhPrivacyServerSubsession::VirtualRelease() |
|
120 { |
|
121 //delete ourselves - can be called on a via CS on a leave |
|
122 delete this; // we are allocated via the GetImpl above, and a handle to "us" is returned |
|
123 } |
|
124 |
|
125 void CNrhPrivacyServerSubsession::SetClientReady(const RMessage2& aMessage) |
|
126 { |
|
127 iPrivacyControllerMessage = aMessage; |
|
128 |
|
129 /* |
|
130 * See whether there are any messages which have been received since |
|
131 * sending the last one on to the client |
|
132 */ |
|
133 TInt pendingMessages = iPendingMessage.Count(); |
|
134 if(pendingMessages) |
|
135 { |
|
136 TNrhServerMessageType messageType = iPendingMessage[0]; |
|
137 iPendingMessage.Remove(0); |
|
138 switch(messageType) |
|
139 { |
|
140 case ENrhServerPrivacyRequest: |
|
141 { |
|
142 TPrivacyRequestParams privacyRequestParams = |
|
143 iPendingPrivacyRequests[0]; |
|
144 |
|
145 TPrivacyRequestParamsPckgC privacyRequestParamsPckg(privacyRequestParams); |
|
146 MessageUtils::Write(iPrivacyControllerMessage, |
|
147 EPrivacyRequestParams, |
|
148 privacyRequestParamsPckg); |
|
149 iPrivacyControllerMessage.Complete(ENrhServerPrivacyRequest); |
|
150 iPendingPrivacyRequests.Delete(0); |
|
151 break; |
|
152 } |
|
153 |
|
154 case ENrhServerLocationUpdate: |
|
155 { |
|
156 TLocationUpdateParams locationUpdateParams; |
|
157 locationUpdateParams.iSessionId = iPendingLocationUpdates[0].iSessionId; |
|
158 |
|
159 //It is necessary to update tha class type and size to TPositionInfo class type and size |
|
160 //in case if the pos update is of TPositionCourseInfo, TPositionSatelliteInfo, |
|
161 //TPositionExtendedSatelliteInfo or HPositionGenericInfo class type. |
|
162 // Because only TPositionInfo part is passed to the LbsPrivacyController. |
|
163 TPositionInfoClassTypeFixer posFixer = iPendingLocationUpdates[0].iPositionInfo; |
|
164 locationUpdateParams.iPositionInfo = posFixer; |
|
165 |
|
166 TLocationUpdateParamsPckgC locationUpdateParamsPckg(locationUpdateParams); |
|
167 |
|
168 MessageUtils::Write(iPrivacyControllerMessage, |
|
169 ELocationUpdateParams, |
|
170 locationUpdateParamsPckg); |
|
171 iPrivacyControllerMessage.Complete(ENrhServerLocationUpdate); |
|
172 iPendingLocationUpdates.Remove(0); |
|
173 break; |
|
174 } |
|
175 |
|
176 case ENrhServerLbsSessionComplete: |
|
177 { |
|
178 TLbsSessionCompleteParams lbsSessionCompleteParams = |
|
179 iPendingSessionCompletes[0]; |
|
180 TLbsSessionCompleteParamsPckgC lbsSessionCompleteParamsPckg(lbsSessionCompleteParams); |
|
181 |
|
182 MessageUtils::Write(iPrivacyControllerMessage, |
|
183 ELbsSessionCompleteParams, |
|
184 lbsSessionCompleteParamsPckg); |
|
185 iPrivacyControllerMessage.Complete(ENrhServerLbsSessionComplete); |
|
186 iPendingSessionCompletes.Remove(0); |
|
187 break; |
|
188 } |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 void CNrhPrivacyServerSubsession::CancelClientReady(const RMessage2& aMessage) |
|
194 { |
|
195 // Cancel the outstanding request as well. |
|
196 if(!iPrivacyControllerMessage.IsNull()) |
|
197 { |
|
198 iPrivacyControllerMessage.Complete(KErrNone); |
|
199 } |
|
200 |
|
201 // Complete this message (the cancel request) |
|
202 aMessage.Complete(KErrNone); |
|
203 } |
|
204 |
|
205 void CNrhPrivacyServerSubsession::HandlePrivacyResponse(const RMessage2& aMessage) |
|
206 { |
|
207 |
|
208 // Get the data from the IPC message |
|
209 TPrivacyResponseParams privacyResponseParams; |
|
210 TPckg<TPrivacyResponseParams> privacyResponseParamsBuf(privacyResponseParams); |
|
211 |
|
212 MessageUtils::Read(aMessage, 0, privacyResponseParamsBuf); |
|
213 |
|
214 TLbsNetworkEnumInt::TLbsPrivacyResponseInt response; |
|
215 |
|
216 if(privacyResponseParams.iResult == CLbsPrivacyController::ERequestAccepted) |
|
217 { |
|
218 response = TLbsNetworkEnumInt::EPrivacyResponseAccepted; |
|
219 } |
|
220 else |
|
221 { |
|
222 response = TLbsNetworkEnumInt::EPrivacyResponseRejected; |
|
223 } |
|
224 |
|
225 iNrhServer->PrivacyObserver()->OnRespondNetworkLocationRequest(privacyResponseParams.iSessionId, |
|
226 response, KErrNone); |
|
227 |
|
228 aMessage.Complete(KErrNone); |
|
229 |
|
230 } |
|
231 |
|
232 void CNrhPrivacyServerSubsession::HandlePrivacyCancel(const RMessage2& aMessage) |
|
233 { |
|
234 |
|
235 // Get the data from the IPC message |
|
236 TPrivacyCancelParams privacyCancelParams; |
|
237 TPckg<TPrivacyCancelParams> privacyCancelParamsBuf(privacyCancelParams); |
|
238 |
|
239 MessageUtils::Read(aMessage, 0, privacyCancelParamsBuf); |
|
240 |
|
241 iNrhServer->PrivacyObserver()->OnCancelNetworkLocationRequest(privacyCancelParams.iSessionId); |
|
242 |
|
243 aMessage.Complete(KErrNone); |
|
244 |
|
245 } |
|
246 void CNrhPrivacyServerSubsession::ProcessNetworkLocationRequest(TLbsNetSessionIdInt aSessionId, |
|
247 const TLbsNetworkEnumInt::TLbsNetProtocolServiceInt /*aSessionType*/, |
|
248 const TLbsExternalRequestInfo& aRequestInfo, |
|
249 const TLbsNetPosRequestPrivacyInt& aNetPosRequestPrivacy, |
|
250 TBool /*aIsEmergency*/) |
|
251 { |
|
252 __ASSERT_DEBUG((aRequestInfo.ClassType() == EExternalRequestInfoClass) |
|
253 || (aRequestInfo.ClassType() == |
|
254 (EExternalRequestInfoClass | EExternalRequestInfoClass2)), |
|
255 Panic(ENrhPanicInvalidExternalRequestInfoType)); |
|
256 |
|
257 TPrivacyRequestParams privacyRequestData; |
|
258 privacyRequestData.iSessionId = aSessionId; |
|
259 Mem::Copy(&privacyRequestData.iRequestInfo, |
|
260 &aRequestInfo, |
|
261 aRequestInfo.ClassSize()); |
|
262 privacyRequestData.iRequestPrivacy = aNetPosRequestPrivacy; |
|
263 |
|
264 if(!iPrivacyControllerMessage.IsNull()) |
|
265 { |
|
266 TPrivacyRequestParamsPckgC privacyRequestDataPckg(privacyRequestData); |
|
267 MessageUtils::Write(iPrivacyControllerMessage, |
|
268 EPrivacyRequestParams, |
|
269 privacyRequestDataPckg); |
|
270 iPrivacyControllerMessage.Complete(ENrhServerPrivacyRequest); |
|
271 } |
|
272 else |
|
273 { |
|
274 TRAPD(err, iPendingPrivacyRequests.AppendL(privacyRequestData)); |
|
275 // No point flagging a pending message if we didn't manage to store it |
|
276 if(err == KErrNone) |
|
277 { |
|
278 err = iPendingMessage.Append(ENrhServerPrivacyRequest); |
|
279 } |
|
280 } |
|
281 |
|
282 } |
|
283 |
|
284 void CNrhPrivacyServerSubsession::ProcessNetworkPositionUpdate(TLbsNetSessionIdInt aSessionId, |
|
285 const TPositionInfo& aPositionInfo) |
|
286 { |
|
287 //It is necessary to update tha class type and size to TPositionInfo class type and size |
|
288 //in case if the pos update is of TPositionCourseInfo, TPositionSatelliteInfo, |
|
289 //or HPositionGenericInfo class type. Because only TPositionInfo part is |
|
290 //passed to the LbsPrivacyController. |
|
291 TLocationUpdateParams locationUpdateParams; |
|
292 locationUpdateParams.iSessionId = aSessionId; |
|
293 TPositionInfoClassTypeFixer posFixer = aPositionInfo; |
|
294 locationUpdateParams.iPositionInfo = posFixer; |
|
295 |
|
296 if(!iPrivacyControllerMessage.IsNull()) |
|
297 { |
|
298 TLocationUpdateParamsPckgC locationUpdateParamsPckg(locationUpdateParams); |
|
299 MessageUtils::Write(iPrivacyControllerMessage, |
|
300 ELocationUpdateParams, |
|
301 locationUpdateParamsPckg); |
|
302 iPrivacyControllerMessage.Complete(ENrhServerLocationUpdate); |
|
303 } |
|
304 else |
|
305 { |
|
306 TInt err = iPendingLocationUpdates.Append(locationUpdateParams); |
|
307 // No point flagging a pending message if we didn't manage to store it |
|
308 if(err == KErrNone) |
|
309 { |
|
310 err = iPendingMessage.Append(ENrhServerLocationUpdate); |
|
311 } |
|
312 } |
|
313 } |
|
314 |
|
315 |
|
316 void CNrhPrivacyServerSubsession::ProcessRequestComplete(TLbsNetSessionIdInt aSessionId, |
|
317 TInt aReason) |
|
318 { |
|
319 |
|
320 |
|
321 TLbsSessionCompleteParams lbsSessionCompleteParams; |
|
322 lbsSessionCompleteParams.iSessionId = aSessionId; |
|
323 lbsSessionCompleteParams.iReason = aReason; |
|
324 |
|
325 if(!iPrivacyControllerMessage.IsNull()) |
|
326 { |
|
327 TLbsSessionCompleteParamsPckgC lbsSessionCompleteParamsPckg(lbsSessionCompleteParams); |
|
328 MessageUtils::Write(iPrivacyControllerMessage, |
|
329 ELbsSessionCompleteParams, |
|
330 lbsSessionCompleteParamsPckg); |
|
331 iPrivacyControllerMessage.Complete(ENrhServerLbsSessionComplete); |
|
332 } |
|
333 else |
|
334 { |
|
335 TInt err = iPendingSessionCompletes.Append(lbsSessionCompleteParams); |
|
336 // No point flagging a pending message if we didn't manage to store it |
|
337 if(err == KErrNone) |
|
338 { |
|
339 err = iPendingMessage.Append(ENrhServerLbsSessionComplete); |
|
340 } |
|
341 } |
|
342 } |
|
343 |
|
344 /** Check the version of MLbsPrivacyObserver the client is using is supported. |
|
345 */ |
|
346 TInt CNrhPrivacyServerSubsession::CheckPrivacyObserverVersion(const RMessage2& aMessage) |
|
347 { |
|
348 TInt result = KErrNone; |
|
349 |
|
350 TNrhPrivacyControllerData data; |
|
351 TPckg<TNrhPrivacyControllerData> dataPckg(data); |
|
352 MessageUtils::Read(aMessage, 1, dataPckg); |
|
353 |
|
354 if (data.iVersion.iMajor == KLbsPrivacyObserverVersionMajor |
|
355 && data.iVersion.iMinor == KLbsPrivacyObserverVersionMinor) |
|
356 { |
|
357 result = KErrNone; |
|
358 } |
|
359 else if (data.iVersion.iMajor == KLbsPrivacyObserverVersion2Major |
|
360 && data.iVersion.iMinor == KLbsPrivacyObserverVersion2Minor) |
|
361 { |
|
362 #if defined(SYMBIAN_LOCATION_PRIVACY_V2) |
|
363 result = KErrNone; |
|
364 #else |
|
365 result = KErrNotSupported; |
|
366 #endif // SYMBIAN_LOCATION_PRIVACY_V2 |
|
367 } |
|
368 else |
|
369 { |
|
370 // Unrecognised version; so return KErrNotSupported |
|
371 result = KErrNotSupported; |
|
372 } |
|
373 |
|
374 return result; |
|
375 } |