summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Zhang <li2012.zhang@samsung.com>2016-06-27 16:04:48 +0800
committerLi Zhang <li2012.zhang@samsung.com>2016-06-27 17:29:35 +0800
commitebf365d938d46edf27bcd952ef4bd385cacbca19 (patch)
treea2a210b0ea654780763d44fc44e32fc518a62b52
parentf8e9bd8e010d8b4c9b06184b7709feefa81b1884 (diff)
downloadisf-ebf365d938d46edf27bcd952ef4bd385cacbca19.tar.gz
isf-ebf365d938d46edf27bcd952ef4bd385cacbca19.tar.bz2
isf-ebf365d938d46edf27bcd952ef4bd385cacbca19.zip
Asynchronous reading fd for get_surrounding_text and get_selection_text functions
Change-Id: If983b97203ac6ef1ffb0b6a43b59e902d34fcb13
-rw-r--r--configure.ac2
-rw-r--r--ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp22
-rw-r--r--ism/modules/panelagent/wayland/isf_wsc_context.h4
-rw-r--r--ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp193
-rw-r--r--ism/src/isf_info_manager.cpp16
-rw-r--r--ism/src/isf_info_manager.h4
-rw-r--r--ism/src/isf_panel_agent_base.cpp4
-rw-r--r--ism/src/isf_panel_agent_base.h4
-rw-r--r--ism/src/isf_panel_agent_manager.cpp8
-rw-r--r--ism/src/isf_panel_agent_manager.h4
-rw-r--r--ism/src/scim_helper.cpp90
-rw-r--r--ism/src/scim_socket.cpp138
-rw-r--r--ism/src/scim_socket.h6
13 files changed, 223 insertions, 272 deletions
diff --git a/configure.ac b/configure.ac
index d55b80a4..ddd04ade 100644
--- a/configure.ac
+++ b/configure.ac
@@ -194,8 +194,6 @@ AC_SUBST(UINT16)
AC_SUBST(UINT32)
AC_SUBST(UINT64)
-AC_CHECK_MEMBERS([struct msghdr.msg_control],,, [#include <sys/socket.h>])
-
# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([gettimeofday memmove memset nl_langinfo setlocale daemon])
diff --git a/ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp b/ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp
index 85ff2ede..d2e61eeb 100644
--- a/ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp
+++ b/ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp
@@ -1193,7 +1193,7 @@ private:
unlock();
}
- void socket_helper_get_surrounding_text(int client, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after, const int fd) {
+ void socket_helper_get_surrounding_text(int client, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after) {
SCIM_DEBUG_MAIN(4) << __FUNCTION__ << " (" << client << ")\n";
LOGD ("client id:%d\n", client);
@@ -1225,7 +1225,7 @@ private:
unlock();
}
- void socket_helper_get_selection(int client, uint32 context_id, const int fd) {
+ void socket_helper_get_selection(int client, uint32 context_id) {
SCIM_DEBUG_MAIN(4) << __FUNCTION__ << " (" << client << ")\n";
LOGD ("client id:%d\n", client);
@@ -2479,14 +2479,7 @@ private:
if (m_recv_trans.get_data(uuid) &&
m_recv_trans.get_data(maxlen_before) &&
m_recv_trans.get_data(maxlen_after)) {
- int fd;
- client.read_fd (&fd);
- if (fd == -1) {
- LOGW ("wrong format of transaction\n");
- } else {
- m_info_manager->socket_helper_get_surrounding_text(client_id, uuid, maxlen_before, maxlen_after, fd);
- close (fd);
- }
+ m_info_manager->socket_helper_get_surrounding_text(client_id, uuid, maxlen_before, maxlen_after);
} else {
LOGW ("wrong format of transaction\n");
}
@@ -2503,14 +2496,7 @@ private:
String uuid;
if (m_recv_trans.get_data(uuid)) {
- int fd;
- client.read_fd (&fd);
- if (fd == -1) {
- LOGW ("wrong format of transaction\n");
- } else {
- m_info_manager->socket_helper_get_selection(client_id, uuid, fd);
- close (fd);
- }
+ m_info_manager->socket_helper_get_selection(client_id, uuid);
} else {
LOGW ("wrong format of transaction\n");
}
diff --git a/ism/modules/panelagent/wayland/isf_wsc_context.h b/ism/modules/panelagent/wayland/isf_wsc_context.h
index 8b880d97..f939e9db 100644
--- a/ism/modules/panelagent/wayland/isf_wsc_context.h
+++ b/ism/modules/panelagent/wayland/isf_wsc_context.h
@@ -80,8 +80,10 @@ struct _WSCContextISF {
KeycodeRepository _keysym2keycode;
keyboard_input_key_handler_t key_handler;
-
+ Ecore_Fd_Handler* surrounding_text_fd_read_handler;
+ Ecore_Fd_Handler* selection_text_fd_read_handler;
char *surrounding_text;
+ char *selection_text;
char *preedit_str;
char *language;
diff --git a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp
index cb9bfda3..f564891e 100644
--- a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp
+++ b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp
@@ -34,6 +34,7 @@
#include <pthread.h>
#include <langinfo.h>
#include <unistd.h>
+#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
@@ -401,6 +402,7 @@ _wsc_im_ctx_cursor_position(void *data, struct wl_input_method_context *im_ctx,
LOGD ("im_context = %p cursor_pos = %d\n", im_ctx, cursor_pos);
if (!wsc_ctx || !wsc_ctx->impl) return;
wsc_ctx->impl->cursor_pos = cursor_pos;
+ wsc_ctx->surrounding_cursor = cursor_pos;
caps_mode_check (wsc_ctx, EINA_FALSE, EINA_TRUE);
g_info_manager->socket_update_cursor_position (cursor_pos);
}
@@ -1291,6 +1293,10 @@ isf_wsc_context_add (WSCContextISF *wsc_ctx)
WSCContextISF* context_scim = wsc_ctx;
if (!context_scim) return;
+ context_scim->surrounding_text_fd_read_handler = NULL;
+ context_scim->selection_text_fd_read_handler = NULL;
+ context_scim->surrounding_text = NULL;
+ context_scim->selection_text = NULL;
context_scim->impl = new_ic_impl (context_scim);
if (context_scim->impl == NULL) {
@@ -1333,6 +1339,30 @@ isf_wsc_context_del (WSCContextISF *wsc_ctx)
WSCContextISF *context_scim = wsc_ctx;
+ if (context_scim->selection_text_fd_read_handler) {
+ int fd = ecore_main_fd_handler_fd_get(context_scim->selection_text_fd_read_handler);
+ close(fd);
+ ecore_main_fd_handler_del(context_scim->selection_text_fd_read_handler);
+ context_scim->selection_text_fd_read_handler = NULL;
+ }
+
+ if (context_scim->selection_text) {
+ free (context_scim->selection_text);
+ context_scim->selection_text = NULL;
+ }
+
+ if (context_scim->surrounding_text_fd_read_handler) {
+ int fd = ecore_main_fd_handler_fd_get(context_scim->surrounding_text_fd_read_handler);
+ close(fd);
+ ecore_main_fd_handler_del(context_scim->surrounding_text_fd_read_handler);
+ context_scim->surrounding_text_fd_read_handler = NULL;
+ }
+
+ if (context_scim->surrounding_text) {
+ free (context_scim->surrounding_text);
+ context_scim->surrounding_text = NULL;
+ }
+
if (context_scim) {
if (context_scim->id != _ic_list->id) {
WSCContextISF * pre = _ic_list;
@@ -2707,12 +2737,85 @@ public:
_update_preedit_string (context_id, wstr, attrs, caret);
}
+ static Eina_Bool
+ surrounding_text_fd_read_func(void* data, Ecore_Fd_Handler* fd_handler) {
+ if (fd_handler == NULL || data == NULL)
+ return ECORE_CALLBACK_RENEW;
+
+ WSCContextISF* wsc_ctx = (WSCContextISF*)data;
+
+ int fd = ecore_main_fd_handler_fd_get(fd_handler);
+ char buff[512];
+ int len = read (fd, buff, sizeof(buff));
+ if (len == 0) {
+ LOGD ("update");
+ g_info_manager->socket_update_surrounding_text (wsc_ctx->surrounding_text ? wsc_ctx->surrounding_text : "", wsc_ctx->surrounding_cursor);
+ } else if (len < 0) {
+ LOGW ("failed");
+ } else {
+ buff[len] = '\0';
+ if (wsc_ctx->surrounding_text == NULL) {
+ wsc_ctx->surrounding_text = (char*)malloc (len + 1);
+ if (wsc_ctx->surrounding_text) {
+ memcpy (wsc_ctx->surrounding_text, buff, len);
+ wsc_ctx->surrounding_text[len] = '\0';
+ return ECORE_CALLBACK_RENEW;
+ } else {
+ LOGE ("malloc failed");
+ }
+ } else {
+ int old_len = strlen(wsc_ctx->surrounding_text);
+ void * _new = realloc (wsc_ctx->surrounding_text, len + old_len + 1);
+ if (_new) {
+ wsc_ctx->surrounding_text = (char*)_new;
+ memcpy (wsc_ctx->surrounding_text + old_len, buff, len);
+ wsc_ctx->surrounding_text[old_len + len] = '\0';
+ return ECORE_CALLBACK_RENEW;
+ } else {
+ LOGE ("realloc failed");
+ }
+ }
+ }
+
+ if (wsc_ctx->surrounding_text_fd_read_handler) {
+ close(fd);
+ ecore_main_fd_handler_del(wsc_ctx->surrounding_text_fd_read_handler);
+ wsc_ctx->surrounding_text_fd_read_handler = NULL;
+ }
+
+ if (wsc_ctx->surrounding_text) {
+ free (wsc_ctx->surrounding_text);
+ wsc_ctx->surrounding_text = NULL;
+ }
+
+ return ECORE_CALLBACK_RENEW;
+ }
+
void
- socket_helper_get_surrounding_text (int id, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after, const int fd) {
- LOGD ("client id:%d, fd:%d", id, fd);
+ socket_helper_get_surrounding_text (int id, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after) {
+ LOGD ("client id:%d", id);
WSCContextISF* ic = find_ic (context_id);
- if (ic)
- wl_input_method_context_get_surrounding_text(ic->im_ctx, maxlen_before, maxlen_after, fd);
+
+ int filedes[2];
+ if (pipe2(filedes,O_CLOEXEC|O_NONBLOCK) ==-1 ) {
+ LOGW ("create pipe failed");
+ return;
+ }
+ LOGD("%d,%d",filedes[0],filedes[1]);
+ wl_input_method_context_get_surrounding_text(ic->im_ctx, maxlen_before, maxlen_after, filedes[1]);
+ ecore_wl_flush();
+ close (filedes[1]);
+ if (ic->surrounding_text_fd_read_handler) {
+ int fd = ecore_main_fd_handler_fd_get(ic->surrounding_text_fd_read_handler);
+ close(fd);
+ ecore_main_fd_handler_del(ic->surrounding_text_fd_read_handler);
+ ic->surrounding_text_fd_read_handler = NULL;
+ }
+ if (ic->surrounding_text) {
+ free (ic->surrounding_text);
+ ic->surrounding_text = NULL;
+ }
+ ic->surrounding_text_fd_read_handler = ecore_main_fd_handler_add(filedes[0], ECORE_FD_READ, surrounding_text_fd_read_func, ic, NULL, NULL);
}
void
@@ -2752,14 +2855,88 @@ public:
}
}
+ static Eina_Bool
+ selection_text_fd_read_func(void* data, Ecore_Fd_Handler* fd_handler) {
+ if (fd_handler == NULL || data == NULL)
+ return ECORE_CALLBACK_RENEW;
+
+ WSCContextISF* wsc_ctx = (WSCContextISF*)data;
+ LOGD("");
+ int fd = ecore_main_fd_handler_fd_get(fd_handler);
+ char buff[512];
+ int len = read (fd, buff, sizeof(buff));
+ if (len == 0) {
+ LOGD ("update");
+ g_info_manager->socket_update_selection (wsc_ctx->selection_text ? wsc_ctx->selection_text : "");
+ } else if (len < 0) {
+ LOGW ("failed");
+ } else {
+ buff[len] = '\0';
+ if (wsc_ctx->selection_text == NULL) {
+ wsc_ctx->selection_text = (char*)malloc (len + 1);
+ if (wsc_ctx->selection_text) {
+ memcpy (wsc_ctx->selection_text, buff, len);
+ wsc_ctx->selection_text[len] = '\0';
+ return ECORE_CALLBACK_RENEW;
+ } else {
+ LOGE ("malloc failed");
+ }
+ } else {
+ int old_len = strlen(wsc_ctx->selection_text);
+ void * _new = realloc (wsc_ctx->selection_text, len + old_len + 1);
+ if (_new) {
+ wsc_ctx->selection_text = (char*)_new;
+ memcpy (wsc_ctx->selection_text + old_len, buff, len);
+ wsc_ctx->selection_text[old_len + len] = '\0';
+ return ECORE_CALLBACK_RENEW;
+ } else {
+ LOGE ("realloc failed");
+ }
+ }
+ }
+
+ if (wsc_ctx->selection_text_fd_read_handler) {
+ close(fd);
+ ecore_main_fd_handler_del(wsc_ctx->selection_text_fd_read_handler);
+ wsc_ctx->selection_text_fd_read_handler = NULL;
+ }
+
+ if (wsc_ctx->selection_text) {
+ free (wsc_ctx->selection_text);
+ wsc_ctx->selection_text = NULL;
+ }
+
+ return ECORE_CALLBACK_RENEW;
+ }
+
void
- socket_helper_get_selection (int id, uint32 context_id, const int fd) {
- LOGD ("client id:%d, fd:%d", id, fd);
+ socket_helper_get_selection (int id, uint32 context_id) {
+ LOGD ("client id:%d", id);
WSCContextISF* ic = find_ic (context_id);
- if (ic) {
- wl_input_method_context_get_selection_text (ic->im_ctx, fd);
+ int filedes[2];
+ if (pipe2(filedes,O_CLOEXEC|O_NONBLOCK) ==-1 ) {
+ LOGW ("create pipe failed");
+ return;
+ }
+ LOGD("%d,%d",filedes[0],filedes[1]);
+ wl_input_method_context_get_selection_text(ic->im_ctx, filedes[1]);
+ ecore_wl_flush();
+ close (filedes[1]);
+
+ if (ic->selection_text_fd_read_handler) {
+ int fd = ecore_main_fd_handler_fd_get(ic->selection_text_fd_read_handler);
+ close(fd);
+ ecore_main_fd_handler_del(ic->selection_text_fd_read_handler);
+ ic->selection_text_fd_read_handler = NULL;
}
+
+ if (ic->selection_text) {
+ free (ic->selection_text);
+ ic->selection_text = NULL;
+ }
+
+ ic->selection_text_fd_read_handler = ecore_main_fd_handler_add(filedes[0], ECORE_FD_READ, selection_text_fd_read_func, ic, NULL, NULL);
}
void process_key_event_done(int id, uint32 context_id, KeyEvent &key, uint32 ret, uint32 serial) {
diff --git a/ism/src/isf_info_manager.cpp b/ism/src/isf_info_manager.cpp
index 0ea1e216..630fb3fd 100644
--- a/ism/src/isf_info_manager.cpp
+++ b/ism/src/isf_info_manager.cpp
@@ -3148,7 +3148,7 @@ client context helpers: %d, helpers uuid count: %d",
}
}
//SCIM_TRANS_CMD_GET_SURROUNDING_TEXT
- void socket_helper_get_surrounding_text (int client, String uuid, uint32 maxlen_before, uint32 maxlen_after, const int fd) {
+ void socket_helper_get_surrounding_text (int client, String uuid, uint32 maxlen_before, uint32 maxlen_after) {
SCIM_DEBUG_MAIN (4) << __FUNCTION__ << " (" << client << ")\n";
LOGD ("");
int focused_client;
@@ -3157,7 +3157,7 @@ client context helpers: %d, helpers uuid count: %d",
ClientInfo client_info = socket_get_client_info (focused_client);
if (client_info.type == FRONTEND_CLIENT) {
- m_panel_agent_manager.socket_helper_get_surrounding_text (focused_client, focused_context, maxlen_before, maxlen_after, fd);
+ m_panel_agent_manager.socket_helper_get_surrounding_text (focused_client, focused_context, maxlen_before, maxlen_after);
}
}
//SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT
@@ -3174,7 +3174,7 @@ client context helpers: %d, helpers uuid count: %d",
}
}
//SCIM_TRANS_CMD_GET_SELECTION
- void socket_helper_get_selection (int client, String uuid, const int fd) {
+ void socket_helper_get_selection (int client, String uuid) {
SCIM_DEBUG_MAIN (4) << __FUNCTION__ << " (" << client << ")\n";
LOGD ("");
int focused_client;
@@ -3183,7 +3183,7 @@ client context helpers: %d, helpers uuid count: %d",
ClientInfo client_info = socket_get_client_info (focused_client);
if (client_info.type == FRONTEND_CLIENT) {
- m_panel_agent_manager.socket_helper_get_selection (focused_client, focused_context, fd);
+ m_panel_agent_manager.socket_helper_get_selection (focused_client, focused_context);
}
}
//SCIM_TRANS_CMD_SET_SELECTION
@@ -4617,9 +4617,9 @@ void InfoManager::socket_helper_commit_string (int client, uint32 target_ic, Str
}
//SCIM_TRANS_CMD_GET_SURROUNDING_TEXT
-void InfoManager::socket_helper_get_surrounding_text (int client, String uuid, uint32 maxlen_before, uint32 maxlen_after, const int fd)
+void InfoManager::socket_helper_get_surrounding_text (int client, String uuid, uint32 maxlen_before, uint32 maxlen_after)
{
- m_impl->socket_helper_get_surrounding_text (client, uuid, maxlen_before, maxlen_after, fd);
+ m_impl->socket_helper_get_surrounding_text (client, uuid, maxlen_before, maxlen_after);
}
//SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT
@@ -4629,9 +4629,9 @@ void InfoManager::socket_helper_delete_surrounding_text (int client, uint32 offs
}
//SCIM_TRANS_CMD_GET_SELECTION
-void InfoManager::socket_helper_get_selection (int client, String uuid, const int fd)
+void InfoManager::socket_helper_get_selection (int client, String uuid)
{
- m_impl->socket_helper_get_selection (client, uuid, fd);
+ m_impl->socket_helper_get_selection (client, uuid);
}
//SCIM_TRANS_CMD_SET_SELECTION
diff --git a/ism/src/isf_info_manager.h b/ism/src/isf_info_manager.h
index 9ae90225..36541d00 100644
--- a/ism/src/isf_info_manager.h
+++ b/ism/src/isf_info_manager.h
@@ -886,13 +886,13 @@ public:
void socket_helper_commit_string (int client, uint32 target_ic, String target_uuid, WideString wstr);
//SCIM_TRANS_CMD_GET_SURROUNDING_TEXT
- void socket_helper_get_surrounding_text (int client, String uuid, uint32 maxlen_before, uint32 maxlen_after, const int fd);
+ void socket_helper_get_surrounding_text (int client, String uuid, uint32 maxlen_before, uint32 maxlen_after);
//SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT
void socket_helper_delete_surrounding_text (int client, uint32 offset, uint32 len);
//SCIM_TRANS_CMD_GET_SELECTION
- void socket_helper_get_selection (int client, String uuid, const int fd);
+ void socket_helper_get_selection (int client, String uuid);
//SCIM_TRANS_CMD_SET_SELECTION
void socket_helper_set_selection (int client, uint32 start, uint32 end);
diff --git a/ism/src/isf_panel_agent_base.cpp b/ism/src/isf_panel_agent_base.cpp
index 150f13d8..55955015 100644
--- a/ism/src/isf_panel_agent_base.cpp
+++ b/ism/src/isf_panel_agent_base.cpp
@@ -399,7 +399,7 @@ void PanelAgentBase::socket_helper_key_event (int client, uint32 context, int cm
//SCIM_TRANS_CMD_GET_SURROUNDING_TEXT
//socket_helper_get_surrounding_text
-void PanelAgentBase::socket_helper_get_surrounding_text (int client, uint32 context, uint32 maxlen_before, uint32 maxlen_after, const int fd)
+void PanelAgentBase::socket_helper_get_surrounding_text (int client, uint32 context, uint32 maxlen_before, uint32 maxlen_after)
{
LOGW ("not implemented for %s", m_name.c_str ());
}
@@ -410,7 +410,7 @@ void PanelAgentBase::socket_helper_delete_surrounding_text (int client, uint32 c
LOGD ("not implemented ");
}
//SCIM_TRANS_CMD_GET_SELECTION
-void PanelAgentBase::socket_helper_get_selection (int client, uint32 context, const int fd)
+void PanelAgentBase::socket_helper_get_selection (int client, uint32 context)
{
LOGW ("not implemented for %s", m_name.c_str ());
}
diff --git a/ism/src/isf_panel_agent_base.h b/ism/src/isf_panel_agent_base.h
index 6273badf..2fb53cdb 100644
--- a/ism/src/isf_panel_agent_base.h
+++ b/ism/src/isf_panel_agent_base.h
@@ -644,7 +644,7 @@ public:
*
* @return none.
*/
- virtual void socket_helper_get_surrounding_text (int client, uint32 context, uint32 maxlen_before, uint32 maxlen_after, const int fd);
+ virtual void socket_helper_get_surrounding_text (int client, uint32 context, uint32 maxlen_before, uint32 maxlen_after);
/**
* @brief socket_helper_delete_surrounding_text.
@@ -662,7 +662,7 @@ public:
*
* @return none.
*/
- virtual void socket_helper_get_selection (int client, uint32 context, const int fd);
+ virtual void socket_helper_get_selection (int client, uint32 context);
/**
* @brief socket_helper_set_selection.
diff --git a/ism/src/isf_panel_agent_manager.cpp b/ism/src/isf_panel_agent_manager.cpp
index e1e94c88..590c882f 100644
--- a/ism/src/isf_panel_agent_manager.cpp
+++ b/ism/src/isf_panel_agent_manager.cpp
@@ -653,12 +653,12 @@ void PanelAgentManager::socket_helper_key_event (int id, uint32 context_id, int
_p->socket_helper_key_event (id, context_id, cmd, key);
}
-void PanelAgentManager::socket_helper_get_surrounding_text (int id, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after, const int fd)
+void PanelAgentManager::socket_helper_get_surrounding_text (int id, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after)
{
PanelAgentPointer _p = m_impl->get_panel_agent_by_id (id);
if (!_p.null ())
- _p->socket_helper_get_surrounding_text (id, context_id, maxlen_before, maxlen_after, fd);
+ _p->socket_helper_get_surrounding_text (id, context_id, maxlen_before, maxlen_after);
}
void PanelAgentManager::socket_helper_delete_surrounding_text (int id, uint32 context_id, uint32 offset, uint32 len)
@@ -669,12 +669,12 @@ void PanelAgentManager::socket_helper_delete_surrounding_text (int id, uint32 co
_p->socket_helper_delete_surrounding_text (id, context_id, offset, len);
}
-void PanelAgentManager::socket_helper_get_selection (int id, uint32 context_id, const int fd)
+void PanelAgentManager::socket_helper_get_selection (int id, uint32 context_id)
{
PanelAgentPointer _p = m_impl->get_panel_agent_by_id (id);
if (!_p.null ())
- _p->socket_helper_get_selection (id, context_id, fd);
+ _p->socket_helper_get_selection (id, context_id);
}
void PanelAgentManager::socket_helper_set_selection (int id, uint32 context_id, uint32 start, uint32 end)
diff --git a/ism/src/isf_panel_agent_manager.h b/ism/src/isf_panel_agent_manager.h
index 540015c0..52a6a2bd 100644
--- a/ism/src/isf_panel_agent_manager.h
+++ b/ism/src/isf_panel_agent_manager.h
@@ -325,9 +325,9 @@ public:
void helper_process_imengine_event (int client, uint32 context, const String& ic_uuid, const Transaction& nest_transaction);
void process_helper_event (int client, uint32 context, String target_uuid, String active_uuid, Transaction& nest_trans);
void socket_helper_key_event (int client, uint32 context, int cmd , KeyEvent& key);
- void socket_helper_get_surrounding_text (int client, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after, const int fd);
+ void socket_helper_get_surrounding_text (int client, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after);
void socket_helper_delete_surrounding_text (int client, uint32 context_id, uint32 offset, uint32 len);
- void socket_helper_get_selection (int client, uint32 context_id, const int fd);
+ void socket_helper_get_selection (int client, uint32 context_id);
void socket_helper_set_selection (int client, uint32 context_id, uint32 start, uint32 end);
void update_ise_input_context (int focused_client, uint32 focused_context, uint32 type, uint32 value);
void send_private_command (int focused_client, uint32 focused_context, String command);
diff --git a/ism/src/scim_helper.cpp b/ism/src/scim_helper.cpp
index 82fbab94..d34b6ad0 100644
--- a/ism/src/scim_helper.cpp
+++ b/ism/src/scim_helper.cpp
@@ -48,7 +48,6 @@
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include "scim_private.h"
#include "scim.h"
@@ -2003,62 +2002,27 @@ HelperAgent::get_surrounding_text (int maxlen_before, int maxlen_after, String &
m_impl->send.put_data (maxlen_before);
m_impl->send.put_data (maxlen_after);
m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
-
-#ifdef WAYLAND
- int filedes[2];
- if (pipe2(filedes,O_CLOEXEC|O_NONBLOCK) ==-1 ) {
- LOGD ("create pipe failed");
- return;
- }
- LOGD("%d,%d",filedes[0],filedes[1]);
-
- m_impl->socket_active.write_fd (filedes[1]);
- close (filedes[1]);
-
- for (int i = 0; i < 3; i++) {
- int fds[3];
- fds[0] = m_impl->socket_active.get_id();
- fds[1] = filedes[0];
- fds[2] = 0;
- if (!scim_wait_for_data (fds)) {
- LOGE ("");
- break;
- }
-
- if (fds[1]) {
- char buff[512];
- int len = read (fds[1], buff, sizeof(buff) - 1);
- if (len <= 0)
- break;
- else {
- buff[len] = '\0';
- text.append (buff);
- }
- }
- if (fds[0])
- filter_event ();
- }
- close (filedes[0]);
- cursor = m_impl->cursor_pos;
-#else
if (m_impl->surrounding_text) {
free (m_impl->surrounding_text);
m_impl->surrounding_text = NULL;
}
for (int i = 0; i < 3; i++) {
- if (filter_event () && m_impl->surrounding_text) {
+ filter_event ();
+ if (!m_impl->socket.is_connected ())
+ break;
+ if (m_impl->surrounding_text) {
text = m_impl->surrounding_text;
cursor = m_impl->cursor_pos;
break;
}
+ //timeout
}
if (m_impl->surrounding_text) {
free (m_impl->surrounding_text);
m_impl->surrounding_text = NULL;
}
-#endif
}
/**
@@ -2123,58 +2087,26 @@ HelperAgent::get_selection_text (String &text)
m_impl->send.put_command (SCIM_TRANS_CMD_GET_SELECTION);
m_impl->send.put_data ("");
m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
-#ifdef WAYLAND
- int filedes[2];
- if (pipe2 (filedes,O_CLOEXEC|O_NONBLOCK) == -1 ) {
- LOGD ("create pipe failed");
- return;
- }
- LOGD("%d,%d", filedes[0], filedes[1]);
-
- m_impl->socket_active.write_fd (filedes[1]);
- close (filedes[1]);
-
- for (int i = 0; i < 3; i++) {
- int fds[3];
- fds[0] = m_impl->socket_active.get_id();
- fds[1] = filedes[0];
- fds[2] = 0;
- if (!scim_wait_for_data (fds)) {
- LOGE ("");
- break;
- }
-
- if (fds[1]) {
- char buff[512];
- int len = read (fds[1], buff, sizeof(buff) - 1);
- if (len <= 0)
- break;
- else {
- buff[len] = '\0';
- text.append (buff);
- }
- }
- if (fds[0])
- filter_event ();
- }
- close (filedes[0]);
-#else
if (m_impl->selection_text) {
free (m_impl->selection_text);
m_impl->selection_text = NULL;
}
for (int i = 0; i < 3; i++) {
- if (filter_event () && m_impl->selection_text) {
+ filter_event ();
+ if (!m_impl->socket.is_connected ())
+ break;
+ if (m_impl->selection_text) {
text = m_impl->selection_text;
break;
}
+ //timeout
}
+
if (m_impl->selection_text) {
free (m_impl->selection_text);
m_impl->selection_text = NULL;
}
-#endif
}
/**
diff --git a/ism/src/scim_socket.cpp b/ism/src/scim_socket.cpp
index 847929d5..81a83dc0 100644
--- a/ism/src/scim_socket.cpp
+++ b/ism/src/scim_socket.cpp
@@ -374,95 +374,6 @@ public:
return m_id >= 0;
}
- void write_fd (int fd) {
- struct msghdr msg;
- char buff[]={0};
- struct iovec iov[1];
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
- union{
- struct cmsghdr cm;
- char control[CMSG_SPACE (sizeof (int))];
- }control_un;
- struct cmsghdr *cmptr;
- msg.msg_control = control_un.control;
- msg.msg_controllen = sizeof(control_un.control);
- cmptr = CMSG_FIRSTHDR (&msg);
- cmptr->cmsg_len = CMSG_LEN (sizeof(int));
- cmptr->cmsg_level = SOL_SOCKET;
- cmptr->cmsg_type = SCM_RIGHTS;
- memcpy (CMSG_DATA (cmptr), &fd, sizeof(int));
-#else
- msg.msg_accrights = (caddr_t)&fd;
- msg.msg_accrightslen = sizeof (int);
-#endif
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- iov[0].iov_base = buff;
- iov[0].iov_len = sizeof (buff);
- msg.msg_iov = iov;
- msg.msg_iovlen = 1;
- sendmsg (m_id, &msg, 0);
- }
-
- void read_fd (int *fd) {
- struct msghdr msg;
- char buff[]={0};
- struct iovec iov[1];
-#ifndef HAVE_STRUCT_MSGHDR_MSG_CONTROL
- int newfd;
-#endif
-
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
- union{
- struct cmsghdr cm;
- char control[CMSG_SPACE (sizeof (int))];
- }control_un;
- struct cmsghdr *cmptr;
- msg.msg_control = control_un.control;
- msg.msg_controllen = sizeof (control_un.control);
-#else
- msg.msg_accrights = (caddr_t) &newfd;
- msg.msg_accrightslen = sizeof (int);
-#endif
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- iov[0].iov_base = buff;
- iov[0].iov_len = sizeof (buff);
- msg.msg_iov = iov;
- msg.msg_iovlen = 1;
- while (true) {
- if (recvmsg (m_id, &msg, 0) <= 0) {
- if (errno == EAGAIN)
- continue;
- *fd = -1;
- LOGE ("%d", errno);
- return;
- }
- break;
- }
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
- cmptr = CMSG_FIRSTHDR (&msg);
- if ((cmptr != NULL) && (cmptr->cmsg_len == CMSG_LEN (sizeof (int)))) {
- if (cmptr->cmsg_level != SOL_SOCKET || cmptr->cmsg_type != SCM_RIGHTS) {
- *fd = -1;
- LOGE ("unknow message");
- return;
- }
- memcpy (fd, CMSG_DATA (cmptr), sizeof(int));
- }
- else
- {
- *fd = -1;
- LOGE ("unknow message format");
- }
-#else
- if (msg.msg_accrightslen == sizeof (int))
- *fd = newfd;
- else
- *fd = -1;
-#endif
- }
-
int read (void *buf, size_t size) {
if (!buf || !size) { m_err = EINVAL; return -1; }
if (m_id < 0) { m_err = EBADF; return -1; }
@@ -962,18 +873,6 @@ Socket::set_nonblock_mode ()
return m_impl->set_nonblock_mode ();
}
-void
-Socket::write_fd (int fd) const
-{
- m_impl->write_fd (fd);
-}
-
-void
-Socket::read_fd (int *fd) const
-{
- m_impl->read_fd (fd);
-}
-
bool
Socket::create (SocketFamily family)
{
@@ -1695,43 +1594,6 @@ scim_socket_accept_connection (uint32 &key,
return String ("");
}
-bool
-scim_wait_for_data (int *fds)
-{
- fd_set _fd_set;
- int max_fd;
- int *_fds;
- if (fds == NULL)
- return false;
- max_fd = *fds;
- FD_ZERO (&_fd_set);
- for (_fds = fds; *_fds; _fds++) {
- FD_SET (*_fds, &_fd_set);
- if (*_fds > max_fd)
- max_fd = *_fds;
- }
- while (true) {
- int ret = select (max_fd + 1, &_fd_set, NULL, NULL, NULL);
- if (ret < 0) {
- if (errno == EINTR)
- continue;
- LOGW ("%d", errno);
- return false;
- }
- else if (ret == 0)
- continue;
- else
- break;
- }
-
- for (_fds = fds; *_fds; _fds++) {
- if (!FD_ISSET(*_fds, &_fd_set))
- *_fds = 0;
- }
- return true;
-}
-
-
} // namespace scim
/*
diff --git a/ism/src/scim_socket.h b/ism/src/scim_socket.h
index 73721095..3cb92501 100644
--- a/ism/src/scim_socket.h
+++ b/ism/src/scim_socket.h
@@ -282,10 +282,6 @@ public:
*/
int set_nonblock_mode ();
- void write_fd (int fd) const;
- void read_fd (int *fd) const;
-
-
protected:
/**
@@ -654,8 +650,6 @@ EXAPI String scim_socket_accept_connection (uint32 &key,
const String &client_types,
const Socket &socket,
int timeout = -1);
-
-EXAPI bool scim_wait_for_data (int *fds);
/** @} */
} // namespace scim