atext/server/src/maincommon.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 31 Aug 2010 16:20:16 +0300
branchRCL_3
changeset 23 5b153be919d4
parent 0 29b1cd4cb562
permissions -rw-r--r--
Revision: 201031 Kit: 201035

/*
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#include "atextsrvcommon.h"
#include "atextclientsrvcommon.h"
#include "debug.h"

static void RunServerL();

/**
* Main entry-point for the server process.
**/
GLDEF_C TInt E32Main()
    {
    TRACE_STATIC_FUNC

    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();
    TInt retTrap = KErrNoMemory;
    if ( cleanup )
        {
        TRAP( retTrap, RunServerL() );
        delete cleanup;
        }
    __UHEAP_MARKEND;
    TRACE_FUNC_EXIT
    return retTrap;
    }

/**
Create the active scheduler and server instances, and start the
server.
*/
static void RunServerL()
    {
    TRACE_STATIC_FUNC
	TFindServer find( KATExtSrvName );
    TFullName name;

    if ( find.Next(name) == KErrNone )
        {
        // Server is already up
        TRACE_INFO((_L("ext srv already running.")))
        return;
        }

    User::LeaveIfError( User::RenameThread(KATExtSrvName) );
    // Create and install the active scheduler.
    CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
    CleanupStack::PushL( scheduler );
    CActiveScheduler::Install( scheduler );

    // Create the server.
    CATExtSrvCommon* server = CATExtSrvCommon::NewLC();

    // Initialisation complete, now signal the client
    RProcess::Rendezvous( KErrNone );

    // Ready to run. This only returns when the server is closing down.
    CActiveScheduler::Start();

    // Clean up the server and scheduler.
    CleanupStack::PopAndDestroy( server );
    CleanupStack::PopAndDestroy( scheduler );
    TRACE_FUNC_EXIT
    }