66
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-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: Search Server session
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <s32mem.h>
|
|
22 |
#include <searchresult.h>
|
|
23 |
#include <searchtextsnippet.h>
|
|
24 |
#include "searchserversession.h"
|
|
25 |
#include "searchserverdefines.h"
|
|
26 |
#include "searchserver.h"
|
|
27 |
#include "searchdocumentid.h"
|
|
28 |
#include "searchlightresult.h"
|
|
29 |
|
|
30 |
|
|
31 |
// ====================================== MEMBER FUNCTIONS =========================================
|
|
32 |
|
|
33 |
// -------------------------------------------------------------------------------------------------
|
|
34 |
// CSearchServerSession::NewL
|
|
35 |
// Symbian OS 2 phased constructor.
|
|
36 |
// -------------------------------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
CSearchServerSession* CSearchServerSession::NewL( CSearchServer& aServer, CSearchPluginInterface * aSearchPluginInterface )
|
|
39 |
{
|
|
40 |
CSearchServerSession* self = CSearchServerSession::NewLC( aServer, aSearchPluginInterface );
|
|
41 |
CleanupStack::Pop( self );
|
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
// -------------------------------------------------------------------------------------------------
|
|
46 |
// CSearchServerSession::NewLC
|
|
47 |
// Symbian OS 2 phased constructor.
|
|
48 |
// -------------------------------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
CSearchServerSession* CSearchServerSession::NewLC( CSearchServer& aServer, CSearchPluginInterface * aSearchPluginInterface )
|
|
51 |
{
|
|
52 |
CSearchServerSession* self = new( ELeave ) CSearchServerSession( aServer );
|
|
53 |
CleanupStack::PushL( self );
|
|
54 |
self->ConstructL( aSearchPluginInterface );
|
|
55 |
return self;
|
|
56 |
}
|
|
57 |
|
|
58 |
// -------------------------------------------------------------------------------------------------
|
|
59 |
// CSearchServerSession::~CSearchServerSession
|
|
60 |
// Destructor
|
|
61 |
// -------------------------------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
CSearchServerSession::~CSearchServerSession()
|
|
64 |
{
|
|
65 |
TBool isHeavyResults = EFalse;
|
|
66 |
//Check for heavy res asked
|
|
67 |
if ( iSearchManager )
|
|
68 |
isHeavyResults = iSearchManager->IsHeavyResultsAsked();
|
|
69 |
|
|
70 |
//delete manager
|
|
71 |
if ( iSearchManager )
|
|
72 |
{
|
|
73 |
delete iSearchManager;
|
|
74 |
iSearchManager = NULL;
|
|
75 |
}
|
|
76 |
|
|
77 |
//delete query
|
|
78 |
idocIdArray.ResetAndDestroy();
|
|
79 |
|
|
80 |
iLightResultBackup.Reset();
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
//Reset iLightResult
|
|
85 |
iLightResult.Reset();
|
|
86 |
|
|
87 |
//Reset iResultArray
|
|
88 |
iResultArray.Reset();
|
|
89 |
|
|
90 |
//Reset iSupportedContent
|
|
91 |
iSupportedContent.ResetAndDestroy();
|
|
92 |
|
|
93 |
//Reset iServiceIdArray
|
|
94 |
iServiceIdArray.Reset();
|
|
95 |
|
|
96 |
//if there is a Message complete
|
|
97 |
if ( !iMessage.IsNull() )
|
|
98 |
{
|
|
99 |
iMessage.Complete( KErrNone );
|
|
100 |
}
|
|
101 |
|
|
102 |
//Inform that session has been destroyed
|
|
103 |
TRAP_IGNORE(iSearchServer.SessionDestroyedL());
|
|
104 |
}
|
|
105 |
|
|
106 |
// -------------------------------------------------------------------------------------------------
|
|
107 |
// CSearchServerSession::ErrorHappened
|
|
108 |
// Other Items are commented in the header
|
|
109 |
// -------------------------------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
void CSearchServerSession::ErrorHappened( const TInt& aErrorCode )
|
|
112 |
{
|
|
113 |
// must do cleanup if error happend while results are being fetched casue old results
|
|
114 |
// must be deleted
|
|
115 |
iErrorBuffer = aErrorCode;
|
|
116 |
}
|
|
117 |
|
|
118 |
// -------------------------------------------------------------------------------------------------
|
|
119 |
// CSearchServerSession::ServiceL
|
|
120 |
// Handles the servicing of a client request that has been passed to the server.
|
|
121 |
// Other items are included in a header
|
|
122 |
// -------------------------------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
void CSearchServerSession::ServiceL( const RMessage2& aMessage )
|
|
125 |
{
|
|
126 |
DispatchMessageL( aMessage );
|
|
127 |
}
|
|
128 |
|
|
129 |
// -------------------------------------------------------------------------------------------------
|
|
130 |
// CSearchServerSession::ResultFoundL
|
|
131 |
// Other Items are commented in the header
|
|
132 |
// -------------------------------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
void CSearchServerSession::ResultFoundL( RPointerArray<CSearchLightResult>& aResult, TInt aCurrentDocument,
|
|
135 |
TInt aTotalDocuments )
|
|
136 |
{
|
|
137 |
//Copy the currentDoc and Total Document
|
|
138 |
iCurrentDocument = aCurrentDocument;
|
|
139 |
iTotalDocuments = aTotalDocuments;
|
|
140 |
// Inform client that data is available
|
|
141 |
SignalClientL( aResult, aCurrentDocument );
|
|
142 |
//Inform the manager that Message is Available/NotAvailable
|
|
143 |
iSearchManager->SetFlagL( !iMessage.IsNull() );
|
|
144 |
}
|
|
145 |
|
|
146 |
// -------------------------------------------------------------------------------------------------
|
|
147 |
// CSearchServerSession::SearchFinishedL
|
|
148 |
// Other Items are commented in the header
|
|
149 |
// -------------------------------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void CSearchServerSession::SearchFinishedL( TInt aSearchResult, TInt aTotalNumberOfResults )
|
|
152 |
{
|
|
153 |
|
|
154 |
iFullyFinishedBuffer = EFinished;
|
|
155 |
//Inform the client that search has been completed
|
|
156 |
SignalClientL(aSearchResult,aTotalNumberOfResults);
|
|
157 |
}
|
|
158 |
|
|
159 |
// -------------------------------------------------------------------------------------------------
|
|
160 |
// CSearchServerSession::ResultsRetrieveCompleteL
|
|
161 |
// Other Items are commented in the header
|
|
162 |
// -------------------------------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
void CSearchServerSession::ResultsRetrieveCompleteL( RPointerArray<CSearchResult>& aResultArray )
|
|
165 |
{
|
|
166 |
//Copy the Heavy results into iResultArray
|
|
167 |
for (TInt i =0 ;i< aResultArray.Count(); i++)
|
|
168 |
{
|
|
169 |
iResultArray.AppendL(aResultArray[i]);
|
|
170 |
}
|
|
171 |
//Send heavy results to client
|
|
172 |
SignalClientL( ); // Inform client that data is available
|
|
173 |
//Inform the manager that Message is Available/NotAvailable
|
|
174 |
iSearchManager->SetFlagL( !iMessage.IsNull() );
|
|
175 |
}
|
|
176 |
|
|
177 |
// -------------------------------------------------------------------------------------------------
|
|
178 |
// CSearchServerSession::CSearchServerSession
|
|
179 |
// Performs the first phase of two phase construction.
|
|
180 |
// -------------------------------------------------------------------------------------------------
|
|
181 |
//
|
|
182 |
CSearchServerSession::CSearchServerSession( CSearchServer& aServer )
|
|
183 |
: iFullyFinishedBuffer(ENotFinished),
|
|
184 |
iGetContentTypes(ETrue),
|
|
185 |
iGetServiceId(ETrue),
|
|
186 |
iSearchServer( aServer )
|
|
187 |
{
|
|
188 |
|
|
189 |
}
|
|
190 |
|
|
191 |
// -------------------------------------------------------------------------------------------------
|
|
192 |
// CSearchServerSession::ConstructL
|
|
193 |
// Performs the second phase construction.
|
|
194 |
// -------------------------------------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
void CSearchServerSession::ConstructL( CSearchPluginInterface * aSearchPluginInterface )
|
|
197 |
{
|
|
198 |
//Create Manager
|
|
199 |
iSearchManager = CSearchManager::NewL( (*this ), aSearchPluginInterface );
|
|
200 |
//Create the server session
|
|
201 |
iSearchServer.SessionCreatedL( );
|
|
202 |
|
|
203 |
}
|
|
204 |
|
|
205 |
|
|
206 |
// -------------------------------------------------------------------------------------------------
|
|
207 |
// CSearchServerSession::DispatchMessageL
|
|
208 |
// Services a clients request.
|
|
209 |
// -------------------------------------------------------------------------------------------------
|
|
210 |
//
|
|
211 |
void CSearchServerSession::DispatchMessageL( const RMessage2& aMessage )
|
|
212 |
{
|
|
213 |
TInt error = KErrNone ;
|
|
214 |
//Get the Value of the Function requested by the client
|
|
215 |
switch ( aMessage.Function() )
|
|
216 |
{
|
|
217 |
//To set the Query
|
|
218 |
case ESetSearchQuery:
|
|
219 |
{
|
|
220 |
SetSearchQueryL( aMessage );
|
|
221 |
|
|
222 |
}
|
|
223 |
break;
|
|
224 |
|
|
225 |
//Start Search Has been requested..so invoke the start search function
|
|
226 |
case ESearch:
|
|
227 |
{
|
|
228 |
SearchL( aMessage );
|
|
229 |
}
|
|
230 |
return; // Return here so that Complete() isn't called on the message
|
|
231 |
|
|
232 |
//The client wants to get the results, hence give the results back
|
|
233 |
|
|
234 |
case EGetSearchResults: // Synchronous
|
|
235 |
{
|
|
236 |
GetSearchResultsL( aMessage );
|
|
237 |
}
|
|
238 |
return; //Should not call Complete() as we will have to send ResultRetrieve
|
|
239 |
|
|
240 |
//Client requests Content types
|
|
241 |
case EGetContentTypes: // Synchronous
|
|
242 |
{
|
|
243 |
GetContentTypesL( aMessage );
|
|
244 |
}
|
|
245 |
return;
|
|
246 |
|
|
247 |
//Client requests Services
|
|
248 |
case EGetService:
|
|
249 |
{
|
|
250 |
GetServiceIdL( aMessage );
|
|
251 |
}
|
|
252 |
return;
|
|
253 |
|
|
254 |
//Client requests Cancel ongoing search
|
|
255 |
case ECancelSearch: //Synchronous
|
|
256 |
{
|
|
257 |
CancelSearchL( aMessage);
|
|
258 |
}
|
|
259 |
break;
|
|
260 |
|
|
261 |
//Client requests Cancel heavy results asked
|
|
262 |
case ECancelResults:
|
|
263 |
CancelResult( aMessage );
|
|
264 |
break;
|
|
265 |
|
|
266 |
//Client askes to continue search
|
|
267 |
case EContinueSearch:
|
|
268 |
{
|
|
269 |
ContinueSearchL( aMessage );
|
|
270 |
}
|
|
271 |
return;
|
|
272 |
|
|
273 |
//Client asks light results
|
|
274 |
case EGetLightResults:
|
|
275 |
{
|
|
276 |
GetLightResultsL(aMessage);
|
|
277 |
}
|
|
278 |
return;
|
|
279 |
|
|
280 |
//Client asks haevy results
|
|
281 |
case EGetHeavyResults:
|
|
282 |
{
|
|
283 |
GetHeavyResultsL(aMessage);
|
|
284 |
}
|
|
285 |
return;
|
|
286 |
|
|
287 |
//Client asks DocID
|
|
288 |
case EGetDocumentID:
|
|
289 |
GetDocumentIDArrayL(aMessage);
|
|
290 |
break;
|
|
291 |
|
|
292 |
//Client asks Launch application
|
|
293 |
case ELaunchApp:
|
|
294 |
TRAP( error, LaunchApplicationL(aMessage) );
|
|
295 |
break;
|
|
296 |
//Client request Launch information
|
|
297 |
case EGetLaunchInfo:
|
|
298 |
GetLaunchInfoL( aMessage );
|
|
299 |
break;
|
|
300 |
//In case Search Query has to be set, then the SearchQuery function is involked
|
|
301 |
default: // Dont know this request, thus panic client
|
|
302 |
//PanicClient( EBadRequest );
|
|
303 |
//return;
|
|
304 |
break;
|
|
305 |
}
|
|
306 |
//Duplicate the specified handle in the client thread, with the completion code
|
|
307 |
aMessage.Complete( error );
|
|
308 |
}
|
|
309 |
|
|
310 |
// -------------------------------------------------------------------------------------------------
|
|
311 |
// CSearchServerSession::GetServiceIdL
|
|
312 |
// Other Items are commented in the header
|
|
313 |
// -------------------------------------------------------------------------------------------------
|
|
314 |
//
|
|
315 |
void CSearchServerSession::GetServiceIdL( const RMessage2& aMessage )
|
|
316 |
{
|
|
317 |
//dont ask supported services if already got
|
|
318 |
if ( iGetServiceId )
|
|
319 |
{
|
|
320 |
iGetServiceId = EFalse;
|
|
321 |
//Ask supported services to manager
|
|
322 |
iSearchManager->GetSupportedServicesL( iServiceIdArray );
|
|
323 |
}
|
|
324 |
|
|
325 |
TInt numofresults = iServiceIdArray.Count();
|
|
326 |
|
|
327 |
//Put all IDs into Des
|
|
328 |
CBufFlat* tmpBuf = CBufFlat::NewL( KDefaultSerBufSize );
|
|
329 |
CleanupStack::PushL( tmpBuf );
|
|
330 |
RBufWriteStream writestream( *tmpBuf );
|
|
331 |
writestream.PushL();
|
|
332 |
writestream.WriteInt32L(numofresults);
|
|
333 |
for (TInt index = 0; index< numofresults; index++)
|
|
334 |
{
|
|
335 |
writestream.WriteInt32L( iServiceIdArray[index].iUid );
|
|
336 |
}
|
|
337 |
writestream.CommitL();
|
|
338 |
|
|
339 |
HBufC8* serviceIDDes = HBufC8::NewLC( tmpBuf->Size() );
|
|
340 |
TPtr8 serviceIDDesPtr = serviceIDDes->Des();
|
|
341 |
tmpBuf->Read( 0, serviceIDDesPtr, tmpBuf->Size() );
|
|
342 |
|
|
343 |
if (aMessage.GetDesMaxLengthL(0) < serviceIDDes->Size())
|
|
344 |
{
|
|
345 |
//if Des of Client is too small to send the IDs send length instead
|
|
346 |
TInt bufferSize = serviceIDDes->Size();
|
|
347 |
TPckgC<TInt> bufferSizePackage(bufferSize);
|
|
348 |
aMessage.WriteL(0, bufferSizePackage);
|
|
349 |
aMessage.Complete(KErrOverflow);
|
|
350 |
}
|
|
351 |
else
|
|
352 |
{
|
|
353 |
//send service IDs to client
|
|
354 |
aMessage.WriteL(0, *serviceIDDes);
|
|
355 |
aMessage.Complete(KErrNone);
|
|
356 |
}
|
|
357 |
|
|
358 |
// tempBuffer, stream, buffer
|
|
359 |
CleanupStack::PopAndDestroy(3, tmpBuf);
|
|
360 |
|
|
361 |
}
|
|
362 |
|
|
363 |
// -------------------------------------------------------------------------------------------------
|
|
364 |
// CSearchServerSession::GetContentTypesL
|
|
365 |
// Other Items are commented in the header
|
|
366 |
// -------------------------------------------------------------------------------------------------
|
|
367 |
//
|
|
368 |
void CSearchServerSession::GetContentTypesL( const RMessage2& aMessage )
|
|
369 |
{
|
|
370 |
//dont ask supported contents if already got
|
|
371 |
if ( iGetContentTypes )
|
|
372 |
{
|
|
373 |
iGetContentTypes = EFalse;
|
|
374 |
TPckgBuf<TInt> serviceIdPckg;
|
|
375 |
aMessage.ReadL( 0, serviceIdPckg );
|
|
376 |
TUid serviceid;
|
|
377 |
serviceid.iUid = serviceIdPckg();
|
|
378 |
//Ask supported Contents to manager
|
|
379 |
iSearchManager->GetSupportedContentClassesL( iSupportedContent, serviceid );
|
|
380 |
}
|
|
381 |
|
|
382 |
//Put all Ids contents into Des
|
|
383 |
CBufFlat* tmpBuf = CBufFlat::NewL( KDefaultSerBufSize );
|
|
384 |
CleanupStack::PushL( tmpBuf );
|
|
385 |
RBufWriteStream writestream( *tmpBuf );
|
|
386 |
writestream.PushL();
|
|
387 |
|
|
388 |
TInt numofresults = iSupportedContent.Count();
|
|
389 |
writestream.WriteInt32L(numofresults);
|
|
390 |
for(TInt index = 0; index< numofresults; index++)
|
|
391 |
{
|
|
392 |
iSupportedContent[index]->ExternalizeL( writestream );
|
|
393 |
}
|
|
394 |
|
|
395 |
writestream.CommitL();
|
|
396 |
|
|
397 |
HBufC8* searchContentArrayDes = HBufC8::NewLC( tmpBuf->Size() );
|
|
398 |
TPtr8 searchContentArrayDesPtr = searchContentArrayDes->Des();
|
|
399 |
tmpBuf->Read( 0, searchContentArrayDesPtr, tmpBuf->Size() );
|
|
400 |
|
|
401 |
TPtr8 pbuffer(searchContentArrayDes->Des());
|
|
402 |
|
|
403 |
|
|
404 |
if (aMessage.GetDesMaxLengthL(1) < searchContentArrayDes->Size())
|
|
405 |
{
|
|
406 |
//If clent Buffer length is too less to put contents send size instead
|
|
407 |
TInt bufferSize = searchContentArrayDes->Size();
|
|
408 |
TPckgC<TInt> bufferSizePackage(bufferSize);
|
|
409 |
aMessage.WriteL(1, bufferSizePackage);
|
|
410 |
aMessage.Complete(KErrOverflow);
|
|
411 |
}
|
|
412 |
else
|
|
413 |
{
|
|
414 |
//Put contents into Client buffer
|
|
415 |
aMessage.WriteL(1, *searchContentArrayDes);
|
|
416 |
aMessage.Complete(KErrNone);
|
|
417 |
}
|
|
418 |
CleanupStack::PopAndDestroy(3, tmpBuf); // tempBuffer, stream, buffer
|
|
419 |
}
|
|
420 |
|
|
421 |
// -------------------------------------------------------------------------------------------------
|
|
422 |
// CSearchServerSession::SetSearchQueryL
|
|
423 |
// Other Items are commented in a header
|
|
424 |
// -------------------------------------------------------------------------------------------------
|
|
425 |
//
|
|
426 |
void CSearchServerSession::SetSearchQueryL( const RMessage2& aMessage )
|
|
427 |
{
|
|
428 |
iMessage = aMessage;
|
|
429 |
//First check if the input is valid
|
|
430 |
TInt len = aMessage.GetDesLength( 0 );
|
|
431 |
|
|
432 |
if ( len < 0 )
|
|
433 |
{
|
|
434 |
PanicClient( KErrBadDescriptor );
|
|
435 |
}
|
|
436 |
|
|
437 |
//Get the Query First
|
|
438 |
//Create a buffer to restore the query from the Message
|
|
439 |
HBufC8* searchQueryDes = HBufC8::NewLC( len);
|
|
440 |
|
|
441 |
//Get the pointer to the descriptor of the buffer
|
|
442 |
TPtr8 searchQueryDesPtr = searchQueryDes->Des();
|
|
443 |
|
|
444 |
aMessage.ReadL( 0, searchQueryDesPtr );
|
|
445 |
|
|
446 |
// Internalize the search result array.
|
|
447 |
RDesReadStream readStream;
|
|
448 |
CleanupClosePushL( readStream );
|
|
449 |
readStream.Open( searchQueryDesPtr );
|
|
450 |
|
|
451 |
|
|
452 |
iMaxResults = readStream.ReadInt32L();
|
|
453 |
iGranularity = readStream.ReadInt32L();
|
|
454 |
iInterval = readStream.ReadInt32L();
|
|
455 |
//Make the Query
|
|
456 |
iSearchQuery = CSearchQuery::NewL( readStream );
|
|
457 |
|
|
458 |
//Delete the allocated memory
|
|
459 |
CleanupStack::PopAndDestroy( &readStream );
|
|
460 |
CleanupStack::PopAndDestroy(searchQueryDes);
|
|
461 |
//CleanupStack::PopAndDestroy( searchQueryDes );
|
|
462 |
|
|
463 |
|
|
464 |
}
|
|
465 |
|
|
466 |
// -------------------------------------------------------------------------------------------------
|
|
467 |
// CSearchServerSession::SearchL
|
|
468 |
// Other Items are commented in a header
|
|
469 |
// -------------------------------------------------------------------------------------------------
|
|
470 |
//
|
|
471 |
void CSearchServerSession::SearchL( const RMessage2& aMessage )
|
|
472 |
{
|
|
473 |
|
|
474 |
//Clean up the resources needed before the next search
|
|
475 |
iLightResultBackup.Reset();
|
|
476 |
idocIdArray.ResetAndDestroy();
|
|
477 |
iLightResult.Reset();
|
|
478 |
iResultArray.Reset();
|
|
479 |
iMessage = aMessage;
|
|
480 |
//Ask Manager to cleanup the resources for Next Search
|
|
481 |
iSearchManager->CleanupResourcesL();
|
|
482 |
//Inform the manager that Message is Available/NotAvailable
|
|
483 |
iSearchManager->SetFlagL( !iMessage.IsNull() );
|
|
484 |
//Ask Manager to satrt the Search
|
|
485 |
iSearchManager->SearchL( iSearchQuery, iGranularity ,iMaxResults, iInterval );
|
|
486 |
if(iSearchQuery)
|
|
487 |
{
|
|
488 |
|
|
489 |
delete iSearchQuery;
|
|
490 |
iSearchQuery = NULL;
|
|
491 |
}
|
|
492 |
}
|
|
493 |
|
|
494 |
// -------------------------------------------------------------------------------------------------
|
|
495 |
// CSearchServerSession::GetLightResultsL
|
|
496 |
// Other Items are commented in the header
|
|
497 |
// -------------------------------------------------------------------------------------------------
|
|
498 |
//
|
|
499 |
void CSearchServerSession::GetLightResultsL( const RMessage2& aMessage )
|
|
500 |
{
|
|
501 |
//Put number of LigthRes, LightRes into Dynamic buffer
|
|
502 |
TInt numofresults = iLightResult.Count();
|
|
503 |
CBufFlat* tmpBuf = CBufFlat::NewL( KDefaultSerBufSize );
|
|
504 |
CleanupStack::PushL( tmpBuf );
|
|
505 |
RBufWriteStream writestream( *tmpBuf );
|
|
506 |
writestream.PushL();
|
|
507 |
writestream.WriteInt32L(numofresults);
|
|
508 |
for (TInt index = 0; index< numofresults; index++)
|
|
509 |
{
|
|
510 |
iLightResult[index]->ExternalizeL( writestream );
|
|
511 |
}
|
|
512 |
writestream.CommitL();
|
|
513 |
//Copy LigthRes, LightRes into Des from Dynamic buffer
|
|
514 |
HBufC8* searchLightResultsDes = HBufC8::NewLC( tmpBuf->Size() );
|
|
515 |
TPtr8 searchLightResultsDesPtr = searchLightResultsDes->Des();
|
|
516 |
tmpBuf->Read( 0, searchLightResultsDesPtr, tmpBuf->Size() );
|
|
517 |
|
|
518 |
if (aMessage.GetDesMaxLengthL(0) < searchLightResultsDes->Size())
|
|
519 |
{
|
|
520 |
//Send the size of the Light Res if size of the Des provided by
|
|
521 |
//client is not enough
|
|
522 |
TInt bufferSize = searchLightResultsDes->Size();
|
|
523 |
TPckgC<TInt> bufferSizePackage(bufferSize);
|
|
524 |
aMessage.WriteL(0, bufferSizePackage);
|
|
525 |
aMessage.Complete(KErrOverflow);
|
|
526 |
}
|
|
527 |
else
|
|
528 |
{
|
|
529 |
//send the light results to cleint
|
|
530 |
aMessage.Write( 0, *searchLightResultsDes );
|
|
531 |
aMessage.Complete(KErrNone);
|
|
532 |
iLightResult.Reset();
|
|
533 |
}
|
|
534 |
CleanupStack::PopAndDestroy( 3, tmpBuf );
|
|
535 |
|
|
536 |
|
|
537 |
}
|
|
538 |
|
|
539 |
// -------------------------------------------------------------------------------------------------
|
|
540 |
// CSearchServerSession::ContinueSearchL
|
|
541 |
// Other Items are commented in the header
|
|
542 |
// -------------------------------------------------------------------------------------------------
|
|
543 |
//
|
|
544 |
void CSearchServerSession::ContinueSearchL( const RMessage2& aMessage )
|
|
545 |
{
|
|
546 |
iMessage = aMessage;
|
|
547 |
|
|
548 |
if (iFullyFinishedBuffer == EFinished)
|
|
549 |
{
|
|
550 |
//if seach is finished inform client
|
|
551 |
TPckgBuf<TInt> fullyFinishedPckg( iFullyFinishedBuffer );
|
|
552 |
|
|
553 |
TPckgBuf<TBool> searchresultPckg( 0 );
|
|
554 |
|
|
555 |
iMessage.Write(0,fullyFinishedPckg);
|
|
556 |
iMessage.Write(1,searchresultPckg);
|
|
557 |
iMessage.Complete(iErrorBuffer);
|
|
558 |
}
|
|
559 |
//Inform the manager that Message is Available/NotAvailable
|
|
560 |
iSearchManager->SetFlagL( !iMessage.IsNull() );
|
|
561 |
}
|
|
562 |
|
|
563 |
// -------------------------------------------------------------------------------------------------
|
|
564 |
// CSearchServerSession::GetDocumentIDArrayL
|
|
565 |
// Other Items are commented in a header
|
|
566 |
// -------------------------------------------------------------------------------------------------
|
|
567 |
//
|
|
568 |
void CSearchServerSession::GetDocumentIDArrayL( const RMessage2& aMessage )
|
|
569 |
{
|
|
570 |
iMessage = aMessage;
|
|
571 |
|
|
572 |
idocIdArray.ResetAndDestroy();
|
|
573 |
|
|
574 |
//First check if the input is valid
|
|
575 |
TInt len = aMessage.GetDesLength( 0 );
|
|
576 |
|
|
577 |
if ( len < 0 )
|
|
578 |
{
|
|
579 |
PanicClient( KErrBadDescriptor );
|
|
580 |
}
|
|
581 |
|
|
582 |
//Get the Query First
|
|
583 |
//Create a buffer to restore the query from the Message
|
|
584 |
HBufC8* searchQueryDes = HBufC8::NewLC( len);
|
|
585 |
|
|
586 |
//Get the pointer to the descriptod of the buffer
|
|
587 |
TPtr8 searchQueryDesPtr = searchQueryDes->Des();
|
|
588 |
|
|
589 |
aMessage.ReadL( 0, searchQueryDesPtr );
|
|
590 |
|
|
591 |
// Internalize the search result array.
|
|
592 |
RDesReadStream readStream;
|
|
593 |
CleanupClosePushL( readStream );
|
|
594 |
readStream.Open( searchQueryDesPtr );
|
|
595 |
TInt count = readStream.ReadInt32L();
|
|
596 |
for(TInt i = 0; i<count; i++)
|
|
597 |
{
|
|
598 |
CSearchDocumentId* docId = CSearchDocumentId::NewL( readStream );
|
|
599 |
idocIdArray.AppendL( docId );
|
|
600 |
}
|
|
601 |
CleanupStack::PopAndDestroy( &readStream );
|
|
602 |
CleanupStack::PopAndDestroy(searchQueryDes);
|
|
603 |
|
|
604 |
}
|
|
605 |
|
|
606 |
// -------------------------------------------------------------------------------------------------
|
|
607 |
// CSearchServerSession::GetSearchResultsL
|
|
608 |
// Other Items are commented in the header
|
|
609 |
// -------------------------------------------------------------------------------------------------
|
|
610 |
//
|
|
611 |
void CSearchServerSession::GetSearchResultsL( const RMessage2& aMessage )
|
|
612 |
{
|
|
613 |
iMessage = aMessage;
|
|
614 |
//Send docIDs to manager to get Heavy results
|
|
615 |
iSearchManager->GetResultsL( idocIdArray );
|
|
616 |
}
|
|
617 |
|
|
618 |
|
|
619 |
// -------------------------------------------------------------------------------------------------
|
|
620 |
// CSearchServerSession::GetHeavyResultsL
|
|
621 |
// Other Items are commented in the header
|
|
622 |
// -------------------------------------------------------------------------------------------------
|
|
623 |
//
|
|
624 |
void CSearchServerSession::GetHeavyResultsL( const RMessage2& aMessage )
|
|
625 |
{
|
|
626 |
//Put count and heavy results in Dynamic buffer
|
|
627 |
TInt numofresults = iResultArray.Count();
|
|
628 |
CBufFlat* tmpBuf = CBufFlat::NewL( KDefaultSerBufSize );
|
|
629 |
CleanupStack::PushL( tmpBuf );
|
|
630 |
RBufWriteStream writestream( *tmpBuf );
|
|
631 |
writestream.PushL();
|
|
632 |
writestream.WriteInt32L(numofresults);
|
|
633 |
|
|
634 |
for ( TInt index = 0; index< numofresults; index++ )
|
|
635 |
{
|
|
636 |
//resultStreamSize += aSupportedContentClasses[index]->StreamSize();
|
|
637 |
iResultArray[index]->ExternalizeL( writestream );
|
|
638 |
}
|
|
639 |
writestream.CommitL();
|
|
640 |
|
|
641 |
HBufC8* searchHeavyResultsDes = HBufC8::NewLC( tmpBuf->Size() );
|
|
642 |
|
|
643 |
//Get the pointer to the descriptor of the buffer
|
|
644 |
TPtr8 searchHeavyResultsDesPtr = searchHeavyResultsDes->Des();
|
|
645 |
|
|
646 |
tmpBuf->Read( 0, searchHeavyResultsDesPtr, tmpBuf->Size() );
|
|
647 |
|
|
648 |
if (aMessage.GetDesMaxLengthL(0) < searchHeavyResultsDes->Size())
|
|
649 |
{
|
|
650 |
//If size of the Des is too small to send the res to client
|
|
651 |
//send size
|
|
652 |
TInt bufferSize = searchHeavyResultsDes->Size();
|
|
653 |
TPckgC<TInt> bufferSizePackage(bufferSize);
|
|
654 |
aMessage.WriteL(0, bufferSizePackage);
|
|
655 |
aMessage.Complete(KErrOverflow);
|
|
656 |
}
|
|
657 |
else
|
|
658 |
{
|
|
659 |
//send heavy res to client
|
|
660 |
aMessage.Write( 0, *searchHeavyResultsDes );
|
|
661 |
aMessage.Complete(KErrNone);
|
|
662 |
iResultArray.Reset();
|
|
663 |
}
|
|
664 |
|
|
665 |
CleanupStack::PopAndDestroy( 3, tmpBuf );
|
|
666 |
|
|
667 |
|
|
668 |
}
|
|
669 |
|
|
670 |
// -------------------------------------------------------------------------------------------------
|
|
671 |
// CSearchServerSession::CancelSearchL
|
|
672 |
// Other Items are commented in the header
|
|
673 |
// -------------------------------------------------------------------------------------------------
|
|
674 |
//
|
|
675 |
void CSearchServerSession::CancelSearchL( const RMessage2&)
|
|
676 |
{
|
|
677 |
|
|
678 |
//Ask manager to cancel the search
|
|
679 |
iSearchManager->Cancel();
|
|
680 |
//Ask manager to complette the seach after cancelling it
|
|
681 |
iSearchManager->SearchCompleteAfterCancelL();
|
|
682 |
if( !iMessage.IsNull() )
|
|
683 |
iMessage.Complete( KErrNone );
|
|
684 |
}
|
|
685 |
|
|
686 |
// -------------------------------------------------------------------------------------------------
|
|
687 |
// CSearchServerSession::CancelResult
|
|
688 |
// Other Items are commented in the header
|
|
689 |
// -------------------------------------------------------------------------------------------------
|
|
690 |
//
|
|
691 |
void CSearchServerSession::CancelResult( const RMessage2& )
|
|
692 |
{
|
|
693 |
|
|
694 |
//Ask manager to cancel the heavy res
|
|
695 |
iSearchManager->CancelResultsRetrieve();
|
|
696 |
if( !iMessage.IsNull() )
|
|
697 |
iMessage.Complete( KErrNone );
|
|
698 |
|
|
699 |
}
|
|
700 |
|
|
701 |
// -------------------------------------------------------------------------------------------------
|
|
702 |
// CSearchServerSession::LaunchApplication
|
|
703 |
// Other Items are commented in the header
|
|
704 |
// -------------------------------------------------------------------------------------------------
|
|
705 |
//
|
|
706 |
void CSearchServerSession::LaunchApplicationL( const RMessage2& aMessage )
|
|
707 |
{
|
|
708 |
TInt len = aMessage.GetDesLength( 0 );
|
|
709 |
|
|
710 |
if ( len < 0 )
|
|
711 |
{
|
|
712 |
PanicClient( KErrBadDescriptor );
|
|
713 |
}
|
|
714 |
//Create a buffer to restore the query from the Message
|
|
715 |
HBufC8* searchContentDes = HBufC8::NewLC( len );
|
|
716 |
|
|
717 |
//Get the pointer to the descriptod of the buffer
|
|
718 |
TPtr8 searchContentDesPtr = searchContentDes->Des();
|
|
719 |
aMessage.ReadL( 0, searchContentDesPtr );
|
|
720 |
// Internalize the search result array.
|
|
721 |
RDesReadStream readStream;
|
|
722 |
CleanupClosePushL( readStream );
|
|
723 |
readStream.Open( searchContentDesPtr );
|
|
724 |
CSearchDocumentId* documentId = CSearchDocumentId::NewL(readStream);
|
|
725 |
//Ask manager to Lauch the application
|
|
726 |
iSearchManager->LaunchApplicationL( *documentId );
|
|
727 |
delete documentId;
|
|
728 |
|
|
729 |
CleanupStack::PopAndDestroy( &readStream );
|
|
730 |
CleanupStack::PopAndDestroy(searchContentDes);
|
|
731 |
|
|
732 |
}
|
|
733 |
|
|
734 |
// -------------------------------------------------------------------------------------------------
|
|
735 |
// CSearchServerSession::SignalClient
|
|
736 |
// Other Items are commented in the header
|
|
737 |
// -------------------------------------------------------------------------------------------------
|
|
738 |
//
|
|
739 |
void CSearchServerSession::SignalClientL(TInt aSearchResult, TInt aTotalDocument)
|
|
740 |
{
|
|
741 |
//If there is an outstanding req complete the request
|
|
742 |
if ( !iMessage.IsNull() )
|
|
743 |
{
|
|
744 |
//Send back iFullyFinishedBuffer and search result count to client
|
|
745 |
iFullyFinishedBuffer = EFinished;
|
|
746 |
TPckgBuf<TInt> fullyFinishedPckg( iFullyFinishedBuffer );
|
|
747 |
|
|
748 |
TPckgBuf<TBool> searchresultPckg( aSearchResult );
|
|
749 |
|
|
750 |
TPckgBuf<TInt> totaldocPckg( aTotalDocument );
|
|
751 |
|
|
752 |
RDesWriteStream writestream;
|
|
753 |
|
|
754 |
CleanupClosePushL( writestream );
|
|
755 |
//fullyFinishedPckg for search finished or not
|
|
756 |
iMessage.Write( 0, fullyFinishedPckg ); // Search fully finished flag
|
|
757 |
//searchresultPckg for search res count
|
|
758 |
iMessage.Write( 1, searchresultPckg);
|
|
759 |
iMessage.Complete( iErrorBuffer ); // If error occured, we inform about it
|
|
760 |
CleanupStack::PopAndDestroy( &writestream );
|
|
761 |
iRequestOutstanding = EFalse;
|
|
762 |
|
|
763 |
iErrorBuffer = KErrNone;
|
|
764 |
}
|
|
765 |
|
|
766 |
}
|
|
767 |
|
|
768 |
|
|
769 |
// -------------------------------------------------------------------------------------------------
|
|
770 |
// CSearchServerSession::SignalClient
|
|
771 |
// Other Items are commented in the header
|
|
772 |
// -------------------------------------------------------------------------------------------------
|
|
773 |
//
|
|
774 |
void CSearchServerSession::SignalClientL( RPointerArray<CSearchLightResult>& aResult, TInt aSearchResult)
|
|
775 |
{
|
|
776 |
//If there is an outstanding req complete the request
|
|
777 |
if ( !iMessage.IsNull() )
|
|
778 |
{
|
|
779 |
iFullyFinishedBuffer = ENotFinished;
|
|
780 |
TPckgBuf<TInt> fullyFinishedPckg( iFullyFinishedBuffer );
|
|
781 |
TPckgBuf<TInt> searchresPckg( aSearchResult );
|
|
782 |
for(TInt i =0 ;i<aResult.Count();i++)
|
|
783 |
{
|
|
784 |
iLightResult.AppendL(aResult[i]);
|
|
785 |
iLightResultBackup.AppendL(aResult[i]);
|
|
786 |
}
|
|
787 |
|
|
788 |
TInt count = aResult.Count();
|
|
789 |
TPckgBuf<TInt> resultcountPckg( count );
|
|
790 |
//fullyFinishedPckg for search finished or not
|
|
791 |
iMessage.Write( 0, fullyFinishedPckg );
|
|
792 |
//search res count
|
|
793 |
iMessage.Write( 1, resultcountPckg );
|
|
794 |
//total res
|
|
795 |
iMessage.Write( 2, searchresPckg );
|
|
796 |
iMessage.Complete( iErrorBuffer ); // If error occured, we inform about it
|
|
797 |
iRequestOutstanding = EFalse;
|
|
798 |
iErrorBuffer = KErrNone;
|
|
799 |
}
|
|
800 |
}
|
|
801 |
|
|
802 |
// -------------------------------------------------------------------------------------------------
|
|
803 |
// CSearchServerSession::SignalClient
|
|
804 |
// Other Items are commented in the header
|
|
805 |
// -------------------------------------------------------------------------------------------------
|
|
806 |
//
|
|
807 |
void CSearchServerSession::SignalClientL( )
|
|
808 |
{
|
|
809 |
//If there is an outstanding req complete the request
|
|
810 |
if ( !iMessage.IsNull() )
|
|
811 |
{
|
|
812 |
|
|
813 |
iFullyFinishedBuffer = EResult;
|
|
814 |
TPckgBuf<TInt> fullyFinishedPckg( iFullyFinishedBuffer );
|
|
815 |
//fullyFinishedPckg for search finished or not
|
|
816 |
iMessage.Write( 0, fullyFinishedPckg );
|
|
817 |
|
|
818 |
iMessage.Complete( iErrorBuffer ); // If error occured, we inform about it
|
|
819 |
|
|
820 |
iRequestOutstanding = EFalse;
|
|
821 |
|
|
822 |
iFullyFinishedBuffer = EFalse;
|
|
823 |
|
|
824 |
iErrorBuffer = KErrNone;
|
|
825 |
}
|
|
826 |
}
|
|
827 |
|
|
828 |
// -------------------------------------------------------------------------------------------------
|
|
829 |
// CSearchServerSession::PanicClient
|
|
830 |
// Panics the client.
|
|
831 |
// -------------------------------------------------------------------------------------------------
|
|
832 |
//
|
|
833 |
|
|
834 |
void CSearchServerSession::PanicClient( TInt /*aPanic*/ )
|
|
835 |
{
|
|
836 |
//Message().Panic( KSearchServerPanic , aPanic );// Message()????
|
|
837 |
}
|
|
838 |
|
|
839 |
// -------------------------------------------------------------------------------------------------
|
|
840 |
// CSearchServerSession::GetLaunchInfoL
|
|
841 |
// Get the launch infor of specified file
|
|
842 |
// -------------------------------------------------------------------------------------------------
|
|
843 |
//
|
|
844 |
void CSearchServerSession::GetLaunchInfoL( const RMessage2& aMessage )
|
|
845 |
{
|
|
846 |
TInt len = aMessage.GetDesLength( 0 );
|
|
847 |
if ( len < 0 )
|
|
848 |
{
|
|
849 |
PanicClient( KErrBadDescriptor );
|
|
850 |
}
|
|
851 |
HBufC8* searchContentDes = HBufC8::NewLC( len );
|
|
852 |
TPtr8 searchContentDesPtr = searchContentDes->Des();
|
|
853 |
aMessage.ReadL( 0, searchContentDesPtr );
|
|
854 |
RDesReadStream readStream;
|
|
855 |
CleanupClosePushL( readStream );
|
|
856 |
readStream.Open( searchContentDesPtr );
|
|
857 |
CSearchDocumentId* documentId = CSearchDocumentId::NewL(readStream);
|
|
858 |
HBufC8* launchInfo = iSearchManager->GetLaunchInfoL( *documentId );
|
|
859 |
if( launchInfo )
|
|
860 |
{
|
|
861 |
TPtr8 launchInfoPtr=launchInfo->Des();
|
|
862 |
aMessage.WriteL( 1, launchInfoPtr );
|
|
863 |
|
|
864 |
delete launchInfo ;
|
|
865 |
launchInfo = NULL;
|
|
866 |
}
|
|
867 |
if( documentId )
|
|
868 |
{
|
|
869 |
delete documentId;
|
|
870 |
documentId = NULL;
|
|
871 |
}
|
|
872 |
CleanupStack::PopAndDestroy( &readStream );
|
|
873 |
CleanupStack::PopAndDestroy( searchContentDes );
|
|
874 |
}
|
|
875 |
// End of File
|