emul_state: rewrite and cleaned-up some functions
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 10 Jul 2015 08:48:53 +0000 (17:48 +0900)
committerSangho Park <sangho.p@samsung.com>
Mon, 13 Jul 2015 11:29:23 +0000 (20:29 +0900)
Change-Id: I4ad76ecd44adb20ba2ebf6d5f4deabe875fbfa08
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/display/qt5_supplement.cpp
tizen/src/ecs/ecs_msg_device.c
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/emulator.c
tizen/src/emulator_legacy.c

index 3db48b8ddafc365a3a7f072344ff475bc00816fd..824a1da7fab72ff7a317c48d1c4de932f4460f3f 100644 (file)
@@ -93,14 +93,14 @@ void qt5_gui_init(void)
     /* parameter parsing */
     // TODO:
 
-    uiInfo->vmName = QString(get_emul_vm_name()).trimmed();
+    uiInfo->vmName = QString(get_vm_name()).trimmed();
     qDebug() << "VM name :" <<  uiInfo->vmName;
 
     uiInfo->resolution.setWidth(get_emul_resolution_width());
     uiInfo->resolution.setHeight(get_emul_resolution_height());
     uiInfo->basePort = get_emul_vm_base_port();
 
-    uiInfo->vmDataPath = QDir(get_emul_vm_data_path()).canonicalPath();
+    uiInfo->vmDataPath = QDir(get_vm_data_path()).canonicalPath();
     if (uiInfo->vmDataPath.endsWith(QDir::separator()) == false) {
         uiInfo->vmDataPath += QDir::separator();
     }
index 1fda07564342ae6d5c1d03a15e9a4a8c959c7050..12dd48482a834f009edd69dc47dc226d277c8f22 100644 (file)
@@ -412,7 +412,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
     } else if (!strcmp(cmd, "input")) {
         msgproc_device_req_input(ccli, msg, cmd);
     } else if (!strcmp(cmd, "vmname")) {
-        const char* vmname = get_emul_vm_name();
+        const char* vmname = get_vm_name();
         msgproc_device_ans(ccli, cmd, true, vmname);
     } else if (!strcmp(cmd, "nfc")) {
         msgproc_device_req_nfc(ccli, msg);
index b5c405f5274b212e4ff30dbf707a1ebc7cd62f50..434219b252f2e0904a06649a68c7aa1a594565e1 100644 (file)
@@ -413,83 +413,10 @@ int get_emul_num_lock_state(void)
     return _emul_state.qemu_num_lock;
 }
 
-/* drive image file */
-const char* get_drive_image_file(void)
-{
-    char *drive_image_file = get_variable("drive_image_file");
-
-    if (drive_image_file) {
-        return drive_image_file;
-    }
-
-    // we should parse from "drive" parameter.
-    // so qemu_main() had to be called before.
-    BlockBackend *bb = blk_by_name("drive");
-    if (bb) {
-        BlockDriverState *bs = blk_bs(bb);
-        set_variable("drive_image_file", bs->filename, false);
-
-        return bs->filename;
-    }
-
-    // called before device initialized
-    // or very weired situation
-    LOG_SEVERE("Can not identify main drive image file !!!\n");
-
-    return "";
-}
-
-/* vm name */
-const char* get_emul_vm_name(void)
-{
-    const char *vm_name = get_variable("vm_name");
-
-    // if there is no "vm_name" we make it from drive image name.
-    if (!vm_name) {
-        char *drive_file = g_strdup(get_drive_image_file());
-        set_variable("vm_name", basename(drive_file), true);
-        g_free(drive_file);
-
-        vm_name = get_variable("vm_name");
-    }
-
-    return vm_name;
-}
-
-/* http proxy */
-const char* get_http_proxy_addr(void)
-{
-    const char *http_proxy_addr = get_variable("http_proxy_addr");
-    if (http_proxy_addr) {
-        return http_proxy_addr;
-    }
-
-    const char *kernel_cmdline = qemu_opt_get(qemu_get_machine_opts(), "append");
-
-    // kernel cmdline always contains proxy information
-    char *buf = g_strstr_len(kernel_cmdline, -1, HTTP_PROXY_PREFIX);
-    if (buf) {
-        char **token = g_strsplit_set(buf, "= ", 3);
-        if (token[0] && token[1] && g_strcmp0(token[1], "")) {
-            LOG_INFO("HTTP proxy address : %s\n", token[1]);
-            set_variable("http_proxy_addr", token[1], false);
-            g_strfreev(token);
-
-            http_proxy_addr = get_variable("http_proxy_addr");
-
-            return http_proxy_addr;
-        }
-        g_strfreev(token);
-    }
-
-    LOG_INFO("HTTP proxy address is not set.\n");
-
-    return NULL;
-}
 
 void set_emul_profile(const char *profile)
 {
-    LOG_INFO("EMULATOR_PROFILE: %s\n", profile);
+    LOG_INFO("emulator_profile: %s\n", profile);
     strncpy(_emul_state.emulator_profile, profile, sizeof(_emul_state.emulator_profile));
     _emul_state.emulator_profile[sizeof(_emul_state.emulator_profile) -1] = 0;
 }
@@ -574,21 +501,154 @@ const char* get_emul_file_sharing_path(void)
     return _emul_info.file_sharing_path;
 }
 
-/* VM data path */
-void set_emul_vm_data_path(const char *path)
+//
+// cleaned-up
+//
+
+// launch_conf_path
+const char *launch_conf_file = NULL;
+
+// drive image file
+static const char *drive_image_file = NULL;
+
+const char* get_drive_image_file(void)
+{
+    if (drive_image_file) {
+        return drive_image_file;
+    }
+
+    // we should parse from "drive" parameter.
+    // so qemu_main() had to be called before.
+    BlockBackend *bb = blk_by_name("drive");
+    if (bb) {
+        BlockDriverState *bs = blk_bs(bb);
+        drive_image_file = g_strdup(bs->filename);
+
+        return drive_image_file;
+    }
+
+    // called before device initialized
+    // or very weired situation
+    LOG_WARNING("Can not identify main drive image file !!!\n");
+
+    return "";
+}
+
+
+// http proxy
+static const char *http_proxy_addr = NULL;
+
+const char* get_http_proxy_addr(void)
 {
-    _emul_info.vm_data_path = path;
+    if (http_proxy_addr) {
+        return http_proxy_addr;
+    }
+
+    const char *kernel_cmdline = qemu_opt_get(qemu_get_machine_opts(), "append");
+
+    // kernel cmdline always contains proxy information
+    char *buf = g_strstr_len(kernel_cmdline, -1, HTTP_PROXY_PREFIX);
+    if (buf) {
+        char **token = g_strsplit_set(buf, "= ", 3);
+        if (token[0] && token[1] && g_strcmp0(token[1], "")) {
+            http_proxy_addr = g_strdup(token[1]);
+            g_strfreev(token);
+
+            LOG_INFO("HTTP proxy address: %s\n", http_proxy_addr);
+
+            return http_proxy_addr;
+        }
+        g_strfreev(token);
+    }
+
+    http_proxy_addr = "";
+
+    LOG_INFO("HTTP proxy address is not set.\n");
+
+    return http_proxy_addr;
 }
 
-const char* get_emul_vm_data_path(void)
+// vm_name
+static const char *vm_name = NULL;
+
+const char *get_vm_name(void)
 {
-    if (_emul_info.vm_data_path) {
-        return _emul_info.vm_data_path;
+    if (vm_name) {
+        return vm_name;
     }
 
-    // FIXME: we should support commandline users
-    _emul_info.vm_data_path = g_strdup_printf("%s/%s",
-            get_variable("vms_path"), get_emul_vm_name());
+    // check variable
+    const char *var_vm_name = get_variable("vm_name");
+
+    // check drive image name
+    char *drive_file_vm_name = g_path_get_basename(get_drive_image_file());
+
+    // remove file extension
+    char *last_dot = g_strrstr(drive_file_vm_name, ".");
+    if (last_dot) {
+        *last_dot = '\0';
+    }
+
+    // if it has "emulimg-" prefix - it may be made by emulator-manager
+    // we should remove it
+    int start_index = 0;
+    if (!strncmp("emulimg-", drive_file_vm_name, 8)) {
+        start_index = 8;
+    }
+
+    if (g_strcmp0(var_vm_name, drive_file_vm_name + start_index)) {
+        // when drive_file_vm_name != var_vm_name
+        // we should warn to users
+        LOG_WARNING("vm_name and image_file_name is not matched\n");
+    } else {
+        // we choose drive_file_vm_name when var_vm_name is not provided
+        // or they contain same name
+    }
+
+    vm_name = g_strdup(drive_file_vm_name + start_index);
+
+    g_free(drive_file_vm_name);
+
+    LOG_INFO("VM name: %s\n", vm_name);
+
+    return vm_name;
+}
+
+// vm_data_path
+static const char *vm_data_path = NULL;
+
+#ifdef SUPPORT_LEGACY_ARGS
+void set_vm_data_path(const char *path)
+{
+    vm_data_path = path;
+
+    LOG_INFO("VM data path: %s\n", vm_data_path);
+}
+#endif
+
+const char* get_vm_data_path(void)
+{
+    if (vm_data_path) {
+        return vm_data_path;
+    }
+
+    // check drive image file path
+    char *drive_image_path = g_path_get_dirname(get_drive_image_file());
+
+    // check launch conf file path
+    char *conf_file_path = g_path_get_dirname(launch_conf_file);
+
+    if (g_strcmp0(drive_image_path, conf_file_path)) {
+        // when drive_image_path != launch_conf_path
+        // we should warn to users
+        LOG_WARNING("drive_image_path and launch_conf_path is not matched\n");
+    }
+
+    vm_data_path = drive_image_path;
+
+    g_free(conf_file_path);
+
+    LOG_INFO("VM data path: %s\n", vm_data_path);
 
-    return _emul_info.vm_data_path;
+    return vm_data_path;
 }
index 5b8090d010cec5eca08f05888093cc68b05081e8..7727f26f261f9f549e700b69b9a70b17e0249fc1 100644 (file)
@@ -108,7 +108,6 @@ typedef  struct EmulatorConfigInfo {
     const char *file_sharing_path;
     const char *vm_ram_size;
     int serial_port;
-    const char *vm_data_path;
     /* add here */
 } EmulatorConfigInfo;
 
@@ -148,15 +147,12 @@ void set_emul_host_ip(char *ip);
 void set_emul_gpu_accel(bool enable);
 void set_emul_file_sharing_path(const char *path);
 void set_emul_ram_size(const char *size);
-void set_emul_vm_data_path(const char *path);
 
 void set_emulator_condition(int state);
 void set_emul_rotation(short rotation_type);
 void set_emul_caps_lock_state(int state);
 void set_emul_num_lock_state(int state);
 void set_emul_tap_enable(bool enable);
-void set_emul_http_proxy_addr(char *addr);
-void set_emul_http_proxy_port(char *port);
 void set_emul_profile(const char *profile);
 void set_emuld_connection(bool connected);
 void set_sdb_connection(bool connected);
@@ -173,14 +169,12 @@ int get_emul_vm_base_port(void);
 int get_device_serial_number(void);
 int get_emul_ecs_port(void);
 int get_emul_serial_port(void);
-const char* get_emul_vm_name(void);
 int get_emul_spice_port(void);
 const char* get_emul_skin_path(void);
 bool get_emul_gpu_accel(void);
 bool get_emul_cpu_accel(void);
 const char* get_emul_file_sharing_path(void);
 const char* get_emul_ram_size(void);
-const char* get_emul_vm_data_path(void);
 
 int get_emulator_condition(void);
 short get_emul_rotation(void);
@@ -195,8 +189,6 @@ char* get_emul_profile(void);
 
 bool get_emuld_connection(void);
 bool get_sdb_connection(void);
-const char* get_drive_image_file(void);
-const char* get_http_proxy_addr(void);
 bool is_netclient_tap_attached(void);
 int get_max_touch_point(void);
 
@@ -205,4 +197,15 @@ MultiTouchState *get_emul_multi_touch_state(void);
 void set_multi_touch_enable(int mode);
 int get_multi_touch_enable(void);
 
+// cleaned-up
+extern const char* launch_conf_file;
+
+const char* get_drive_image_file(void);
+const char* get_http_proxy_addr(void);
+const char* get_vm_name(void);
+#ifdef SUPPORT_LEGACY_ARGS
+void set_vm_data_path(const char *path);
+#endif
+const char* get_vm_data_path(void);
+
 #endif /* __EMUL_STATE_H__ */
index 5b572d28ccde8d445eb7b4539a37c6f15f3a8445..97902f1e5f32ac78d59e77bff40421ca8a83f9bb 100644 (file)
@@ -208,6 +208,10 @@ void prepare_maru_after_device_init(void)
     start_ecs();
     start_sdb_noti_server(get_emul_vm_base_port() + SDB_UDP_SENSOR_INDEX);
     sdb_setup();
+
+    // only for intent logging of essential information
+    get_vm_name();
+    get_vm_data_path();
 }
 
 #if defined(CONFIG_SDL) || defined(CONFIG_USE_SHM)
@@ -231,8 +235,6 @@ static int emulator_main(int argc, char *argv[], char **envp)
     }
 #endif
 
-    gchar *conf = NULL;
-
     int c = 0;
 
     _qemu_argv = g_malloc(sizeof(char*) * ARGS_LIMIT);
@@ -258,15 +260,14 @@ static int emulator_main(int argc, char *argv[], char **envp)
             set_variable(argv[optind - 1], argv[optind], true);
             break;
         case 'c':
-            set_variable("conf", optarg, true);
-            conf = g_strdup(optarg);
+            launch_conf_file = g_strdup(optarg);
             break;
         default:
             break;
         }
     }
 
-    if (!conf) {
+    if (!launch_conf_file) {
         fprintf(stderr, "Usage: %s {-c|--conf} conf_file ...\n",
                         basename(argv[0]));
 
@@ -279,7 +280,7 @@ static int emulator_main(int argc, char *argv[], char **envp)
 
     set_bin_path_os(_qemu_argv[0]);
 
-    if (!load_conf(conf)) {
+    if (!load_conf(launch_conf_file)) {
         return -1;
     }
 
index dc8c46e87a33d6b414047ab6aea7c1306afa0a6a..cc1cbf329ab751476b2d07511685848155ca5549 100644 (file)
@@ -143,7 +143,7 @@ static void set_image_and_log_path(char *qemu_argv)
         strcpy(tizen_target_path, g_path_get_dirname(path));
     }
 
-    set_emul_vm_data_path(tizen_target_path);
+    set_vm_data_path(tizen_target_path);
     set_variable("vm_name", g_path_get_basename(tizen_target_path), true);
     set_variable("drive_image_file", path, true);
     free(path);