|
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: Launches JavaInstaller with given arguments |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifdef __SYMBIAN32__ |
|
19 #include <spawn.h> |
|
20 #else |
|
21 #include <stdio.h> |
|
22 #endif //__SYMBIAN32__ |
|
23 #include <errno.h> |
|
24 #include <string> |
|
25 #include <string.h> |
|
26 |
|
27 #include "logger.h" |
|
28 #include "javajniutils.h" |
|
29 #include "javacommonutils.h" |
|
30 #include "javaprocessconstants.h" |
|
31 #include "com_nokia_mj_impl_tckrunner_Installer.h" |
|
32 |
|
33 using std::wstring; |
|
34 |
|
35 |
|
36 const int MAX_PARAMS = 16; |
|
37 |
|
38 void jobjectArrayToCharArray(JNIEnv* aEnv, jobjectArray aArgs, char** aArr) |
|
39 { |
|
40 int len = aEnv->GetArrayLength(aArgs); |
|
41 |
|
42 for (int i = 0; i < len; i++) |
|
43 { |
|
44 jstring jstr = (jstring)aEnv->GetObjectArrayElement(aArgs, i); |
|
45 wstring s = java::util::JniUtils::jstringToWstring(aEnv, jstr); |
|
46 aEnv->DeleteLocalRef(jstr); |
|
47 |
|
48 aArr[i] = java::util::JavaCommonUtils::wstringToUtf8(s); |
|
49 LOG1WSTR(ETckRunner, EInfo, "Added arg=%s", s); |
|
50 } |
|
51 } |
|
52 |
|
53 |
|
54 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_tckrunner_Installer__1launchJavaInstaller( |
|
55 JNIEnv* aEnv, |
|
56 jobject, |
|
57 jobjectArray aArgs) |
|
58 { |
|
59 int rc = 0; |
|
60 |
|
61 const char* av[MAX_PARAMS + 5]; |
|
62 int index = 0; |
|
63 av[index++] = java::runtime::JAVA_PROCESS; |
|
64 av[index++] = java::runtime::JAVA_INSTALLER_STARTER_DLL; |
|
65 av[index++] = "poll"; |
|
66 av[index++] = "-address=tck"; |
|
67 |
|
68 int args = aEnv->GetArrayLength(aArgs); |
|
69 char** installerArgs = new char*[args]; |
|
70 jobjectArrayToCharArray(aEnv, aArgs, installerArgs); |
|
71 |
|
72 for (int i=0; i<args && i < MAX_PARAMS; i++) |
|
73 { |
|
74 av[index++] = installerArgs[i]; |
|
75 } |
|
76 av[index] = NULL; |
|
77 |
|
78 int pid = 0; |
|
79 #ifdef __SYMBIAN32__ |
|
80 rc = posix_spawn(&pid, av[0], NULL, NULL, (char*const*)av, NULL); |
|
81 #else |
|
82 if (!(pid = fork())) |
|
83 { |
|
84 rc = execvp(av[0], (char*const*)av); |
|
85 if (rc == -1) |
|
86 { |
|
87 rc = errno; |
|
88 } |
|
89 } |
|
90 #endif // __SYMBIAN32__ |
|
91 |
|
92 for (int i=0; i<args; i++) |
|
93 { |
|
94 delete[] installerArgs[i]; |
|
95 } |
|
96 delete[] installerArgs; |
|
97 |
|
98 if (rc) |
|
99 { |
|
100 ELOG3(ETckRunner, "%s failed, %s - errno=%d", __PRETTY_FUNCTION__, strerror(rc), rc); |
|
101 } |
|
102 |
|
103 return rc; |
|
104 } |