convergedconnectionhandler/cchclient/src/cchserver.cpp
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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:  RCCHServer implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <cchclientserver.h>
       
    21 
       
    22 #include "cchserver.h"
       
    23 #include "cchlogger.h" 
       
    24 #include "cchclientserverinternal.h"
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 // None
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES
       
    30 // None
       
    31 
       
    32 // CONSTANTS
       
    33 // None
       
    34 
       
    35 // MACROS
       
    36 // None
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 const TUint8 KCCHServerStartAttempts = 2;
       
    40 
       
    41 // MODULE DATA STRUCTURES
       
    42 // None
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 // None
       
    46 
       
    47 // FORWARD DECLARATIONS
       
    48 // None
       
    49 
       
    50 // ============================= LOCAL FUNCTIONS =============================
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS =============================
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // RCCHServer::RCCHServer
       
    56 // C++ default constructor can NOT contain any code, that might leave.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C RCCHServer::RCCHServer() : RSessionBase()
       
    60     {
       
    61     CCHLOGSTRING( "RCCHServer::RCCHClient" );    
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // RCCHServer::Connect
       
    66 // (other items were commented in a header).
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C TInt RCCHServer::Connect()
       
    70     {
       
    71     CCHLOGSTRING( "RCCHServer::Connect" );
       
    72     TInt error( KErrNone );
       
    73     TUint8 retry = KCCHServerStartAttempts;
       
    74     
       
    75     for ( ;; )
       
    76         {
       
    77         error = CreateSession( KCCHServerName, 
       
    78                                Version(), 
       
    79                                KCCHMessageSlots );
       
    80 
       
    81         CCHLOGSTRING2
       
    82             ("RCCHServer CreateSession result: %d", error );
       
    83         
       
    84         if ( KErrNotFound != error && KErrServerTerminated != error )
       
    85             {
       
    86             break;
       
    87             }
       
    88         
       
    89         // Need to restart server
       
    90         if ( 0 == --retry )
       
    91             {
       
    92             break;
       
    93             }                    
       
    94         error = StartServer();
       
    95         CCHLOGSTRING2
       
    96             ( "RCCHServer::Connect, StartServer() returned %d", error );
       
    97         
       
    98         if ( KErrNone != error && KErrAlreadyExists != error )
       
    99             {
       
   100             break;
       
   101             }
       
   102         }
       
   103 
       
   104     return error;    
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // RCCHServer::Disconnect
       
   109 // (other items were commented in a header).
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C void RCCHServer::Disconnect()
       
   113     {
       
   114     CCHLOGSTRING( "RCCHServer::Disconnect" );
       
   115     RHandleBase::Close();
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // RCCHServer::Version
       
   120 // (other items were commented in a header).
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 TVersion RCCHServer::Version() const
       
   124     {
       
   125     return ( TVersion( KCCHServMajorVersionNumber,
       
   126                        KCCHServMinorVersionNumber,
       
   127                        KCCHServBuildVersionNumber ) );
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // RCCHServer::StartServer
       
   132 // (other items were commented in a header).
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 EXPORT_C TInt RCCHServer::StartServer() const
       
   136     {
       
   137     CCHLOGSTRING( "RCCHServer::StartServer" );
       
   138     TInt error( KErrNone );
       
   139     RProcess server;
       
   140     const TUidType serverUid( KNullUid, KNullUid, KCCHServerUid );
       
   141     error = server.Create( KCCHServerExe, KNullDesC, serverUid );
       
   142     
       
   143     if ( KErrNone == error )
       
   144         {
       
   145         TRequestStatus status;
       
   146         server.Rendezvous( status );
       
   147         
       
   148         if ( status != KRequestPending )
       
   149             {
       
   150             server.Kill( 0 );   // abort startup
       
   151             }
       
   152         else
       
   153             {
       
   154             server.Resume();    // logon OK - start the server
       
   155             }
       
   156             
       
   157         CCHLOGSTRING( "RCCHServer::StartServer(): Started" );
       
   158         
       
   159         User::WaitForRequest( status );     // wait for start or death
       
   160         
       
   161         // we can't use the 'exit reason' if the server panicked as this
       
   162         // is the panic 'reason' and may be '0' which cannot be distinguished
       
   163         // from KErrNone
       
   164         
       
   165         error = 
       
   166             ( server.ExitType() == EExitPanic ) ? KErrGeneral : status.Int();
       
   167         server.Close();
       
   168         }
       
   169     return error;
       
   170     }
       
   171     
       
   172 // ========================== OTHER EXPORTED FUNCTIONS =======================
       
   173 
       
   174 //  End of File