eventcast: fix an infinite loop of notifier routine. 30/29430/1
authorKitae Kim <kt920.kim@samsung.com>
Mon, 27 Oct 2014 05:11:03 +0000 (14:11 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Tue, 28 Oct 2014 01:18:47 +0000 (09:18 +0800)
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 <kt920.kim@samsung.com>
tizen/src/display/maru_sdl.c
tizen/src/ecs/ecs.h
tizen/src/ecs/ecs_eventcast.c
tizen/src/eventcast/common.c
tizen/src/eventcast/encode_fb.c
tizen/src/eventcast/sensor.c
tizen/src/eventcast/touch.c

index ac4ab296dd30b22ec9951824c6fe4d295c0e1fdf..88697b2e0081f85492cb5f5b5cf4cae138099cf9 100644 (file)
@@ -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;
index 51f258265bfd48b634eaf1e9425e6701359e3aa2..ae55d365bb36a8cad52e495242636b603c6113ff 100644 (file)
@@ -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"
index 25aec621300b62bf8e8cc5a041f3de97edb72362..a2792cba9d584e9b6804d3f051436dac0321a795 100644 (file)
@@ -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:
index f938c3011463298df27c6eaff960d00f7f99c63f..f7c15384368f9f0f1cc9fa93fdd6cdb5712de26a 100644 (file)
@@ -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);
index 77d9cefbd1a82b3f4878aeef137bae9de3b316f7..1f5bf5ce78a8346b8e1bb0f93a3124524f96b79b 100644 (file)
@@ -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)
index b69c48caf66db397974680592bf798f560a21b90..952c218d8250856e35351c143d5029bc9d5b8548 100644 (file)
@@ -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;
index 08887d667101fe9515cc5ec0acc0a4450e017a5b..f0be2b430704374fd9942919bde888c846ee0bdb 100644 (file)
@@ -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);