bearermanagement/mpm/src/mpmlauncher.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 15 Mar 2010 12:42:11 +0200
branchRCL_3
changeset 13 68f0c7cd80ec
parent 0 5a93021fdf25
child 73 70ee5458c95d
permissions -rw-r--r--
Revision: 201009 Kit: 201010

/*
* 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