phoneclientserver/phoneserver/Src/Standard/PhSrvStartUp.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Mar 2010 09:40:14 +0200
changeset 12 ae8abd0db65c
parent 0 ff3b6d0fd310
child 13 e32024264ebb
permissions -rw-r--r--
Revision: 201007 Kit: 201011

/*
* Copyright (c) 2002-2004 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:  Start Up functionality of Phone Server.
*
*/



// INCLUDE FILES
#include "PhSrvStartUp.h" 
#include "CPhSrvScheduler.h" 
#include "CPhSrvServer.h" 
#include "PhSrvUtils.h" 


// ============================ MEMBER FUNCTIONS ===============================


// -----------------------------------------------------------------------------
// PhoneServerStartUpUtils::CreateAndRunServerL
// 
// Creates a server instance, active scheduler, etc, and
// starts the server going by starting the active scheduler.
// -----------------------------------------------------------------------------
//
void PhoneServerStartUpUtils::CreateAndRunServerL()
    {
    CPhSrvScheduler* scheduler = new( ELeave ) CPhSrvScheduler();
    CleanupStack::PushL( scheduler );
    CActiveScheduler::Install( scheduler );

    // Create the server
    CPhSrvServer* server = CPhSrvServer::NewL();
    CleanupStack::PushL( server );

    // Attempt to rename the thread - it isn't critial if this fails
#ifdef _DEBUG
    TInt err = 
#endif // _DEBUG

    User::RenameThread( KPhServerThreadName );

    __ASSERT_DEBUG( err == KErrNone, 
        PhoneServerUtils::Panic(EPhoneServerPanicCouldNotRenameServerThread ) );

    // Now that the server has been started okay, we can signal the
    // client so that they can attempt to connect.

    RProcess::Rendezvous( KErrNone );

    // The final step in the chain is to start the active scheduler
    // which will allow the server to be fully operational and enable
    // request processing.
    CActiveScheduler::Start();

    // Cleanup the server and scheduler
    // Check also that the last poped item was scheduler.
    CleanupStack::PopAndDestroy( 2, scheduler );
    }


// -----------------------------------------------------------------------------
// PhoneServerStartUpUtils::PrepareServerEnvironment
// 
// Creates a cleanup stack trap harness and attemps to run
// the server.
// -----------------------------------------------------------------------------
//
TInt PhoneServerStartUpUtils::PrepareServerEnvironment()
    {
    TInt err = KErrNoMemory;

    CTrapCleanup* cleanup = CTrapCleanup::New();
    if ( cleanup )
        {
        TRAP( err, CreateAndRunServerL() );
        }
    delete cleanup;

    return err;
    }



// -----------------------------------------------------------------------------
// E32Main (MARM ONLY - RUNNING SERVER IN THREAD INSIDE PROCESS)
// 
// Satisfies EPOCEXE build criteria. Called by Kernel when
// a new process is created, and is used to start the server going.
// -----------------------------------------------------------------------------
//
GLDEF_C TInt E32Main()
    {
    TInt err;

    err = PhoneServerStartUpUtils::PrepareServerEnvironment();

    return err;
    }



// End of File