|
1 /* |
|
2 * Copyright (c) 2005 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 "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: Implementation of Client API for the landmark server. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <badesca.h> |
|
22 #include <epos_poslmservercommon.h> |
|
23 #include "EPos_RPosLandmarkServer.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt KDefaultMessageSlots = 4; |
|
27 const TInt KPosLmNumberOfTrials = 5; |
|
28 const TUid KLandmarksServerUid = { 0x101fdf81 }; |
|
29 const TInt KGranularity = 10; |
|
30 const TInt KPreAllocLengthURI = 1024; |
|
31 const TInt KPreAllocLengthDbInfo = 2048; |
|
32 |
|
33 _LIT(KPosLandmarksServerImg, "EPosLmServer"); |
|
34 |
|
35 |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // C++ default constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // |
|
42 EXPORT_C RPosLandmarkServer::RPosLandmarkServer() : |
|
43 RSessionBase(), |
|
44 iExtension(NULL) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // RPosLandmarkServer::Connect |
|
50 // |
|
51 // (other items were commented in a header). |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C TInt RPosLandmarkServer::Connect() |
|
55 { |
|
56 TBool retrying = ETrue; |
|
57 TInt counter = KPosLmNumberOfTrials; |
|
58 TInt err; |
|
59 |
|
60 |
|
61 while (retrying && counter > 0) |
|
62 { |
|
63 err = CreateSession( |
|
64 KPosLandmarksServerName, |
|
65 TVersion( |
|
66 KPosLmServerMajorVersionNumber, |
|
67 KPosLmServerMinorVersionNumber, |
|
68 KPosLmServerBuildVersionNumber), |
|
69 KDefaultMessageSlots); |
|
70 |
|
71 if (err != KErrNotFound && err != KErrServerTerminated) |
|
72 { |
|
73 // Session is up. |
|
74 retrying = EFalse; |
|
75 } |
|
76 else if (--counter > 0) |
|
77 { |
|
78 err = StartServer(); |
|
79 |
|
80 if (err != KErrAlreadyExists && err != KErrNone) |
|
81 { |
|
82 // Server returned error code other than |
|
83 // KErrAlreadyExists or KErrNone. The client should |
|
84 // receive this code. |
|
85 retrying = EFalse; |
|
86 } |
|
87 } |
|
88 } |
|
89 |
|
90 return err; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // RPosLandmarkServer::Close |
|
95 // |
|
96 // (other items were commented in a header). |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 EXPORT_C void RPosLandmarkServer::Close() |
|
100 { |
|
101 RSessionBase::Close(); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // RPosLandmarkServer::ListDatabasesLC |
|
106 // |
|
107 // (other items were commented in a header). |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 EXPORT_C CDesCArray* RPosLandmarkServer::ListDatabasesLC( |
|
111 const TDesC& aProtocol) |
|
112 { |
|
113 TInt allocLength = 0; |
|
114 CDesCArray* array = new (ELeave) CDesCArrayFlat(KGranularity); |
|
115 CleanupStack::PushL(array); |
|
116 |
|
117 CleanupStack::PushL(TCleanupItem(*FreeRsc, this)); |
|
118 |
|
119 HBufC8* buffer = SendMessageLC(EPosLmServerListDatabaseUris, |
|
120 aProtocol, KPreAllocLengthURI, allocLength); |
|
121 |
|
122 PopulateArrayL(array, buffer); |
|
123 CleanupStack::PopAndDestroy(buffer); |
|
124 CleanupStack::Pop(); //FreeRsc |
|
125 |
|
126 if (allocLength > 0) |
|
127 { |
|
128 buffer = SendMessageLC(EPosLmServerRemainingDatabaseUris, |
|
129 KNullDesC, allocLength, allocLength); |
|
130 PopulateArrayL(array, buffer); |
|
131 CleanupStack::PopAndDestroy(buffer); |
|
132 } |
|
133 return array; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // RPosLandmarkServer::ListDatabasesL |
|
138 // |
|
139 // (other items were commented in a header). |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C void RPosLandmarkServer::ListDatabasesL( |
|
143 RPointerArray<HPosLmDatabaseInfo>& aDatabaseInfoArray, |
|
144 const TDesC& aProtocol) |
|
145 { |
|
146 CleanupStack::PushL(TCleanupItem(*FreeRsc, this)); |
|
147 |
|
148 TInt allocLength = 0; |
|
149 HBufC8* buffer = SendMessageLC(EPosLmServerListDatabaseInfo, |
|
150 aProtocol, KPreAllocLengthDbInfo, allocLength); |
|
151 |
|
152 PopulateArrayL(aDatabaseInfoArray, buffer); |
|
153 CleanupStack::PopAndDestroy(buffer); |
|
154 CleanupStack::Pop(); //FreeRsc |
|
155 |
|
156 if (allocLength > 0) |
|
157 { |
|
158 buffer = SendMessageLC(EPosLmServerRemainingDatabaseInfo, |
|
159 KNullDesC, allocLength, allocLength); |
|
160 PopulateArrayL(aDatabaseInfoArray, buffer); |
|
161 CleanupStack::PopAndDestroy(buffer); |
|
162 } |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // RPosLandmarkServer::RegisterDatabase |
|
167 // |
|
168 // (other items were commented in a header). |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 EXPORT_C TInt RPosLandmarkServer::RegisterDatabase( |
|
172 HPosLmDatabaseInfo& aDatabaseInfo) |
|
173 { |
|
174 TInt size = aDatabaseInfo.Size(); |
|
175 TPtr8 ptr(reinterpret_cast<TUint8*>(&aDatabaseInfo), size, size); |
|
176 |
|
177 return SendReceive(EPosLmServerRegisterDatabase, TIpcArgs(&ptr)); |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // RPosLandmarkServer::UnregisterDatabase |
|
182 // |
|
183 // (other items were commented in a header). |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 EXPORT_C TInt RPosLandmarkServer::UnregisterDatabase( |
|
187 const TDesC& aDatabaseUri, |
|
188 TChar aDriveLetter) |
|
189 { |
|
190 TPckgC<TChar> drivePckg(aDriveLetter); |
|
191 return SendReceive(EPosLmServerUnregisterDatabase, |
|
192 TIpcArgs(&aDatabaseUri, &drivePckg)); |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // RPosLandmarkServer::UnregisterAllDatabases |
|
197 // |
|
198 // (other items were commented in a header). |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 EXPORT_C TInt RPosLandmarkServer::UnregisterAllDatabases( |
|
202 const TDesC& aProtocol) |
|
203 { |
|
204 return SendReceive(EPosLmServerUnregisterAllDatabases, |
|
205 TIpcArgs(&aProtocol)); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // RPosLandmarkServer::ModifyDatabaseSettings |
|
210 // |
|
211 // (other items were commented in a header). |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 EXPORT_C TInt RPosLandmarkServer::ModifyDatabaseSettings( |
|
215 const TDesC& aDatabaseUri, |
|
216 const TPosLmDatabaseSettings& aDatabaseSettings, |
|
217 TChar aDriveLetter) |
|
218 { |
|
219 TPckgC<TChar> drivePckg(aDriveLetter); |
|
220 TPckgC<TPosLmDatabaseSettings> settingsPckg(aDatabaseSettings); |
|
221 |
|
222 return SendReceive(EPosLmServerModifyDatabaseSettings, |
|
223 TIpcArgs(&aDatabaseUri, &drivePckg, &settingsPckg)); |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // RPosLandmarkServer::GetDatabaseInfo |
|
228 // |
|
229 // (other items were commented in a header). |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 EXPORT_C TInt RPosLandmarkServer::GetDatabaseInfo( |
|
233 HPosLmDatabaseInfo& aDatabaseInfo) |
|
234 { |
|
235 TInt size = aDatabaseInfo.Size(); |
|
236 TPtr8 ptr(reinterpret_cast<TUint8*>(&aDatabaseInfo), size, size); |
|
237 |
|
238 return SendReceive( |
|
239 EPosLmServerReadDatabaseSettings, TIpcArgs(&ptr)); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // RPosLandmarkServer::ReportEvent |
|
244 // |
|
245 // (other items were commented in a header). |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 EXPORT_C TInt RPosLandmarkServer::ReportEvent( |
|
249 const TPosLmDatabaseEvent& aEvent, |
|
250 const TDesC& aDatabaseUri) |
|
251 { |
|
252 TPckgC<TPosLmDatabaseEvent> eventPckg(aEvent); |
|
253 |
|
254 return SendReceive(EPosLmServerReportDbEvent, |
|
255 TIpcArgs(&aDatabaseUri, &eventPckg)); |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // RPosLandmarkServer::StartServer |
|
260 // |
|
261 // (other items were commented in a header). |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 TInt RPosLandmarkServer::StartServer() |
|
265 { |
|
266 TRequestStatus started; |
|
267 |
|
268 const TUidType serverUid(KNullUid, KNullUid, KLandmarksServerUid); |
|
269 |
|
270 /** |
|
271 EPOC is easy, we just create a new server process. Simultaneous launching |
|
272 of two such processes should be detected when the second one attempts to |
|
273 create the server object, failing with KErrAlreadyExists. |
|
274 **/ |
|
275 RProcess server; |
|
276 TInt ret = server.Create(KPosLandmarksServerImg, KNullDesC, serverUid); |
|
277 |
|
278 if (ret != KErrNone) |
|
279 { |
|
280 return ret; |
|
281 } |
|
282 |
|
283 server.Rendezvous(started); |
|
284 // |
|
285 // logon OK - start the server |
|
286 server.Resume(); |
|
287 |
|
288 User::WaitForRequest(started); // wait for start or death |
|
289 |
|
290 server.Close(); |
|
291 |
|
292 return started.Int(); |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // RPosLandmarkServer::SendMessageLC |
|
297 // |
|
298 // (other items were commented in a header). |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 HBufC8* RPosLandmarkServer::SendMessageLC( |
|
302 TInt aFunction, |
|
303 const TDesC& aDes, |
|
304 TInt aLength, |
|
305 TInt& aAllocLength) |
|
306 { |
|
307 HBufC8* buffer = HBufC8::NewLC(aLength); |
|
308 TPtr8 bufPtr = buffer->Des(); |
|
309 |
|
310 TPckg<TInt> allocPckg(aAllocLength); |
|
311 User::LeaveIfError(SendReceive(aFunction, |
|
312 TIpcArgs(&aDes, &bufPtr, &allocPckg))); |
|
313 return buffer; |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // RPosLandmarkServer::PopulateArrayL |
|
318 // |
|
319 // (other items were commented in a header). |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 void RPosLandmarkServer::PopulateArrayL( |
|
323 CDesCArray* aArray, |
|
324 HBufC8* aBuffer) |
|
325 { |
|
326 if (aBuffer->Length() > 0) |
|
327 { |
|
328 TUint8* bufPointer = const_cast<TUint8*>(aBuffer->Ptr()); |
|
329 const TUint8* endPointer = bufPointer + aBuffer->Size(); |
|
330 while (bufPointer < endPointer) |
|
331 { |
|
332 TPckgBuf<TInt> intPckg; |
|
333 intPckg.Copy(bufPointer, intPckg.MaxLength()); |
|
334 |
|
335 TInt uriLength = intPckg(); |
|
336 TInt uriSize = uriLength * 2; |
|
337 bufPointer += intPckg.Size(); |
|
338 HBufC* uri = HBufC::NewLC(uriSize); |
|
339 uri->Des().SetLength(uriLength); |
|
340 |
|
341 TPtr8 uriPtr(reinterpret_cast<TUint8*>( |
|
342 const_cast<TUint16*>(uri->Ptr())), uriSize, uriSize); |
|
343 uriPtr.Copy(bufPointer, uriSize); |
|
344 bufPointer += uriSize; |
|
345 |
|
346 aArray->AppendL(*uri); |
|
347 CleanupStack::PopAndDestroy(uri); |
|
348 } |
|
349 } |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // RPosLandmarkServer::PopulateArrayL |
|
354 // |
|
355 // (other items were commented in a header). |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 void RPosLandmarkServer::PopulateArrayL( |
|
359 RPointerArray<HPosLmDatabaseInfo>& aDatabaseInfoArray, |
|
360 HBufC8* aBuffer) |
|
361 { |
|
362 if (aBuffer->Length() > 0) |
|
363 { |
|
364 TInt currentLength = 0; |
|
365 TInt bufferLength = aBuffer->Length(); |
|
366 do { |
|
367 TUint8* infoPtr = |
|
368 const_cast<TUint8*>(aBuffer->Ptr() + currentLength); |
|
369 HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC( |
|
370 *(reinterpret_cast<HPosLmDatabaseInfo*>(infoPtr))); |
|
371 |
|
372 aDatabaseInfoArray.AppendL(dbInfo); |
|
373 currentLength += dbInfo->Size(); |
|
374 CleanupStack::Pop(dbInfo); |
|
375 } while (currentLength < bufferLength); |
|
376 } |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // RPosLandmarkServer::FreeResources |
|
381 // |
|
382 // (other items were commented in a header). |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void RPosLandmarkServer::FreeResources() |
|
386 { |
|
387 SendReceive(EPosLmServerFreeResources, TIpcArgs(TIpcArgs::ENothing)); |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // RPosLandmarkServer::FreeRsc |
|
392 // |
|
393 // (other items were commented in a header). |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 void RPosLandmarkServer::FreeRsc(TAny* aParam) |
|
397 { |
|
398 reinterpret_cast<RPosLandmarkServer*>(aParam)->FreeResources(); |
|
399 } |
|
400 |
|
401 // End of File |