atext/server/src/maincommon.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 /*
       
     2 * Copyright (c) 2008 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 
       
    19 #include "atextsrvcommon.h"
       
    20 #include "atextclientsrvcommon.h"
       
    21 #include "debug.h"
       
    22 
       
    23 static void RunServerL();
       
    24 
       
    25 /**
       
    26 * Main entry-point for the server process.
       
    27 **/
       
    28 GLDEF_C TInt E32Main()
       
    29     {
       
    30     TRACE_STATIC_FUNC
       
    31 
       
    32     __UHEAP_MARK;
       
    33     CTrapCleanup* cleanup = CTrapCleanup::New();
       
    34     TInt retTrap = KErrNoMemory;
       
    35     if ( cleanup )
       
    36         {
       
    37         TRAP( retTrap, RunServerL() );
       
    38         delete cleanup;
       
    39         }
       
    40     __UHEAP_MARKEND;
       
    41     TRACE_FUNC_EXIT
       
    42     return retTrap;
       
    43     }
       
    44 
       
    45 /**
       
    46 Create the active scheduler and server instances, and start the
       
    47 server.
       
    48 */
       
    49 static void RunServerL()
       
    50     {
       
    51     TRACE_STATIC_FUNC
       
    52 	TFindServer find( KATExtSrvName );
       
    53     TFullName name;
       
    54 
       
    55     if ( find.Next(name) == KErrNone )
       
    56         {
       
    57         // Server is already up
       
    58         TRACE_INFO((_L("ext srv already running.")))
       
    59         return;
       
    60         }
       
    61 
       
    62     User::LeaveIfError( User::RenameThread(KATExtSrvName) );
       
    63     // Create and install the active scheduler.
       
    64     CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
       
    65     CleanupStack::PushL( scheduler );
       
    66     CActiveScheduler::Install( scheduler );
       
    67 
       
    68     // Create the server.
       
    69     CATExtSrvCommon* server = CATExtSrvCommon::NewLC();
       
    70 
       
    71     // Initialisation complete, now signal the client
       
    72     RProcess::Rendezvous( KErrNone );
       
    73 
       
    74     // Ready to run. This only returns when the server is closing down.
       
    75     CActiveScheduler::Start();
       
    76 
       
    77     // Clean up the server and scheduler.
       
    78     CleanupStack::PopAndDestroy( server );
       
    79     CleanupStack::PopAndDestroy( scheduler );
       
    80     TRACE_FUNC_EXIT
       
    81     }