emulator: clean up emulator exit logic 97/22997/5
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 16 Jun 2014 04:52:14 +0000 (13:52 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 16 Jun 2014 07:27:43 +0000 (16:27 +0900)
Some shutdown/exit funtions use "exit_notifier" instead of exit_emulator().
Remove some unnecessary header inclusion.

Change-Id: I78617d439f1c133ba8332e6fca8622a6b4289c71
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
13 files changed:
tizen/src/ecs/ecs.c
tizen/src/ecs/ecs.h
tizen/src/emulator.c
tizen/src/emulator.h
tizen/src/guest_server.c
tizen/src/guest_server.h
tizen/src/maru_display.c
tizen/src/maru_display.h
tizen/src/mloop_event.c
tizen/src/mloop_event.h
tizen/src/skin/maruskin_server.c
tizen/src/skin/maruskin_server.h
tizen/src/tethering/app_tethering.c

index 758ae1555595fe91c531b27e9f072ee4a32b9673..310900a735ee6273a70dfde797fd9fb9337dc4ca 100644 (file)
@@ -46,6 +46,7 @@
 #include "config.h"
 #include "qapi/qmp/qint.h"
 
+#include "emulator.h"
 #include "sdb.h"
 #include "ecs.h"
 #include "guest_server.h"
@@ -722,7 +723,7 @@ static void* ecs_initialize(void* args) {
     return NULL;
 }
 
-int stop_ecs(void) {
+static int stop_ecs(void) {
     INFO("ecs is closing.\n");
     if (NULL != current_ecs) {
         current_ecs->ecs_running = 0;
@@ -734,6 +735,11 @@ int stop_ecs(void) {
     return 0;
 }
 
+static void ecs_notify_exit(Notifier *notifier, void *data) {
+    stop_ecs();
+}
+static Notifier ecs_exit = { .notify = ecs_notify_exit };
+
 int start_ecs(void) {
     pthread_t thread_id;
 
@@ -741,6 +747,9 @@ int start_ecs(void) {
         ERR("pthread creation failed.\n");
         return -1;
     }
+
+    emulator_add_exit_notifier(&ecs_exit);
+
     return 0;
 }
 
index a3297c38e94ad6853cde7aeb427d4b9f47c56172..6a28958179925c85e8ebbcaa6f6f9b9840a8dd6c 100644 (file)
@@ -165,7 +165,6 @@ typedef struct nfc_msg_info {
 }nfc_msg_info;
 
 int start_ecs(void);
-int stop_ecs(void);
 
 ECS_Client *find_client(unsigned char id, unsigned char type);
 bool handle_protobuf_msg(ECS_Client* cli, char* data, const int len);
index d9460767607db34d93549ad8ccad380e1a200ee7..66919d3227b1c7a0b83b7c09f60b6d134ff3ba0e 100644 (file)
 #include "emulator_options.h"
 #include "check_gl.h"
 #include "maru_err_table.h"
-#include "maru_display.h"
 #include "mloop_event.h"
 #include "osutil.h"
 #include "sdb.h"
 #include "skin/maruskin_server.h"
 #include "debug_ch.h"
 #include "ecs/ecs.h"
-#include "tethering/app_tethering.h"
 
 #ifdef CONFIG_SDL
 #include <SDL.h>
@@ -107,24 +105,21 @@ const char *get_log_path(void)
     return log_path;
 }
 
+void emulator_add_exit_notifier(Notifier *notify)
+{
+    qemu_add_exit_notifier(notify);
+}
+
 void exit_emulator(void)
 {
     INFO("exit emulator!\n");
 
-    mloop_ev_stop();
-    shutdown_skin_server();
-    shutdown_guest_server();
-    stop_ecs();
-    disconnect_tethering_app();
-
 #if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
     if (shmctl(g_shmid, IPC_RMID, 0) == -1) {
         ERR("shmctl failed\n");
         perror("emulator.c: ");
     }
 #endif
-
-    maru_display_fini();
 }
 
 static void construct_main_window(int skin_argc, char *skin_argv[],
index 400992c7c3a664668a05ee9cdbca038a105c74e4..d3106404f48618aa958cde529d41514ed1f70d2a 100644 (file)
@@ -40,6 +40,7 @@
 #include "maru_common.h"
 #include "qapi/qmp/qlist.h"
 #include "qemu/option.h"
+#include "sysemu/sysemu.h"
 
 #define MAXLEN  512
 #define MAXPACKETLEN 60
@@ -48,7 +49,6 @@
 extern gchar bin_path[];
 extern gchar log_path[];
 
-void exit_emulator(void);
 char *get_bin_path(void);
 const gchar * prepare_maru(const gchar * const kernel_cmdline);
 void start_skin(void);
@@ -56,4 +56,7 @@ 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 ff004bc38e5e448033ef4985ff39b42c4b566c49..6306637efb2e47a81fe46f94ba6f99de15f2d0bb 100644 (file)
@@ -611,17 +611,24 @@ static void* run_guest_server(void* args)
     return NULL;
 }
 
+static void shutdown_guest_server(void)
+{
+    INFO("shutdown_guest_server.\n");
+
+    close_server();
+}
+
+static void guest_server_notify_exit(Notifier *notifier, void *data) {
+    shutdown_guest_server();
+}
+static Notifier guest_server_exit = { .notify = guest_server_notify_exit };
+
 void start_guest_server(int server_port)
 {
     QemuThread thread_id;
     svr_port = server_port;
     qemu_thread_create(&thread_id, "guest_server", run_guest_server, NULL, QEMU_THREAD_DETACHED);
     INFO("created guest server thread\n");
-}
-
-void shutdown_guest_server(void)
-{
-    INFO("shutdown_guest_server.\n");
 
-    close_server();
+    emulator_add_exit_notifier(&guest_server_exit);
 }
index 76efd9cbbe19987cee1cd4c265f257688ebcf085..2f0404d885662b131dff3a021f8e7dbbd032279b 100644 (file)
@@ -35,7 +35,6 @@
 #include <pthread.h>
 
 void start_guest_server( int server_port );
-void shutdown_guest_server( void );
 
 #define STATE_RUNNING 0
 #define STATE_SUSPEND 1
index 328330e1952e307f85bda5a043bfa6c0b0d1fd40..b00f144b1ca9cb295085d9a15b4ad907612dedb3 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 
+#include "emulator.h"
 #include "maru_common.h"
 #include "maru_display.h"
 #include "debug_ch.h"
@@ -42,6 +43,24 @@ MULTI_DEBUG_CHANNEL(tizen, display);
 
 MaruScreenShot* screenshot = NULL;
 
+static void maru_display_fini(void)
+{
+    INFO("fini qemu display\n");
+
+    g_free(screenshot);
+
+#ifndef CONFIG_USE_SHM
+    maru_sdl_quit();
+#else
+    maru_shm_quit();
+#endif
+}
+
+static void maru_display_notify_exit(Notifier *notifier, void *data) {
+    maru_display_fini();
+}
+static Notifier maru_display_exit = { .notify = maru_display_notify_exit };
+
 //TODO: interface
 void maru_display_init(DisplayState *ds)
 {
@@ -64,19 +83,8 @@ void maru_display_init(DisplayState *ds)
     screenshot->pixels = NULL;
     screenshot->request = false;
     screenshot->ready = false;
-}
-
-void maru_display_fini(void)
-{
-    INFO("fini qemu display\n");
-
-    g_free(screenshot);
 
-#ifndef CONFIG_USE_SHM
-    maru_sdl_quit();
-#else
-    maru_shm_quit();
-#endif
+    emulator_add_exit_notifier(&maru_display_exit);
 }
 
 void maru_display_resize(void)
index a6e496b1111ab4b00bd4ef29c32abc9e6df0c515..c9c4552912d3e15027b6d6a9c3ab403fa2fc7225 100644 (file)
@@ -40,7 +40,6 @@ typedef struct MaruScreenShot {
 } MaruScreenShot;
 
 void maru_display_init(DisplayState *ds);
-void maru_display_fini(void);
 void maru_display_resize(void);
 void maru_display_update(void);
 void maru_display_invalidate(bool on);
index c126982992a0d4c8bc200f62cb88da34b4dd2b5e..a341d2062c5dfaf52a54ffb8575c1f91cd0a8b62 100644 (file)
@@ -529,18 +529,25 @@ static void mloop_evcb_recv(struct mloop_evsock *ev)
     }
 }
 
+static void mloop_ev_stop(void)
+{
+    qemu_set_fd_handler(mloop.sockno, NULL, NULL, NULL);
+    mloop_evsock_remove(&mloop);
+}
+
+static void mloop_ev_notify_exit(Notifier *notifier, void *data) {
+    mloop_ev_stop();
+}
+static Notifier mloop_ev_exit = { .notify = mloop_ev_notify_exit };
+
 void mloop_ev_init(void)
 {
     int ret = mloop_evsock_create(&mloop);
     if (ret == 0) {
         qemu_set_fd_handler(mloop.sockno, (IOHandler *)mloop_evcb_recv, NULL, &mloop);
     }
-}
 
-void mloop_ev_stop(void)
-{
-    qemu_set_fd_handler(mloop.sockno, NULL, NULL, NULL);
-    mloop_evsock_remove(&mloop);
+    emulator_add_exit_notifier(&mloop_ev_exit);
 }
 
 void mloop_evcmd_raise_intr(void *irq)
index 1e19b7fbe18d0807280bd687fbac4dcce6d550b9..95df1f0cfaeae8a287a7c0fdb99de21b47acbfba 100644 (file)
@@ -35,7 +35,6 @@ extern "C" {
 #endif
 
 void mloop_ev_init(void);
-void mloop_ev_stop(void);
 
 void mloop_evcmd_usbkbd(int on);
 void mloop_evcmd_usbdisk(char *img);
index a932c5b028bc64bd99aa1278ac78071e1b2aa6a4..ebf6ce6cdca4b8ccbd197b164484492033adc45f 100644 (file)
@@ -29,6 +29,7 @@
 
 
 #include <pthread.h>
+#include "emulator.h"
 #include "maru_common.h"
 #include "maruskin_server.h"
 #include "maruskin_operation.h"
@@ -173,35 +174,7 @@ static void* do_heart_beat(void* args);
 static int start_heart_beat(void);
 static void stop_heart_beat(void);
 
-
-int start_skin_server(int argc, char** argv,
-    int qemu_argc, char** qemu_argv)
-{
-    skin_argc = argc;
-    skin_argv = argv;
-
-    parse_skinconfig_prop();
-
-    /* arguments have higher priority than '.skinconfig.properties' */
-    parse_skin_args();
-
-    INFO("ignore_heartbeat : %d\n", ignore_heartbeat);
-
-    qmu_argc = qemu_argc;
-    qmu_argv = qemu_argv;
-
-    qemu_mutex_init(&mutex_send_data);
-    qemu_mutex_init(&mutex_recv_heartbeat_count);
-    qemu_mutex_init(&mutex_draw_display);
-
-    QemuThread qemu_thread;
-    qemu_thread_create(&qemu_thread, "skin-server", run_skin_server,
-        NULL, QEMU_THREAD_DETACHED);
-
-    return 1;
-}
-
-void shutdown_skin_server(void)
+static void shutdown_skin_server(void)
 {
     INFO("shutdown_skin_server\n");
 
@@ -267,6 +240,37 @@ void shutdown_skin_server(void)
     qemu_mutex_destroy(&mutex_draw_display);
 }
 
+static void skin_server_notify_exit(Notifier *notifier, void *data) {
+    shutdown_skin_server();
+}
+static Notifier skin_server_exit = { .notify = skin_server_notify_exit };
+
+int start_skin_server(int argc, char** argv,
+    int qemu_argc, char** qemu_argv)
+{
+    skin_argc = argc;
+    skin_argv = argv;
+
+    parse_skinconfig_prop();
+
+    /* arguments have higher priority than '.skinconfig.properties' */
+    parse_skin_args();
+
+    INFO("ignore_heartbeat : %d\n", ignore_heartbeat);
+
+    qmu_argc = qemu_argc;
+    qmu_argv = qemu_argv;
+
+    QemuThread qemu_thread;
+
+    qemu_thread_create(&qemu_thread, "skin-server", run_skin_server,
+        NULL, QEMU_THREAD_DETACHED);
+
+    emulator_add_exit_notifier(&skin_server_exit);
+
+    return 1;
+}
+
 void notify_draw_frame(void)
 {
 #if 0
index 54a4cf723fe71efba73f491b45699b230f32f062..0db67fc05d9c02bd982bf5e3f042497d13b43539 100644 (file)
@@ -31,7 +31,6 @@
 #define MARUSKIN_SERVER_H_
 
 int start_skin_server(int argc, char** argv, int qemu_argc, char** qemu_argv);
-void shutdown_skin_server(void);
 
 void notify_draw_frame(void);
 void notify_draw_blank_guide(void);
index 2eae4e26a1f1c82a04973b711ad6537140411b83..bb6d0db75e57d22a6de59981039673f794a330d7 100644 (file)
@@ -38,6 +38,7 @@
 #include "qemu/sockets.h"
 #include "ui/console.h"
 
+#include "emulator.h"
 #include "emul_state.h"
 #include "app_tethering.h"
 #include "../ecs/ecs_tethering.h"
@@ -994,6 +995,33 @@ static void set_tethering_multitouch_status(int status)
     send_tethering_touch_status_ecp();
 }
 
+int disconnect_tethering_app(void)
+{
+    int sock = 0;
+
+    INFO("disconnect app from ecp\n");
+
+    sock = tethering_sock;
+    if (sock < 0) {
+        ERR("tethering socket is terminated or not ready\n");
+    } else {
+        destroy_tethering_io_handler(sock);
+#if 0
+        if (get_tethering_app_state()) {
+            send_emul_state_msg();
+        }
+#endif
+        end_tethering_socket(sock);
+    }
+
+    return 0;
+}
+
+static void tethering_notify_exit(Notifier *notifier, void *data) {
+    disconnect_tethering_app();
+}
+static Notifier tethering_exit = { .notify = tethering_notify_exit };
+
 int connect_tethering_app(const char *ipaddress, int port)
 {
     int sock = 0, ret = 0;
@@ -1014,27 +1042,7 @@ int connect_tethering_app(const char *ipaddress, int port)
     ret = register_tethering_io_handler(sock);
     send_handshake_req_msg();
 
-    return ret;
-}
-
-int disconnect_tethering_app(void)
-{
-    int sock = 0;
+    emulator_add_exit_notifier(&tethering_exit);
 
-    INFO("disconnect app from ecp\n");
-
-    sock = tethering_sock;
-    if (sock < 0) {
-        ERR("tethering socket is terminated or not ready\n");
-    } else {
-        destroy_tethering_io_handler(sock);
-#if 0
-        if (get_tethering_app_state()) {
-            send_emul_state_msg();
-        }
-#endif
-        end_tethering_socket(sock);
-    }
-
-    return 0;
+    return ret;
 }