|
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 "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: This is the PS server client side interface implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "RPsSession.h" |
|
21 #include "CPsData.h" |
|
22 #include "CPcsDebug.h" |
|
23 |
|
24 // ---------------------------------------------------------------------------- |
|
25 // StartServer |
|
26 // Starts the server. Used only when the server is implemented as a transient. |
|
27 // ---------------------------------------------------------------------------- |
|
28 TInt StartServer() |
|
29 { |
|
30 PRINT ( _L("Enter RPsSession->StartServer") ); |
|
31 |
|
32 RProcess server; |
|
33 server.Create ( KPcsServerExeName, KNullDesC ); |
|
34 |
|
35 TRequestStatus status; |
|
36 server.Rendezvous(status); |
|
37 |
|
38 if ( status != KRequestPending ) |
|
39 { |
|
40 server.Kill(0); |
|
41 server.Close(); |
|
42 return KErrGeneral; |
|
43 } |
|
44 else |
|
45 { |
|
46 server.Resume(); |
|
47 } |
|
48 |
|
49 User::WaitForRequest(status); |
|
50 |
|
51 if ( status != KErrNone ) |
|
52 { |
|
53 server.Close(); |
|
54 return status.Int(); |
|
55 } |
|
56 |
|
57 PRINT ( _L("End RPsSession->StartServer") ); |
|
58 |
|
59 return KErrNone; |
|
60 } |
|
61 // ============================== MEMBER FUNCTIONS ============================ |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // RPsSession::RPsSession |
|
65 // Constructor |
|
66 // ---------------------------------------------------------------------------- |
|
67 RPsSession::RPsSession() : RSessionBase(), |
|
68 iSearchQueryBufferPtr (0, 0), |
|
69 iResultsBufferPtr (0, 0) |
|
70 { |
|
71 PRINT ( _L("Enter RPsSession::RPsSession") ); |
|
72 PRINT ( _L("End RPsSession::RPsSession") ); |
|
73 } |
|
74 |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // RPsSession::Connects to the search server |
|
78 // Returns the version number |
|
79 // ---------------------------------------------------------------------------- |
|
80 TInt RPsSession::Connect() |
|
81 { |
|
82 PRINT ( _L("Enter RPsSession::Connect") ); |
|
83 |
|
84 TInt err = CreateSession( KPcsServerName, Version() ); |
|
85 if ( err != KErrNone ) |
|
86 { |
|
87 PRINT ( _L("Predictive Search server not running. Trying to start") ); |
|
88 RMutex mutex; |
|
89 TInt errMutex = mutex.CreateGlobal( KPcsServerName ); |
|
90 if ( errMutex == KErrAlreadyExists ) |
|
91 { |
|
92 mutex.OpenGlobal( KPcsServerName ); |
|
93 } |
|
94 mutex.Wait(); |
|
95 err = CreateSession( KPcsServerName, Version() ); |
|
96 if ( err != KErrNone ) |
|
97 { |
|
98 err = StartServer(); |
|
99 PRINT1( _L("Predictive Search Engine, StartServer(), Err = %d"), err ); |
|
100 if ( err == KErrNone ) |
|
101 { |
|
102 err = CreateSession( KPcsServerName, Version() ); |
|
103 } |
|
104 } |
|
105 mutex.Signal(); |
|
106 mutex.Close(); |
|
107 } |
|
108 |
|
109 PRINT ( _L("End RPsSession::Connect") ); |
|
110 |
|
111 return err; |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // RPsSession::Version |
|
116 // Returns the version number |
|
117 // ---------------------------------------------------------------------------- |
|
118 TVersion RPsSession::Version() const |
|
119 { |
|
120 return ( TVersion ( KPcsServerMajorVersionNumber, |
|
121 KPcsServerMinorVersionNumber, |
|
122 KPcsServerBuildVersionNumber ) ); |
|
123 } |
|
124 |
|
125 // ---------------------------------------------------------------------------- |
|
126 // RPsSession::SearchL |
|
127 // Initiate a search request. |
|
128 // ---------------------------------------------------------------------------- |
|
129 void RPsSession::SetSearchSettingsL(const TDes8& aSettings) |
|
130 { |
|
131 PRINT ( _L("Enter RPsSession::SetSearchSettingsL") ); |
|
132 |
|
133 TIpcArgs args(&aSettings); |
|
134 |
|
135 // Send the search settings to the server. sync call |
|
136 TRequestStatus status; |
|
137 SendReceive(ESearchSettings, |
|
138 args, |
|
139 status); |
|
140 User::WaitForRequest(status); |
|
141 |
|
142 PRINT ( _L("End RPsSession::SetSearchSettingsL") ); |
|
143 } |
|
144 |
|
145 // ---------------------------------------------------------------------------- |
|
146 // RPsSession::SearchL |
|
147 // Initiate a search request. |
|
148 // ---------------------------------------------------------------------------- |
|
149 void RPsSession::SearchL(const TDes8& aSearchQuery, |
|
150 TPtr8 aResultsBuffer, |
|
151 TRequestStatus& aStatus) |
|
152 { |
|
153 PRINT ( _L("Enter RPsSession::SearchL") ); |
|
154 |
|
155 // Hold the pointer to buffers till the async request is complete |
|
156 iSearchQueryBufferPtr.Set(aSearchQuery); |
|
157 iResultsBufferPtr.Set(aResultsBuffer); |
|
158 |
|
159 TIpcArgs args(&iSearchQueryBufferPtr, &iResultsBufferPtr); |
|
160 |
|
161 aStatus = KRequestPending; |
|
162 |
|
163 // Initiate the search request |
|
164 SendReceive(ESearch, |
|
165 args, |
|
166 aStatus ); |
|
167 |
|
168 PRINT ( _L("End RPsSession::SearchL") ); |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // RPsSession::CancelSearch |
|
173 // Send a request to cancel search. Synchronous. |
|
174 // ---------------------------------------------------------------------------- |
|
175 void RPsSession::CancelSearch() |
|
176 { |
|
177 PRINT ( _L("Enter RPsSession::CancelSearch") ); |
|
178 |
|
179 TRequestStatus status; |
|
180 |
|
181 SendReceive(ECancelSearch, |
|
182 TIpcArgs(), |
|
183 status ); |
|
184 |
|
185 User::WaitForRequest(status); |
|
186 |
|
187 PRINT ( _L("End RPsSession::CancelSearch") ); |
|
188 } |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // RPsSession::SearchL |
|
192 // Initiate a search request. |
|
193 // ---------------------------------------------------------------------------- |
|
194 void RPsSession::SearchL(const TDes8& aSearchQuery, |
|
195 const TDes8& aSearchData, |
|
196 TPtr8 aResultsBuffer) |
|
197 { |
|
198 PRINT ( _L("Enter RPsSession::SearchL") ); |
|
199 |
|
200 TIpcArgs args(&aSearchQuery, &aSearchData, &aResultsBuffer); |
|
201 |
|
202 TRequestStatus status; |
|
203 |
|
204 // Initiate the search request |
|
205 SendReceive(ESearchInput, |
|
206 args, |
|
207 status ); |
|
208 |
|
209 User::WaitForRequest(status); |
|
210 |
|
211 PRINT ( _L("End RPsSession::SearchL") ); |
|
212 } |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // RPsSession::SearchMatchStringL |
|
216 // Initiate a search request. |
|
217 // ---------------------------------------------------------------------------- |
|
218 void RPsSession::SearchMatchStringL(const TDes8& aSearchQuery, |
|
219 const TDes8& aSearchData, |
|
220 TDes& aResultsBuffer) |
|
221 { |
|
222 PRINT ( _L("Enter RPsSession::SearchMatchStringL") ); |
|
223 |
|
224 TIpcArgs args(&aSearchQuery, &aSearchData, &aResultsBuffer); |
|
225 |
|
226 TRequestStatus status; |
|
227 |
|
228 // Initiate the search request |
|
229 SendReceive(ESearchMatchString, |
|
230 args, |
|
231 status ); |
|
232 |
|
233 User::WaitForRequest(status); |
|
234 |
|
235 PRINT ( _L("End RPsSession::SearchMatchStringL") ); |
|
236 } |
|
237 |
|
238 // ---------------------------------------------------------------------------- |
|
239 // RPsSession::SendNewBufferL |
|
240 // Send a new buffer to recover the search results. |
|
241 // ---------------------------------------------------------------------------- |
|
242 void RPsSession::SendNewBufferL(TPtr8 aResultsBuffer, |
|
243 TRequestStatus& aStatus) |
|
244 { |
|
245 PRINT ( _L("Enter RPsSession::SendNewBufferL") ); |
|
246 |
|
247 iResultsBufferPtr.Set(aResultsBuffer); |
|
248 |
|
249 aStatus = KRequestPending; |
|
250 |
|
251 // Search command is reused here. Hence there is no need to fill |
|
252 // the search query. |
|
253 TIpcArgs args(TIpcArgs::ENothing, |
|
254 &iResultsBufferPtr); |
|
255 |
|
256 SendReceive(ESearch, |
|
257 args, |
|
258 aStatus); |
|
259 |
|
260 PRINT ( _L("Enter RPsSession::SendNewBufferL") ); |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // RPsSession::IsLanguageSupportedL() |
|
265 // Checks if the language variant is supported by |
|
266 // the predictive search engine. |
|
267 // Synchronous |
|
268 // ----------------------------------------------------------------------------- |
|
269 void RPsSession::IsLanguageSupportedL(const TDes8& aLanguage, |
|
270 TPtr8 aResultsBuffer) |
|
271 { |
|
272 PRINT ( _L("Enter RPsSession::IsLanguageSupportedL") ); |
|
273 |
|
274 TIpcArgs args(&aLanguage, &aResultsBuffer); |
|
275 TRequestStatus status; |
|
276 |
|
277 // initiate the request |
|
278 SendReceive(ELangSupport, |
|
279 args, |
|
280 status); |
|
281 |
|
282 User::WaitForRequest(status); |
|
283 |
|
284 PRINT ( _L("End RPsSession::IsLanguageSupportedL") ); |
|
285 } |
|
286 |
|
287 // ---------------------------------------------------------------------------- |
|
288 // RPsSession::GetDataOrderL |
|
289 // Send a request to the PS server to recover data fields supported by a store. |
|
290 // ---------------------------------------------------------------------------- |
|
291 void RPsSession::GetDataOrderL(const TDes8& aURI, |
|
292 TPtr8 aResultsBuffer) |
|
293 { |
|
294 PRINT ( _L("Enter RPsSession::GetDataOrderL") ); |
|
295 |
|
296 TIpcArgs args(&aURI, &aResultsBuffer); |
|
297 |
|
298 TRequestStatus status; |
|
299 |
|
300 // Initiate the request |
|
301 SendReceive(EGetDataOrder, |
|
302 args, |
|
303 status ); |
|
304 |
|
305 User::WaitForRequest(status); |
|
306 |
|
307 PRINT ( _L("End RPsSession::GetDataOrderL") ); |
|
308 } |
|
309 |
|
310 // ---------------------------------------------------------------------------- |
|
311 // RPsSession::GetSortOrderL |
|
312 // Send a request to the PS server to recover sort order supported by a store. |
|
313 // ---------------------------------------------------------------------------- |
|
314 void RPsSession::GetSortOrderL(const TDes8& aURI, |
|
315 TPtr8 aResultsBuffer) |
|
316 { |
|
317 PRINT ( _L("Enter RPsSession::GetSortOrderL") ); |
|
318 |
|
319 TIpcArgs args(&aURI, &aResultsBuffer); |
|
320 |
|
321 TRequestStatus status; |
|
322 |
|
323 // Initiate the request |
|
324 SendReceive(EGetSortOrder, |
|
325 args, |
|
326 status ); |
|
327 |
|
328 User::WaitForRequest(status); |
|
329 |
|
330 PRINT ( _L("End RPsSession::GetSortOrderL") ); |
|
331 } |
|
332 |
|
333 // ---------------------------------------------------------------------------- |
|
334 // RPsSession::ChangeSortOrderL |
|
335 // Send a request to the PS server to set sort order for a store. |
|
336 // ---------------------------------------------------------------------------- |
|
337 void RPsSession::ChangeSortOrderL(const TDes8& aInput) |
|
338 { |
|
339 PRINT ( _L("Enter RPsSession::ChangeSortOrderL") ); |
|
340 |
|
341 TIpcArgs args(&aInput); |
|
342 |
|
343 TRequestStatus status; |
|
344 |
|
345 // Initiate the request |
|
346 SendReceive(ESetSortOrder, |
|
347 args, |
|
348 status ); |
|
349 |
|
350 User::WaitForRequest(status); |
|
351 |
|
352 PRINT ( _L("End RPsSession::ChangeSortOrderL") ); |
|
353 } |
|
354 |
|
355 // ---------------------------------------------------------------------------- |
|
356 // RPsSession::ShutdownServerL |
|
357 // Shutsdown the PS Server. Synchronous. |
|
358 // ---------------------------------------------------------------------------- |
|
359 void RPsSession::ShutdownServerL() |
|
360 { |
|
361 PRINT ( _L("Enter RPsSession::ShutdownServerL") ); |
|
362 |
|
363 TIpcArgs args; |
|
364 |
|
365 TRequestStatus status; |
|
366 SendReceive(EShutdown, args, status ); |
|
367 User::WaitForRequest(status); |
|
368 |
|
369 PRINT ( _L("End RPsSession::ShutdownServerL") ); |
|
370 } |
|
371 |
|
372 // End of File |