From: SeokYeon Hwang Date: Mon, 16 Jun 2014 04:52:14 +0000 (+0900) Subject: emulator: clean up emulator exit logic X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~228^2^2~142 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0b3a0a1a4b17e5a9d616f6bf80822e689f33e24b;p=sdk%2Femulator%2Fqemu.git emulator: clean up emulator exit logic Some shutdown/exit funtions use "exit_notifier" instead of exit_emulator(). Remove some unnecessary header inclusion. Change-Id: I78617d439f1c133ba8332e6fca8622a6b4289c71 Signed-off-by: SeokYeon Hwang --- diff --git a/tizen/src/ecs/ecs.c b/tizen/src/ecs/ecs.c index 758ae15555..310900a735 100644 --- a/tizen/src/ecs/ecs.c +++ b/tizen/src/ecs/ecs.c @@ -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; } diff --git a/tizen/src/ecs/ecs.h b/tizen/src/ecs/ecs.h index a3297c38e9..6a28958179 100644 --- a/tizen/src/ecs/ecs.h +++ b/tizen/src/ecs/ecs.h @@ -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); diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index d946076760..66919d3227 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -41,14 +41,12 @@ #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 @@ -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[], diff --git a/tizen/src/emulator.h b/tizen/src/emulator.h index 400992c7c3..d3106404f4 100644 --- a/tizen/src/emulator.h +++ b/tizen/src/emulator.h @@ -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__ */ diff --git a/tizen/src/guest_server.c b/tizen/src/guest_server.c index ff004bc38e..6306637efb 100644 --- a/tizen/src/guest_server.c +++ b/tizen/src/guest_server.c @@ -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); } diff --git a/tizen/src/guest_server.h b/tizen/src/guest_server.h index 76efd9cbbe..2f0404d885 100644 --- a/tizen/src/guest_server.h +++ b/tizen/src/guest_server.h @@ -35,7 +35,6 @@ #include void start_guest_server( int server_port ); -void shutdown_guest_server( void ); #define STATE_RUNNING 0 #define STATE_SUSPEND 1 diff --git a/tizen/src/maru_display.c b/tizen/src/maru_display.c index 328330e195..b00f144b1c 100644 --- a/tizen/src/maru_display.c +++ b/tizen/src/maru_display.c @@ -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) diff --git a/tizen/src/maru_display.h b/tizen/src/maru_display.h index a6e496b111..c9c4552912 100644 --- a/tizen/src/maru_display.h +++ b/tizen/src/maru_display.h @@ -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); diff --git a/tizen/src/mloop_event.c b/tizen/src/mloop_event.c index c126982992..a341d2062c 100644 --- a/tizen/src/mloop_event.c +++ b/tizen/src/mloop_event.c @@ -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) diff --git a/tizen/src/mloop_event.h b/tizen/src/mloop_event.h index 1e19b7fbe1..95df1f0cfa 100644 --- a/tizen/src/mloop_event.h +++ b/tizen/src/mloop_event.h @@ -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); diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c index a932c5b028..ebf6ce6cdc 100644 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -29,6 +29,7 @@ #include +#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 diff --git a/tizen/src/skin/maruskin_server.h b/tizen/src/skin/maruskin_server.h index 54a4cf723f..0db67fc05d 100644 --- a/tizen/src/skin/maruskin_server.h +++ b/tizen/src/skin/maruskin_server.h @@ -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); diff --git a/tizen/src/tethering/app_tethering.c b/tizen/src/tethering/app_tethering.c index 2eae4e26a1..bb6d0db75e 100644 --- a/tizen/src/tethering/app_tethering.c +++ b/tizen/src/tethering/app_tethering.c @@ -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; }