phoneclientserver/phoneserver/Src/Standard/PhSrvStartUp.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Start Up functionality of Phone Server.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "PhSrvStartUp.h"
       
    22 #include "CPhSrvScheduler.h"
       
    23 #include "CPhSrvServer.h"
       
    24 #include "PhSrvUtils.h"
       
    25 
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // PhoneServerStartUpUtils::CreateAndRunServerL
       
    32 // 
       
    33 // Creates a server instance, active scheduler, etc, and
       
    34 // starts the server going by starting the active scheduler.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 void PhoneServerStartUpUtils::CreateAndRunServerL()
       
    38     {
       
    39     CPhSrvScheduler* scheduler = new( ELeave ) CPhSrvScheduler();
       
    40     CleanupStack::PushL( scheduler );
       
    41     CActiveScheduler::Install( scheduler );
       
    42 
       
    43     // Create the server
       
    44     CPhSrvServer* server = CPhSrvServer::NewL();
       
    45     CleanupStack::PushL( server );
       
    46 
       
    47     // Attempt to rename the thread - it isn't critial if this fails
       
    48 #ifdef _DEBUG
       
    49     TInt err = 
       
    50 #endif // _DEBUG
       
    51 
       
    52     User::RenameThread( KPhServerThreadName );
       
    53 
       
    54     __ASSERT_DEBUG( err == KErrNone, 
       
    55         PhoneServerUtils::Panic(EPhoneServerPanicCouldNotRenameServerThread ) );
       
    56 
       
    57     // Now that the server has been started okay, we can signal the
       
    58     // client so that they can attempt to connect.
       
    59 
       
    60     RProcess::Rendezvous( KErrNone );
       
    61 
       
    62     // The final step in the chain is to start the active scheduler
       
    63     // which will allow the server to be fully operational and enable
       
    64     // request processing.
       
    65     CActiveScheduler::Start();
       
    66 
       
    67     // Cleanup the server and scheduler
       
    68     // Check also that the last poped item was scheduler.
       
    69     CleanupStack::PopAndDestroy( 2, scheduler );
       
    70     }
       
    71 
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // PhoneServerStartUpUtils::PrepareServerEnvironment
       
    75 // 
       
    76 // Creates a cleanup stack trap harness and attemps to run
       
    77 // the server.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 TInt PhoneServerStartUpUtils::PrepareServerEnvironment()
       
    81     {
       
    82     TInt err = KErrNoMemory;
       
    83 
       
    84     CTrapCleanup* cleanup = CTrapCleanup::New();
       
    85     if ( cleanup )
       
    86         {
       
    87         TRAP( err, CreateAndRunServerL() );
       
    88         }
       
    89     delete cleanup;
       
    90 
       
    91     return err;
       
    92     }
       
    93 
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // E32Main (MARM ONLY - RUNNING SERVER IN THREAD INSIDE PROCESS)
       
    98 // 
       
    99 // Satisfies EPOCEXE build criteria. Called by Kernel when
       
   100 // a new process is created, and is used to start the server going.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 GLDEF_C TInt E32Main()
       
   104     {
       
   105     TInt err;
       
   106 
       
   107     err = PhoneServerStartUpUtils::PrepareServerEnvironment();
       
   108 
       
   109     return err;
       
   110     }
       
   111 
       
   112 
       
   113 
       
   114 // End of File