osutil: get_java_path() move to osutil-win32.c
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 22 Oct 2015 07:23:56 +0000 (16:23 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 23 Oct 2015 07:22:02 +0000 (16:22 +0900)
qemu_oom_check() uses new QT5 dialog for reporting errors. Finally,
get_java_path() is called by tizen specific logics only. Then it
can move to tizen specific utility now.

Change-Id: I9f2d0dd26715059734bc8242320de01c539a331c
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/emul_state.c
tizen/src/emulator_common.h
tizen/src/hw/pci/maru_camera_win32.h
tizen/src/ui/menu/contextmenu.cpp
tizen/src/util/osutil-win32.c
tizen/src/util/osutil.h
util/oslib-win32.c

index a9f57dc..3de5768 100644 (file)
@@ -65,6 +65,10 @@ extern bool hax_allowed;
 
 DECLARE_DEBUG_CHANNEL(emul_state);
 
+#define MAXLEN  512
+#define HTTP_PROXY_PREFIX "http_proxy="
+#define HOST_IP_PREFIX "host_ip="
+
 static EmulatorConfigInfo _emul_info = {0,};
 static EmulatorConfigState _emul_state;
 
index bb297d3..1e0ea8d 100644 (file)
 #include <glib/gstdio.h>
 #include <glib/gprintf.h>
 #include <limits.h>
+#include <errno.h>
 #include "config-host.h"
 
 #ifdef CONFIG_DARWIN
 #include "sys/syslimits.h"
 #endif
 
+#ifdef CONFIG_WIN32
+#if defined(__MINGW64_VERSION_MAJOR)
+#define __MINGW_W64__
+#endif
+#endif
+
 #if !defined(PATH_MAX)
 #if defined(MAX_PATH)
 #define PATH_MAX    MAX_PATH
 #endif
 
 #define JAVA_MAX_COMMAND_LENGTH 1024
-#define MAXLEN  512
-#define HTTP_PROXY_PREFIX "http_proxy="
-#define HOST_IP_PREFIX "host_ip="
-
 
+#ifdef CONFIG_JAVA_UI
 #define JAR_SKINFILE "emulator-skin.jar"
 #define JAVA_LIBRARY_PATH "-Djava.library.path"
-
+#define JAVA_SIMPLEMODE_OPTION "simple.msg"
+#define JAVA_EXEFILE_PATH "java"
 #ifndef CONFIG_DARWIN
 #define JAVA_EXEOPTION "-jar"
 #else
 #define JAVA_EXEOPTION "-XstartOnFirstThread -jar" // Must start the Java window on the first thread on Mac
 #endif
-#define JAVA_SIMPLEMODE_OPTION "simple.msg"
-
-#ifdef CONFIG_WIN32
-#define MY_KEY_WOW64_64KEY 0x0100
-#ifdef __cplusplus
-extern "C" {
-#endif
-int is_wow64(void);
-bool get_java_path(char **java_path);
-#ifdef __cplusplus
-}
-#endif
-#else
-#define JAVA_EXEFILE_PATH "java"
 #endif
 
 #endif /* __EMULATOR_COMMON_H__ */
index a8009f2..2a86f9a 100644 (file)
@@ -100,7 +100,9 @@ DECLARE_INTERFACE_(IGrabCallback, IUnknown)
 #define IGrabCallback_Grab(T,a,b) (T)->lpVtbl->Grab(T,a,b)
 #endif /* COBJMACROS */
 
-#if defined(__MINGW64_VERSION_MAJOR)
+#include "emulator_common.h"
+
+#ifdef __MINGW_W64__
 #include <strmif.h>
 #include <control.h>
 #include <amvideo.h>
index db2f603..d24eac1 100644 (file)
@@ -41,6 +41,7 @@ extern "C" {
 // FIXME: To avoid very complex header inclusion chains
 void qemu_system_graceful_shutdown_request(unsigned int sec);
 
+#include "util/osutil.h"
 #include "util/device_hotplug.h"
 #include "util/ui_operations.h"
 }
index 1677eab..c56bae9 100644 (file)
@@ -281,3 +281,108 @@ int remove_sdcard_lock_os(char *sdcard)
         return ERR_UNLCK;
     }
 }
+
+typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
+int is_wow64(void)
+{
+    int result = 0;
+    LPFN_ISWOW64PROCESS fnIsWow64Process;
+
+    /* IsWow64Process is not available on all supported versions of Windows.
+       Use GetModuleHandle to get a handle to the DLL that contains the function
+       and GetProcAddress to get a pointer to the function if available. */
+
+    fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
+        GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
+
+    if (NULL != fnIsWow64Process) {
+        if (!fnIsWow64Process(GetCurrentProcess(), &result)) {
+            /* No need to handle error,
+               just check whether is this WoW64 process */
+        }
+    }
+    return result;
+}
+
+#define MY_KEY_WOW64_64KEY 0x0100
+static char wow64_java_path[PATH_MAX];
+bool get_java_path(char **java_path)
+{
+    int index;
+    LONG res;
+    HKEY hKey, hSubKey;
+    char strChoosenName[PATH_MAX] = {0};
+    char strSubKeyName[PATH_MAX] = {0};
+    char strJavaHome[PATH_MAX] = {0};
+    DWORD dwSubKeyNameMax = PATH_MAX;
+    DWORD dwBufLen = PATH_MAX;
+    char strKeyList[4][64] = {
+                /* 64bit runtime */
+                "SOFTWARE\\JavaSoft\\Java Runtime Environment",
+                "SOFTWARE\\JavaSoft\\Java Development Kit",
+                /* 32bit runtime */
+                "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment",
+                "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Development Kit"
+            };
+
+    if (wow64_java_path[0] != '\0') {
+        strcpy(*java_path, wow64_java_path);
+        return true;
+    }
+
+    for (index = 0; index < ARRAY_SIZE(strKeyList); index++) {
+        res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                           strKeyList[index],
+                           0,
+                           KEY_QUERY_VALUE |
+                           KEY_ENUMERATE_SUB_KEYS |
+                           MY_KEY_WOW64_64KEY,
+                           &hKey);
+        if (res == ERROR_SUCCESS) {
+            break;
+        }
+    }
+
+    if (res == ERROR_SUCCESS) {
+        index = 0;
+        do {
+            dwSubKeyNameMax = PATH_MAX;
+            res = RegEnumKeyEx(hKey,
+                               index++,
+                               (LPSTR)strSubKeyName,
+                               &dwSubKeyNameMax,
+                               NULL, NULL, NULL, NULL);
+            if (strcmp(strChoosenName, strSubKeyName) < 0) {
+                strcpy(strChoosenName, strSubKeyName);
+            }
+        } while (res == ERROR_SUCCESS);
+
+        RegOpenKeyEx(hKey, strChoosenName, 0,
+                     KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hSubKey);
+        RegQueryValueEx(hSubKey, "JavaHome", NULL,
+                        NULL, (LPBYTE)strJavaHome, &dwBufLen);
+        RegCloseKey(hSubKey);
+        RegCloseKey(hKey);
+    } else {
+        /* TODO:
+           get from %winDir%\System32
+           but, is this really needed?
+        */
+        DWORD dwRet = 0;
+        char strJavaHomeVar[PATH_MAX] = {0,};
+        dwRet = GetEnvironmentVariable("JAVA_HOME",
+                                       strJavaHomeVar,
+                                       PATH_MAX);
+        if (dwRet != 0 && dwRet < PATH_MAX) {
+            strcpy(strJavaHome, strJavaHomeVar);
+        }
+    }
+    if (strJavaHome[0] != '\0') {
+        sprintf(*java_path, "\"%s\\bin\\javaw.exe\"", strJavaHome);
+        strcpy(wow64_java_path, *java_path);
+    } else {
+        return false;
+    }
+
+    return true;
+}
index bcfe1c6..cc9e95c 100644 (file)
 #ifndef __OSUTIL_H__
 #define __OSUTIL_H__
 
-#include "qemu-common.h"
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "emulator_common.h"
+#ifdef CONFIG_WIN32
+#include "sysemu/os-win32.h"
+#else
+#include "sysemu/os-posix.h"
+#endif
 
 #define DEFAULTBUFLEN 512
 #define ERR_SUCCESS 0
@@ -60,6 +68,9 @@ typedef struct sdcard_info
 #ifndef CONFIG_WIN32
 bool make_sdcard_lock_posix(char *sdcard);
 int remove_sdcard_lock_posix(char *sdcard);
+#else
+int is_wow64(void);
+bool get_java_path(char **java_path);
 #endif
 
 void print_system_info_os(void);
index de9fd7e..23d934a 100644 (file)
 /* this must come after including "trace.h" */
 #include <shlobj.h>
 
-#ifdef CONFIG_MARU
-#include "tizen/src/emulator_common.h"
-
-typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
-
-int is_wow64(void)
-{
-    int result = 0;
-    LPFN_ISWOW64PROCESS fnIsWow64Process;
-
-    /* IsWow64Process is not available on all supported versions of Windows.
-       Use GetModuleHandle to get a handle to the DLL that contains the function
-       and GetProcAddress to get a pointer to the function if available. */
-
-    fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
-        GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
-
-    if (NULL != fnIsWow64Process) {
-        if (!fnIsWow64Process(GetCurrentProcess(), &result)) {
-            /* No need to handle error,
-               just check whether is this WoW64 process */
-        }
-    }
-    return result;
-}
-
-static char wow64_java_path[JAVA_MAX_COMMAND_LENGTH];
-bool get_java_path(char **java_path)
-{
-    int index;
-    LONG res;
-    HKEY hKey, hSubKey;
-    char strChoosenName[JAVA_MAX_COMMAND_LENGTH] = {0};
-    char strSubKeyName[JAVA_MAX_COMMAND_LENGTH] = {0};
-    char strJavaHome[JAVA_MAX_COMMAND_LENGTH] = {0};
-    DWORD dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH;
-    DWORD dwBufLen = JAVA_MAX_COMMAND_LENGTH;
-    char strKeyList[4][64] = {
-                /* 64bit runtime */
-                "SOFTWARE\\JavaSoft\\Java Runtime Environment",
-                "SOFTWARE\\JavaSoft\\Java Development Kit",
-                /* 32bit runtime */
-                "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment",
-                "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Development Kit"
-            };
-
-    if (wow64_java_path[0] != '\0') {
-        strcpy(*java_path, wow64_java_path);
-        return true;
-    }
-
-    for (index = 0; index < ARRAY_SIZE(strKeyList); index++) {
-        res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                           strKeyList[index],
-                           0,
-                           KEY_QUERY_VALUE |
-                           KEY_ENUMERATE_SUB_KEYS |
-                           MY_KEY_WOW64_64KEY,
-                           &hKey);
-        if (res == ERROR_SUCCESS) {
-            break;
-        }
-    }
-
-    if (res == ERROR_SUCCESS) {
-        index = 0;
-        do {
-            dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH;
-            res = RegEnumKeyEx(hKey,
-                               index++,
-                               (LPSTR)strSubKeyName,
-                               &dwSubKeyNameMax,
-                               NULL, NULL, NULL, NULL);
-            if (strcmp(strChoosenName, strSubKeyName) < 0) {
-                strcpy(strChoosenName, strSubKeyName);
-            }
-        } while (res == ERROR_SUCCESS);
-
-        RegOpenKeyEx(hKey, strChoosenName, 0,
-                     KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hSubKey);
-        RegQueryValueEx(hSubKey, "JavaHome", NULL,
-                        NULL, (LPBYTE)strJavaHome, &dwBufLen);
-        RegCloseKey(hSubKey);
-        RegCloseKey(hKey);
-    } else {
-        /* TODO:
-           get from %winDir%\System32
-           but, is this really needed?
-        */
-        DWORD dwRet = 0;
-        char strJavaHomeVar[JAVA_MAX_COMMAND_LENGTH] = {0,};
-        dwRet = GetEnvironmentVariable("JAVA_HOME",
-                                       strJavaHomeVar,
-                                       JAVA_MAX_COMMAND_LENGTH);
-        if (dwRet != 0 && dwRet < JAVA_MAX_COMMAND_LENGTH) {
-            strcpy(strJavaHome, strJavaHomeVar);
-        }
-    }
-    if (strJavaHome[0] != '\0') {
-        sprintf(*java_path, "\"%s\\bin\\javaw.exe\"", strJavaHome);
-        strcpy(wow64_java_path, *java_path);
-    } else {
-        return false;
-    }
-
-    return true;
-}
-#endif
-
 void *qemu_oom_check(void *ptr)
 {
     if (ptr == NULL) {