From: Ji-hoon Lee Date: Wed, 9 Aug 2017 12:39:46 +0000 (+0900) Subject: Handle the case WebIME reloads and losts init information X-Git-Tag: submit/tizen/20180410.042339~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32df1232e34fc8c451f42c5e6ce532b950b8f623;p=platform%2Fcore%2Fuifw%2Flibscl-core.git Handle the case WebIME reloads and losts init information Change-Id: I41ce3723ba0572c46c98ac5158a49cdeda1afecd --- diff --git a/src/legacy_support/websocket.cpp b/src/legacy_support/websocket.cpp index 4fecacc..f3946d6 100644 --- a/src/legacy_support/websocket.cpp +++ b/src/legacy_support/websocket.cpp @@ -75,6 +75,8 @@ static int callback_http(struct lws *wsi, struct per_session_data__keyboard { int session_id; int valid; + int need_init; + int initialized; }; static int callback_keyboard(struct lws *wsi, @@ -115,6 +117,8 @@ static int callback_keyboard(struct lws *wsi, pss->session_id = ++last_session_id; LOGD("LWS_CALLBACK_ESTABLISHED : %p %d", g_ws_server_context, pss->session_id); pss->valid = false; + pss->need_init = false; + pss->initialized = false; if (g_ws_server_context) { lws_callback_on_writable_all_protocol(g_ws_server_context, &protocols[PROTOCOL_KEYBOARD]); } @@ -126,19 +130,46 @@ static int callback_keyboard(struct lws *wsi, case LWS_CALLBACK_SERVER_WRITEABLE: if (agent) { + /* Ignore valid check since the magic key is not used anymore */ + if (!pss->valid) pss->valid = true; + /* We allow data tranmission only if this client is guaranteed to be valid */ if (pss->valid) { pthread_mutex_lock(&g_ws_server_mutex); std::queue& messages = agent->get_send_message_queue(); - /* One write allowed per one writable callback */ - if (messages.size() > 0) { - ISE_MESSAGE &message = messages.front(); + + if (pss->need_init && !pss->initialized) { + ISE_MESSAGE message; + message.type = ISE_MESSAGE_TYPE_STRINGS[ISE_MESSAGE_TYPE_PLAIN]; + message.command = ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_INIT]; std::string str = CISEMessageSerializer::serialize(message); - LOGD("SEND_WEBSOCKET_MESSAGE : %s", str.c_str()); + LOGD("SEND_WEBSOCKET_MESSAGE : %d %s", pss->session_id, str.c_str()); n = snprintf((char *)p, bufsize, "%s", str.c_str()); /* too small for partial */ n = lws_write(wsi, p, n, LWS_WRITE_TEXT); - messages.pop(); + pss->need_init = false; + pss->initialized = true; + } else { + /* One write allowed per one writable callback */ + if (messages.size() > 0) { + ISE_MESSAGE &message = messages.front(); + bool drop = false; + if (message.command.compare(ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_INIT]) == 0) { + if (pss->initialized) { + drop = true; + } else { + pss->initialized = true; + } + } + if (!drop) { + std::string str = CISEMessageSerializer::serialize(message); + LOGD("SEND_WEBSOCKET_MESSAGE : %d %s", pss->session_id, str.c_str()); + n = snprintf((char *)p, bufsize, "%s", str.c_str()); + /* too small for partial */ + n = lws_write(wsi, p, n, LWS_WRITE_TEXT); + } + messages.pop(); + } } if (messages.size() > 0) { ecore_pipe_write(agent->get_message_pipe(), MESSAGE_LEFT, strlen(MESSAGE_LEFT)); @@ -146,7 +177,7 @@ static int callback_keyboard(struct lws *wsi, pthread_mutex_unlock(&g_ws_server_mutex); if (n < 0) { - LOGE("ERROR %d writing to di socket\n", n); + LOGE("ERROR %d writing to di socket %d", n, pss->session_id); return -1; } @@ -154,7 +185,7 @@ static int callback_keyboard(struct lws *wsi, lws_callback_on_writable_all_protocol(g_ws_server_context, &protocols[PROTOCOL_KEYBOARD]); } } else { - LOGD("Rejecting data transmission since client is not valid"); + LOGD("Rejecting data transmission since client is not valid : %d", pss->session_id); } } break; @@ -175,8 +206,16 @@ static int callback_keyboard(struct lws *wsi, } */ pss->valid = true; + + if (agent->initalized()) { + pss->need_init = true; + lws_callback_on_writable_all_protocol(g_ws_server_context, &protocols[PROTOCOL_KEYBOARD]); + } } + /* Ignore valid check since the magic key is not used anymore */ + if (!pss->valid) pss->valid = true; + if (pss->valid) { pthread_mutex_lock(&g_ws_server_mutex); std::queue& messages = agent->get_recv_message_queue(); @@ -192,7 +231,7 @@ static int callback_keyboard(struct lws *wsi, pthread_mutex_unlock(&g_ws_query_mutex); } } else { - LOGD("Ignoring data received since client is not valid"); + LOGD("Ignoring data received since client is not valid %d", pss->session_id); } } @@ -233,6 +272,7 @@ CWebHelperAgentWebSocket::CWebHelperAgentWebSocket() } m_current_instance = this; m_message_pipe = NULL; + m_initialized = false; } CWebHelperAgentWebSocket::~CWebHelperAgentWebSocket() @@ -318,6 +358,8 @@ bool CWebHelperAgentWebSocket::init() on_init(); + m_initialized = true; + return ret; } diff --git a/src/legacy_support/websocket.h b/src/legacy_support/websocket.h index 98483cb..d032ed9 100644 --- a/src/legacy_support/websocket.h +++ b/src/legacy_support/websocket.h @@ -205,6 +205,8 @@ public: bool init(); bool exit(); + bool initalized() { return m_initialized; } + void signal(int sig); void on_init(); @@ -258,6 +260,8 @@ protected: std::queue m_recv_message_queue; Ecore_Pipe *m_message_pipe; + + bool m_initialized; }; #endif // _WEB_HELPER_AGENT_WEBSOCKET_H_