Replace Ecore_Fd_handler with GIOChannel in remote input. 77/111877/3
authorInHong Han <inhong1.han@samsung.com>
Tue, 24 Jan 2017 11:38:59 +0000 (20:38 +0900)
committerInHong Han <inhong1.han@samsung.com>
Wed, 25 Jan 2017 01:25:36 +0000 (10:25 +0900)
Use GIOChannel to support g_main_loop instead of ecore_main_loop from remote input
Change-Id: I31ff0653038c2be37d1b1ae54d6281710c1f64aa

ism/src/Makefile.am
ism/src/isf_remote_control.cpp

index 1dc0d55..93494de 100644 (file)
@@ -170,7 +170,8 @@ libscim@SCIM_EPOCH@_la_CXXFLAGS = @EVAS_CFLAGS@ \
                          @DB_UTIL_CFLAGS@ \
                          @TZPLATFORM_CONFIG_CFLAGS@ \
                          @PKGMGR_INFO_CFLAGS@ \
-                         @VCONF_CFLAGS@
+                         @VCONF_CFLAGS@ \
+                         @GLIB_CFLAGS@
 
 libscim@SCIM_EPOCH@_la_LDFLAGS  = -version-info $(SCIM_CURRENT):$(SCIM_REVISION):$(SCIM_AGE) \
                          -export-dynamic \
@@ -185,6 +186,7 @@ libscim@SCIM_EPOCH@_la_LDFLAGS  = -version-info $(SCIM_CURRENT):$(SCIM_REVISION)
                          @TZPLATFORM_CONFIG_LIBS@ \
                          @PKGMGR_INFO_LIBS@ \
                          @VCONF_LIBS@ \
+                         @GLIB_LIBS@ \
                          -lstdc++
 
 libscim@SCIM_EPOCH@_la_LIBADD  = libltdlc.la
index 1b76335..a790b72 100644 (file)
@@ -2,7 +2,7 @@
 #define Uses_ISF_REMOTE_CLIENT
 #define Uses_STL_STRING
 
-#include <Ecore.h>
+#include <glib.h>
 #include <dlog.h>
 
 #include "scim.h"
@@ -20,7 +20,10 @@ static bool focus_flag;
 
 struct _remote_control_client {
     RemoteInputClient remote_client;
-    Ecore_Fd_Handler *remote_fd_handler = NULL;
+    GIOChannel *remote_client_iochannel = NULL;
+    guint remote_client_iochannel_read;
+    guint remote_client_iochannel_err;
+    guint remote_client_iochannel_hup;
     int remote_client_id;
     remote_control_focus_in_cb focus_in_cb;
     void* focus_in_cb_user_data;
@@ -34,78 +37,86 @@ struct _remote_control_client {
     void* input_resource_changed_cb_user_data;
 };
 
-static Eina_Bool
-remote_handler(void *data, Ecore_Fd_Handler *fd_handler)
+static gboolean
+remote_handler(GIOChannel *source, GIOCondition condition, gpointer user_data)
 {
-    remote_control_client *client = static_cast<remote_control_client*>(data);
-
-    if (client->remote_client.has_pending_event()) {
-        switch (client->remote_client.recv_callback_message()) {
-            case REMOTE_CONTROL_CALLBACK_FOCUS_IN:
-            {
-                LOGD ("REMOTE_CONTROL_CALLBACK_FOCUS_IN");
-                focus_flag = true;
-                client->focus_in_cb (client->focus_in_cb_user_data);
-                break;
-            }
-            case REMOTE_CONTROL_CALLBACK_FOCUS_OUT:
-            {
-                LOGD ("REMOTE_CONTROL_CALLBACK_FOCUS_OUT");
-                focus_flag = false;
-                client->focus_out_cb (client->focus_out_cb_user_data);
-                break;
-            }
-            case REMOTE_CONTROL_CALLBACK_ENTRY_METADATA:
-            {
-                if (focus_flag) {
-                    remote_control_entry_metadata_s *data = new remote_control_entry_metadata_s;
-                    int hint = 0, layout = 0, variation = 0, autocapital_type = 0, return_key_disabled = 0;
-
-                    client->remote_client.get_entry_metadata (&hint, &layout, &variation, &autocapital_type, &return_key_disabled);
-                    data->hint = static_cast<Ecore_IMF_Input_Hints> (hint);
-                    data->layout = static_cast<Ecore_IMF_Input_Panel_Layout> (layout);
-                    data->variation = variation;
-                    data->autocapital_type = static_cast<Ecore_IMF_Autocapital_Type> (autocapital_type);
-                    data->return_key_disabled = return_key_disabled;
-
-                    LOGD ("REMOTE_CONTROL_CALLBACK_ENTRY_METADATA hint: 0x%04x, layout: %d, variation: %d, autocapital: %d, return_key: %d",
-                        data->hint, data->layout, data->variation, data->autocapital_type, data->return_key_disabled);
-                    client->metadata_cb (client->metadata_cb_user_data, data);
-                    delete data;
+    if (condition == G_IO_IN) {
+        remote_control_client *client = static_cast<remote_control_client*>(user_data);
+        if (client->remote_client.has_pending_event()) {
+            switch (client->remote_client.recv_callback_message()) {
+                case REMOTE_CONTROL_CALLBACK_FOCUS_IN:
+                {
+                    LOGD ("REMOTE_CONTROL_CALLBACK_FOCUS_IN");
+                    focus_flag = true;
+                    client->focus_in_cb (client->focus_in_cb_user_data);
+                    break;
                 }
-                break;
-            }
-            case REMOTE_CONTROL_CALLBACK_TEXT_UPDATED:
-            {
-                if (focus_flag) {
-                    String surrounding_text;
-                    int cursor = -1;
-
-                    client->remote_client.get_surrounding_text (surrounding_text, &cursor);
-                    SECURE_LOGD ("REMOTE_CONTROL_CALLBACK_TEXT_UPDATED \"%s\" %d", surrounding_text.c_str (), cursor);
-                    client->text_updated_cb (client->text_updated_cb_user_data, surrounding_text.c_str (), cursor);
+                case REMOTE_CONTROL_CALLBACK_FOCUS_OUT:
+                {
+                    LOGD ("REMOTE_CONTROL_CALLBACK_FOCUS_OUT");
+                    focus_flag = false;
+                    client->focus_out_cb (client->focus_out_cb_user_data);
+                    break;
                 }
-                break;
-            }
-            case REMOTE_CONTROL_CALLBACK_INPUT_RESOURCE:
-            {
-                if (focus_flag) {
-                    int resource = 0;
-
-                    client->remote_client.get_input_resource (&resource);
-                    LOGD ("REMOTE_CONTROL_CALLBACK_INPUT_RESOURCE: %s", (resource ? "REMOTE" : "LOCAL"));
-                    client->input_resource_changed_cb (client->input_resource_changed_cb_user_data,
-                        static_cast<remote_control_input_resource> (resource));
+                case REMOTE_CONTROL_CALLBACK_ENTRY_METADATA:
+                {
+                    if (focus_flag) {
+                        remote_control_entry_metadata_s *data = new remote_control_entry_metadata_s;
+                        int hint = 0, layout = 0, variation = 0, autocapital_type = 0, return_key_disabled = 0;
+
+                        client->remote_client.get_entry_metadata (&hint, &layout, &variation, &autocapital_type, &return_key_disabled);
+                        data->hint = static_cast<Ecore_IMF_Input_Hints> (hint);
+                        data->layout = static_cast<Ecore_IMF_Input_Panel_Layout> (layout);
+                        data->variation = variation;
+                        data->autocapital_type = static_cast<Ecore_IMF_Autocapital_Type> (autocapital_type);
+                        data->return_key_disabled = return_key_disabled;
+
+                        LOGD ("REMOTE_CONTROL_CALLBACK_ENTRY_METADATA hint: 0x%04x, layout: %d, variation: %d, autocapital: %d, return_key: %d",
+                            data->hint, data->layout, data->variation, data->autocapital_type, data->return_key_disabled);
+                        client->metadata_cb (client->metadata_cb_user_data, data);
+                        delete data;
+                    }
+                    break;
+                }
+                case REMOTE_CONTROL_CALLBACK_TEXT_UPDATED:
+                {
+                    if (focus_flag) {
+                        String surrounding_text;
+                        int cursor = -1;
+
+                        client->remote_client.get_surrounding_text (surrounding_text, &cursor);
+                        SECURE_LOGD ("REMOTE_CONTROL_CALLBACK_TEXT_UPDATED \"%s\" %d", surrounding_text.c_str (), cursor);
+                        client->text_updated_cb (client->text_updated_cb_user_data, surrounding_text.c_str (), cursor);
+                    }
+                    break;
+                }
+                case REMOTE_CONTROL_CALLBACK_INPUT_RESOURCE:
+                {
+                    if (focus_flag) {
+                        int resource = 0;
+
+                        client->remote_client.get_input_resource (&resource);
+                        LOGD ("REMOTE_CONTROL_CALLBACK_INPUT_RESOURCE: %s", (resource ? "REMOTE" : "LOCAL"));
+                        client->input_resource_changed_cb (client->input_resource_changed_cb_user_data,
+                            static_cast<remote_control_input_resource> (resource));
+                    }
+                    break;
                 }
-                break;
+                case REMOTE_CONTROL_CALLBACK_ERROR:
+                    break;
+                default:
+                    break;
             }
-            case REMOTE_CONTROL_CALLBACK_ERROR:
-                break;
-            default:
-                break;
+        } else {
+            LOGE ("Failed to receive callback message\n");
+            return (gboolean)FALSE;
         }
+    } else if (condition == G_IO_ERR || condition == G_IO_HUP) {
+        LOGE ("Failed to receive callback message\n");
+        return (gboolean)FALSE;
     }
-    return ECORE_CALLBACK_RENEW;
+
+    return (gboolean)TRUE;
 }
 
 EXAPI remote_control_client * remote_control_connect(void)
@@ -128,12 +139,16 @@ EXAPI remote_control_client * remote_control_connect(void)
         client->remote_client_id = client->remote_client.get_panel2remote_connection_number();
 
         if (client->remote_client_id >= 0) {
-            client->remote_fd_handler = ecore_main_fd_handler_add(client->remote_client_id, ECORE_FD_READ, remote_handler, client, NULL, NULL);
+            client->remote_client_iochannel = g_io_channel_unix_new(client->remote_client_id);
 
-            if (client->remote_fd_handler == NULL) {
+            if (client->remote_client_iochannel == NULL) {
                 LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
                 goto cleanup;
             }
+
+            client->remote_client_iochannel_read = g_io_add_watch (client->remote_client_iochannel, G_IO_IN,  remote_handler, client);
+            client->remote_client_iochannel_err = g_io_add_watch (client->remote_client_iochannel, G_IO_ERR,  remote_handler, client);
+            client->remote_client_iochannel_hup = g_io_add_watch (client->remote_client_iochannel, G_IO_HUP,  remote_handler, client);
         }
         else {
             LOGE ("REMOTE_CONTROL_INVALID_OPERATION");
@@ -165,8 +180,22 @@ EXAPI int remote_control_disconnect(remote_control_client *client)
     if (error_e)
         return error_e;
 
-    if (client->remote_fd_handler)
-        ecore_main_fd_handler_del(client->remote_fd_handler);
+    if (client->remote_client_iochannel)
+        g_io_channel_unref (client->remote_client_iochannel);
+
+    if (client->remote_client_iochannel_read)
+        g_source_remove (client->remote_client_iochannel_read);
+
+    if (client->remote_client_iochannel_err)
+        g_source_remove (client->remote_client_iochannel_err);
+
+    if (client->remote_client_iochannel_hup)
+        g_source_remove (client->remote_client_iochannel_hup);
+
+    client->remote_client_iochannel = NULL;
+    client->remote_client_iochannel_read = 0;
+    client->remote_client_iochannel_err = 0;
+    client->remote_client_iochannel_hup = 0;
 
     client->remote_client.close_connection();