bearermanagement/mpm/src/mpmlauncher.cpp
author Simon Howkins <simonh@symbian.org>
Thu, 18 Nov 2010 15:05:52 +0000
branchRCL_3
changeset 76 40780c2f3a6b
parent 13 68f0c7cd80ec
child 73 70ee5458c95d
permissions -rw-r--r--
Adjusted to avoid exports, etc, from a top-level bld.inf

/*
* Copyright (c) 2004-2005 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: MPM Client DLL Entry Point
*
*/

/**
@file mpmlauncher.cpp
Mobility Policy Manager client DLL entry point.
*/

// INCLUDE FILES
#include <e32std.h>
#include "mpmlauncher.h"
#include "mpmlogger.h"

// ============================= LOCAL FUNCTIONS ===============================

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

// -----------------------------------------------------------------------------
// MPMLauncher::LaunchServer
// -----------------------------------------------------------------------------
//
TInt MPMLauncher::LaunchServer(
    const TDesC& aServerFileName,
    const TUid& aServerUid2,
    const TUid& aServerUid3)
    {
    MPMLOGSTRING("MPMLauncher::LaunchServer")
    const TUidType serverUid(KNullUid,aServerUid2,aServerUid3);
    RSemaphore semaphore;
    TInt err( KErrNone );

    err = semaphore.CreateGlobal( KMPMLauncherSemaphore, 0 );
    if ( err != KErrNone )
        {
        // Creating semaphore failed, which means some other thread is
        // creating the server right. Propagate error KErrServerBusy
        // to inform the client it should try connecting again.
        return KErrServerBusy;
        }
    
    MPMLOGSTRING("Create a new server process")
    RProcess server;
    TInt r=server.Create(aServerFileName,KNullDesC,serverUid);
    
    if ( r != KErrNone )
        {
        MPMLOGSTRING2("Server process creation returned error: %d", r)
        semaphore.Close();
        return r;
        }
    TRequestStatus stat;
    server.Rendezvous(stat);
    if ( stat != KRequestPending )
        {
        server.Kill(0);        // abort startup
        }
    else
        {
        server.Resume();    // logon OK - start the server
        }
    User::WaitForRequest(stat);        // wait for start or death
    // we can't use the 'exit reason' if the server panicked as this
    // is the panic 'reason' and may be '0' which cannot be distinguished
    // from KErrNone
    r = ( server.ExitType() == EExitPanic ) ? KErrGeneral : stat.Int();
    server.Close();
    semaphore.Close();
    return r;
    }


// ========================== OTHER EXPORTED FUNCTIONS =========================


//  End of File