From 7e33d89040ea1f065643b1b04951e84f36615d13 Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Mon, 27 Oct 2014 14:11:03 +0900 Subject: [PATCH] eventcast: fix an infinite loop of notifier routine. Whenever a client connects to a server, notifier function is registered to notifier_list repeatedly. It makes emulator become infinite loop state when emulator is terminated. Change-Id: Ib7c92c03bb659290df5434c17822db08b2fa60a8 Signed-off-by: Kitae Kim --- tizen/src/display/maru_sdl.c | 2 +- tizen/src/ecs/ecs.h | 2 +- tizen/src/ecs/ecs_eventcast.c | 26 ++++++++--------- tizen/src/eventcast/common.c | 49 +++++++++++++++++++-------------- tizen/src/eventcast/encode_fb.c | 2 +- tizen/src/eventcast/sensor.c | 2 +- tizen/src/eventcast/touch.c | 2 +- 7 files changed, 47 insertions(+), 38 deletions(-) diff --git a/tizen/src/display/maru_sdl.c b/tizen/src/display/maru_sdl.c index ac4ab296dd..88697b2e00 100644 --- a/tizen/src/display/maru_sdl.c +++ b/tizen/src/display/maru_sdl.c @@ -633,7 +633,7 @@ bool maru_extract_framebuffer(void *buffer) maru_do_pixman_dpy_surface(dpy_surface->image); buffer_size = surface_stride(dpy_surface) * surface_height(dpy_surface); - INFO("extract framebuffer %d\n", buffer_size); + TRACE("extract framebuffer %d\n", buffer_size); memcpy(buffer, surface_data(dpy_surface), buffer_size); return true; diff --git a/tizen/src/ecs/ecs.h b/tizen/src/ecs/ecs.h index 51f258265b..ae55d365bb 100644 --- a/tizen/src/ecs/ecs.h +++ b/tizen/src/ecs/ecs.h @@ -57,7 +57,7 @@ #define COMMAND_TYPE_MONITOR "monitor" #define COMMAND_TYPE_DEVICE "device" -#define COMMAND_TYPE_TETHERING "tethering" +#define COMMAND_TYPE_TETHERING "eventcast" #define MSG_TYPE_SENSOR "sensor" #define MSG_TYPE_LOCATION "location" diff --git a/tizen/src/ecs/ecs_eventcast.c b/tizen/src/ecs/ecs_eventcast.c index 25aec62130..a2792cba9d 100644 --- a/tizen/src/ecs/ecs_eventcast.c +++ b/tizen/src/ecs/ecs_eventcast.c @@ -54,7 +54,7 @@ static int eventcast_port = 0; void send_eventcast_sensor_status_ecp(void) { - LOG_INFO(">> send eventcast_event_status to ecp\n"); + LOG_TRACE("send event_status to ecp\n"); send_eventcast_status_ntf(ECS_EVENTCAST_MSG_GROUP_ECP, ECS_EVENTCAST_MSG_ACTION_SENSOR_STATUS); } @@ -67,7 +67,7 @@ void send_eventcast_touch_status_ecp(void) void send_eventcast_connection_status_ecp(void) { - LOG_INFO(">> send eventcast_connection_status to ecp\n"); + LOG_TRACE("send connection_status to ecp\n"); send_eventcast_status_ntf(ECS_EVENTCAST_MSG_GROUP_ECP, ECS_EVENTCAST_MSG_ACTION_CONNECTION_STATUS); } @@ -86,7 +86,7 @@ static void send_eventcast_port_ecp(void) return; } - LOG_TRACE(">> send port_num: %d\n", eventcast_port); + LOG_TRACE("send port_num: %d\n", eventcast_port); g_snprintf(data, sizeof(data) - 1, "%d", eventcast_port); length = strlen(data); @@ -96,7 +96,7 @@ static void send_eventcast_port_ecp(void) memcpy(msg + 13, &action, sizeof(unsigned char)); memcpy(msg + 14, data, length); - LOG_TRACE(">> send eventcast_ntf to ecp. action=%d, group=%d, data=%s\n", + LOG_TRACE("send eventcast_ntf to ecp. action=%d, group=%d, data=%s\n", action, group, data); send_eventcast_ntf((const char *)msg); @@ -121,7 +121,7 @@ static void send_eventcast_connection_info(void) return; } - LOG_INFO(">> send port_num: %d\n", eventcast_port); + LOG_INFO("send eventcast port: %d\n", eventcast_port); { const char *ip = get_eventcast_connected_ipaddr(); int port = get_eventcast_connected_port(); @@ -146,7 +146,7 @@ static void send_eventcast_connection_info(void) memcpy(msg + 13, &action, sizeof(unsigned char)); memcpy(msg + 14, data, length); - LOG_INFO(">> send connection msg to ecp. " + LOG_INFO("send connection msg to ecp. " "action=%d, group=%d, data=%s length=%d\n", action, group, data, length); @@ -192,7 +192,7 @@ static void send_eventcast_status_ntf(type_group group, type_action action) memcpy(msg + 13, &action, sizeof(unsigned char)); memcpy(msg + 14, data, 1); - LOG_TRACE(">> send eventcast_ntf to ecp. action=%d, group=%d, data=%s\n", + LOG_TRACE("send eventcast_ntf to ecp. action=%d, group=%d, data=%s\n", action, group, data); send_eventcast_ntf((const char *)msg); @@ -219,7 +219,7 @@ static bool send_eventcast_ntf(const char *data) const char* ijdata = (data + catsize + 2 + 1 + 1); - LOG_TRACE(">> header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); + LOG_TRACE("header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); ECS__Master master = ECS__MASTER__INIT; ECS__EventCastNtf ntf = ECS__EVENT_CAST_NTF__INIT; @@ -291,7 +291,7 @@ bool msgproc_eventcast_req(ECS_Client* ccli, ECS__EventCastReq* msg) switch(action) { case ECS_EVENTCAST_MSG_ACTION_CONNECT: - LOG_INFO("MSG_ACTION_CONNECT\n"); + LOG_TRACE("MSG_ACTION_CONNECT\n"); if (msg->data.data && msg->data.len > 0) { const gchar *data = (const gchar *)msg->data.data; @@ -320,22 +320,22 @@ bool msgproc_eventcast_req(ECS_Client* ccli, ECS__EventCastReq* msg) connect_eventcast_app(ip_address, port); eventcast_port = port; - LOG_TRACE(">> port_num: %d, %d\n", port, eventcast_port); + LOG_TRACE("port_num: %d, %d\n", port, eventcast_port); g_free(ip_address); g_strfreev(server_addr); } else { - LOG_INFO("ip address and port value are null\n"); + LOG_SEVERE("ip address and port value are null\n"); } break; case ECS_EVENTCAST_MSG_ACTION_DISCONNECT: - LOG_INFO(">> MSG_ACTION_DISCONNECT\n"); + LOG_TRACE("MSG_ACTION_DISCONNECT\n"); disconnect_eventcast_app(); eventcast_port = 0; break; case ECS_EVENTCAST_MSG_ACTION_CONNECTION_STATUS: case ECS_EVENTCAST_MSG_ACTION_SENSOR_STATUS: case ECS_EVENTCAST_MSG_ACTION_TOUCH_STATUS: - LOG_TRACE(">> get_status_action\n"); + LOG_TRACE("get_status_action\n"); send_eventcast_status_ntf(group, action); break; default: diff --git a/tizen/src/eventcast/common.c b/tizen/src/eventcast/common.c index f938c30114..f7c1538436 100644 --- a/tizen/src/eventcast/common.c +++ b/tizen/src/eventcast/common.c @@ -50,7 +50,7 @@ #include "util/new_debug_ch.h" -DECLARE_DEBUG_CHANNEL(app_tethering); +DECLARE_DEBUG_CHANNEL(app_eventcast); #define EVENTCAST_MSG_HANDSHAKE_KEY 100 #define MSG_BUF_SIZE 255 @@ -108,6 +108,8 @@ static void set_eventcast_app_state(bool state); static bool get_eventcast_app_state(void); #endif +static bool is_notifier = false; + // create master message static void *build_eventcast_msg(Eventcast__EventCastMsg* msg, int *payloadsize) { @@ -180,7 +182,7 @@ bool send_msg_to_controller(void *msg) result = select(sockfd + 1, NULL, &writefds, NULL, &timeout); if (result < 0) { - LOG_INFO("not possible to send data\n"); + LOG_SEVERE("not possible to send data\n"); ret = false; break; } @@ -650,6 +652,7 @@ static void end_eventcast_socket(int sockfd) LOG_TRACE("enter: %s\n", __func__); + LOG_INFO("close eventcast socket\n"); if (closesocket(sockfd) < 0) { perror("closesocket failure"); return; @@ -657,7 +660,6 @@ static void end_eventcast_socket(int sockfd) eventcast_client->fd = -1; - LOG_INFO("close eventcast socket\n"); set_eventcast_connection_status(DISCONNECTED); set_eventcast_sensor_status(status); set_eventcast_touch_status(status); @@ -685,7 +687,7 @@ int get_eventcast_connection_status(void) if (!eventcast_client) { LOG_INFO("eventcast_client is null\n"); - LOG_INFO("tetherging connection status: %d\n", status); + LOG_INFO("connection status: %d\n", status); return DISCONNECTED; } @@ -693,31 +695,31 @@ int get_eventcast_connection_status(void) status = eventcast_client->status; qemu_mutex_unlock(&eventcast_client->mutex); - LOG_INFO("tetherging connection status: %d\n", status); + LOG_INFO("connection status: %d\n", status); return status; } int get_eventcast_connected_port(void) { - if (!eventcast_client) { - LOG_SEVERE("eventcast_client is null\n"); - return 0; - } + if (!eventcast_client) { + LOG_SEVERE("eventcast_client is null\n"); + return 0; + } - LOG_TRACE("connected port: %d\n", eventcast_client->port); - return eventcast_client->port; + LOG_TRACE("connected port: %d\n", eventcast_client->port); + return eventcast_client->port; } const char *get_eventcast_connected_ipaddr(void) { - if (!eventcast_client) { - LOG_SEVERE("eventcast client is null\n"); - return NULL; - } + if (!eventcast_client) { + LOG_SEVERE("eventcast client is null\n"); + return NULL; + } - LOG_TRACE("connected ip address: %s\n", eventcast_client->ipaddress); - return eventcast_client->ipaddress; + LOG_TRACE("connected ip address: %s\n", eventcast_client->ipaddress); + return eventcast_client->ipaddress; } static void set_eventcast_connection_status(int status) @@ -787,7 +789,7 @@ int disconnect_eventcast_app(void) { int sock = 0; - LOG_INFO("disconnect app from ecp\n"); + LOG_INFO("disconnect evencast_client from app\n"); if (!eventcast_client) { LOG_SEVERE("eventcast client instance is NULL\n"); return -1; @@ -802,6 +804,9 @@ int disconnect_eventcast_app(void) end_eventcast_socket(sock); } + g_free(eventcast_client); + eventcast_client = NULL; + return 0; } @@ -848,13 +853,17 @@ static void *initialize_eventcast_socket(void *opaque) reset_eventcast_recv_buf(&recv_buf); send_handshake_req_msg(); - emulator_add_exit_notifier(&eventcast_exit); + if (!is_notifier) { + LOG_INFO("add eventcast_exit_notifier\n"); + emulator_add_exit_notifier(&eventcast_exit); + is_notifier = true; + } while (1) { qemu_mutex_lock(&client->mutex); if (client->status == DISCONNECTED) { qemu_mutex_unlock(&client->mutex); - LOG_INFO("disconnected socket. destroy this thread\n"); + LOG_INFO("disconnected socket and destory this thread\n"); break; } qemu_mutex_unlock(&client->mutex); diff --git a/tizen/src/eventcast/encode_fb.c b/tizen/src/eventcast/encode_fb.c index 77d9cefbd1..1f5bf5ce78 100644 --- a/tizen/src/eventcast/encode_fb.c +++ b/tizen/src/eventcast/encode_fb.c @@ -45,7 +45,7 @@ #include "util/new_debug_ch.h" -DECLARE_DEBUG_CHANNEL(app_tethering); +DECLARE_DEBUG_CHANNEL(app_eventcast); #if !defined(CONFIG_SDL) && !defined(CONFIG_USE_SHM) bool maru_extract_framebuffer(void *buffer) diff --git a/tizen/src/eventcast/sensor.c b/tizen/src/eventcast/sensor.c index b69c48caf6..952c218d82 100644 --- a/tizen/src/eventcast/sensor.c +++ b/tizen/src/eventcast/sensor.c @@ -50,7 +50,7 @@ #include "util/new_debug_ch.h" -DECLARE_DEBUG_CHANNEL(app_tethering); +DECLARE_DEBUG_CHANNEL(app_eventcast); typedef struct sensor_state { bool is_sensor_event; diff --git a/tizen/src/eventcast/touch.c b/tizen/src/eventcast/touch.c index 08887d6671..f0be2b4307 100644 --- a/tizen/src/eventcast/touch.c +++ b/tizen/src/eventcast/touch.c @@ -37,7 +37,7 @@ #include "ecs/ecs_eventcast.h" #include "util/new_debug_ch.h" -DECLARE_DEBUG_CHANNEL(app_tethering); +DECLARE_DEBUG_CHANNEL(app_eventcast); static int touch_device_status; static bool send_display_image_data(void); -- 2.34.1