emulator: introduced 'keyword' variable 01/31201/2
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 2 Dec 2014 12:45:16 +0000 (21:45 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 2 Dec 2014 12:48:00 +0000 (21:48 +0900)
Introduced 'keyword' variable that is provided by emulator itself.
Removed redundant static functions.

Change-Id: Ib007914f1e66d9da4a71aeb8cb0919aea60ff6d3
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/emulator.c
tizen/src/emulator_legacy.c
tizen/src/emulator_options.c
tizen/src/emulator_options.h
tizen/src/util/new_debug_ch.c
tizen/src/util/osutil-darwin.c
tizen/src/util/osutil-linux.c
tizen/src/util/osutil-win32.c

index 0f47b12fd67e3526d90acd0d0f2db2af2d5c4623..98ca01527a882c44915b065202fab7ab1cd37e93 100644 (file)
@@ -47,7 +47,6 @@ static EmulatorConfigState _emul_state;
 
 /* misc */
 char remote_bin_path[PATH_MAX] = { 0, };
-char bin_path[PATH_MAX] = { 0, };
 #ifdef SUPPORT_LEGACY_ARGS
 // for compatibility
 char log_path[PATH_MAX] = { 0, };
@@ -60,6 +59,11 @@ const char *get_remote_bin_path(void)
 
 const char *get_bin_path(void)
 {
+    const char *bin_path = get_variable(KEYWORD_BIN_PATH);
+    // guarantee bin_path is not NULL
+    if (!bin_path) {
+        bin_path = "";
+    }
     return bin_path;
 }
 
index 5c9d599651b9a000d92e83403873872966379fa6..79d9b8b8fd07a2144061c5fe92d252da014d2ff4 100644 (file)
@@ -114,7 +114,6 @@ typedef struct EmulatorConfigState {
 
 /* misc */
 extern char remote_bin_path[];
-extern char bin_path[];
 #ifdef SUPPORT_LEGACY_ARGS
 extern char log_path[];
 #endif
index 70257a5984baf4403b8827f7d453368fc5f38785..735c273c38f86b8c89618ec72cf5d3d5d46722a8 100644 (file)
@@ -103,29 +103,9 @@ static void construct_main_window(int skin_argc, char *skin_argv[],
 }
 #endif
 
-static void get_host_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy)
-{
-    get_host_proxy_os(http_proxy, https_proxy, ftp_proxy, socks_proxy);
-}
-
-static void set_bin_path(char const *const exec_argv)
-{
-    set_bin_path_os(exec_argv);
-}
-
-static void make_vm_lock(void)
-{
-    make_vm_lock_os();
-}
-
-static void remove_vm_lock(void)
-{
-    remove_vm_lock_os();
-}
-
 static void emulator_notify_exit(Notifier *notifier, void *data)
 {
-    remove_vm_lock();
+    remove_vm_lock_os();
 
     int i;
     for (i = 0; i < _qemu_argc; ++i) {
@@ -206,7 +186,7 @@ static void prepare_basic_features(gchar * const kernel_cmdline)
     clean_websocket_port(SIGKILL);
 #endif
 
-    make_vm_lock();
+    make_vm_lock_os();
 
     maru_device_hotplug_init();
 
@@ -214,7 +194,7 @@ static void prepare_basic_features(gchar * const kernel_cmdline)
 
     sdb_setup(get_device_serial_number() + SDB_UDP_SENSOR_INDEX);
 
-    get_host_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
+    get_host_proxy_os(http_proxy, https_proxy, ftp_proxy, socks_proxy);
 
     gchar * const tmp_str = g_strdup_printf(" sdb_port=%d,"
         " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s"
@@ -370,7 +350,7 @@ static int emulator_main(int argc, char *argv[], char **envp)
     _qemu_argc = 0;
     _qemu_argv[_qemu_argc++] = g_strdup(argv[0]);
 
-    set_bin_path(_qemu_argv[0]);
+    set_bin_path_os(_qemu_argv[0]);
 
     if (!load_profile_default(conf, profile)) {
         return -1;
index 3b8194c95f667e31c03eb0498a462dd7778dc1b3..32350df8f99209b80f6c69745bec0308a6d0c8e9 100644 (file)
@@ -82,11 +82,6 @@ extern char **_skin_argv;
 extern int _qemu_argc;
 extern char **_qemu_argv;
 
-static void set_bin_path(gchar * exec_argv)
-{
-    set_bin_path_os(exec_argv);
-}
-
 static void print_system_info(void)
 {
 #define DIV 1024
@@ -167,14 +162,9 @@ static void set_image_and_log_path(char *qemu_argv)
     strcat(log_path, LOGFILE);
 }
 
-static void remove_vm_lock(void)
-{
-    remove_vm_lock_os();
-}
-
 static void emulator_notify_exit(Notifier *notifier, void *data)
 {
-    remove_vm_lock();
+    remove_vm_lock_os();
 
     INFO("Exit emulator...\n");
 }
@@ -290,7 +280,7 @@ int legacy_emulator_main(int argc, char * argv[], char **envp)
 {
     legacy_parse_options(argc, argv, &_skin_argc,
                 &_skin_argv, &_qemu_argc, &_qemu_argv);
-    set_bin_path(_qemu_argv[0]);
+    set_bin_path_os(_qemu_argv[0]);
     extract_qemu_info(_qemu_argc, _qemu_argv);
 
     INFO("Emulator start !!!\n");
index 7a5df2b48a5ceb6b16d529a1604f097ad886e2da..4507eb6c5dea9a65eecd717cf73f5661a5d3376e 100644 (file)
@@ -67,6 +67,7 @@ void set_variable(const char * const arg1, const char * const arg2,
             break;
     }
 
+    // strip quotes
     name = g_strdup(arg1 + i);
     if(!arg2) {
         value = g_strdup("");
@@ -140,7 +141,7 @@ static char *substitute_variables(char *src)
     int end_index = -1;
     char *str;
 
-    // strip ""
+    // strip quotes
     int len = strlen(src);
     if (src[0] == '"' && src[len - 1] == '"') {
         src[len - 1] = '\0';
index ee9a8989068d5b90807f0d173ed4c32797af2e5d..1ac865850b70114e26cb6df12f4afe9ddb8b49f5 100644 (file)
@@ -31,6 +31,8 @@
 
 #include "emulator_common.h"
 
+#define KEYWORD_BIN_PATH    "_BIN_PATH_"
+
 void set_variable(const char * const arg1, const char * const arg2, bool override);
 char *get_variable(const char * const name);
 void reset_variables(void);
index 8537ee314bb099f81d61950b0738f7d5cf329cf5..22d25a994c716761e8533c950693533c620e5378 100644 (file)
@@ -220,18 +220,15 @@ static void debug_init(void)
     char *debug = NULL;
     FILE *fp = NULL;
     char *tmp = NULL;
+    const char *bin_path = get_bin_path();
 
     if (nb_debug_options != -1) {
         return;  /* already initialized */
     }
 
     nb_debug_options = 0;
-    if (0 == strlen(bin_path)) {
-        g_strlcpy(debugchfile, "DEBUGCH", MAX_FILE_LEN);
-    } else {
-        g_strlcat(debugchfile, bin_path, MAX_FILE_LEN);
-        g_strlcat(debugchfile, "DEBUGCH", MAX_FILE_LEN);
-    }
+    g_strlcpy(debugchfile, bin_path, MAX_FILE_LEN);
+    g_strlcat(debugchfile, "DEBUGCH", MAX_FILE_LEN);
 
     fp = fopen(debugchfile, "r");
     if (fp == NULL) {
index 39560a8d5acdcf2d9ccf2c36d0c2a464cbc6dbf1..d8c5ffa8e5f84c0b75b49c5b03ac94c6bdf79f4d 100644 (file)
@@ -127,7 +127,8 @@ void remove_vm_lock_os(void)
 
 void set_bin_path_os(char const *const exec_argv)
 {
-    gchar *file_name = NULL;
+    char *file_name = NULL;
+    char bin_path[PATH_MAX] = { 0, };
 
     if (!exec_argv) {
         return;
@@ -146,8 +147,10 @@ void set_bin_path_os(char const *const exec_argv)
     }
 
     g_strlcpy(bin_path, data, strlen(data) - strlen(file_name) + 1);
-
     g_strlcat(bin_path, "/", PATH_MAX);
+
+    set_variable(KEYWORD_BIN_PATH, bin_path, true);
+
     free(data);
 }
 
index 3c253fed01016b006dbc5d0ad28f3987dde285d7..16f0e6c178f8f847939f3417b703a32ad437d94c 100644 (file)
@@ -38,9 +38,9 @@
 #include "osutil.h"
 #include "emulator.h"
 #include "emul_state.h"
-#include "debug_ch.h"
 #include "maru_err_table.h"
 #include "sdb.h"
+#include "emulator_options.h"
 
 #ifndef CONFIG_LINUX
 #error
@@ -58,6 +58,7 @@
 #include "hw/virtio/maru_virtio_evdi.h"
 #endif
 
+#include "debug_ch.h"
 MULTI_DEBUG_CHANNEL(emulator, osutil);
 
 static int g_shmid;
@@ -163,7 +164,8 @@ void remove_vm_lock_os(void)
 
 void set_bin_path_os(char const *const exec_argv)
 {
-    gchar link_path[PATH_MAX] = { 0, };
+    char link_path[PATH_MAX] = { 0, };
+    char bin_path[PATH_MAX] = { 0, };
     char *file_name = NULL;
 
     ssize_t len = readlink("/proc/self/exe", link_path, sizeof(link_path) - 1);
@@ -180,6 +182,8 @@ void set_bin_path_os(char const *const exec_argv)
 
     g_strlcat(bin_path, "/", PATH_MAX);
 
+    set_variable(KEYWORD_BIN_PATH, bin_path, true);
+
 #ifdef CONFIG_SPICE
     g_strlcpy(remote_bin_path, link_path, strlen(link_path) - strlen(file_name) - 2);
     g_strlcat(remote_bin_path, "remote/bin/", PATH_MAX);
index 96e5cc4b5e422de942979dce71f3f66d287f685d..cbcf18b6dfc907e0eeb31d538fd0ac5353e7f556 100644 (file)
@@ -145,8 +145,9 @@ void remove_vm_lock_os(void)
 
 void set_bin_path_os(char const *const exec_argv)
 {
-    gchar link_path[PATH_MAX] = { 0, };
-    gchar *file_name = NULL;
+    char link_path[PATH_MAX] = { 0, };
+    char bin_path[PATH_MAX] = { 0, };
+    char *file_name = NULL;
 
     if (!GetModuleFileName(NULL, link_path, PATH_MAX)) {
         return;
@@ -154,8 +155,9 @@ void set_bin_path_os(char const *const exec_argv)
 
     file_name = g_strrstr(link_path, "\\");
     g_strlcpy(bin_path, link_path, strlen(link_path) - strlen(file_name) + 1);
-
     g_strlcat(bin_path, "\\", PATH_MAX);
+
+    set_variable(KEYWORD_BIN_PATH, bin_path, true);
 }
 
 int get_number_of_processors(void)