Print module logs and keygrab status 20/70720/4 accepted/tizen/common/20160624.132522 accepted/tizen/ivi/20160624.064541 accepted/tizen/mobile/20160624.064319 accepted/tizen/tv/20160624.064256 accepted/tizen/wearable/20160624.064550 submit/tizen/20160624.014657
authorJeongHyun Kang <jhyuni.kang@samsung.com>
Mon, 13 Jun 2016 05:44:51 +0000 (14:44 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Fri, 24 Jun 2016 00:38:18 +0000 (17:38 -0700)
Change-Id: Idba03746c1dd8576fd7c3e65b34fc1ed3db143aa

src/e_mod_keyrouter_events.c
src/e_mod_main_wl.c
src/e_mod_main_wl.h

index 23e0824e7f6ec9e29b494e2e937d38a0e91a4b7b..e1b619fd21e501ebdf43e3dd64da48c919154cca 100644 (file)
@@ -530,3 +530,92 @@ e_keyrouter_util_get_pid(struct wl_client *client, struct wl_resource *surface)
 
    return pid;
 }
+
+char *
+e_keyrouter_util_cmd_get_from_pid(int pid)
+{
+   Eina_List *l;
+   E_Comp_Connected_Client_Info *cdata;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp, NULL);
+
+   EINA_LIST_FOREACH(e_comp->connected_clients, l, cdata)
+     {
+        if (cdata->pid == pid) return strdup(cdata->name);
+     }
+
+   return NULL;
+}
+
+typedef struct _keycode_map{
+    xkb_keysym_t keysym;
+    xkb_keycode_t keycode;
+}keycode_map;
+
+static void
+find_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, void *data)
+{
+   keycode_map *found_keycodes = (keycode_map *)data;
+   xkb_keysym_t keysym = found_keycodes->keysym;
+   int nsyms = 0;
+   const xkb_keysym_t *syms_out = NULL;
+
+   nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out);
+   if (nsyms && syms_out)
+     {
+        if (*syms_out == keysym)
+          {
+             found_keycodes->keycode = key;
+          }
+     }
+}
+
+int
+_e_keyrouter_keycode_get_from_keysym(struct xkb_keymap *keymap, xkb_keysym_t keysym)
+{
+   keycode_map found_keycodes = {0,};
+   found_keycodes.keysym = keysym;
+   xkb_keymap_key_for_each(keymap, find_keycode, &found_keycodes);
+
+   return found_keycodes.keycode;
+}
+
+int
+e_keyrouter_util_keycode_get_from_string(char * name)
+{
+   struct xkb_keymap *keymap = NULL;
+   xkb_keysym_t keysym = 0x0;
+   int keycode = 0;
+
+   keymap = e_comp_wl->xkb.keymap;
+   EINA_SAFETY_ON_NULL_GOTO(keymap, finish);
+
+   keysym = xkb_keysym_from_name(name, XKB_KEYSYM_NO_FLAGS);
+   EINA_SAFETY_ON_FALSE_GOTO(keysym != XKB_KEY_NoSymbol, finish);
+
+   keycode = _e_keyrouter_keycode_get_from_keysym(keymap, keysym);
+
+   KLDBG("request name: %s, return value: %d\n", name, keycode);
+
+   return keycode;
+
+finish:
+   return 0;
+}
+
+char *
+e_keyrouter_util_keyname_get_from_keycode(int keycode)
+{
+   struct xkb_state *state;
+   xkb_keysym_t sym = XKB_KEY_NoSymbol;
+   char name[256] = {0, };
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, NULL);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl->xkb.state, NULL);
+
+   state = e_comp_wl->xkb.state;
+   sym = xkb_state_key_get_one_sym(state, keycode);
+   xkb_keysym_get_name(sym, name, sizeof(name));
+
+   return strdup(name);
+}
index 34ce7218015fdaa8008956b65e30442f188e1f92..38636e9ec41ec4104fc3ba863dc394d9c4cb4ad5 100644 (file)
@@ -625,6 +625,210 @@ _e_keyrouter_cb_bind(struct wl_client *client, void *data, uint32_t version, uin
    wl_resource_set_implementation(resource, &_e_keyrouter_implementation, krt_instance, _e_keyrouter_cb_destory);
 }
 
+static void
+_e_keyrouter_keygrab_status_print(FILE *log_fl, Eina_List *list)
+{
+   Eina_List *l;
+   E_Keyrouter_Key_List_NodePtr kdata;
+   int pid;
+   char *cmd;
+
+   EINA_LIST_FOREACH(list, l, kdata)
+     {
+        pid = e_keyrouter_util_get_pid(kdata->wc, kdata->surface);
+        cmd = e_keyrouter_util_cmd_get_from_pid(pid);
+        fprintf(log_fl, "                [surface: %p, client: %p, pid: %d(%s)]\n", kdata->surface, kdata->wc, pid, cmd);
+        if (kdata->surface)
+          {
+             fprintf(log_fl, "                    -- Surface Information --\n");
+             fprintf(log_fl, "                        = client: %p\n", wl_resource_get_client(kdata->surface));
+             fprintf(log_fl, "                        = resource: %s(%d)\n", wl_resource_get_name(kdata->surface), wl_resource_get_id(kdata->surface));
+          }
+        else
+          {
+             fprintf(log_fl, "                    -- Client Information --\n");
+             fprintf(log_fl, "                        = connected fd: %d\n", wl_client_get_fd(kdata->wc));
+          }
+     }
+}
+
+
+static void
+_e_keyrouter_info_print(void *data, const char *log_path)
+{
+   char *keyname, *cmd;
+   int  i, c, pid, *idata;
+   FILE *log_fl;
+   Eina_List *l, *ll;
+   E_Keyrouter_Registered_Window_Info *rdata;
+
+   log_fl = fopen(log_path, "a");
+   if (!log_fl)
+     {
+        KLERR("failed: open file(%s)\n", log_path);
+        return;
+     }
+
+   setvbuf(log_fl, NULL, _IOLBF, 512);
+
+   fprintf(log_fl, "\n===== Keyrouter Information =====\n");
+   fprintf(log_fl, "    ----- Grabbable Keys -----\n");
+   for (i = 8; i < krt->max_tizen_hwkeys; i++)
+     {
+        if (!krt->HardKeys[i].keycode) continue;
+
+        keyname = e_keyrouter_util_keyname_get_from_keycode(i);
+
+        fprintf(log_fl, "         Key [%3d], Keyname: %s\n", i, keyname);
+
+        free(keyname);
+        keyname = NULL;
+     }
+   fprintf(log_fl, "    ----- End -----\n\n");
+
+   fprintf(log_fl, "    ----- Register Window List -----\n");
+   EINA_LIST_FOREACH(krt->registered_window_list, l, rdata)
+     {
+        pid = e_keyrouter_util_get_pid(NULL, rdata->surface);
+        cmd = e_keyrouter_util_cmd_get_from_pid(pid);
+        fprintf(log_fl, "        [ surface: %p, client: %p, pid: %d(%s) ]\n",
+                         rdata->surface, wl_resource_get_client(rdata->surface), pid, cmd);
+        free(cmd);
+        cmd = NULL;
+        c = 0;
+        EINA_LIST_FOREACH(rdata->keys, ll, idata)
+          {
+             keyname = e_keyrouter_util_keyname_get_from_keycode(*idata);
+             if (c == 0)
+               fprintf(log_fl, "            registered key: Key [%3d], Keyname: %s\n", *idata, keyname);
+             else
+               fprintf(log_fl, "                            Key [%3d], Keyname: %s\n", *idata, keyname);
+             c++;
+             free(keyname);
+             keyname = NULL;
+          }
+     }
+   fprintf(log_fl, "    ----- End -----\n\n");
+
+   fclose(log_fl);
+   log_fl = NULL;
+}
+
+static void
+_e_keyrouter_keygrab_print(void *data, const char *log_path)
+{
+   Eina_List *l;
+   E_Keyrouter_Key_List_NodePtr kdata;
+   E_Client *ec_focus;
+   struct wl_resource *surface_focus;
+   struct wl_client *wc_focus;
+   int pid_focus, pid, i;
+   char *cmd_focus, *cmd, *keyname;
+   FILE *log_fl;
+
+   (void) data;
+
+   log_fl = fopen(log_path, "a");
+   if (!log_fl)
+     {
+        KLERR("failed: open file(%s)\n", log_path);
+        return;
+     }
+
+   setvbuf(log_fl, NULL, _IOLBF, 512);
+
+   fprintf(log_fl, "\n===== Keygrab Status =====\n");
+
+   ec_focus = e_client_focused_get();
+   fprintf(log_fl, "    ----- Focus Window Info -----\n");
+   if (ec_focus)
+     {
+        surface_focus = e_keyrouter_util_get_surface_from_eclient(ec_focus);
+        wc_focus = wl_resource_get_client(surface_focus);
+        pid_focus = e_keyrouter_util_get_pid(NULL, surface_focus);
+        cmd_focus = e_keyrouter_util_cmd_get_from_pid(pid_focus);
+
+        fprintf(log_fl, "        Focus Client: E_Client: %p\n", ec_focus);
+        fprintf(log_fl, "                      Surface: %p, Client: %p\n", surface_focus, wc_focus);
+        fprintf(log_fl, "                      pid: %d, cmd: %s\n", pid_focus, cmd_focus);
+        free(cmd_focus);
+     }
+   else
+     {
+        fprintf(log_fl, "        No Focus Client\n");
+     }
+   fprintf(log_fl, "    ----- End -----\n\n");
+
+   fprintf(log_fl, "    ----- Grabbed keys Info -----\n");
+   for (i = 8; i < krt->max_tizen_hwkeys; i++)
+     {
+        if (!krt->HardKeys[i].keycode) continue;
+        if (!krt->HardKeys[i].excl_ptr &&
+            !krt->HardKeys[i].or_excl_ptr &&
+            !krt->HardKeys[i].top_ptr &&
+            !krt->HardKeys[i].shared_ptr &&
+            !krt->HardKeys[i].registered_ptr)
+          continue;
+
+        keyname = e_keyrouter_util_keyname_get_from_keycode(i);
+
+        fprintf(log_fl, "        [ Keycode: %d, Keyname: %s ]\n", i, keyname);
+
+        free(keyname);
+        keyname = NULL;
+
+        if (krt->HardKeys[i].excl_ptr)
+          {
+             fprintf(log_fl, "            == Exclusive Grab ==\n");
+             EINA_LIST_FOREACH(krt->HardKeys[i].excl_ptr, l, kdata)
+               {
+                  pid = e_keyrouter_util_get_pid(kdata->wc, kdata->surface);
+                  cmd = e_keyrouter_util_cmd_get_from_pid(pid);
+                  fprintf(log_fl, "                [surface: %p, client: %p, pid: %d(%s)]\n", kdata->surface, kdata->wc, pid, cmd);
+                  free(cmd);
+                  cmd = NULL;
+                  if (kdata->surface)
+                    {
+                       fprintf(log_fl, "                    -- Surface Information --\n");
+                       fprintf(log_fl, "                        = wl_client: %p\n", wl_resource_get_client(kdata->surface));
+                       fprintf(log_fl, "                        = resource: %s(%d)\n", wl_resource_get_name(kdata->surface), wl_resource_get_id(kdata->surface));
+                    }
+                  else
+                    {
+                       fprintf(log_fl, "                    -- Client Information --\n");
+                       fprintf(log_fl, "                        = connected fd: %d\n", wl_client_get_fd(kdata->wc));
+                    }
+                  break;
+               }
+            }
+
+        if (krt->HardKeys[i].or_excl_ptr)
+          {
+             fprintf(log_fl, "            == Overidable Exclusive Grab ==\n");
+             _e_keyrouter_keygrab_status_print(log_fl, krt->HardKeys[i].or_excl_ptr);
+          }
+
+        if (krt->HardKeys[i].top_ptr)
+          {
+             fprintf(log_fl, "            == Top Position Grab ==\n");
+             _e_keyrouter_keygrab_status_print(log_fl, krt->HardKeys[i].top_ptr);
+          }
+
+        if (krt->HardKeys[i].shared_ptr)
+          {
+             fprintf(log_fl, "            == Shared Grab ==\n");
+             _e_keyrouter_keygrab_status_print(log_fl, krt->HardKeys[i].shared_ptr);
+          }
+
+        fprintf(log_fl, "\n");
+     }
+
+   fprintf(log_fl, "    ----- End -----\n\n");
+
+   fclose(log_fl);
+   log_fl = NULL;
+}
+
 static Eina_Bool
 _event_filter(void *data, void *loop_data EINA_UNUSED, int type, void *event)
 {
@@ -923,6 +1127,9 @@ _e_keyrouter_deinit_handlers(void)
 
    EINA_LIST_FREE(krt->handlers, h)
      ecore_event_handler_del(h);
+
+   e_info_server_hook_set("keyrouter", NULL, NULL);
+   e_info_server_hook_set("keygrab", NULL, NULL);
 }
 
 static void
@@ -930,6 +1137,9 @@ _e_keyrouter_init_handlers(void)
 {
    E_LIST_HANDLER_APPEND(krt->handlers, E_EVENT_CLIENT_STACK, _e_keyrouter_client_cb_stack, NULL);
    E_LIST_HANDLER_APPEND(krt->handlers, E_EVENT_CLIENT_REMOVE, _e_keyrouter_client_cb_remove, NULL);
+
+   e_info_server_hook_set("keyrouter", _e_keyrouter_info_print, NULL);
+   e_info_server_hook_set("keygrab", _e_keyrouter_keygrab_print, NULL);
 }
 
 static Eina_Bool
index d8159ab56dc7fe08dff6e5684d12e18ef76d7df1..972f85c195ce9c4f2f49d9f7473dfb09a1b8fc3c 100644 (file)
@@ -181,6 +181,9 @@ Eina_Bool IsInvisibleGetWindow(struct wl_resource *surface);
 
 struct wl_resource *e_keyrouter_util_get_surface_from_eclient(E_Client *client);
 int e_keyrouter_util_get_pid(struct wl_client *client, struct wl_resource *surface);
+char *e_keyrouter_util_cmd_get_from_pid(int pid);
+int e_keyrouter_util_keycode_get_from_string(char *name);
+char *e_keyrouter_util_keyname_get_from_keycode(int keycode);
 
 void e_keyrouter_conf_init(E_Keyrouter_Config_Data *kconfig);
 void e_keyrouter_conf_deinit(E_Keyrouter_Config_Data *kconfig);