enlightenment_info -connected_clients add 86/53286/1
authorJunghwan Choi <jhhh.choi@samsung.com>
Thu, 3 Dec 2015 09:48:28 +0000 (18:48 +0900)
committerJunghwan Choi <jhhh.choi@samsung.com>
Thu, 3 Dec 2015 09:48:28 +0000 (18:48 +0900)
Change-Id: I5d4483fc1be9e0fe73bc0c7df49bec065493b598
Signed-off-by: Junghwan Choi <jhhh.choi@samsung.com>
src/bin/e_comp.h
src/bin/e_comp_wl.c
src/bin/e_info_client.c
src/bin/e_info_server.c [changed mode: 0644->0755]

index 9eea32196e4878b7d0a2f3ed11060d00a5699415..72a699a4e764c0eda78db591c9ad1e6773e6cd10 100644 (file)
@@ -17,6 +17,7 @@ typedef struct _E_Comp_Client_Data E_Comp_Client_Data;
 #endif
 
 typedef struct _E_Comp_Demo_Style_Item E_Comp_Demo_Style_Item;
+typedef struct _E_Comp_Connected_Client_Info E_Comp_Connected_Client_Info;
 
 # define E_COMP_TYPE (int) 0xE0b01003
 
@@ -142,6 +143,8 @@ struct _E_Comp
    Eina_Bool       saver : 1;
    Eina_Bool       shape_queue_blocked : 1;
    Eina_Bool       calc_fps : 1;
+
+   Eina_List      *connected_clients;
 };
 
 
@@ -155,6 +158,14 @@ struct _E_Comp_Demo_Style_Item
    Evas_Object *client;
 };
 
+struct _E_Comp_Connected_Client_Info
+{
+   const char *name;
+   int pid;
+   int uid;
+   int gid;
+};
+
 typedef enum
 {
    E_COMP_ENGINE_NONE = 0,
index e7d18146272d16811bb5cc598c1f5dd05ba8d8b6..fbf7c3b45680bc4f02a62a7ca84aa6b5556459bf 100644 (file)
@@ -2370,6 +2370,32 @@ static const struct wl_compositor_interface _e_comp_interface =
    _e_comp_wl_compositor_cb_region_create
 };
 
+static void
+_e_comp_wl_pname_get(pid_t pid, char* name, int size)
+{
+   if (!name) return;
+
+   FILE *h;
+   char proc[512], pname[512];
+   size_t len;
+
+   snprintf(proc, 512,"/proc/%d/cmdline", pid);
+
+   h = fopen(proc, "r");
+   if (!h) return;
+
+   len = fread(pname, sizeof(char), 512, h);
+   if (len > 0)
+     {
+        if ('\n' == pname[len - 1])
+          pname[len - 1] = '\0';
+     }
+
+   fclose(h);
+
+   strncpy(name, pname, size);
+}
+
 static void
 _e_comp_wl_pname_print(pid_t pid)
 {
@@ -2416,6 +2442,26 @@ _e_comp_wl_compositor_cb_unbind(struct wl_resource *res_comp)
          (unsigned int)res_comp,
          (unsigned int)client,
          pid, uid, gid);
+
+   E_Comp *comp;
+   if ((comp = wl_resource_get_user_data(res_comp)))
+     {
+        Eina_List *l;
+        E_Comp_Connected_Client_Info *cinfo;
+        EINA_LIST_FOREACH(comp->connected_clients, l, cinfo)
+          {
+             if (cinfo->pid == pid)
+               break;
+             cinfo = NULL;
+          }
+        if (cinfo)
+          {
+             if (cinfo->name)
+               eina_stringshare_del(cinfo->name);
+             comp->connected_clients = eina_list_remove(comp->connected_clients, cinfo);
+             E_FREE(cinfo);
+          }
+     }
 }
 
 static void
@@ -2453,6 +2499,20 @@ _e_comp_wl_compositor_cb_bind(struct wl_client *client, void *data, uint32_t ver
          pid, uid, gid);
 
    _e_comp_wl_pname_print(pid);
+
+   char *name[512];
+   _e_comp_wl_pname_get(pid, name, sizeof(name));
+
+   E_Comp_Connected_Client_Info *cinfo;
+   cinfo = E_NEW(E_Comp_Connected_Client_Info, 1);
+   if (cinfo)
+     {
+        cinfo->name = eina_stringshare_add(name);
+        cinfo->pid = pid;
+        cinfo->uid = uid;
+        cinfo->gid = gid;
+        comp->connected_clients= eina_list_append(comp->connected_clients, cinfo);
+     }
 }
 
 static void
index 70fe37cd4a9e4b9921d5cb663ffbcfd89495faf6..769a8beb1252c35d7856e3f1b412e941a4350d8b 100644 (file)
@@ -402,6 +402,62 @@ _e_info_client_prop_prop_info(int argc, char **argv)
      }
 }
 
+static void
+_cb_window_proc_connected_clients_get(const Eldbus_Message *msg)
+{
+   const char *name = NULL, *text = NULL;
+   Eldbus_Message_Iter *array, *ec;
+   Eina_Bool res;
+
+   res = eldbus_message_error_get(msg, &name, &text);
+   EINA_SAFETY_ON_TRUE_GOTO(res, finish);
+
+   res = eldbus_message_arguments_get(msg, "a(ss)", &array);
+   EINA_SAFETY_ON_FALSE_GOTO(res, finish);
+
+   printf("--------------------------------------[ connected clients ]-----------------------------------------------------\n");
+   int cnt = 0;
+   while (eldbus_message_iter_get_and_next(array, 'r', &ec))
+     {
+        const char *title;
+        const char *value;
+        res = eldbus_message_iter_arguments_get(ec,
+                                                "ss",
+                                                &title,
+                                                &value);
+        if (!res)
+          {
+             printf("Failed to get connected clients info\n");
+             continue;
+          }
+
+        if (!strcmp(title, "[Connected Clients]"))
+          {
+             printf("\n[%2d] %s\n", ++cnt, value);
+          }
+        else if (!strcmp(title, "[E_Client Info]"))
+          {
+             printf("      |----- %s :: %s\n", title, value);
+          }
+     }
+
+finish:
+   if ((name) || (text))
+     {
+        printf("errname:%s errmsg:%s\n", name, text);
+     }
+}
+
+static void
+_e_info_client_proc_connected_clients(int argc, char **argv)
+{
+   if (!_e_info_client_eldbus_message("get_connected_clients", _cb_window_proc_connected_clients_get))
+     {
+        printf("_e_info_client_eldbus_message error");
+        return;
+     }
+}
+
 static struct
 {
    const char *option;
@@ -435,6 +491,11 @@ static struct
       "print window infomation",
       _e_info_client_prop_prop_info
    },
+   {
+      "connected_clients", NULL,
+      "print connected clients on Enlightenment",
+      _e_info_client_proc_connected_clients
+   },
 };
 
 static void
old mode 100644 (file)
new mode 100755 (executable)
index 6ceea2b..23e9693
@@ -90,6 +90,74 @@ _e_info_server_cb_window_info_get(const Eldbus_Service_Interface *iface EINA_UNU
    return reply;
 }
 
+static void
+_msg_connected_clients_append(Eldbus_Message_Iter *iter)
+{
+   Eldbus_Message_Iter *array_of_ec;
+   E_Client *ec;
+   Evas_Object *o;
+
+   eldbus_message_iter_arguments_append(iter, "a(ss)", &array_of_ec);
+
+   Eina_List *l;
+   E_Comp_Connected_Client_Info *cinfo;
+
+
+   Eldbus_Message_Iter* struct_of_ec;
+
+#define __CONNECTED_CLIENTS_ARG_APPEND_TYPE(title, str, x...) ({                           \
+                                                               char __temp[128] = {0,};                                                     \
+                                                               snprintf(__temp, sizeof(__temp), str, ##x);                                  \
+                                                               eldbus_message_iter_arguments_append(array_of_ec, "(ss)", &struct_of_ec);    \
+                                                               eldbus_message_iter_arguments_append(struct_of_ec, "ss", (title), (__temp)); \
+                                                               eldbus_message_iter_container_close(array_of_ec, struct_of_ec);})
+
+   EINA_LIST_FOREACH(e_comp->connected_clients, l, cinfo)
+     {
+        __CONNECTED_CLIENTS_ARG_APPEND_TYPE("[Connected Clients]", "name:%20s pid:%3d uid:%3d gid:%3d", cinfo->name ?: "NO_NAME", cinfo->pid, cinfo->uid, cinfo->gid);
+        for (o = evas_object_top_get(e_comp->evas); o; o = evas_object_below_get(o))
+          {
+             Ecore_Window win;
+             uint32_t res_id = 0;
+             pid_t pid = -1;
+
+             ec = evas_object_data_get(o, "E_Client");
+             if (!ec) continue;
+             if (e_client_util_ignored_get(ec)) continue;
+
+             win = e_client_util_win_get(ec);
+
+             if (ec->pixmap)
+               res_id = e_pixmap_res_id_get(ec->pixmap);
+#ifdef HAVE_WAYLAND_ONLY
+             if (ec->comp_data)
+               {
+                  E_Comp_Wl_Client_Data *cdata = (E_Comp_Wl_Client_Data*)ec->comp_data;
+                  if (cdata->surface)
+                    wl_client_get_credentials(wl_resource_get_client(cdata->surface), &pid, NULL, NULL);
+               }
+#endif
+             if (cinfo->pid == pid)
+               {
+                  __CONNECTED_CLIENTS_ARG_APPEND_TYPE("[E_Client Info]", "win:0x%08x res_id:%5d, name:%20s, geo:(%4d, %4d, %4dx%4d), layer:%5d, visible:%d, argb:%d",
+                                                      win, res_id, e_client_util_name_get(ec) ?: "NO_NAME", ec->x, ec->y, ec->w, ec->h, ec->layer, ec->visible, ec->argb);
+               }
+          }
+     }
+
+   eldbus_message_iter_container_close(iter, array_of_ec);
+}
+
+static Eldbus_Message *
+_e_info_server_cb_connected_clients_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
+{
+   Eldbus_Message *reply = eldbus_message_method_return_new(msg);
+
+   _msg_connected_clients_append(eldbus_message_iter_get(reply));
+
+   return reply;
+}
+
 static void
 _msg_window_prop_client_append(Eldbus_Message_Iter *iter, E_Client *target_ec)
 {
@@ -486,6 +554,7 @@ static const Eldbus_Method methods[] = {
    { "eina_log_levels", ELDBUS_ARGS({"s", "eina log levels"}), NULL, _e_info_server_cb_eina_log_levels, 0 },
    { "eina_log_path", ELDBUS_ARGS({"s", "eina log path"}), NULL, _e_info_server_cb_eina_log_path, 0 },
    { "get_window_prop", ELDBUS_ARGS({"us", "query_mode_value"}), ELDBUS_ARGS({"a(ss)", "array_of_ec"}), _e_info_server_cb_window_prop_get, 0},
+   { "get_connected_clients", NULL, ELDBUS_ARGS({"a(ss)", "array of ec"}), _e_info_server_cb_connected_clients_get, 0 },
    { NULL, NULL, NULL, NULL, 0 }
 };