From: JeongHyun Kang Date: Wed, 15 Jun 2016 06:34:29 +0000 (+0900) Subject: enlightenment_info: Add module info and keygrab status X-Git-Tag: submit/tizen/20160616.140123~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=74e878aca5fadee57e59b80f1511706061e4868e;p=platform%2Fupstream%2Fenlightenment.git enlightenment_info: Add module info and keygrab status - 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 --- diff --git a/src/bin/e_info_client.c b/src/bin/e_info_client.c index f7d489bf10..18a9ee51b0 100644 --- a/src/bin/e_info_client.c +++ b/src/bin/e_info_client.c @@ -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 } }; diff --git a/src/bin/e_info_server.c b/src/bin/e_info_server.c index e731b5788b..c0a265d81c 100644 --- a/src/bin/e_info_server.c +++ b/src/bin/e_info_server.c @@ -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 } }; diff --git a/src/bin/e_info_server.h b/src/bin/e_info_server.h index 6ea1dc15fe..1f4223e8d7 100644 --- a/src/bin/e_info_server.h +++ b/src/bin/e_info_server.h @@ -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