From: Jinhyung Choi Date: Thu, 10 Oct 2013 03:55:26 +0000 (+0900) Subject: ecs:keep alive checking & device(network & keyboard) msg handling added X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~691 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f8daf47c948121bead79e74680b7f90c0ac994f2;p=sdk%2Femulator%2Fqemu.git ecs:keep alive checking & device(network & keyboard) msg handling added Signed-off-by: Jinhyung Choi --- diff --git a/package/changelog b/package/changelog index 9aded06c08..cb37ba2666 100644 --- a/package/changelog +++ b/package/changelog @@ -1,3 +1,10 @@ +* 1.5.102 +- supports qmp handling for ecs. +- added keep alive checking routine for ecs. +== Jinhyung Choi 2013-10-10 +* 1.5.101 +- fixed sync problem when closing avcodec context. +== Kitae Kim 2013-09-30 * 1.5.97 - YAGL module is excluded from the build on MacOS in temparary. == Jinhyung Jo 2013-09-27 diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest index 1fc2ad904f..5604fc75bb 100644 --- a/package/pkginfo.manifest +++ b/package/pkginfo.manifest @@ -1,4 +1,4 @@ -Version: 1.5.97 +Version: 1.5.102 Maintainer: Yeong-Kyoon Lee Source: emulator diff --git a/tizen/src/ecs/ecs.c b/tizen/src/ecs/ecs.c index be54ddc929..e83bad52cc 100644 --- a/tizen/src/ecs/ecs.c +++ b/tizen/src/ecs/ecs.c @@ -48,6 +48,7 @@ #include "sdb.h" #include "ecs.h" +#include "guest_server.h" #include "genmsg/ecs.pb-c.h" @@ -62,17 +63,50 @@ clients = QTAILQ_HEAD_INITIALIZER(clients); static ECS_State *current_ecs; +static void* keepalive_buf; +static int payloadsize; + static int port; static int port_setting = -1; static pthread_mutex_t mutex_clilist = PTHREAD_MUTEX_INITIALIZER; -static inline void start_logging(void) { - char path[256]; - char* home; +static char* get_emulator_ecs_log_path(void) +{ + gchar *emulator_ecs_log_path = NULL; + gchar *tizen_sdk_data = NULL; +#ifndef CONFIG_WIN32 + char emulator_ecs[] = "/emulator/vms/ecs.log"; +#else + char emulator_ecs[] = "\\emulator\\vms\\ecs.log"; +#endif + + tizen_sdk_data = get_tizen_sdk_data_path(); + if (!tizen_sdk_data) { + LOG("failed to get tizen-sdk-data path.\n"); + return NULL; + } + + emulator_ecs_log_path = + g_malloc(strlen(tizen_sdk_data) + sizeof(emulator_ecs) + 1); + if (!emulator_ecs_log_path) { + LOG("failed to allocate memory.\n"); + return NULL; + } + + g_snprintf(emulator_ecs_log_path, strlen(tizen_sdk_data) + sizeof(emulator_ecs), + "%s%s", tizen_sdk_data, emulator_ecs); - home = getenv(LOG_HOME); - sprintf(path, "%s%s", home, LOG_PATH); + g_free(tizen_sdk_data); + + LOG("ecs log path: %s\n", emulator_ecs_log_path); + return emulator_ecs_log_path; +} + +static inline void start_logging(void) { + char* path = get_emulator_ecs_log_path(); + if (!path) + return; #ifdef _WIN32 FILE* fnul; @@ -94,7 +128,7 @@ static inline void start_logging(void) { int fd = open("/dev/null", O_RDONLY); dup2(fd, 0); - fd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0640); + fd = creat(path, 0640); if (fd < 0) { fd = open("/dev/null", O_WRONLY); } @@ -104,7 +138,7 @@ static inline void start_logging(void) { } int ecs_write(int fd, const uint8_t *buf, int len) { - LOG("write buflen : %d, buf : %s", len, buf); + LOG("write buflen : %d, buf : %s", len, (char*)buf); if (fd < 0) { return -1; } @@ -134,6 +168,7 @@ void ecs_client_close(ECS_Client* clii) { } bool send_to_all_client(const char* data, const int len) { + LOG("data len: %d, data: %s", len, data); pthread_mutex_lock(&mutex_clilist); ECS_Client *clii; @@ -207,6 +242,10 @@ static void ecs_close(ECS_State *cs) { cs->mon = NULL; } + if (keepalive_buf) { + g_free(keepalive_buf); + } + if (NULL != cs->alive_timer) { qemu_del_timer(cs->alive_timer); cs->alive_timer = NULL; @@ -395,6 +434,8 @@ static int ecs_add_client(ECS_State *cs, int fd) { pthread_mutex_unlock(&mutex_clilist); +// send_ecs_version_check(clii); + return 0; } @@ -449,13 +490,42 @@ static void epoll_init(ECS_State *cs) { } #endif +static void send_keep_alive_msg(ECS_Client *clii) { + send_to_client(clii->client_fd, keepalive_buf, payloadsize); +} + +static void make_keep_alive_msg(void) { + int len_pack = 0; + char msg [5] = {'s','e','l','f'}; + + ECS__Master master = ECS__MASTER__INIT; + ECS__KeepAliveReq req = ECS__KEEP_ALIVE_REQ__INIT; + + req.time_str = (char*) g_malloc(5); + + strncpy(req.time_str, msg, 4); + + master.type = ECS__MASTER__TYPE__KEEPALIVE_REQ; + master.keepalive_req = &req; + + len_pack = ecs__master__get_packed_size(&master); + payloadsize = len_pack + 4; + + keepalive_buf = g_malloc(len_pack + 4); + if (!keepalive_buf) { + LOG("keep alive message creation is failed."); + return; + } + + ecs__master__pack(&master, keepalive_buf + 4); + + len_pack = htonl(len_pack); + memcpy(keepalive_buf, &len_pack, 4); +} + static void alive_checker(void *opaque) { - /* - ECS_State *cs = opaque; - ECS_Client *clii; - QObject *obj; - obj = qobject_from_jsonf("{\"type\":\"self\"}"); + ECS_Client *clii; if (NULL != current_ecs && !current_ecs->ecs_running) { return; @@ -465,17 +535,17 @@ static void alive_checker(void *opaque) { { if (1 == clii->keep_alive) { LOG("get client fd %d - keep alive fail", clii->client_fd); - //ecs_client_close(clii); + ecs_client_close(clii); continue; } LOG("set client fd %d - keep alive 1", clii->client_fd); clii->keep_alive = 1; - ecs_json_emitter(clii, obj); + send_keep_alive_msg(clii); } - qemu_mod_timer(cs->alive_timer, + qemu_mod_timer(current_ecs->alive_timer, qemu_get_clock_ns(vm_clock) + get_ticks_per_sec() * TIMER_ALIVE_S); - */ + } static int socket_initialize(ECS_State *cs, QemuOpts *opts) { @@ -502,6 +572,8 @@ static int socket_initialize(ECS_State *cs, QemuOpts *opts) { FD_SET(fd, &cs->reads); #endif + make_keep_alive_msg(); + cs->alive_timer = qemu_new_timer_ns(vm_clock, alive_checker, cs); qemu_mod_timer(cs->alive_timer, @@ -755,6 +827,22 @@ bool handle_protobuf_msg(ECS_Client* cli, char* data, int len) if (!msg) goto fail; msgproc_nfc_req(cli, msg); + } +#if 0 + else if (master->type == ECS__MASTER__TYPE__CHECKVERSION_REQ) + { + ECS__CheckVersionReq* msg = master->checkversion_req; + if (!msg) + goto fail; + msgproc_checkversion_req(cli, msg); + } +#endif + else if (master->type == ECS__MASTER__TYPE__KEEPALIVE_ANS) + { + ECS__KeepAliveAns* msg = master->keepalive_ans; + if (!msg) + goto fail; + msgproc_keepalive_ans(cli, msg); } ecs__master__free_unpacked(master, NULL); diff --git a/tizen/src/ecs/ecs.h b/tizen/src/ecs/ecs.h index fe5634933a..a4c200cfa9 100644 --- a/tizen/src/ecs/ecs.h +++ b/tizen/src/ecs/ecs.h @@ -41,6 +41,8 @@ #include "genmsg/ecs.pb-c.h" #include "genmsg/ecs_ids.pb-c.h" +#define ECS_VERSION "1.0" + #define ECS_DEBUG 1 #ifdef ECS_DEBUG @@ -188,6 +190,11 @@ bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg); bool msgproc_monitor_req(ECS_Client *ccli, ECS__MonitorReq* msg); bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg); bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg); +void msgproc_checkversion_req(ECS_Client* ccli, ECS__CheckVersionReq* msg); +void msgproc_keepalive_ans(ECS_Client* ccli, ECS__KeepAliveAns* msg); + +/* version check */ +//void send_ecs_version_check(ECS_Client* ccli); /* request */ int accel_min_max(double value); diff --git a/tizen/src/ecs/ecs_msg.c b/tizen/src/ecs/ecs_msg.c index f2acac12af..ee128b6703 100644 --- a/tizen/src/ecs/ecs_msg.c +++ b/tizen/src/ecs/ecs_msg.c @@ -32,6 +32,7 @@ #include "hw/qdev.h" #include "net/net.h" +#include "net/slirp.h" #include "ui/console.h" #include "migration/migration.h" #include "qapi/qmp/qint.h" @@ -100,21 +101,24 @@ bool send_to_ecp(ECS__Master* master) } return true; } - - -// message handlers - #if 0 -bool msgproc_start_req(ECS_Client* ccli, ECS__StartReq* msg) +static bool send_to_single_client(ECS__Master* master, ECS_Client *ccli) { - LOG("ecs_startinfo_req"); - - int hostkbd_status = mloop_evcmd_get_hostkbd_status(); - - LOG("hostkbd_status = %d", hostkbd_status); + int payloadsize = 0; + void* buf = build_master(master, &payloadsize); + if (!buf) + { + LOG("invalid buf"); + return false; + } - send_start_ans(hostkbd_status); + if (!send_to_client(ccli->client_fd, buf, payloadsize)) + return false; + if (buf) + { + g_free(buf); + } return true; } #endif @@ -171,22 +175,72 @@ bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg) return true; } #if 0 -bool msgproc_control_msg(ECS_Client *cli, ECS__ControlMsg* msg) +void msgproc_checkversion_req(ECS_Client* ccli, ECS__CheckVersionReq* msg) { - if (msg->type == ECS__CONTROL_MSG__CONTROL_TYPE__HOSTKEYBOARD_REQ) + int datalen = 0; + if (msg->has_data) { - ECS__HostKeyboardReq* hkr = msg->hostkeyboard_req; - if (!hkr) - return false; - msgproc_control_hostkeyboard_req(cli, hkr); + datalen = msg->data.len; + if (msg->data.data && msg->data.len > 0) + { + const char* data = (const char*)msg->data.data; + memcpy(sndbuf + 14, data, datalen); + LOG(">> print len = %zd, data\" %s\"", strlen(data), data); + } } +} - return true; +void send_ecs_version_check(ECS_Client *ccli) +{ + int len_pack = 0; + int payloadsize = 0; + const char* ecs_version = ECS_VERSION; + + ECS__Master master = ECS__MASTER__INIT; + ECS__CheckVersionReq req = ECS__CHECK_VERSION_REQ__INIT; + + req.version_str = (char*) g_malloc(10); + + strncpy(req.version_str, ecs_version, strlen(ecs_version)); + LOG("ecs version: %s", req.version_str); + + master.type = ECS__MASTER__TYPE__CHECKVERSION_REQ; + master.checkversion_req = &req; + + send_to_single_client(master, ccli); } #endif +void msgproc_keepalive_ans (ECS_Client* ccli, ECS__KeepAliveAns* msg) +{ + ccli->keep_alive = 0; +} + +static void send_host_keyboard_ntf (void) +{ + type_length length = (unsigned short)1; + type_group group = GROUP_STATUS; + type_action action = 122; + int is_on = mloop_evcmd_get_hostkbd_status(); + + char* keyboard_msg = (char*) malloc(15); + if(!keyboard_msg) + return; + + memcpy(keyboard_msg, "HKeyboard", 10); + memcpy(keyboard_msg + 10, &length, sizeof(unsigned short)); + memcpy(keyboard_msg + 12, &group, sizeof(unsigned char)); + memcpy(keyboard_msg + 13, &action, sizeof(unsigned char)); + memcpy(keyboard_msg + 14, (is_on?"1":"0"), 1); + + send_device_ntf(keyboard_msg, 15); + + if (keyboard_msg) + free(keyboard_msg); +} bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) { + int is_on = 0; char cmd[10]; char* data = NULL; memset(cmd, 0, 10); @@ -197,7 +251,8 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) if (msg->has_data && msg->data.len > 0) { - data = (char*)msg->data.data; + data = (char*) g_malloc0(msg->data.len + 1); + memcpy(data, msg->data.data, msg->data.len); } LOG(">> header = cmd = %s, length = %d, action=%d, group=%d", cmd, length, @@ -219,12 +274,38 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) } else { set_sensor_data(length, data); } + } else if (!strncmp(cmd, "Network", 7)) { + LOG(">>> Network msg: '%s'", data); + if(net_slirp_redir(data) < 0) { + LOG( "redirect [%s] fail \n", data); + } else { + LOG("redirect [%s] success\n", data); + } + } else if (!strncmp(cmd, "HKeyboard", 8)) { + if (group == MSG_GROUP_STATUS) { + send_host_keyboard_ntf(); + } else { + if (!strncmp(data, "1", 1)) { + is_on = 1; + } + onoff_host_kbd(is_on); + } + } else if (!strncmp(cmd, MSG_TYPE_NFC, 3)) { + if (group == MSG_GROUP_STATUS) { + send_to_nfc(request_nfc_get, data, length); + } + else + { + send_to_nfc(request_nfc_set, data, length); + } } + if (data) + g_free(data); + return true; } - bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg) { char cmd[10]; @@ -244,27 +325,6 @@ bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg) return true; } -#if 0 -bool msgproc_screen_dump_req(ECS_Client *ccli, ECS__ScreenDumpReq* msg) -{ - - return true; -} - - -// begin control command - -void msgproc_control_hostkeyboard_req(ECS_Client *clii, ECS__HostKeyboardReq* req) -{ - int64_t is_on = req->ison; - onoff_host_kbd(is_on); -} -#endif -// end control command - - -// - bool ntf_to_injector(const char* data, const int len) { type_length length = 0; type_group group = 0; @@ -327,27 +387,7 @@ bool ntf_to_injector(const char* data, const int len) { return true; } -#if 0 -bool send_start_ans(int host_keyboard_onff) -{ - ECS__Master master = ECS__MASTER__INIT; - ECS__StartAns ans = ECS__START_ANS__INIT; - - ans.has_host_keyboard_onoff = 1; - ans.host_keyboard_onoff = host_keyboard_onff; - ans.has_camera_onoff = 1; - ans.camera_onoff = 1; - - ans.has_earjack_onoff = 1; - ans.earjack_onoff = 1; - - master.type = ECS__MASTER__TYPE__START_ANS; - master.start_ans = &ans; - - return send_to_ecp(&master); -} -#endif bool send_injector_ntf(const char* data, const int len) { type_length length = 0; @@ -404,27 +444,6 @@ bool send_injector_ntf(const char* data, const int len) return true; } -#if 0 -bool send_hostkeyboard_ntf(int is_on) -{ - ECS__Master master = ECS__MASTER__INIT; - ECS__ControlMsg ctl = ECS__CONTROL_MSG__INIT; - - ECS__HostKeyboardNtf ntf = ECS__HOST_KEYBOARD_NTF__INIT; - - ntf.has_ison = 1; - ntf.ison = is_on; - - ctl.type = ECS__CONTROL_MSG__CONTROL_TYPE__HOSTKEYBOARD_NTF; - ctl.hostkeyboard_ntf = &ntf; - - master.type = ECS__MASTER__TYPE__CONTROL_MSG; - master.control_msg = &ctl; - - return send_to_ecp(&master); -} -#endif - bool send_device_ntf(const char* data, const int len) { type_length length = 0; @@ -440,7 +459,6 @@ bool send_device_ntf(const char* data, const int len) read_val_char(data + catsize + 2, &group); read_val_char(data + catsize + 2 + 1, &action); - const char* ijdata = (data + catsize + 2 + 1 + 1); LOG("<< header cat = %s, length = %d, action=%d, group=%d", cat, length,action, group); diff --git a/tizen/src/ecs/msg/ecs.proto b/tizen/src/ecs/msg/ecs.proto index 974a696524..ad7fa07d53 100644 --- a/tizen/src/ecs/msg/ecs.proto +++ b/tizen/src/ecs/msg/ecs.proto @@ -17,7 +17,6 @@ message CheckVersionAns { message KeepAliveReq { optional string time_str = 1; - } message KeepAliveAns { diff --git a/tizen/src/guest_server.c b/tizen/src/guest_server.c index 98933a4b28..0c44bc46c9 100644 --- a/tizen/src/guest_server.c +++ b/tizen/src/guest_server.c @@ -246,7 +246,7 @@ static gchar *get_old_tizen_sdk_data_path(void) /* * get tizen-sdk-data path from sdk.info. */ -static gchar *get_tizen_sdk_data_path(void) +gchar *get_tizen_sdk_data_path(void) { gchar *emul_bin_path = NULL; gchar *sdk_info_file_path = NULL; diff --git a/tizen/src/guest_server.h b/tizen/src/guest_server.h index aa5afd466b..81d46ded13 100644 --- a/tizen/src/guest_server.h +++ b/tizen/src/guest_server.h @@ -37,6 +37,8 @@ pthread_t start_guest_server( int server_port ); void shutdown_guest_server( void ); +gchar *get_tizen_sdk_data_path(void); + #define STATE_RESUME 0 #define STATE_SUSPEND 1