|
1 // Copyright (c) 2007-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 // Class implementation of RPrivacyServer |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 @released |
|
22 */ |
|
23 |
|
24 // INCLUDE FILES |
|
25 #include <e32std.h> |
|
26 #include "lbsprivacyclient.h" |
|
27 #include "lbsprivacyservermsgenums.h" |
|
28 #include "lbssystemcontroller.h" |
|
29 #include "lbsdevloggermacros.h" |
|
30 |
|
31 const TInt KPosNumberOfTrials = 16; |
|
32 |
|
33 // The name of the server |
|
34 _LIT(KPrivacyServerName,"LBSPrivacyServer"); |
|
35 |
|
36 /* |
|
37 * C++ default constructor |
|
38 */ |
|
39 RPrivacyServer::RPrivacyServer() |
|
40 : RSessionBase(),iRequestInfoPkg(iRequestInfo), |
|
41 iNetPosRequestPrivacyPkg(iNetPosRequestPrivacy), |
|
42 iRequestIdPkg(iRequestId), |
|
43 iRequestIdUint32Pkg(iRequestIdUint32) |
|
44 { |
|
45 } |
|
46 |
|
47 |
|
48 /* |
|
49 * Destructor |
|
50 */ |
|
51 RPrivacyServer::~RPrivacyServer() |
|
52 { |
|
53 } |
|
54 |
|
55 /** |
|
56 * Opens a connection with the server. This method must be called |
|
57 * before any other operation. |
|
58 * @return KErrNone if the operation was successful, otherwise |
|
59 * one of the system-wide error codes. |
|
60 */ |
|
61 |
|
62 TInt RPrivacyServer::Connect(TLbsProxyApiType aApiType) |
|
63 { |
|
64 TInt err = KErrNone; |
|
65 |
|
66 // Attempt to start the server and create a session |
|
67 for (TInt retry = 0; retry < KPosNumberOfTrials; retry++) |
|
68 { |
|
69 TVersion version; |
|
70 if (aApiType == ELbsProxyApiTypeLocal) |
|
71 { |
|
72 version = TVersion(KLbsLocalPrivacyAPIVersionMajor, |
|
73 KLbsLocalPrivacyAPIVersionMinor, |
|
74 KLbsLocalPrivacyAPIVersionBuild); |
|
75 } |
|
76 else |
|
77 { |
|
78 version = TVersion(KLbsNetworkPrivacyAPIVersionMajor, |
|
79 KLbsNetworkPrivacyAPIVersionMinor, |
|
80 KLbsNetworkPrivacyAPIVersionBuild); |
|
81 } |
|
82 |
|
83 err = CreateSession(KPrivacyServerName, version); |
|
84 if (err == KErrNone) |
|
85 { |
|
86 break; // We have a session |
|
87 } |
|
88 // Server already started |
|
89 if (err == KErrAlreadyExists) |
|
90 { |
|
91 err = KErrNone; //Server already started |
|
92 break; |
|
93 } |
|
94 |
|
95 // Can't create a session |
|
96 if ((err == KErrNotFound) || (err == KErrServerTerminated)) |
|
97 { |
|
98 // Start Lbs |
|
99 // We're not interested in the error code returned as we must retry KPosNumberOfTrials times anyway |
|
100 StartLbsSystem(); |
|
101 } |
|
102 }// for |
|
103 return err; |
|
104 } |
|
105 |
|
106 /** |
|
107 * Verifies that a requesting remote party is allowed to do a |
|
108 * request. |
|
109 * @param aRequestId An id for the request. |
|
110 * @param aRequestInfo the requestInfo that should be used for |
|
111 * verification. |
|
112 * @param aRequestAction The timeout decision in case a network timeout |
|
113 * occurs. |
|
114 * @param aStatus is set to KErrNone if the request is allowed and |
|
115 * KErrAccessDenied if it is not. |
|
116 */ |
|
117 void RPrivacyServer::VerifyLocationRequest(TInt& aRequestId,TLbsExternalRequestInfo2& aRequestInfo, |
|
118 TLbsNetPosRequestPrivacy& aNetPosRequestPrivacy, |
|
119 TRequestStatus& aStatus) |
|
120 { |
|
121 iRequestInfo = aRequestInfo; |
|
122 |
|
123 iNetPosRequestPrivacy = aNetPosRequestPrivacy; |
|
124 |
|
125 RSemaphore semaphore; |
|
126 |
|
127 TInt err = semaphore.CreateGlobal(KNullDesC, 0, EOwnerThread); |
|
128 if(err != KErrNone) |
|
129 { |
|
130 aStatus = KRequestPending; |
|
131 TRequestStatus* status = &aStatus; |
|
132 User::RequestComplete(status, err); |
|
133 } |
|
134 |
|
135 TIpcArgs args(&iRequestIdPkg,&iRequestInfoPkg,&iNetPosRequestPrivacyPkg, semaphore); |
|
136 |
|
137 SendReceive(ELbsPrivacyServerVerifyLocation,args,aStatus); |
|
138 |
|
139 semaphore.Wait(); |
|
140 semaphore.Close(); |
|
141 aRequestId = iRequestId; |
|
142 } |
|
143 |
|
144 /** |
|
145 * Cancels an outstanding verification request. |
|
146 * @param aRequestId An Id for the request. |
|
147 * @param aCancelReason A cancel reason. |
|
148 * @return KErrNone, if the send operation is successful; KErrServerTerminated, |
|
149 * if the server no longer present; KErrServerBusy, if there are no message slots available; |
|
150 * KErrNoMemory, if there is insufficient memory available. |
|
151 */ |
|
152 TInt RPrivacyServer::CancelVerifyLocationRequest(TInt aRequestId , TInt aCancelReason) |
|
153 { |
|
154 TIpcArgs args(aRequestId, aCancelReason); |
|
155 return (SendReceive(ELbsPrivacyServerCancelVerifyLocationRequest, args)); |
|
156 } |
|
157 /** |
|
158 * Notifies the user that a service or user has made a location request. |
|
159 * This notification is used for requests that don't have been verified |
|
160 * by the privacy server. |
|
161 * @param aRequestInfo the requestInfo that should be used for notification. |
|
162 * @param aRequestId An id for the request. |
|
163 * @return KErrNone, if the send operation is successful; KErrServerTerminated, |
|
164 * if the server no longer present; KErrServerBusy, if there are no message slots available; |
|
165 * KErrNoMemory, if there is insufficient memory available. |
|
166 */ |
|
167 |
|
168 TInt RPrivacyServer::NotifyLocationRequest(TLbsExternalRequestInfo2& aRequestInfo, TInt& aRequestId, |
|
169 TLbsNetPosRequestPrivacy& aNetPosRequestPrivacy) |
|
170 { |
|
171 |
|
172 TPckg<TLbsExternalRequestInfo2> requestInfoPkg(aRequestInfo); |
|
173 TPckg<TLbsNetPosRequestPrivacy> netPosRequestPrivacyPkg(aNetPosRequestPrivacy); |
|
174 TPckg<TInt> pkgReqId(aRequestId); |
|
175 |
|
176 TIpcArgs args(&requestInfoPkg,&pkgReqId,&netPosRequestPrivacyPkg); |
|
177 return(SendReceive(ELbsPrivacyServerNotifyLocation, args)); |
|
178 } |
|
179 /** |
|
180 * Called to report that a verification timed out. |
|
181 * @param aRequestInfo the requestInfo that should be used for verification. |
|
182 * @param aRequestId The request id. |
|
183 * @param aRequestAction The reason for a notification. |
|
184 * @return KErrNone, if the send operation is successful; KErrServerTerminated, |
|
185 * if the server no longer present; KErrServerBusy, if there are no message slots available; |
|
186 * KErrNoMemory, if there is insufficient memory available. |
|
187 */ |
|
188 |
|
189 TInt RPrivacyServer::NotifyVerificationTimeout(TLbsExternalRequestInfo2& aRequestInfo,TInt aRequestId, |
|
190 TLbsNetPosRequestPrivacy& aNetPosRequestPrivacy) |
|
191 { |
|
192 TPckg<TLbsExternalRequestInfo2> requestInfoPkg(aRequestInfo); |
|
193 TPckg<TLbsNetPosRequestPrivacy> netPosRequestPrivacyPkg(aNetPosRequestPrivacy); |
|
194 TIpcArgs args(&requestInfoPkg,aRequestId,&netPosRequestPrivacyPkg); |
|
195 return (SendReceive(ELbsPrivacyServerNotifyVerificationTimeout, args)); |
|
196 } |
|
197 |
|
198 /** |
|
199 * Sends an asynchronous privacy request to the Privacy Protocol Module. The method waits |
|
200 * for the server to write the request ID parameter and then returns. |
|
201 * |
|
202 * @param aRequestID The request id |
|
203 * @param aRequestInfo The details of the request |
|
204 * @param aPrivacyRequest The actual request, the type and preferred action |
|
205 * @param aStatus The TRequestStatus that should be completed |
|
206 */ |
|
207 void RPrivacyServer::NewPrivacyRequest(TUint32& aRequestId, const TLbsExternalRequestInfo& aRequestInfo, |
|
208 const TLbsNetPosRequestPrivacy& aPrivacyRequest, TRequestStatus& aStatus) |
|
209 { |
|
210 Mem::Copy(&iRequestInfo, &aRequestInfo, aRequestInfo.ClassSize()); |
|
211 |
|
212 iNetPosRequestPrivacy = aPrivacyRequest; |
|
213 |
|
214 RSemaphore semaphore; |
|
215 |
|
216 TInt err = semaphore.CreateGlobal(KNullDesC, 0, EOwnerThread); |
|
217 if(err != KErrNone) |
|
218 { |
|
219 aStatus = KRequestPending; |
|
220 TRequestStatus* status = &aStatus; |
|
221 User::RequestComplete(status, err); |
|
222 } |
|
223 |
|
224 TIpcArgs args(&iRequestIdUint32Pkg,&iRequestInfoPkg,&iNetPosRequestPrivacyPkg, semaphore); |
|
225 |
|
226 // The IPC Message is sent with a different ordinal for local and network requests |
|
227 // so that different capability checking can be done depending on the source of the request |
|
228 if(aRequestInfo.RequestSource() == TLbsExternalRequestInfo::ERequestSourceLocal) |
|
229 { |
|
230 SendReceive(ELbsPrivacyServerNewPrivacyRequestLocal,args,aStatus); |
|
231 } |
|
232 else |
|
233 { |
|
234 SendReceive(ELbsPrivacyServerNewPrivacyRequestNetwork,args,aStatus); |
|
235 } |
|
236 |
|
237 semaphore.Wait(); |
|
238 semaphore.Close(); |
|
239 aRequestId = iRequestIdUint32; |
|
240 } |
|
241 |
|
242 /** |
|
243 * Sends an asynchronous privacy request to the Privacy Protocol Module. |
|
244 * |
|
245 * @param aRequestID The request id |
|
246 * @param aRequestInfo The details of the request |
|
247 * @param aPrivacyRequest The actual request, the type and preferred action |
|
248 * @param aStatus The TRequestStatus that should be completed |
|
249 */ |
|
250 void RPrivacyServer::RepeatPrivacyRequest(TUint32 aRequestId, const TLbsExternalRequestInfo& aRequestInfo, |
|
251 const TLbsNetPosRequestPrivacy& aPrivacyRequest, TRequestStatus& aStatus) |
|
252 { |
|
253 Mem::Copy(&iRequestInfo, &aRequestInfo, aRequestInfo.ClassSize()); |
|
254 |
|
255 iNetPosRequestPrivacy = aPrivacyRequest; |
|
256 |
|
257 TIpcArgs args(aRequestId,&iRequestInfoPkg,&iNetPosRequestPrivacyPkg); |
|
258 // The IPC Message is sent with a different ordinal for local and network requests |
|
259 // so that different capability checking can be done depending on the source of the request |
|
260 if(aRequestInfo.RequestSource() == TLbsExternalRequestInfo::ERequestSourceLocal) |
|
261 { |
|
262 SendReceive(ELbsPrivacyServerRepeatPrivacyRequestLocal,args,aStatus); |
|
263 } |
|
264 else |
|
265 { |
|
266 SendReceive(ELbsPrivacyServerRepeatPrivacyRequestNetwork,args,aStatus); |
|
267 } |
|
268 } |
|
269 |
|
270 /** |
|
271 * Tells the Privacy Protocol Module the request session is finished. |
|
272 * |
|
273 * @param aRequestId The ID of the request session to complete |
|
274 * @param aReason The reason for which the session is ended |
|
275 */ |
|
276 TInt RPrivacyServer::CompleteRequest(TUint32 aRequestId, TInt aReason) |
|
277 { |
|
278 TIpcArgs args(aRequestId, aReason); |
|
279 return (SendReceive(ELbsPrivacyServerCompleteRequest, args)); |
|
280 } |
|
281 |
|
282 /** |
|
283 *Close the connection to the server |
|
284 */ |
|
285 void RPrivacyServer::Close() |
|
286 { |
|
287 RSessionBase::Close(); |
|
288 } |
|
289 |
|
290 /* Start the LBS system |
|
291 ** open the system controller and issue the Lbsroot startup request |
|
292 */ |
|
293 TInt RPrivacyServer::StartLbsSystem() |
|
294 { |
|
295 RLbsSystemController systemController; |
|
296 |
|
297 TRAPD(startErr, systemController.OpenL(KLbsNetworkPrivacyApiUid)); |
|
298 |
|
299 if(startErr == KErrNone) |
|
300 { |
|
301 startErr = systemController.RequestSystemStartup(); |
|
302 systemController.Close(); |
|
303 } |
|
304 |
|
305 return (startErr); |
|
306 } |
|
307 |