javaruntimes/installer/starterexe/src/main.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Main program for the JavaInstaller process
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <memory>
       
    20 #include <sstream>
       
    21 #include <unistd.h>
       
    22 
       
    23 #include "exceptionbase.h"
       
    24 #include "javaoslayer.h"
       
    25 #include "javaprocessconstants.h"
       
    26 #include "logger.h"
       
    27 #include "runtimeexception.h"
       
    28 
       
    29 #ifdef __SYMBIAN32__
       
    30 #include "javasymbianoslayer.h"
       
    31 #endif // __SYMBIAN32__
       
    32 
       
    33 using namespace java::runtime;
       
    34 using namespace java::util;
       
    35 
       
    36 int main(int argc, char *argv[])
       
    37 {
       
    38     JELOG(EJavaRuntime, "INSTALLEREXE main()");
       
    39     JavaOsLayer::startUpTrace("INSTALLEREXE main() start", -1, -1);
       
    40 
       
    41     int result = -1;
       
    42     try
       
    43     {
       
    44 #ifdef __SYMBIAN32__
       
    45         std::auto_ptr<HBufC> installerProcess(
       
    46             stringToDes(java::runtime::JAVA_PROCESS));
       
    47 
       
    48         std::ostringstream params;
       
    49         params << java::runtime::JAVA_INSTALLER_STARTER_DLL << " ";
       
    50         for (int i = 1; i < argc; i++)
       
    51         {
       
    52             params << argv[i] << " "; // codescanner::accessArrayElementWithoutCheck2
       
    53         }
       
    54         std::auto_ptr<HBufC> installerArgs(stringToDes(params.str().c_str()));
       
    55 
       
    56         LOG1(EJavaRuntime, EInfo, "INSTALLEREXE main() command line: %s",
       
    57              params.str().c_str());
       
    58 
       
    59         RProcess rp; // codescanner::resourcenotoncleanupstack
       
    60         result = rp.Create(TPtr(installerProcess->Des()), TPtr(installerArgs->Des()));
       
    61         if (KErrNone == result)
       
    62         {
       
    63             // Wait for the exit status of JavaInstaller.
       
    64             TRequestStatus status;
       
    65             rp.Logon(status);
       
    66             rp.Resume();
       
    67             User::WaitForRequest(status);
       
    68             result = status.Int();
       
    69             rp.Close(); // free process kernel object
       
    70         }
       
    71         else
       
    72         {
       
    73             ELOG1(EJavaRuntime, "INSTALLEREXE main(): starting JavaInstaller failed, err=%d", result);
       
    74         }
       
    75 #else // __SYMBIAN32__
       
    76         const char* av[argc + 2];
       
    77         av[0] = java::runtime::JAVA_PROCESS;
       
    78         av[1] = java::runtime::JAVA_INSTALLER_STARTER_DLL;
       
    79         for (int i = 1; i < argc; i++)
       
    80         {
       
    81             av[i+1] = argv[i];
       
    82         }
       
    83         av[argc+1] = NULL; // codescanner::accessArrayElementWithoutCheck2
       
    84         result = execvp(av[0], (char*const*)av);
       
    85 #endif // __SYMBIAN32__
       
    86     }
       
    87     catch (RuntimeException& e)
       
    88     {
       
    89         ELOG1(EJavaRuntime, "INSTALLEREXE main() RuntimeException caught: %s ",
       
    90               e.toString().c_str());
       
    91     }
       
    92     catch (ExceptionBase& e)
       
    93     {
       
    94         ELOG1(EJavaRuntime, "INSTALLEREXE main() ExceptionBase caught: %s ",
       
    95               e.toString().c_str());
       
    96     }
       
    97     catch (std::exception& e)
       
    98     {
       
    99         ELOG1(EJavaRuntime, "INSTALLEREXE main() Exception %s caught", e.what());
       
   100     }
       
   101 
       
   102     LOG1(EJavaRuntime, EInfo, "INSTALLEREXE main() exit = %d", result);
       
   103     JavaOsLayer::startUpTrace("INSTALLEREXE main() end", -1, -1);
       
   104     return result;
       
   105 }