emulator: remove exit_emulator() 66/23066/1
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 17 Jun 2014 02:57:32 +0000 (11:57 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 17 Jun 2014 03:00:37 +0000 (12:00 +0900)
Remove exit_emulator() function.
Mark "static" for some global variables.

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

index 6950108..1d08894 100644 (file)
 #ifdef CONFIG_SDL
 #include <SDL.h>
 #endif
-#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
-#include <sys/ipc.h>
-#include <sys/shm.h>
-extern int g_shmid;
-#endif
 
 #ifdef CONFIG_DARWIN
 #include "ns_event.h"
@@ -114,18 +109,6 @@ void emulator_add_exit_notifier(Notifier *notify)
     qemu_add_exit_notifier(notify);
 }
 
-void exit_emulator(void)
-{
-    INFO("exit emulator!\n");
-
-#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
-    if (shmctl(g_shmid, IPC_RMID, 0) == -1) {
-        ERR("shmctl failed\n");
-        perror("emulator.c: ");
-    }
-#endif
-}
-
 static void construct_main_window(int skin_argc, char *skin_argv[],
                                 int qemu_argc, char *qemu_argv[])
 {
@@ -170,6 +153,29 @@ 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();
+
+    int i;
+    for (i = 0; i < _qemu_argc; ++i) {
+        g_free(_qemu_argv[i]);
+    }
+    for (i = 0; i < _skin_argc; ++i) {
+        g_free(_skin_argv[i]);
+    }
+    reset_variables();
+
+    INFO("Exit emulator...\n");
+}
+
+static Notifier emulator_exit = { .notify = emulator_notify_exit };
+
 static void print_system_info(void)
 {
 #define DIV 1024
@@ -206,6 +212,23 @@ static void print_system_info(void)
     print_system_info_os();
 }
 
+static void print_options_info(void)
+{
+    int i;
+
+    fprintf(stdout, "qemu args: =========================================\n");
+    for (i = 0; i < _qemu_argc; ++i) {
+        fprintf(stdout, "%s ", _qemu_argv[i]);
+    }
+    fprintf(stdout, "\n====================================================\n");
+
+    fprintf(stdout, "skin args: =========================================\n");
+    for (i = 0; i < _skin_argc; ++i) {
+        fprintf(stdout, "%s ", _skin_argv[i]);
+    }
+    fprintf(stdout, "\n====================================================\n");
+}
+
 #define PROXY_BUFFER_LEN  128
 #define DEFAULT_QEMU_DNS_IP "10.0.2.3"
 static void prepare_basic_features(gchar * const kernel_cmdline)
@@ -406,44 +429,20 @@ static int emulator_main(int argc, char *argv[], char **envp)
     }
 
 
-    INFO("Emulator start !!!\n");
+    INFO("Start emulator...\n");
     atexit(maru_atexit);
+    emulator_add_exit_notifier(&emulator_exit);
 
     print_system_info();
 
-    INFO("Prepare running...\n");
-    INFO("tizen_target_img_path: %s\n", tizen_target_img_path);
-
-    int i;
-
-    fprintf(stdout, "qemu args: =========================================\n");
-    for (i = 0; i < _qemu_argc; ++i) {
-        fprintf(stdout, "%s ", _qemu_argv[i]);
-    }
-    fprintf(stdout, "\nqemu args: =========================================\n");
+    print_options_info();
 
-    fprintf(stdout, "skin args: =========================================\n");
-    for (i = 0; i < _skin_argc; ++i) {
-        fprintf(stdout, "%s ", _skin_argv[i]);
-    }
-    fprintf(stdout, "\nskin args: =========================================\n");
-
-    INFO("socket initialize\n");
+    INFO("socket initialize...\n");
     socket_init();
 
-    INFO("qemu main start!\n");
+    INFO("qemu main start...\n");
     qemu_main(_qemu_argc, _qemu_argv, envp);
 
-    for (i = 0; i < _qemu_argc; ++i) {
-        g_free(_qemu_argv[i]);
-    }
-    for (i = 0; i < _skin_argc; ++i) {
-        g_free(_skin_argv[i]);
-    }
-    reset_variables();
-
-    exit_emulator();
-
     return 0;
 }
 
index d310640..e9f9db0 100644 (file)
@@ -56,7 +56,6 @@ void start_skin(void);
 const gchar * get_log_path(void);
 int maru_device_check(QemuOpts *opts);
 
-void exit_emulator(void);
 void emulator_add_exit_notifier(Notifier *notify);
 
 #endif /* __EMULATOR_H__ */
index 014e9a1..132d43f 100644 (file)
@@ -173,6 +173,20 @@ 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();
+
+    INFO("Exit emulator...\n");
+}
+
+static Notifier emulator_exit = { .notify = emulator_notify_exit };
+
 static void redir_output(void)
 {
     FILE *fp;
@@ -287,6 +301,7 @@ int legacy_emulator_main(int argc, char * argv[], char **envp)
 
     INFO("Emulator start !!!\n");
     atexit(maru_atexit);
+    emulator_add_exit_notifier(&emulator_exit);
 
     extract_skin_info(_skin_argc, _skin_argv);
 
@@ -317,7 +332,5 @@ int legacy_emulator_main(int argc, char * argv[], char **envp)
     INFO("qemu main start!\n");
     qemu_main(_qemu_argc, _qemu_argv, envp);
 
-    exit_emulator();
-
     return 0;
 }
index 2cb637b..74a4182 100644 (file)
@@ -56,10 +56,10 @@ MULTI_DEBUG_CHANNEL(qemu, osutil);
 static qemu_timeval tv = { 0, 0 };
 static time_t ti;
 static char buf_time[64];
+static int g_shmid;
+static CFDictionaryRef proxySettings;
 
-int g_shmid;
 extern char tizen_target_img_path[];
-CFDictionaryRef proxySettings;
 
 static char *cfstring_to_cstring(CFStringRef str) {
     if (str == NULL) {
@@ -116,7 +116,7 @@ void make_vm_lock_os(void)
 
 }
 
-void make_vm_unlock_os(void)
+void remove_vm_lock_os(void)
 {
     if (shmctl(g_shmid, IPC_RMID, 0) == -1) {
         ERR("shmctl failed\n");
index 395f940..8ebbb89 100644 (file)
@@ -61,10 +61,11 @@ static qemu_timeval tv = { 0, 0 };
 static time_t ti;
 static char buf_time[64];
 
+static int g_shmid;
+static char *g_shared_memory;
+static int gproxytool = GSETTINGS;
+
 extern char tizen_target_img_path[];
-int g_shmid;
-char *g_shared_memory;
-int gproxytool = GSETTINGS;
 
 /* Getting proxy commands */
 static const char* gproxycmds[][2] = {
@@ -150,7 +151,7 @@ void make_vm_lock_os(void)
     }
 }
 
-void make_vm_unlock_os(void)
+void remove_vm_lock_os(void)
 {
     if (shmctl(g_shmid, IPC_RMID, 0) == -1) {
         ERR("shmctl failed\n");
index 5769dc6..81edc39 100644 (file)
@@ -54,8 +54,8 @@ MULTI_DEBUG_CHANNEL (emulator, osutil);
 static qemu_timeval tv = { 0, 0 };
 static time_t ti;
 static char buf_time[64];
-HANDLE g_hMapFile;
-char *g_pBuf;
+static HANDLE g_hMapFile;
+static char *g_pBuf;
 
 extern char tizen_target_img_path[];
 
@@ -132,7 +132,7 @@ void make_vm_lock_os(void)
     free(shared_memory);
 }
 
-void make_vm_unlock_os(void)
+void remove_vm_lock_os(void)
 {
     if (g_pBuf != NULL) {
         UnmapViewOfFile(g_pBuf);
index 12abfda..338d1cb 100644 (file)
@@ -1,9 +1,9 @@
-/* 
+/*
  * Emulator
  *
  * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
  * SeokYeon Hwang <syeon.hwang@samsung.com>
  * MunKyu Im <munkyu.im@samsung.com>
  * GiWoong Kim <giwoong.kim@samsung.com>
 #define GCONFTOOL 0
 #define GSETTINGS 1
 
-extern const char *pac_tempfile; 
+extern const char *pac_tempfile;
 
 void check_vm_lock_os(void);
 void make_vm_lock_os(void);
-void make_vm_unlock_os(void);
+void remove_vm_lock_os(void);
 
 void set_bin_path_os(gchar *);