|
1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32math.h> |
|
20 #include <e32debug.h> |
|
21 #include <S32MEM.H> |
|
22 #include "common.h" |
|
23 #include "SearchServerLogger.h" |
|
24 #include "SearchServerCommon.h" |
|
25 #include "RSearchServerSession.h" |
|
26 #include "CSearchDocument.h" |
|
27 |
|
28 |
|
29 // FUNCTION PROTOTYPES |
|
30 static TInt StartServer(); |
|
31 static TInt CreateServerProcess(); |
|
32 |
|
33 // RsearchServerSession::RsearchServerSession() |
|
34 // C++ default constructor can NOT contain any code, that might leave. |
|
35 EXPORT_C RSearchServerSession::RSearchServerSession(): RSessionBase() |
|
36 { |
|
37 // No implementation required |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // RsearchServerSession::Connect() |
|
42 // Connects to the server and create a session. |
|
43 // ----------------------------------------------------------------------------- |
|
44 EXPORT_C TInt RSearchServerSession::Connect() |
|
45 { |
|
46 TInt err = StartServer(); |
|
47 |
|
48 if ( KErrNone == err ) |
|
49 { |
|
50 err = CreateSession(KSearchServerName, Version(), KDefaultMessageSlots); |
|
51 } |
|
52 return err; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // A request to close the session. |
|
57 // It makes a call to the server, which deletes the object container and object index |
|
58 // for this session, before calling Close() on the base class. |
|
59 // ----------------------------------------------------------------------------- |
|
60 EXPORT_C void RSearchServerSession::Close() |
|
61 { |
|
62 SendReceive(ESearchServerCloseSession); |
|
63 RHandleBase::Close(); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // RsearchServerSession::Version() |
|
68 // Gets the version number. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C TVersion RSearchServerSession::Version() const |
|
72 { |
|
73 return (TVersion(KSearchServerMajorVersionNumber, KSearchServerMinorVersionNumber, |
|
74 KSearchServerBuildVersionNumber) ); |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // RsearchServerSession::DefineVolumeL() |
|
79 // Drops a qualified BaseAppClass |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C TInt RSearchServerSession::DefineVolume(const TDesC& aQualifiedBaseAppClass, |
|
83 const TDesC& aIndexDbPath) |
|
84 { |
|
85 TIpcArgs args(&aQualifiedBaseAppClass, &aIndexDbPath); |
|
86 return SendReceive(ESearchServerDatabaseDefine, args); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // RsearchServerSession::UnDefineVolumeL() |
|
91 // Drops a qualified BaseAppClass |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C TInt RSearchServerSession::UnDefineVolume(const TDesC& aQualifiedBaseAppClass) |
|
95 { |
|
96 TIpcArgs args(&aQualifiedBaseAppClass); |
|
97 return SendReceive(ESearchServerDatabaseUnDefine, args); |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // RsearchServerSession::StopHouseKeeping() |
|
102 // Stop housekeeping |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C TInt RSearchServerSession::StopHouseKeeping() |
|
106 { |
|
107 TInt err = SendReceive(ESearchServerStopHouseKeeping, TIpcArgs()); |
|
108 return err; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // RsearchServerSession::ContinueHouseKeeping() |
|
113 // Continue housekeeping |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 EXPORT_C TInt RSearchServerSession::ContinueHouseKeeping() |
|
117 { |
|
118 return SendReceive(ESearchServerContinueHouseKeeping, TIpcArgs()); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // RsearchServerSession::ForceHouseKeeping() |
|
123 // Force housekeeping |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C TInt RSearchServerSession::ForceHouseKeeping() |
|
127 { |
|
128 return SendReceive(ESearchServerForceHouseKeeping, TIpcArgs()); |
|
129 } |
|
130 |
|
131 // |
|
132 // |
|
133 // RSearchServerSubSession |
|
134 // |
|
135 // |
|
136 |
|
137 |
|
138 RSearchServerSubSession::RSearchServerSubSession(): |
|
139 iEstimatedResultsCountPckg(iEstimatedResultsCount), |
|
140 iDocumentSizePckg(iDocumentSize) |
|
141 { |
|
142 } |
|
143 |
|
144 TInt RSearchServerSubSession::Open(RSearchServerSession& aSession) |
|
145 { |
|
146 return CreateSubSession(aSession, ESearchServerCreateSubSession); |
|
147 } |
|
148 |
|
149 void RSearchServerSubSession::Close() |
|
150 { |
|
151 RSubSessionBase::CloseSubSession(ESearchServerCloseSubSession); |
|
152 } |
|
153 |
|
154 void RSearchServerSubSession::OpenDatabaseL(const TBool aOpenForSearch, const TDesC& aBaseAppClass, const TDesC& aDefaultSearchField) |
|
155 { |
|
156 TIpcArgs args(&aBaseAppClass, &aDefaultSearchField, aOpenForSearch); |
|
157 User::LeaveIfError( SendReceive(ESearchServerOpenDatabase, args) ); |
|
158 } |
|
159 |
|
160 void RSearchServerSubSession::OpenDatabase(const TBool aOpenForSearch, const TDesC& aBaseAppClass, const TDesC& aDefaultSearchField, TRequestStatus& aStatus) |
|
161 { |
|
162 TIpcArgs args(&aBaseAppClass, &aDefaultSearchField, aOpenForSearch); |
|
163 SendReceive(ESearchServerOpenDatabase, args, aStatus); |
|
164 } |
|
165 |
|
166 EXPORT_C void RSearchServerSubSession::SetAnalyzerL(const TDesC& aAnalyzer) |
|
167 { |
|
168 // Message arguments for the server |
|
169 TIpcArgs args(&aAnalyzer); |
|
170 |
|
171 // This call completes immediately, however the server will not |
|
172 // complete the request until later, so don't pass any local |
|
173 // descriptors as they will be out of scope by the time the server |
|
174 // attempts to read or write |
|
175 User::LeaveIfError( SendReceive(ESearchServerSetAnalyzer, args) ); |
|
176 } |
|
177 |
|
178 EXPORT_C void RSearchServerSubSession::SetAnalyzer(const TDesC& aAnalyzer, TRequestStatus& aStatus) |
|
179 { |
|
180 // Message arguments for the server |
|
181 TIpcArgs args(&aAnalyzer); |
|
182 |
|
183 // This call completes immediately, however the server will not |
|
184 // complete the request until later, so don't pass any local |
|
185 // descriptors as they will be out of scope by the time the server |
|
186 // attempts to read or write |
|
187 SendReceive(ESearchServerSetAnalyzer, args, aStatus); |
|
188 } |
|
189 |
|
190 |
|
191 // RSearchServerSubSession::Search() |
|
192 EXPORT_C void RSearchServerSubSession::SearchL(const TDesC& aSearchTerms) |
|
193 { |
|
194 PERFORMANCE_LOG_START("RSearchServerSubSession::SearchL"); |
|
195 |
|
196 iEstimatedResultsCount = 0; |
|
197 |
|
198 // Message arguments for the server |
|
199 TIpcArgs args(&aSearchTerms, &iEstimatedResultsCountPckg); |
|
200 |
|
201 // This call completes immediately, however the server will not |
|
202 // complete the request until later, so don't pass any local |
|
203 // descriptors as they will be out of scope by the time the server |
|
204 // attempts to read or write |
|
205 User::LeaveIfError( SendReceive(ESearchServerSearch, args) ); |
|
206 } |
|
207 |
|
208 EXPORT_C void RSearchServerSubSession::Search(const TDesC& aSearchTerms, TRequestStatus& aStatus) |
|
209 { |
|
210 PERFORMANCE_LOG_START("RSearchServerSubSession::SearchL"); |
|
211 |
|
212 iEstimatedResultsCount = 0; |
|
213 |
|
214 // Message arguments for the server |
|
215 TIpcArgs args(&aSearchTerms, &iEstimatedResultsCountPckg); |
|
216 |
|
217 // This call completes immediately, however the server will not |
|
218 // complete the request until later, so don't pass any local |
|
219 // descriptors as they will be out of scope by the time the server |
|
220 // attempts to read or write |
|
221 SendReceive(ESearchServerSearch, args, aStatus); |
|
222 } |
|
223 |
|
224 // RSearchServerSubSession::GetEstimatedDocumentCount() |
|
225 TInt RSearchServerSubSession::GetEstimatedDocumentCount() |
|
226 { |
|
227 return iEstimatedResultsCount; |
|
228 } |
|
229 |
|
230 // RSearchServerSubSession::GetDocument() |
|
231 EXPORT_C CSearchDocument* RSearchServerSubSession::GetDocumentL(TInt aIndex) |
|
232 { |
|
233 PERFORMANCE_LOG_START("RSearchServerSubSession::GetDocumentL"); |
|
234 |
|
235 iDocumentSize = 0; |
|
236 |
|
237 // Message arguments for the server |
|
238 TIpcArgs args(aIndex, &iDocumentSizePckg); |
|
239 |
|
240 User::LeaveIfError( SendReceive(ESearchServerGetDocument, args ) ); |
|
241 |
|
242 return GetDocumentObjectL(); |
|
243 } |
|
244 |
|
245 EXPORT_C void RSearchServerSubSession::GetDocument(TInt aIndex, TRequestStatus& aStatus) |
|
246 { |
|
247 PERFORMANCE_LOG_START("RSearchServerSubSession::GetDocument"); |
|
248 |
|
249 iDocumentSize = 0; |
|
250 |
|
251 // Message arguments for the server |
|
252 TIpcArgs args(aIndex, &iDocumentSizePckg); |
|
253 |
|
254 SendReceive(ESearchServerGetDocument, args, aStatus ); |
|
255 } |
|
256 |
|
257 |
|
258 EXPORT_C CSearchDocument* RSearchServerSubSession::GetDocumentObjectL() |
|
259 { |
|
260 PERFORMANCE_LOG_START("CCPixSearcher::GetDocumentObjectL"); |
|
261 |
|
262 CSearchDocument* document = NULL; |
|
263 if (iDocumentSize>0) |
|
264 { |
|
265 HBufC8* buf = HBufC8::NewLC(iDocumentSize); |
|
266 TPtr8 ptr = buf->Des(); |
|
267 User::LeaveIfError(SendReceive(ESearchServerGetDocumentObject, TIpcArgs(&ptr))); |
|
268 |
|
269 RDesReadStream stream; |
|
270 stream.Open(ptr); |
|
271 stream.PushL(); |
|
272 document = CSearchDocument::NewLC(stream); |
|
273 CleanupStack::Pop(document); |
|
274 CleanupStack::PopAndDestroy(&stream); |
|
275 CleanupStack::PopAndDestroy(buf); |
|
276 } |
|
277 |
|
278 return document; |
|
279 } |
|
280 |
|
281 // RSearchServerSubSession::CancelSearch() |
|
282 // Cancels outstanding search from server |
|
283 EXPORT_C void RSearchServerSubSession::CancelAll() const |
|
284 { |
|
285 SendReceive(ESearchServerCancelAll, TIpcArgs()); |
|
286 } |
|
287 |
|
288 // Adds the serialized document to the index |
|
289 EXPORT_C void RSearchServerSubSession::Add(const TDesC8& aSerializedDocument, TRequestStatus& aStatus) |
|
290 { |
|
291 TIpcArgs args(&aSerializedDocument); |
|
292 SendReceive(ESearchServerAdd, args, aStatus); |
|
293 } |
|
294 |
|
295 // Updates the serialized document in the index |
|
296 EXPORT_C void RSearchServerSubSession::Update(const TDesC8& aSerializedDocument, TRequestStatus& aStatus) |
|
297 { |
|
298 TIpcArgs args(&aSerializedDocument); |
|
299 SendReceive(ESearchServerUpdate, args, aStatus); |
|
300 } |
|
301 |
|
302 // Deletes the document uid in the index |
|
303 EXPORT_C void RSearchServerSubSession::Delete(const TDesC& aDocUid, TRequestStatus& aStatus) |
|
304 { |
|
305 TIpcArgs args(&aDocUid); |
|
306 SendReceive(ESearchServerDelete, args, aStatus); |
|
307 } |
|
308 |
|
309 // Resets all of the documents in the index |
|
310 EXPORT_C void RSearchServerSubSession::Reset(TRequestStatus& aStatus) |
|
311 { |
|
312 SendReceive( ESearchServerReset, aStatus ); |
|
313 } |
|
314 |
|
315 // Adds the serialized document to the index |
|
316 EXPORT_C void RSearchServerSubSession::AddL(const TDesC8& aSerializedDocument) |
|
317 { |
|
318 TIpcArgs args( &aSerializedDocument ); |
|
319 User::LeaveIfError( SendReceive(ESearchServerAdd, args) ); |
|
320 } |
|
321 |
|
322 // Updates the serialized document in the index |
|
323 EXPORT_C void RSearchServerSubSession::UpdateL(const TDesC8& aSerializedDocument) |
|
324 { |
|
325 TIpcArgs args(&aSerializedDocument); |
|
326 CPIXLOGSTRING( "RSearchServerSubSession::UpdateL(): sending the request to server" ); |
|
327 User::LeaveIfError( SendReceive(ESearchServerUpdate, args) ); |
|
328 CPIXLOGSTRING( "RSearchServerSubSession::UpdateL(): sent the request to server success" ); |
|
329 } |
|
330 |
|
331 // Deletes the document uid in the index |
|
332 EXPORT_C void RSearchServerSubSession::DeleteL(const TDesC& aDocUid) |
|
333 { |
|
334 TIpcArgs args(&aDocUid); |
|
335 User::LeaveIfError( SendReceive(ESearchServerDelete, args) ); |
|
336 } |
|
337 |
|
338 // Resets all of the documents in the index |
|
339 EXPORT_C void RSearchServerSubSession::ResetL() |
|
340 { |
|
341 User::LeaveIfError( SendReceive(ESearchServerReset) ); |
|
342 } |
|
343 |
|
344 // Issues CPix flush |
|
345 EXPORT_C void RSearchServerSubSession::FlushL() |
|
346 { |
|
347 User::LeaveIfError( SendReceive(ESearchServerFlush) ); |
|
348 } |
|
349 |
|
350 // Issues CPix flush |
|
351 EXPORT_C void RSearchServerSubSession::Flush(TRequestStatus& aStatus) |
|
352 { |
|
353 SendReceive(ESearchServerFlush, aStatus); |
|
354 } |
|
355 |
|
356 |
|
357 // StartServer() |
|
358 // Starts the server if it is not already running |
|
359 static TInt StartServer() |
|
360 { |
|
361 TInt result; |
|
362 |
|
363 TFindServer findsearchServer(KSearchServerName); |
|
364 TFullName name; |
|
365 |
|
366 result = findsearchServer.Next(name); |
|
367 if (result == KErrNone) |
|
368 { |
|
369 // Server already running |
|
370 return KErrNone; |
|
371 } |
|
372 |
|
373 RSemaphore semaphore; |
|
374 result = semaphore.CreateGlobal(KSearchServerSemaphoreName, 0); |
|
375 if (result != KErrNone) |
|
376 { |
|
377 return result; |
|
378 } |
|
379 |
|
380 result = CreateServerProcess(); |
|
381 if (result != KErrNone) |
|
382 { |
|
383 return result; |
|
384 } |
|
385 |
|
386 semaphore.Wait(); |
|
387 semaphore.Close(); |
|
388 |
|
389 return KErrNone; |
|
390 } |
|
391 |
|
392 // CreateServerProcess() |
|
393 // Creates a server process |
|
394 static TInt CreateServerProcess() |
|
395 { |
|
396 TInt result; |
|
397 |
|
398 const TUidType serverUid( KNullUid, KNullUid, KServerUid3); |
|
399 |
|
400 RProcess server; |
|
401 |
|
402 result = server.Create(KSearchServerFilename, KNullDesC, serverUid); |
|
403 if (result != KErrNone) |
|
404 { |
|
405 return result; |
|
406 } |
|
407 |
|
408 server.Resume(); |
|
409 server.Close(); |
|
410 return KErrNone; |
|
411 } |
|
412 |
|
413 // End of File |
|
414 |