Handling the exceptional case 67/38667/3
authorJihoon Kim <jihoon48.kim@samsung.com>
Fri, 24 Apr 2015 04:05:19 +0000 (13:05 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Fri, 24 Apr 2015 04:11:57 +0000 (13:11 +0900)
Change-Id: I790f930f4561b2296961d86faf4704aeb608f6e2

ism/extras/efl_wsc/isf_wsc_control_ui.cpp
ism/extras/efl_wsc/isf_wsc_efl.cpp
ism/extras/efl_wsm/isf_wsm_efl.cpp

index 22740b9e98538b80bf9edee244b1bf7f011ca863..64de0954bc84f6e68bcdccd2706ef2ae95380111 100644 (file)
@@ -60,7 +60,7 @@ static void _isf_wsc_context_init (void)
 static int _get_context_id (WSCContextISF *ctx)
 {
     WSCContextISF *context_scim = ctx;
-    
+
     if (!context_scim) return -1;
 
     return context_scim->id;
@@ -119,7 +119,7 @@ void isf_wsc_context_input_panel_show (WSCContextISF* ctx)
         iseContext.prediction_allow = EINA_FALSE;
 
     isf_wsc_context_prediction_allow_set (ctx, iseContext.prediction_allow);
-    
+
     if (hw_kbd_num != 0) {
         LOGD ("H/W keyboard is existed.\n");
         return;
@@ -146,7 +146,7 @@ void isf_wsc_context_input_panel_show (WSCContextISF* ctx)
     LOGD ("ctx : %p, layout : %d, layout variation : %d\n", ctx, iseContext.layout, iseContext.layout_variation);
     LOGD ("language : %d, cursor position : %d, caps mode : %d\n", iseContext.language, iseContext.cursor_pos, iseContext.caps_mode);
     LOGD ("return_key_type : %d, return_key_disabled : %d, autocapital type : %d\n", iseContext.return_key_type, iseContext.return_key_disabled, iseContext.autocapital_type);
-    
+
     /* calculate packet size */
     length = sizeof (iseContext);
     length += iseContext.imdata_size;
@@ -162,9 +162,9 @@ void isf_wsc_context_input_panel_show (WSCContextISF* ctx)
     int context_id = _get_context_id (ctx);
 
     _isf_wsc_context_input_panel_show (get_panel_client_id (), context_id, packet, length, input_panel_show);
-    
+
     free (packet);
-    
+
     caps_mode_check (ctx, EINA_TRUE, EINA_TRUE);
 }
 
index 48cc4e5b4eca97118608c5662555882c2bb4a578..1ce5f6c2768263d276aae53359ac8e93cd5b4761 100755 (executable)
@@ -277,7 +277,12 @@ void wsc_context_commit_preedit_string(weescim *ctx)
     char *preedit_str = NULL;
     int cursor_pos = 0;
 
-    isf_wsc_context_preedit_string_get(ctx->wsc_ctx, &preedit_str, &cursor_pos);
+    if (!ctx)
+        return;
+
+    if (ctx->wsc_ctx)
+        isf_wsc_context_preedit_string_get(ctx->wsc_ctx, &preedit_str, &cursor_pos);
+
     if (ctx->preedit_str) {
         free(ctx->preedit_str);
         ctx->preedit_str = NULL;
@@ -292,7 +297,12 @@ void wsc_context_send_preedit_string(weescim *ctx)
     char *preedit_str = NULL;
     int cursor_pos = 0;
 
-    isf_wsc_context_preedit_string_get(ctx->wsc_ctx, &preedit_str, &cursor_pos);
+    if (!ctx)
+        return;
+
+    if (ctx->wsc_ctx)
+        isf_wsc_context_preedit_string_get(ctx->wsc_ctx, &preedit_str, &cursor_pos);
+
     if (ctx->preedit_str) {
         free(ctx->preedit_str);
         ctx->preedit_str = NULL;
@@ -307,6 +317,9 @@ void wsc_context_send_key(weescim *ctx, uint32_t keysym, uint32_t modifiers, uin
     uint32_t keycode;
     KeycodeRepository::iterator it = _keysym2keycode.find(keysym);
 
+    if (!ctx || !ctx->im_ctx)
+        return;
+
     if(it == _keysym2keycode.end())
         return;
 
@@ -340,6 +353,7 @@ static void
 _wsc_im_ctx_surrounding_text(void *data, struct wl_input_method_context *im_ctx, const char *text, uint32_t cursor, uint32_t anchor)
 {
     struct weescim *wsc = (weescim*)data;
+    if (!wsc) return;
 
     if (wsc->surrounding_text)
         free (wsc->surrounding_text);
@@ -353,7 +367,8 @@ _wsc_im_ctx_reset(void *data, struct wl_input_method_context *im_ctx)
 {
     struct weescim *wsc = (weescim*)data;
 
-    isf_wsc_context_reset(wsc->wsc_ctx);
+    if (wsc)
+        isf_wsc_context_reset(wsc->wsc_ctx);
 }
 
 static void
@@ -361,9 +376,9 @@ _wsc_im_ctx_content_type(void *data, struct wl_input_method_context *im_ctx, uin
 {
     struct weescim *wsc = (weescim*)data;
 
-    ISF_LOG ("im_context = %p hint = %d purpose = %d", im_ctx, hint, purpose);
+    LOGD ("im_context = %p hint = %d purpose = %d", im_ctx, hint, purpose);
 
-    if (!wsc->context_changed)
+    if (!wsc || !wsc->context_changed)
         return;
 
     wsc->content_hint = hint;
@@ -387,18 +402,20 @@ _wsc_im_ctx_invoke_action(void *data, struct wl_input_method_context *im_ctx, ui
     if (button != BTN_LEFT)
         return;
 
-    wsc_context_send_preedit_string (wsc);
+    if (wsc)
+        wsc_context_send_preedit_string (wsc);
 }
 
 static void
 _wsc_im_ctx_commit_state(void *data, struct wl_input_method_context *im_ctx, uint32_t serial)
 {
     struct weescim *wsc = (weescim*)data;
+    if (!wsc) return;
 
     wsc->serial = serial;
 
     if (wsc->surrounding_text)
-        ISF_LOG ("Surrounding text updated: %s", wsc->surrounding_text);
+        LOGD ("Surrounding text updated: %s", wsc->surrounding_text);
 
     if(wsc->language)
         wl_input_method_context_language (im_ctx, wsc->serial, wsc->language);
@@ -410,6 +427,7 @@ static void
 _wsc_im_ctx_preferred_language(void *data, struct wl_input_method_context *im_ctx, const char *language)
 {
     struct weescim *wsc = (weescim*)data;
+    if (!wsc) return;
 
     if (language && wsc->language && !strcmp (language, wsc->language))
         return;
@@ -421,7 +439,7 @@ _wsc_im_ctx_preferred_language(void *data, struct wl_input_method_context *im_ct
 
     if (language) {
         wsc->language = strdup (language);
-        ISF_LOG ("Language changed, new: '%s'", language);
+        LOGD ("Language changed, new: '%s'", language);
     }
 }
 
@@ -442,7 +460,7 @@ _init_keysym2keycode(struct weescim *wsc)
     uint32_t num_syms;
     const xkb_keysym_t *syms;
 
-    if (!wsc->state)
+    if (!wsc || !wsc->state)
         return;
 
     for (i = 0; i < 256; i++) {
@@ -470,6 +488,8 @@ _wsc_im_keyboard_keymap(void *data,
     struct weescim *wsc = (weescim*)data;
     char *map_str;
 
+    if (!wsc) return;
+
     _fini_keysym2keycode(wsc);
 
     if (wsc->state) {
@@ -503,13 +523,13 @@ _wsc_im_keyboard_keymap(void *data,
     close(fd);
 
     if (!wsc->keymap) {
-        fprintf(stderr, "failed to compile keymap\n");
+        LOGW ("failed to compile keymap\n");
         return;
     }
 
     wsc->state = xkb_state_new(wsc->keymap);
     if (!wsc->state) {
-        fprintf(stderr, "failed to create XKB state\n");
+        LOGW ("failed to create XKB state\n");
         xkb_map_unref(wsc->keymap);
         return;
     }
@@ -521,7 +541,7 @@ _wsc_im_keyboard_keymap(void *data,
     wsc->shift_mask =
         1 << xkb_map_mod_get_index(wsc->keymap, "Shift");
 
-    fprintf(stderr, "create _keysym2keycode\n");
+    LOGW ("create _keysym2keycode\n");
     _init_keysym2keycode(wsc);
 }
 
@@ -540,7 +560,7 @@ _wsc_im_keyboard_key(void *data,
     xkb_keysym_t sym;
     enum wl_keyboard_key_state state = (wl_keyboard_key_state)state_w;
 
-    if (!wsc->state)
+    if (!wsc || !wsc->state)
         return;
 
     code = key + 8;
@@ -568,7 +588,7 @@ _wsc_im_keyboard_modifiers(void *data,
     struct wl_input_method_context *context = wsc->im_ctx;
     xkb_mod_mask_t mask;
 
-    if (!wsc->state)
+    if (!wsc || !wsc->state)
         return;
 
     xkb_state_update_mask(wsc->state, mods_depressed,
@@ -601,6 +621,7 @@ static void
 _wsc_im_activate(void *data, struct wl_input_method *input_method, struct wl_input_method_context *im_ctx)
 {
     struct weescim *wsc = (weescim*)data;
+    if (!wsc) return;
 
     if (wsc->im_ctx)
         wl_input_method_context_destroy (wsc->im_ctx);
@@ -637,6 +658,7 @@ static void
 _wsc_im_deactivate(void *data, struct wl_input_method *input_method, struct wl_input_method_context *im_ctx)
 {
     struct weescim *wsc = (weescim*)data;
+    if (!wsc) return;
 
     isf_wsc_context_input_panel_hide (wsc->wsc_ctx);
     isf_wsc_context_focus_out (wsc->wsc_ctx);
@@ -657,6 +679,7 @@ _wsc_seat_handle_capabilities(void *data, struct wl_seat *seat,
                               uint32_t caps)
 {
     struct weescim *wsc = (weescim*)data;
+    if (!wsc) return;
 
     if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
         wsc->hw_kbd = true;
@@ -676,31 +699,35 @@ _wsc_im_key_handler(struct weescim *wsc,
 {
 }
 
-static void
+static bool
 _wsc_setup(struct weescim *wsc)
 {
     Eina_Inlist *globals;
     struct wl_registry *registry;
     Ecore_Wl_Global *global;
 
+    if (!wsc) return false;
+
     wsc->xkb_context = xkb_context_new((xkb_context_flags)0);
     if (wsc->xkb_context == NULL) {
-        fprintf(stderr, "Failed to create XKB context\n");
-        return;
+        LOGW ("Failed to create XKB context\n");
+        return false;
     }
 
     wsc->key_handler = _wsc_im_key_handler;
 
     wsc->wsc_ctx = isf_wsc_context_new ();
+    if (!wsc->wsc_ctx) return false;
+
     wsc->wsc_ctx->ctx = wsc;
 
     get_language(&wsc->language);
 
     if (!(registry = ecore_wl_registry_get()))
-        return;
+        return false;
 
     if (!(globals = ecore_wl_globals_get()))
-        return;
+        return false;
 
     EINA_INLIST_FOREACH(globals, global) {
         if (strcmp (global->interface, "wl_input_method") == 0)
@@ -710,38 +737,59 @@ _wsc_setup(struct weescim *wsc)
     }
 
     if (wsc->im == NULL) {
-        fprintf(stderr, "Failed because wl_input_method is null\n");
-        return;
+        LOGW ("Failed because wl_input_method is null\n");
+        return false;
     }
 
     /* Input method listener */
-    ISF_LOG ("Adding wl_input_method listener");
-    wl_input_method_add_listener (wsc->im, &wsc_im_listener, wsc);
+    LOGD ("Adding wl_input_method listener");
 
-    wl_seat_add_listener(wsc->seat, &wsc_seat_listener, wsc);
+    if (wsc->im)
+        wl_input_method_add_listener (wsc->im, &wsc_im_listener, wsc);
+    else {
+        LOGW ("Couldn't get wayland input method interface\n");
+        return false;
+    }
+
+    if (wsc->seat)
+        wl_seat_add_listener(wsc->seat, &wsc_seat_listener, wsc);
+    else {
+        LOGW ("Couldn't get wayland seat interface\n");
+        return false;
+    }
 
     isf_wsc_context_add (wsc->wsc_ctx);
+
+    return true;
 }
 
 static void
-_wsc_free(struct weescim *wsc)
+_wsc_free (struct weescim *wsc)
 {
-    _fini_keysym2keycode(wsc);
+    if (!wsc) return;
+
+    _fini_keysym2keycode (wsc);
 
     if (wsc->state) {
-        xkb_state_unref(wsc->state);
+        xkb_state_unref (wsc->state);
         wsc->state = NULL;
     }
 
     if (wsc->keymap) {
-        xkb_map_unref(wsc->keymap);
+        xkb_map_unref (wsc->keymap);
         wsc->keymap = NULL;
     }
 
-    if (wsc->im_ctx)
+    if (wsc->im_ctx) {
         wl_input_method_context_destroy (wsc->im_ctx);
+        wsc->im_ctx = NULL;
+    }
+
+    if (wsc->wsc_ctx) {
+        isf_wsc_context_del (wsc->wsc_ctx);
+        wsc->wsc_ctx = NULL;
+    }
 
-    isf_wsc_context_del(wsc->wsc_ctx);
     isf_wsc_context_shutdown ();
 
     if (wsc->preedit_str) {
@@ -759,11 +807,14 @@ int main (int argc EINA_UNUSED, char **argv EINA_UNUSED)
 {
     sleep(1);
 
-    _wsc_setup(&_wsc);
+    if (!_wsc_setup (&_wsc)) {
+        _wsc_free (&_wsc);
+        return 0;
+    }
 
     ecore_main_loop_begin();
 
-    _wsc_free(&_wsc);
+    _wsc_free (&_wsc);
 
     return 0;
 }
index 32b5fde0d9e85dc7c52f4749aefef4041bbe9ea8..389242f77677fcc0fa9be95e8d4d473f010133e0 100644 (file)
@@ -398,7 +398,7 @@ static struct rectinfo get_ise_geometry ()
     } else {
         /* READ ISE's SIZE HINT HERE */
         int pos_x, pos_y, width, height;
-        
+
         // FIXME: Get the ISE's SIZE.
         pos_x = 0;
         pos_y = 0;
@@ -4083,7 +4083,7 @@ static void check_hardware_keyboard (void)
     }
 
     _config->write (ISF_CONFIG_HARDWARE_KEYBOARD_DETECT, 0);
-    
+
     //FIXME:
     String uuid, name;
     String helper_uuid  = _config->read (SCIM_CONFIG_DEFAULT_HELPER_ISE, String (""));