Track Ecore_IMF and WaylandIMContext pair for checking validity 89/172789/5
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 16 Mar 2018 02:00:03 +0000 (11:00 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 20 Mar 2018 02:12:16 +0000 (02:12 +0000)
Change-Id: I995f1c7730dd6bc4aff22e214b09d5b1d9c77ae6

ism/extras/wayland_immodule/wayland_imcontext.c
ism/extras/wayland_immodule/wayland_imcontext.h
ism/extras/wayland_immodule/wayland_module.c

index dabe019..02c7cc9 100644 (file)
@@ -258,6 +258,79 @@ struct _WaylandIMContext
     //
 };
 
+typedef struct {
+    Ecore_IMF_Context *ctx;
+    WaylandIMContext *imcontext;
+} Ecore_Imf_Wayland_Imcontext_Pair;
+Eina_List *_ecore_imf_wayland_imcontext_pair_list = NULL;
+
+static void _ecore_imf_wayland_imcontext_pair_add (Ecore_IMF_Context *ctx, WaylandIMContext *imcontext)
+{
+    Ecore_Imf_Wayland_Imcontext_Pair *pair = malloc (sizeof (Ecore_Imf_Wayland_Imcontext_Pair));
+    if (pair) {
+        pair->ctx = ctx;
+        pair->imcontext = imcontext;
+
+        _ecore_imf_wayland_imcontext_pair_list = eina_list_append (_ecore_imf_wayland_imcontext_pair_list, pair);
+    }
+}
+
+static Ecore_Imf_Wayland_Imcontext_Pair* _ecore_imf_wayland_imcontext_pair_find (Ecore_IMF_Context *ctx)
+{
+    Eina_List *l;
+    Ecore_Imf_Wayland_Imcontext_Pair *pair;
+    EINA_LIST_FOREACH (_ecore_imf_wayland_imcontext_pair_list, l, pair)
+        if (pair->ctx == ctx) {
+            return pair;
+        }
+    LOGE("The Ecore_Imf %p if not found in Ecore_IMF-WaylandIMContext pair list!!", ctx);
+    return NULL;
+}
+
+static void _ecore_imf_wayland_imcontext_pair_del (Ecore_IMF_Context *ctx)
+{
+    Eina_List *l;
+    Eina_List *l_next;
+    Ecore_Imf_Wayland_Imcontext_Pair *pair;
+
+    EINA_LIST_FOREACH_SAFE (_ecore_imf_wayland_imcontext_pair_list, l, l_next, pair)
+        if (ctx == pair->ctx) {
+            free (pair);
+            _ecore_imf_wayland_imcontext_pair_list = eina_list_remove_list (_ecore_imf_wayland_imcontext_pair_list, l);
+        }
+}
+
+static void _ecore_imf_wayland_imcontext_pair_destroy ()
+{
+    if (_ecore_imf_wayland_imcontext_pair_list) {
+        Ecore_Imf_Wayland_Imcontext_Pair *pair;
+        EINA_LIST_FREE (_ecore_imf_wayland_imcontext_pair_list, pair)
+            free (pair);
+        _ecore_imf_wayland_imcontext_pair_list = NULL;
+    }
+}
+
+static int _ecore_imf_wayland_imcontext_pair_log ()
+{
+    char buffer[255] = { '\0' };
+    int count = 0;
+    Eina_List *l;
+    Ecore_Imf_Wayland_Imcontext_Pair *pair;
+    EINA_LIST_FOREACH(_ecore_imf_wayland_imcontext_pair_list, l, pair) {
+        if (pair) {
+            snprintf(buffer + strlen(buffer), 255 - strlen(buffer), "%s[%p/%p]", (count ? "," : ""), pair->ctx, pair->imcontext);
+        }
+        count++;
+    }
+    if (count == 0) {
+        LOGD("No Ecore_Imf / Wayland_Imcontext pair found");
+    } else {
+        LOGD("%d Pair(s) : %s", count, buffer);
+    }
+
+    return count;
+}
+
 // TIZEN_ONLY(20150708): Support back key
 static void _input_panel_hide(Ecore_IMF_Context *ctx, Eina_Bool instant);
 static Eina_Bool show_input_panel(Ecore_IMF_Context *ctx);
@@ -2634,6 +2707,8 @@ void wayland_im_initialize ()
 
 void wayland_im_uninitialize ()
 {
+    _ecore_imf_wayland_imcontext_pair_destroy ();
+
     unregister_key_handler ();
 
     _win_focus_out_handler_del ();
@@ -2698,8 +2773,20 @@ wayland_im_context_del (Ecore_IMF_Context *ctx)
 {
     WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx);
 
+    Eina_Bool valid = EINA_FALSE;
+    Ecore_Imf_Wayland_Imcontext_Pair *pair = _ecore_imf_wayland_imcontext_pair_find(ctx);
+    if (pair && pair->imcontext == imcontext) {
+        _ecore_imf_wayland_imcontext_pair_del(ctx);
+        valid = EINA_TRUE;
+    }
+    else {
+        LOGE("The Ecore_Imf %p and WaylandIMContext %p pair not found!! pair : %p, pair->imcontext %p",
+            ctx, imcontext, pair, pair ? pair->imcontext : NULL);
+        _ecore_imf_wayland_imcontext_pair_log();
+    }
+
     Ecore_Event_Key *ev;
-    LOGD ("ctx : %p, focused_ctx : %p, show_req_ctx : %p", ctx, _focused_ctx, _show_req_ctx);
+    LOGD ("ctx : %p [%d], focused_ctx : %p, show_req_ctx : %p", ctx, valid, _focused_ctx, _show_req_ctx);
 
     if (!imcontext) return;
 
@@ -3709,3 +3796,8 @@ WaylandIMContext *wayland_im_context_new (struct wl_text_input_manager *text_inp
 
     return context;
 }
+
+void wayland_im_context_pair_set (Ecore_IMF_Context *ctx, WaylandIMContext *imcontext)
+{
+    _ecore_imf_wayland_imcontext_pair_add (ctx, imcontext);
+}
index ae16469..e493b3f 100644 (file)
@@ -131,7 +131,11 @@ wayland_im_context_mime_type_accept_set (Ecore_IMF_Context *ctx, const char *mim
 void
 wayland_im_context_input_panel_position_set (Ecore_IMF_Context *ctx, int x, int y);
 
-WaylandIMContext *wayland_im_context_new        (struct wl_text_input_manager *text_input_manager);
+WaylandIMContext*
+wayland_im_context_new (struct wl_text_input_manager *text_input_manager);
+
+void
+wayland_im_context_pair_set(Ecore_IMF_Context *ctx, WaylandIMContext *imcontext);
 
 extern int _ecore_imf_wayland_log_dom;
 
index 8af86b6..c000b4b 100644 (file)
@@ -157,6 +157,7 @@ im_module_create()
    }
 
    ecore_imf_context_data_set(ctx, ctxd);
+   wayland_im_context_pair_set(ctx, ctxd);
 
    return ctx;