contentpublishingsrv/contentharvester/contentharvesterclient/src/contentharvesterclient.cpp
changeset 93 82b66994846c
parent 92 782e3408c2ab
child 94 dbb8300717f7
equal deleted inserted replaced
92:782e3408c2ab 93:82b66994846c
     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:  
       
    15  *
       
    16 */
       
    17 
       
    18 #include "contentharvesterclient.h"
       
    19 #include "contentharvesterglobals.h"
       
    20 
       
    21 // Number of message slots to reserve for this client server session.
       
    22 const TUint KDefaultMessageSlots( 5);
       
    23 
       
    24 // Function prototypes
       
    25 static TInt StartServer();
       
    26 static TInt CreateServerProcess();
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // RContentHarvesterClient::RContentHarvesterClient
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C RContentHarvesterClient::RContentHarvesterClient()
       
    37 :RSessionBase()
       
    38     {
       
    39     // No implementation required
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // RContentHarvesterClient::Connect
       
    44 // Connect to Content Harvester Server session. 
       
    45 // exist
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C TInt RContentHarvesterClient::Connect()
       
    49     {
       
    50     TInt error = ::StartServer();
       
    51 
       
    52     if ( error == KErrNone )
       
    53         {
       
    54         error = CreateSession( KContentHarvesterName,
       
    55                 Version(),
       
    56                 KDefaultMessageSlots );
       
    57         }
       
    58     return error;
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // RContentHarvesterClient::Update
       
    63 // Client requests to trigger update process
       
    64 // -----------------------------------------------------------------------------
       
    65 
       
    66 EXPORT_C TInt RContentHarvesterClient::Update()
       
    67     {
       
    68     return SendReceive( EContentHarvesterUpdate );
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // RContentHarvesterClient::Stop
       
    73 // Client requests to trigger stop process
       
    74 // -----------------------------------------------------------------------------
       
    75 
       
    76 EXPORT_C TInt RContentHarvesterClient::Stop()
       
    77     {
       
    78     return SendReceive( EContentHarvesterStop );
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // RContentHarvesterClient::Version
       
    83 // Version information.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 TVersion RContentHarvesterClient::Version() const
       
    87     {
       
    88     return (TVersion( KContentHarvesterMajorVersionNumber,
       
    89         KContentHarvesterMinorVersionNumber,
       
    90         KContentHarvesterBuildVersionNumber ) );
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // StartServer
       
    95 // Static method to start the server.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 static TInt StartServer()
       
    99     {
       
   100     TInt result;
       
   101 
       
   102     TFindServer findServer( KContentHarvesterName );
       
   103     TFullName name;
       
   104 
       
   105     result = findServer.Next( name );
       
   106     if ( result != KErrNone )
       
   107         {
       
   108         // Server not running
       
   109         result = CreateServerProcess( );
       
   110         }
       
   111     return result;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CreateServerProcess
       
   116 // Static method to create the server process.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 static TInt CreateServerProcess()
       
   120     {
       
   121     const TUidType serverUid( KNullUid, KNullUid, KServerUid3);
       
   122     RProcess server;
       
   123     TInt result;
       
   124     result = server.Create( KContentHarvesterFilename, KNullDesC, serverUid );
       
   125     if ( result == KErrNone )
       
   126         {
       
   127         TRequestStatus stat = KRequestPending;
       
   128         server.Rendezvous( stat );
       
   129         if ( stat != KRequestPending )
       
   130             {
       
   131             server.Kill( 0 ); // abort startup
       
   132             }
       
   133         else
       
   134             {
       
   135             server.Resume( ); // logon OK - start the server
       
   136             }
       
   137 
       
   138         User::WaitForRequest( stat ); // wait for start or death
       
   139         // we can't use the 'exit reason' if the server panicked as this
       
   140         // is the panic 'reason' and may be '0' which cannot be distinguished
       
   141         // from KErrNone
       
   142         result = (server.ExitType( ) == EExitPanic ) ? KErrGeneral
       
   143             : stat.Int( );
       
   144         }
       
   145     server.Close( );
       
   146     return result;
       
   147     }