enlightenment_info: Add module info and keygrab status 18/70718/6
authorJeongHyun Kang <jhyuni.kang@samsung.com>
Wed, 15 Jun 2016 06:34:29 +0000 (15:34 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Wed, 15 Jun 2016 06:49:05 +0000 (23:49 -0700)
  - Module info: If a module want to print logs, a module add a info callback
                 and enlightenment_info call requested module's callback

Change-Id: Id2237521e7574edae0310ededc93119c9a70542e

src/bin/e_info_client.c
src/bin/e_info_server.c
src/bin/e_info_server.h

index f7d489bf10ed90f7db90d16e1abd2a0940ea8147..18a9ee51b07a2ac9fbacf9f37c8af69b11050469 100644 (file)
@@ -476,6 +476,64 @@ _e_info_client_proc_keymap_info(int argc, char **argv)
       return;
 }
 
+static void
+_e_info_client_proc_module_info(int argc, char **argv)
+{
+   char fd_name[PATH_MAX];
+   int pid;
+
+   if (argc != 3 || !argv[2])
+     {
+        printf("Usage> enlightenment_info -module_info [module name]\n");
+        return;
+     }
+
+   pid = getpid();
+
+   snprintf(fd_name, PATH_MAX, "/proc/%d/fd/1", pid);
+
+   if (!_e_info_client_eldbus_message_with_args("get_module_info", NULL, "ss", argv[2], fd_name))
+     return;
+}
+
+static void
+_e_info_client_proc_keygrab_status(int argc, char **argv)
+{
+   char fd_name[PATH_MAX];
+   int pid;
+   char cwd[PATH_MAX];
+
+   if (argc != 3 || !argv[2])
+     {
+        printf("Usage> enlightenment_info -keygrab_status [console | file path]\n");
+        return;
+     }
+
+   pid = getpid();
+
+   cwd[0] = '\0';
+   if (!getcwd(cwd, sizeof(cwd)))
+     snprintf(cwd, sizeof(cwd), "/tmp");
+
+   if (!strncmp(argv[2], "console", sizeof("console")))
+     snprintf(fd_name, PATH_MAX, "/proc/%d/fd/1", pid);
+   else
+     {
+        if (argv[2][0] == '/')
+          snprintf(fd_name, PATH_MAX, "%s", argv[2]);
+        else
+          {
+             if (strlen(cwd) > 0)
+               snprintf(fd_name, PATH_MAX, "%s/%s", cwd, argv[2]);
+             else
+               snprintf(fd_name, PATH_MAX, "%s", argv[2]);
+          }
+     }
+
+   if (!_e_info_client_eldbus_message_with_args("get_keygrab_status", NULL, "s", fd_name))
+     return;
+}
+
 static char *
 _directory_make(char *path)
 {
@@ -1328,6 +1386,16 @@ static struct
       "[on: 1, off: 0]",
       "On/Off the window effect",
       _e_info_client_proc_effect_control
+   },
+   {
+      "keygrab_status", NULL,
+      "Print a keygrab status",
+      _e_info_client_proc_keygrab_status
+   },
+   {
+      "module_info", NULL,
+      "Print information maintained by extra modules",
+      _e_info_client_proc_module_info
    }
 };
 
index e731b5788b6bfe61f46de3dcb1aec5eaaf0ae3c3..c0a265d81c86a075ecc89f6fe4eade479deaca30 100644 (file)
@@ -62,6 +62,9 @@ static int           e_info_dump_count;
 //FILE pointer for protocol_trace
 static FILE *log_fp_ptrace = NULL;
 
+// Module list for module info
+static Eina_List *module_hook = NULL;
+
 #define BUF_SNPRINTF(fmt, ARG...) do { \
    str_l = snprintf(str_buff, str_r, fmt, ##ARG); \
    str_buff += str_l; \
@@ -1082,6 +1085,93 @@ _e_info_server_cb_keymap_info_get(const Eldbus_Service_Interface *iface EINA_UNU
    return reply;
 }
 
+static void
+_e_info_server_hook_call(const char *module_name, const char *log_path)
+{
+   Eina_List *l;
+   E_Info_Hook *data;
+
+   EINA_LIST_FOREACH(module_hook, l, data)
+     {
+        if (!strncmp(data->module_name, module_name, strlen(module_name)))
+          {
+             data->func(data->data, log_path);
+             break;
+          }
+     }
+}
+
+E_API void
+e_info_server_hook_set(const char *module_name, E_Info_Hook_Cb func, void *data)
+{
+   Eina_List *l, *l_next;
+   E_Info_Hook *hdata, *ndata;
+
+   EINA_SAFETY_ON_NULL_RETURN(module_name);
+
+   EINA_LIST_FOREACH_SAFE(module_hook, l, l_next, hdata)
+     {
+        if (!strncmp(hdata->module_name, module_name, strlen(module_name)))
+          {
+             if (!func)
+               {
+                  eina_stringshare_del(hdata->module_name);
+                  E_FREE(hdata);
+                  module_hook = eina_list_remove_list(module_hook, l);
+               }
+             else
+               {
+                  hdata->func = func;
+                  hdata->data = data;
+               }
+             return;
+          }
+     }
+
+   ndata = E_NEW(E_Info_Hook, 1);
+   EINA_SAFETY_ON_NULL_RETURN(ndata);
+
+   ndata->module_name = eina_stringshare_add(module_name);
+   ndata->func = func;
+   ndata->data = data;
+
+   module_hook = eina_list_append(module_hook, ndata);
+}
+
+static Eldbus_Message *
+_e_info_server_cb_module_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
+{
+   Eldbus_Message *reply = eldbus_message_method_return_new(msg);
+   const char *path = NULL, *module_name = NULL;
+
+   if (!eldbus_message_arguments_get(msg, "ss", &module_name, &path) || !module_name || !path)
+     {
+        ERR("Error getting arguments.");
+        return reply;
+     }
+
+   _e_info_server_hook_call(module_name, path);
+
+   return reply;
+}
+
+static Eldbus_Message *
+_e_info_server_cb_keygrab_status_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
+{
+   Eldbus_Message *reply = eldbus_message_method_return_new(msg);
+   const char *path = NULL;
+
+   if (!eldbus_message_arguments_get(msg, "s", &path) || !path)
+     {
+        ERR("Error getting arguments.");
+        return reply;
+     }
+
+   _e_info_server_hook_call("keygrab", path);
+
+   return reply;
+}
+
 static Eldbus_Message *
 _e_info_server_cb_fps_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
 {
@@ -1417,6 +1507,8 @@ static const Eldbus_Method methods[] = {
 #endif
    { "get_keymap", NULL, ELDBUS_ARGS({"hi", "keymap fd"}), _e_info_server_cb_keymap_info_get, 0},
    { "effect_control", ELDBUS_ARGS({"i", "effect_control"}), NULL, e_info_server_cb_effect_control, 0},
+   { "get_keygrab_status", ELDBUS_ARGS({"s", "get_keygrab_status"}), NULL, _e_info_server_cb_keygrab_status_get, 0},
+   { "get_module_info", ELDBUS_ARGS({"ss", "get_module_info"}), NULL, _e_info_server_cb_module_info_get, 0},
    { NULL, NULL, NULL, NULL, 0 }
 };
 
index 6ea1dc15fe4c2d814626716768a74f73f4ca0407..1f4223e8d7518b365ce5d42e0bf6251cc9ff9da8 100644 (file)
@@ -1,4 +1,6 @@
 #ifdef E_TYPEDEFS
+typedef void (*E_Info_Hook_Cb)(void *data, const char *log_path);
+typedef struct _E_Info_Hook E_Info_Hook;
 #else
 #ifndef E_INFO_SERVER_H
 #define E_INFO_SERVER_H
@@ -16,6 +18,8 @@ struct E_Event_Info_Rotation_Message
 
 E_API extern int E_EVENT_INFO_ROTATION_MESSAGE;
 
+E_API void e_info_server_hook_set(const char *module_name, E_Info_Hook_Cb func, void *data);
+
 EINTERN int e_info_server_init(void);
 EINTERN int e_info_server_shutdown(void);
 
@@ -46,5 +50,12 @@ struct argument_details {
    int nullable;
 };
 
+struct _E_Info_Hook
+{
+   const char *module_name;
+   E_Info_Hook_Cb func;
+   void *data;
+};
+
 #endif
 #endif