DECLARE_DEBUG_CHANNEL(emul_state);
#define MAXLEN 512
-#define HTTP_PROXY_PREFIX "http_proxy="
-#define HOST_IP_PREFIX "host_ip="
static EmulatorConfigInfo _emul_info;
static EmulatorConfigState _emul_state;
-void set_emul_guest_ip(char *ip)
-{
- strncpy(_emul_info.guest_ip, ip, strlen(ip));
-}
-
-char* get_emul_guest_ip(void)
-{
- LOG_INFO("guest ip: %s\n", _emul_info.guest_ip);
- return _emul_info.guest_ip;
-}
-
-// FIXME: should be cleaned up
-void set_emul_host_ip(char *kernel_cmdline)
-{
- char *buf = strstr(kernel_cmdline, HOST_IP_PREFIX);
-
- if (buf) {
- char buf_host_ip[MAXLEN] = {0,};
- int len = strlen(HOST_IP_PREFIX);
- int i, j;
- int max_len = strlen(buf);
- for(i = len, j = 0; i < max_len; i++) {
- if (buf[i] == ' ' || buf[i] == '\0')
- break;
- buf_host_ip[j++] = buf[i];
- }
-
- buf_host_ip[j] = '\0';
- LOG_INFO("host_ip: %s\n", buf_host_ip);
- strncpy(_emul_info.host_ip, buf_host_ip, sizeof(_emul_info.host_ip));
- }
-}
-
-char* get_emul_host_ip(void)
-{
- return _emul_info.host_ip;
-}
-
int get_max_touch_point(void)
{
if (ts) {
return http_proxy_addr;
}
- const char *kernel_cmdline = qemu_opt_get(qemu_get_machine_opts(), "append");
+ 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);
+ char *buf = g_strstr_len(kernel_cmdline, -1, "http_proxy=");
if (buf) {
char **token = g_strsplit_set(buf, "= ", 3);
if (token[0] && token[1] && g_strcmp0(token[1], "")) {
}
// VM base port
-static int vm_base_port = 0;
-
-void set_vm_base_port(int port)
-{
- vm_base_port = port;
-}
+// only set by net_helper.c when start up
+int vm_base_port = -1;
int get_vm_base_port(void)
{
char *ptr = realpath(sdcard_rel_path, sdcard_abs_path);
if (!ptr) {
- LOG_WARNING("fail to get absolute path!\n");
+ LOG_WARNING("Fail to get absolute path !!!\n");
return sdcard_rel_path;
}
#ifndef CONFIG_WIN32
return sdcard_path;
}
+// guest IP
+static const char *guest_ip = NULL;
+
+void set_guest_ip(const char *ip)
+{
+ if (guest_ip) {
+ LOG_WARNING("Guest IP is aleady set !!!\n");
+
+ return;
+ }
+ guest_ip = g_strdup(ip);
+}
+
+const char* get_guest_ip(void)
+{
+ if (!guest_ip) {
+ LOG_WARNING("Guest IP is NULL !!!\n");
+ }
+
+ return guest_ip;
+}
+
+// host IP
+static const char *host_ip = NULL;
+
+const char* get_host_ip(void)
+{
+ if (host_ip) {
+ return host_ip;
+ }
+
+ // try to get from conf
+ const char *host_ip_var = get_variable("host_ip");
+ if (host_ip_var) {
+ host_ip = g_strdup(host_ip_var);
+ return host_ip;
+ }
+
+ // failsafe for legacy
+ // try to parse from kernel commandline
+ const char *kernel_cmdline =
+ qemu_opt_get(qemu_get_machine_opts(), "append");
+ char *buf = g_strstr_len(kernel_cmdline, -1, "host_ip=");
+
+ char **splitted;
+ if (buf && (splitted = g_strsplit(buf, " ", 2))) {
+ if (splitted[0]) {
+ host_ip = g_strdup(splitted[0]);
+ }
+ g_strfreev(splitted);
+
+ return host_ip;
+ }
+
+ g_assert(host_ip != NULL);
+
+ return NULL;
+}
+
// display resolution
// only set by vl.c when start up
int initial_resolution_width = -1;
g_free((void *)vm_data_path);
vm_data_path = NULL;
+
+ g_free((void *)guest_ip);
+ guest_ip = NULL;
+
+ g_free((void *)host_ip);
+ host_ip = NULL;
}
static Notifier emul_state_exit = { .notify = emul_state_notify_exit };
};
typedef struct EmulatorConfigInfo {
- char guest_ip[16];
- char host_ip[16];
-
const char *skin_path;
const char *file_sharing_path;
/* add here */
} EmulatorConfigState;
/* setter */
-void set_emul_guest_ip(char *ip);
-void set_emul_host_ip(char *ip);
-
void set_emulator_condition(int state);
void set_emul_caps_lock_state(int state);
void set_emul_num_lock_state(int state);
int get_host_lock_key_state_darwin(int key);
int get_emul_caps_lock_state(void);
int get_emul_num_lock_state(void);
-char* get_emul_guest_ip(void);
-char* get_emul_host_ip(void);
bool get_emuld_connection(void);
bool get_sdb_connection(void);
extern const char *bin_path;
extern int initial_resolution_width;
extern int initial_resolution_height;
+extern int vm_base_port;
char const *get_bin_path(void);
char const *get_log_redirect_file(void);
uint64_t get_ram_size(void);
-void set_vm_base_port(int port);
int get_vm_base_port(void);
int get_vm_device_serial_number(void);
int get_vm_spice_port(void);
+void set_guest_ip(const char *ip);
+void set_host_ip(const char *ip);
+const char* get_guest_ip(void);
+const char* get_host_ip(void);
+
void set_initial_display_resolution(int width, int height);
int get_display_resolution_width(void);
int get_display_resolution_height(void);