#define Uses_ISF_REMOTE_CLIENT
#define Uses_STL_STRING
-#include <Ecore.h>
+#include <glib.h>
#include <dlog.h>
#include "scim.h"
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;
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)
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");
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();