The list command shows the list of the wayland-tbm clients.
Change-Id: Iec64ba0c9d5ce7b0f9f7a6ad622fa184b4fa7b28
$(WL_TBM_SERVER_LIBS)
libwayland_tbm_server_la_SOURCES = \
wayland-tbm-client.c \
- wayland-tbm-server.c
+ wayland-tbm-server.c \
+ wayland-tbm-util.c
nodist_libwayland_tbm_server_la_SOURCES = \
wayland-tbm-server-protocol.h \
$(WL_TBM_COMMON_LIBS) \
$(WL_TBM_CLIENT_LIBS)
libwayland_tbm_client_la_SOURCES = \
- wayland-tbm-client.c
+ wayland-tbm-client.c \
+ wayland-tbm-util.c
nodist_libwayland_tbm_client_la_SOURCES = \
wayland-tbm-client-protocol.h \
#include "wayland-tbm-client.h"
-#define WL_TBM_LOG(...) fprintf (stderr, __VA_ARGS__)
+#define WL_TBM_DEBUG(fmt, ...) fprintf (stderr, "[WL_TBM:DEBUG(%d)] " fmt, getpid(), ##__VA_ARGS__)
+#define WL_TBM_C_LOG(fmt, ...) fprintf (stderr, "[WL_TBM_C(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
+#define WL_TBM_S_LOG(fmt, ...) fprintf (stderr, "[WL_TBM_S(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
+#define WL_TBM_LOG(fmt, ...) fprintf (stderr, "[WL_TBM(%d)] " fmt, getpid(), ##__VA_ARGS__)
/* check condition */
#define WL_TBM_RETURN_IF_FAIL(cond) {\
typedef enum
{
+ WL_TBM_MONITOR_COMMAND_LIST,
WL_TBM_MONITOR_COMMAND_SHOW,
WL_TBM_MONITOR_COMMAND_TRACE,
} WL_TBM_MONITOR_COMMAND;
uint32_t _wayland_tbm_client_get_embedded_capability(struct wayland_tbm_client *tbm_client);
const char *_wayland_tbm_client_get_embedded_device_name(struct wayland_tbm_client *tbm_client);
+void _wayland_tbm_util_get_appname_brief(char *brief);
+void _wayland_tbm_util_get_appname_from_pid(long pid, char *str);
+
#ifdef __cplusplus
}
#endif
struct wayland_tbm_client_resource {
struct wl_resource *resource;
pid_t pid;
+ char *app_name;
struct wl_list link;
};
{
struct wayland_tbm_server *tbm_srv = wl_resource_get_user_data(resource);
struct wayland_tbm_client_resource *c_res = NULL, *tmp_res;
+ int i = 0;
#ifdef WL_TBM_SERVER_DEBUG
WL_TBM_LOG("[%s]: command=%d, trace_command=%d, target=%d, pid=%d.\n", __func__,
command, trace_command, target, pid);
#endif
+ if (command == WL_TBM_MONITOR_COMMAND_LIST) {
+ WL_TBM_DEBUG("================== app list =======================\n");
+ WL_TBM_DEBUG("no pid app_name\n");
+
+ if (!wl_list_empty(&tbm_srv->client_resource_list)) {
+ wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->client_resource_list, link) {
+ /* skip the requestor (wayland-tbm-monitor */
+ if (c_res->resource == resource)
+ continue;
+
+ if (!c_res->app_name) {
+ c_res->app_name = (char*) calloc(1, 255*sizeof(char));
+
+ _wayland_tbm_util_get_appname_from_pid(c_res->pid, c_res->app_name);
+ _wayland_tbm_util_get_appname_brief(c_res->app_name);
+ }
+
+ WL_TBM_DEBUG("%-3d%-5d%s\n", ++i, c_res->pid, c_res->app_name);
+ }
+ }
+
+ WL_TBM_DEBUG("======================================================\n");
+
+ return;
+ }
+
if (target == WL_TBM_MONITOR_TARGET_CLIENT) {
if (pid < 1) {
wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT, "invalid format");
if (!wl_list_empty(&tbm_srv->client_resource_list)) {
wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->client_resource_list, link) {
if (c_res->resource == resource) {
+#ifdef WL_TBM_SERVER_DEBUG
WL_TBM_LOG("[%s]: resource,%p pid,%d \n", __func__, c_res->resource, c_res->pid);
-
+#endif
wl_list_remove(&c_res->link);
+ if (c_res->app_name)
+ free(c_res->app_name);
+ free(c_res);
break;
}
}
tbm_srv = wl_resource_get_user_data(resource);
wl_client_get_credentials(client, &pid, &uid, &gid);
+#ifdef WL_TBM_SERVER_DEBUG
WL_TBM_LOG("[%s]: resource,%p pid,%d \n", __func__, resource, pid);
+#endif
c_res = calloc (1, sizeof(struct wayland_tbm_client_resource));
c_res->pid = pid;
--- /dev/null
+/*
+Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact:
+ SooChan Lim <sc1.lim@samsung.com>,
+ Sangjin Lee <lsj119@samsung.com>,
+ Boram Park <boram1288.park@samsung.com>,
+ Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "wayland-tbm-int.h"
+
+void
+_wayland_tbm_util_get_appname_brief(char *brief)
+{
+ char delim[] = "/";
+ char *token = NULL;
+ char temp[255] = {0,};
+ char *saveptr = NULL;
+
+ token = strtok_r(brief, delim, &saveptr);
+
+ while (token != NULL) {
+ memset(temp, 0x00, 255*sizeof(char));
+ strncpy(temp, token, 254*sizeof(char));
+ token = strtok_r(NULL, delim, &saveptr);
+ }
+
+ snprintf(brief, sizeof(temp), "%s", temp);
+}
+
+void
+_wayland_tbm_util_get_appname_from_pid(long pid, char *str)
+{
+ FILE* fp;
+ int len;
+ long app_pid = pid;
+ char fn_cmdline[255] = {0,};
+ char cmdline[255] = {0,};
+
+ snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline",app_pid);
+
+ fp = fopen(fn_cmdline, "r");
+ if(fp == 0) {
+ fprintf(stderr,"cannot file open /proc/%ld/cmdline", app_pid);
+ return;
+ }
+
+ if (!fgets(cmdline, 255, fp)) {
+ fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid);
+ fclose(fp);
+ return;
+ }
+ fclose(fp);
+
+ len = strlen(cmdline);
+ if(len < 1)
+ memset(cmdline, 0x00,255);
+ else
+ cmdline[len] = 0;
+
+ snprintf(str, sizeof(cmdline), "%s", cmdline);
+}
+
}
static void
+_wl_tbm_list_usage()
+{
+ WL_TBM_LOG(" list : list the wayland-tbm client\n");
+ WL_TBM_LOG(" list usage : wayland-tbm-monitor list\n");
+ WL_TBM_LOG("\n");
+}
+
+static void
_wl_tbm_usage()
{
WL_TBM_LOG("wayland-tbm-monitor : show/trace the infomation of tbm_bo in clietns and in server.\n");
+ _wl_tbm_list_usage();
_wl_tbm_show_usage();
_wl_tbm_trace_usage();
WL_TBM_LOG("\n");
return 0;
}
- if (!strncmp(argv[1], "show", 4)) {
+ if (!strncmp(argv[1], "list", 4)) {
+ tbm_monitor->options.command = WL_TBM_MONITOR_COMMAND_LIST;
+ } else if (!strncmp(argv[1], "show", 4)) {
if (argc < 3) {
_wl_tbm_show_usage();
return 0;
tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_REGISTER;
if (_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)){
+ WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
_wl_tbm_trace_usage();
return 0;
}
tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_UNREGISTER;
if (_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)){
+ WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
_wl_tbm_trace_usage();
return 0;
}
WL_TBM_RETURN_VAL_IF_FAIL(tbm_monitor != NULL, -1);
ret = _wl_tbm_monitor_process_options(tbm_monitor, argc, argv);
- WL_TBM_GOTO_IF_FAIL(ret != 0, finish);
+ if (!ret) {
+ goto finish;
+ }
tbm_monitor->dpy = wl_display_connect(NULL);
WL_TBM_GOTO_IF_FAIL(tbm_monitor->dpy != NULL, finish);