searcher/searchclient/src/rsearchserversession.cpp
changeset 18 3e1f76dd2722
parent 15 cf5c74390b98
equal deleted inserted replaced
15:cf5c74390b98 18:3e1f76dd2722
    26 #include "CSearchDocument.h"
    26 #include "CSearchDocument.h"
    27 #include "OstTraceDefinitions.h"
    27 #include "OstTraceDefinitions.h"
    28 #ifdef OST_TRACE_COMPILER_IN_USE
    28 #ifdef OST_TRACE_COMPILER_IN_USE
    29 #include "rsearchserversessionTraces.h"
    29 #include "rsearchserversessionTraces.h"
    30 #endif
    30 #endif
    31 
    31 #include "cpixwatchdogcommon.h"
       
    32 #include <centralrepository.h>
    32 
    33 
    33 
    34 
    34 // FUNCTION PROTOTYPES
    35 // FUNCTION PROTOTYPES
    35 static TInt StartServer();
    36 static TInt StartServer( const TDesC& aServerName , TUid aServerUid );
    36 static TInt CreateServerProcess();
    37 static TInt CreateServerProcess( const TDesC& aServerName , TUid aServerUid );
    37 
    38 
    38 // RsearchServerSession::RsearchServerSession()
    39 // RsearchServerSession::RsearchServerSession()
    39 // C++ default constructor can NOT contain any code, that might leave.
    40 // C++ default constructor can NOT contain any code, that might leave.
    40 EXPORT_C RSearchServerSession::RSearchServerSession(): RSessionBase() 
    41 EXPORT_C RSearchServerSession::RSearchServerSession(): RSessionBase() 
    41 	{
    42 	{
    46 // RsearchServerSession::Connect()
    47 // RsearchServerSession::Connect()
    47 // Connects to the server and create a session.
    48 // Connects to the server and create a session.
    48 // -----------------------------------------------------------------------------
    49 // -----------------------------------------------------------------------------
    49 EXPORT_C TInt RSearchServerSession::Connect()
    50 EXPORT_C TInt RSearchServerSession::Connect()
    50 	{
    51 	{
    51 	TInt err = StartServer();
    52     //read the name and Uid of the search server
    52 
    53     TInt err = KErrNotReady;
    53 	if ( KErrNone == err )
    54     // get the watchdog repro 
    54 		{
    55     //TRAP_IGNORE is used to avoid the code scanner error
    55 		err = CreateSession(KSearchServerName, Version(), KDefaultMessageSlots);
    56     CRepository* wdrepo = NULL;
    56 		}
    57     TRAP_IGNORE(wdrepo = CRepository::NewL( KWDrepoUidMenu ));
       
    58     if ( wdrepo )
       
    59         {
       
    60         HBufC* servername = NULL;
       
    61         TUid serveruid = {0};
       
    62         TBuf<KCenrepUidLength> temp;
       
    63         TInt64 value;
       
    64         TLex uidvalue;
       
    65         //read the searchserver UId
       
    66         if ( KErrNone == wdrepo->Get( KSearchServerUIDKey, temp ))
       
    67             {
       
    68             uidvalue.Assign(temp);
       
    69             if (KErrNone == uidvalue.Val( value,EHex ))
       
    70                 serveruid.iUid = value;
       
    71             }
       
    72         //read the search server name
       
    73         if ( KErrNone == wdrepo->Get( KSearchServerNAMEKey, temp ))
       
    74             {
       
    75             //TRAP_IGNORE is used to avoid the code scanner error
       
    76             TRAP_IGNORE(servername = HBufC::NewL( temp.Length() ));
       
    77             TPtr ssname = servername->Des(); 
       
    78             ssname.Copy( temp );
       
    79             }
       
    80         // make sure the server is started before creating connection
       
    81         if ( servername )
       
    82            err = StartServer( *servername , serveruid );
       
    83     
       
    84         if ( KErrNone == err )
       
    85             {
       
    86             err = CreateSession(*servername, Version(), KDefaultMessageSlots);
       
    87             }
       
    88         delete servername;
       
    89         }
       
    90     delete wdrepo;
    57 	return err;
    91 	return err;
    58 	}
    92 	}
    59 
    93 
    60 // -----------------------------------------------------------------------------
    94 // -----------------------------------------------------------------------------
    61 // A request to close the session.
    95 // A request to close the session.
   230 	// This call completes immediately, however the server will not
   264 	// This call completes immediately, however the server will not
   231 	// complete the request until later, so don't pass any local
   265 	// complete the request until later, so don't pass any local
   232 	// descriptors as they will be out of scope by the time the server
   266 	// descriptors as they will be out of scope by the time the server
   233 	// attempts to read or write
   267 	// attempts to read or write
   234 	User::LeaveIfError( SendReceive(ESearchServerSearch, args) );
   268 	User::LeaveIfError( SendReceive(ESearchServerSearch, args) );
       
   269 	OstTrace1( TRACE_NORMAL, RSEARCHSERVERSUBSESSION_SEARCHL, "RSearchServerSubSession::SearchL::sync;iEstimatedResultsCount=%d", iEstimatedResultsCount );
   235 	OstTraceFunctionExit0( RSEARCHSERVERSUBSESSION_SEARCHL_EXIT );
   270 	OstTraceFunctionExit0( RSEARCHSERVERSUBSESSION_SEARCHL_EXIT );
   236 	}
   271 	}
   237 
   272 
   238 EXPORT_C void RSearchServerSubSession::Search(const TDesC& aSearchTerms, TRequestStatus& aStatus)
   273 EXPORT_C void RSearchServerSubSession::Search(const TDesC& aSearchTerms, TRequestStatus& aStatus)
   239 	{
   274 	{
   350     if (iSizeList)
   385     if (iSizeList)
   351         {
   386         {
   352         delete iSizeList;
   387         delete iSizeList;
   353         iSizeList = NULL;
   388         iSizeList = NULL;
   354         }
   389         }
   355     iSizeList = STATIC_CAST(TInt *, User::AllocZL(iReqCount * sizeof(TInt)));
   390     TRAP_IGNORE(iSizeList = STATIC_CAST(TInt *, User::AllocZL(iReqCount * sizeof(TInt))));
   356     //iDocSizeArray
   391     //iDocSizeArray
   357     TPtr8 blob((TUint8*)iSizeList, iReqCount * sizeof(TInt));
   392     TPtr8 blob((TUint8*)iSizeList, iReqCount * sizeof(TInt));
   358 	    
   393 	    
   359     // Message arguments for the server
   394     // Message arguments for the server
   360     TIpcArgs args(aIndex, aCount, &blob);
   395     TIpcArgs args(aIndex, aCount, &blob);
   481     }
   516     }
   482 
   517 
   483 
   518 
   484 // StartServer()
   519 // StartServer()
   485 // Starts the server if it is not already running
   520 // Starts the server if it is not already running
   486 static TInt StartServer()
   521 static TInt StartServer( const TDesC& aServerName , TUid aServerUid )
   487 	{
   522 	{
   488 	TInt result;
   523 	TInt result;
   489 
   524 
   490 	TFindServer findsearchServer(KSearchServerName);
   525 	TFindServer findsearchServer(aServerName);
   491 	TFullName name;
   526 	TFullName name;
   492 
   527 
   493 	result = findsearchServer.Next(name);
   528 	result = findsearchServer.Next(name);
   494 	if (result == KErrNone)
   529 	if (result == KErrNone)
   495 		{
   530 		{
   502 	if (result != KErrNone)
   537 	if (result != KErrNone)
   503 		{
   538 		{
   504 		return result;
   539 		return result;
   505 		}
   540 		}
   506 
   541 
   507 	result = CreateServerProcess();
   542 	result = CreateServerProcess( aServerName,aServerUid );
   508 	if (result != KErrNone)
   543 	if (result != KErrNone)
   509 		{
   544 		{
   510 		return result;
   545 		return result;
   511 		}
   546 		}
   512 
   547 
   516 	return KErrNone;
   551 	return KErrNone;
   517 	}
   552 	}
   518 
   553 
   519 // CreateServerProcess()
   554 // CreateServerProcess()
   520 // Creates a server process
   555 // Creates a server process
   521 static TInt CreateServerProcess()
   556 static TInt CreateServerProcess( const TDesC& aServerName , TUid aServerUid )
   522 	{
   557 	{
   523 	TInt result;
   558 	TInt result;
   524 
   559 
   525 	const TUidType serverUid( KNullUid, KNullUid, KServerUid3);
   560 	const TUidType serverUid( KNullUid, KNullUid, aServerUid);
   526 
   561 
   527 	RProcess server;
   562 	RProcess server;
   528 
   563 
   529 	result = server.Create(KSearchServerFilename, KNullDesC, serverUid);
   564 	result = server.Create(aServerName, KNullDesC, serverUid);
   530 	if (result != KErrNone)
   565 	if (result != KErrNone)
   531 		{
   566 		{
   532 		return result;
   567 		return result;
   533 		}
   568 		}
   534 
   569