javamanager/debugapi/src.s60/applauncher.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 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: AppLauncher can be used to start and stop Java application.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "applauncher.h"
       
    19 
       
    20 #include "logger.h"
       
    21 #include "javauid.h"
       
    22 #include "rtcmessages.h"
       
    23 #include "comms.h"
       
    24 #include "commsmessage.h"
       
    25 #include "commsclientendpoint.h"
       
    26 
       
    27 using namespace java::debug;
       
    28 using namespace java::util;
       
    29 using namespace java::comms;
       
    30 using namespace java::captain;
       
    31 
       
    32 AppLauncher::AppLauncher(const java::util::Uid& aAppUid): mUid(aAppUid), mPid(0)
       
    33 {
       
    34 }
       
    35 
       
    36 AppLauncher::~AppLauncher()
       
    37 {
       
    38 }
       
    39 
       
    40 int AppLauncher::startApp(const std::wstring& aJvmArgs)
       
    41 {
       
    42     JELOG2(EDebugApi);
       
    43 
       
    44     CommsMessage start = createStartAppMessage(aJvmArgs);
       
    45     int rc = sendToJavaCaptain(start);
       
    46 
       
    47     LOG3(EDebugApi, EInfo, "startApp(): uid=%S, result=%d, pid=%d", mUid.toString().c_str(), rc, mPid);
       
    48     return rc;
       
    49 }
       
    50 
       
    51 int AppLauncher::stopApp()
       
    52 {
       
    53     JELOG2(EDebugApi);
       
    54 
       
    55     CommsMessage stop = createStopAppMessage();
       
    56     int rc = sendToJavaCaptain(stop);
       
    57 
       
    58     LOG2(EDebugApi, EInfo, "stopApp(): uid=%S, result=%d", mUid.toString().c_str(), rc);
       
    59     return rc;
       
    60 }
       
    61 
       
    62 CommsMessage AppLauncher::createStartAppMessage(const std::wstring& aJvmArgs)
       
    63 {
       
    64     CommsMessage msg;
       
    65     setLaunchApplicationReqParams(msg, mUid,
       
    66                                   RTC_LAUNCH_TYPE_DEBUG_C,
       
    67                                   RTC_LAUNCH_OPTIONS_RUNNING_IND_REQ_C,
       
    68                                   RTC_LAUNCH_RUNTIME_MIDP_C,
       
    69                                   L"", aJvmArgs);
       
    70     return msg;
       
    71 }
       
    72 
       
    73 CommsMessage AppLauncher::createStopAppMessage()
       
    74 {
       
    75     CommsMessage msg;
       
    76     setTerminateApplicationReqParams(msg, mUid,
       
    77                                      RTC_LAUNCH_OPTIONS_TERMINATE_IND_REQ_C);
       
    78     return msg;
       
    79 }
       
    80 
       
    81 int AppLauncher::sendToJavaCaptain(CommsMessage& aMessage)
       
    82 {
       
    83     CommsClientEndpoint comms;
       
    84     comms.connect(IPC_ADDRESS_JAVA_CAPTAIN_C);
       
    85 
       
    86     CommsMessage reply;
       
    87     int rc = comms.sendReceive(aMessage, reply, WAIT_FOR_EVER);
       
    88     if (!rc)
       
    89     {
       
    90         Uid ignored;
       
    91         reply >> ignored >> rc >> mPid;
       
    92     }
       
    93 
       
    94     comms.disconnect();
       
    95     return rc;
       
    96 }
       
    97 
       
    98 pid_t AppLauncher::getPid()
       
    99 {
       
   100     return mPid;
       
   101 }