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;
}
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;
}
const char *file_sharing_path;
const char *vm_ram_size;
int serial_port;
- const char *vm_data_path;
/* add here */
} EmulatorConfigInfo;
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);
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);
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);
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__ */