client: separate waylad-tbm-monitor from wayalnd-tbm-client 26/207326/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Mon, 3 Jun 2019 07:34:50 +0000 (16:34 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Mon, 3 Jun 2019 08:02:05 +0000 (17:02 +0900)
Change-Id: I7e7ad7e13ff63f833e1777f85d435155b4385b6e

src/Makefile.am
src/wayland-tbm-client.c
src/wayland-tbm-int.h
src/wayland-tbm-monitor-client.c [new file with mode: 0644]

index 7c9441d..a135a4f 100644 (file)
@@ -48,6 +48,7 @@ libwayland_tbm_client_la_LIBADD = \
        $(WL_TBM_CLIENT_LIBS)
 libwayland_tbm_client_la_SOURCES = \
        wayland-tbm-client.c \
+       wayland-tbm-monitor-client.c \
        wayland-tbm-util.c
 
 nodist_libwayland_tbm_client_la_SOURCES =              \
index 222eae8..97cdfcf 100644 (file)
@@ -102,8 +102,6 @@ struct wayland_tbm_surface_queue {
        pthread_mutex_t lock;
 };
 
-static struct wl_tbm_monitor *tbm_monitor;
-
 #define DEBUG_TRACE
 #ifdef DEBUG_TRACE
 #define WL_TBM_TRACE(fmt, ...)   if (bTrace) WL_TBM_C_LOG(fmt, ##__VA_ARGS__)
@@ -266,187 +264,6 @@ static const struct wl_tbm_listener wl_tbm_client_listener = {
        handle_buffer_destroy,
 };
 
-void _waylend_tbm_monitor_client_print_show_to_file(char* show_str)
-{
-       FILE * f = NULL;
-       static int c = 0;
-       char tmp_file[256];
-
-       snprintf(tmp_file, sizeof(tmp_file), "/tmp/tbm_debug_show_%d%d", getpid(), c++);
-       if ((f = fopen(tmp_file, "a+")) != NULL) {
-               WL_TBM_LOG_E("fail to open tmp_file.");
-               fprintf(f, "%s", show_str);
-               fclose(f);
-       }
-}
-
-void _waylend_tbm_monitor_client_show(int argc, char *argv[],
-                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
-{
-       struct wayland_tbm_monitor_path path = {0};
-       char *show_str;
-
-       _wayland_tbm_util_show_path_parse(argv[2], 0, &path);
-
-       if (path.dlog)
-               tbm_bufmgr_debug_show(tbm_client->bufmgr);
-
-       /* we have to save result to some file as reply can be very long */
-       show_str = tbm_bufmgr_debug_tbm_info_get(tbm_client->bufmgr);
-       if (show_str) {
-               _waylend_tbm_monitor_client_print_show_to_file(show_str);
-               free(show_str);
-       }
-
-
-       /* send empty string to close the session */
-       WL_TBM_MONITOR_SNPRINTF(reply, *len, "\n");
-}
-
-void _waylend_tbm_monitor_client_dump_snapshot(int argc, char *argv[],
-                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
-{
-       double scale = 0;
-       int i;
-       char *path = NULL;
-
-       for (i = 1; i < argc; i++) {
-               if (_waylend_tbm_util_scale_parse(argv[i], &scale))
-                       break;
-       }
-
-       path = _wayland_tbm_dump_directory_make();
-       _waylend_tbm_util_dump_snapshot(tbm_client->bufmgr, scale, path);
-       WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): snapshot dump is done. path=%s\n", getpid(), path);
-       free(path);
-}
-
-void _waylend_tbm_monitor_client_dump_queue(int argc, char *argv[],
-                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
-{
-       int st;
-       double scale = 0;
-       int i;
-
-       st = _waylend_tbm_util_proc_state_parse(argv[1]);
-
-       for (i = 2; i < argc; i++) {
-               if (_waylend_tbm_util_scale_parse(argv[i], &scale))
-                       break;
-       }
-
-       st = _waylend_tbm_util_dump_queue(st, tbm_client->bufmgr, scale);
-       WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): queue dump state: %s\n", getpid(),
-                                                       st ? "on" : "off");
-}
-
-void _waylend_tbm_monitor_client_trace(int argc, char *argv[],
-                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
-{
-       int st;
-
-       st = _waylend_tbm_util_trace(_waylend_tbm_util_proc_state_parse(argv[1]),
-                                                               _waylend_tbm_util_resource_parse(argv[2]),
-                                                               tbm_client->bufmgr);
-       WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): trace state: %s\n", getpid() ,
-                                                       st ? "on" : "off");
-}
-
-void _waylend_tbm_monitor_client_debug_level(int argc, char *argv[],
-                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
-{
-       int debug_level = TBM_LOG_LEVEL_NONE;
-       int i;
-
-       for (i = 1; i < argc; i++) {
-               if (_waylend_tbm_util_debug_level_parse(argv[i], &debug_level))
-                       break;
-       }
-
-       _waylend_tbm_util_set_log_level(debug_level);
-       WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): set tbm_log debug_level(%d)\n", getpid(), debug_level);
-}
-
-static struct {
-       const char *opt;
-       void (*func)(int argc, char *argv[], char *reply, int *len, struct wayland_tbm_client *tbm_client);
-} option_proc[] = {
-       {
-               "show",
-               _waylend_tbm_monitor_client_show,
-       },
-       {
-               "dump_snapshot",
-               _waylend_tbm_monitor_client_dump_snapshot,
-       },
-       {
-               "dump_queue",
-               _waylend_tbm_monitor_client_dump_queue,
-       },
-       {
-               "trace",
-               _waylend_tbm_monitor_client_trace,
-       },
-       {
-               "debug_level",
-               _waylend_tbm_monitor_client_debug_level,
-       },
-};
-
-static void
-handle_tbm_monitor_client_done(void *data, struct wl_tbm_monitor *wl_tbm_monitor, const char *message)
-{
-}
-
-static void
-handle_tbm_monitor_client_request_to_client(void *data, struct wl_tbm_monitor *wl_tbm_monitor,
-                               const char * options, const char * request_id)
-{
-       struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
-       char temp[1024];
-       char *argv[WL_TBM_MONITOR_ARGS_MAX] = {0};
-       int argc = 0;
-
-       char message[WL_TBM_MONITOR_REPLY_MSG_LEN] = {0,};
-       int len = sizeof(message);
-       char *reply = message;
-
-       char *end = NULL;
-       int i;
-
-       snprintf(temp, sizeof(temp), "%s", options);
-
-       argv[argc] = strtok_r(temp, " ", &end);
-       while (argv[argc]) {
-               argc++;
-               if (argc == WL_TBM_MONITOR_ARGS_MAX)
-                       break;
-               argv[argc] = strtok_r(NULL, " ", &end);
-       }
-
-#ifdef DEBUG_TRACE
-       WL_TBM_TRACE("receive request_id:%s argc:%d [%s %s] options:'%s'", request_id, argc, argv[0], argv[1], temp);
-#endif
-
-       if (argc > 0) {
-               for (i = 0; i < sizeof(option_proc) / sizeof(option_proc[0]); i++) {
-                       if (argv[0][0] == '-' && !strncmp(argv[0] + 1, option_proc[i].opt, 32)) {
-                               if (option_proc[i].func) {
-                                       option_proc[i].func(argc, argv, reply, &len, tbm_client);
-                                       break;
-                               }
-                       }
-               }
-       }
-
-       wl_tbm_monitor_responce_to_server(tbm_monitor, message, request_id);
-}
-
-static const struct wl_tbm_monitor_listener wl_tbm_monitor_listener = {
-               handle_tbm_monitor_client_done,
-               handle_tbm_monitor_client_request_to_client,
-};
-
 static void
 _wayland_tbm_client_registry_handle_global(void *data,
                                struct wl_registry *registry, uint32_t name,
@@ -471,16 +288,8 @@ _wayland_tbm_client_registry_handle_global(void *data,
                        }
                }
        } else if (!strcmp(interface, "wl_tbm_monitor")) {
-               /*Create wl_monotor proxy by sington*/
-               if (tbm_monitor)
-                       return;
-
-               tbm_monitor = wl_registry_bind(registry, name, &wl_tbm_monitor_interface, version);
-               WL_TBM_RETURN_IF_FAIL(tbm_monitor != NULL);
-
-               wl_proxy_set_queue((struct wl_proxy *)tbm_monitor, NULL);
-
-               wl_tbm_monitor_add_listener(tbm_monitor, &wl_tbm_monitor_listener, tbm_client);
+               if (!wayland_tbm_monitor_client_init(tbm_client, registry, name, version))
+                       WL_TBM_LOG_E("fail to wayland_tbm_monitor_client_init");
        }
 }
 
@@ -597,11 +406,7 @@ wayland_tbm_client_deinit(struct wayland_tbm_client *tbm_client)
                wl_tbm_destroy(tbm_client->wl_tbm);
        }
 
-       if (tbm_monitor
-               && (tbm_client == wl_tbm_monitor_get_user_data(tbm_monitor))) {
-               wl_tbm_monitor_destroy(tbm_monitor);
-               tbm_monitor = NULL;
-       }
+       wayland_tbm_monitor_client_deinit(tbm_client);
 
        wl_list_remove(&tbm_client->queue_info_list);
 
@@ -1399,7 +1204,6 @@ _wayland_tbm_client_find_queue_info_queue(struct wayland_tbm_client *tbm_client,
        return NULL;
 }
 
-
 static void
 _handle_tbm_surface_queue_destroy_notify(tbm_surface_queue_h surface_queue,
                void *data)
index 57c4185..9de3ccb 100644 (file)
@@ -37,6 +37,7 @@ extern "C" {
 #include <tbm_bufmgr.h>
 #include <wayland-util.h>
 #include <tbm_log.h>
+#include <wayland-tbm-client.h>
 
 #define HAVE_DLOG
 #ifdef HAVE_DLOG
@@ -220,9 +221,15 @@ _wayland_tbm_dump_directory_make(void);
 void
 _waylend_tbm_util_set_log_level(int debug_level);
 
+int
+wayland_tbm_monitor_server_init(struct wayland_tbm_server *tbm_srv);
 
-int wayland_tbm_monitor_server_init(struct wayland_tbm_server *tbm_srv);
+int
+wayland_tbm_monitor_client_init(struct wayland_tbm_client *tbm_client,
+       struct wl_registry *registry, uint32_t name, uint32_t version);
 
+void
+wayland_tbm_monitor_client_deinit(struct wayland_tbm_client *tbm_client);
 #ifdef  __cplusplus
 }
 #endif
diff --git a/src/wayland-tbm-monitor-client.c b/src/wayland-tbm-monitor-client.c
new file mode 100644 (file)
index 0000000..53f9b3b
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+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>
+      Roman Marchenko <r.marchenko@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 "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "wayland-tbm-client.h"
+#include "wayland-tbm-client-protocol.h"
+#include "wayland-tbm-int.h"
+
+static struct wl_tbm_monitor *tbm_monitor;
+
+void _waylend_tbm_monitor_client_print_show_to_file(char* show_str)
+{
+       FILE * f = NULL;
+       static int c = 0;
+       char tmp_file[256];
+
+       snprintf(tmp_file, sizeof(tmp_file), "/tmp/tbm_debug_show_%d%d", getpid(), c++);
+       if ((f = fopen(tmp_file, "a+")) != NULL) {
+               WL_TBM_LOG_E("fail to open tmp_file.");
+               fprintf(f, "%s", show_str);
+               fclose(f);
+       }
+}
+
+void _waylend_tbm_monitor_client_show(int argc, char *argv[],
+                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
+{
+       struct wayland_tbm_monitor_path path = {0};
+       char *show_str;
+
+       _wayland_tbm_util_show_path_parse(argv[2], 0, &path);
+
+       if (path.dlog)
+               tbm_bufmgr_debug_show((tbm_bufmgr)wayland_tbm_client_get_bufmgr(tbm_client));
+
+       /* we have to save result to some file as reply can be very long */
+       show_str = tbm_bufmgr_debug_tbm_info_get((tbm_bufmgr)wayland_tbm_client_get_bufmgr(tbm_client));
+       if (show_str) {
+               _waylend_tbm_monitor_client_print_show_to_file(show_str);
+               free(show_str);
+       }
+
+       /* send empty string to close the session */
+       WL_TBM_MONITOR_SNPRINTF(reply, *len, "\n");
+}
+
+void _waylend_tbm_monitor_client_dump_snapshot(int argc, char *argv[],
+                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
+{
+       double scale = 0;
+       int i;
+       char *path = NULL;
+
+       for (i = 1; i < argc; i++) {
+               if (_waylend_tbm_util_scale_parse(argv[i], &scale))
+                       break;
+       }
+
+       path = _wayland_tbm_dump_directory_make();
+       _waylend_tbm_util_dump_snapshot((tbm_bufmgr)wayland_tbm_client_get_bufmgr(tbm_client), scale, path);
+       WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): snapshot dump is done. path=%s\n", getpid(), path);
+       free(path);
+}
+
+void _waylend_tbm_monitor_client_dump_queue(int argc, char *argv[],
+                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
+{
+       int st;
+       double scale = 0;
+       int i;
+
+       st = _waylend_tbm_util_proc_state_parse(argv[1]);
+
+       for (i = 2; i < argc; i++) {
+               if (_waylend_tbm_util_scale_parse(argv[i], &scale))
+                       break;
+       }
+
+       st = _waylend_tbm_util_dump_queue(st, (tbm_bufmgr)wayland_tbm_client_get_bufmgr(tbm_client), scale);
+       WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): queue dump state: %s\n", getpid(),
+                                                       st ? "on" : "off");
+}
+
+void _waylend_tbm_monitor_client_trace(int argc, char *argv[],
+                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
+{
+       int st;
+
+       st = _waylend_tbm_util_trace(_waylend_tbm_util_proc_state_parse(argv[1]),
+                                                               _waylend_tbm_util_resource_parse(argv[2]),
+                                                               (tbm_bufmgr)wayland_tbm_client_get_bufmgr(tbm_client));
+       WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): trace state: %s\n", getpid() ,
+                                                       st ? "on" : "off");
+}
+
+void _waylend_tbm_monitor_client_debug_level(int argc, char *argv[],
+                                     char *reply, int *len, struct wayland_tbm_client *tbm_client)
+{
+       int debug_level = TBM_LOG_LEVEL_NONE;
+       int i;
+
+       for (i = 1; i < argc; i++) {
+               if (_waylend_tbm_util_debug_level_parse(argv[i], &debug_level))
+                       break;
+       }
+
+       _waylend_tbm_util_set_log_level(debug_level);
+       WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): set tbm_log debug_level(%d)\n", getpid(), debug_level);
+}
+
+static struct {
+       const char *opt;
+       void (*func)(int argc, char *argv[], char *reply, int *len, struct wayland_tbm_client *tbm_client);
+} option_proc[] = {
+       {
+               "show",
+               _waylend_tbm_monitor_client_show,
+       },
+       {
+               "dump_snapshot",
+               _waylend_tbm_monitor_client_dump_snapshot,
+       },
+       {
+               "dump_queue",
+               _waylend_tbm_monitor_client_dump_queue,
+       },
+       {
+               "trace",
+               _waylend_tbm_monitor_client_trace,
+       },
+       {
+               "debug_level",
+               _waylend_tbm_monitor_client_debug_level,
+       },
+};
+
+static void
+handle_tbm_monitor_client_done(void *data, struct wl_tbm_monitor *wl_tbm_monitor, const char *message)
+{
+}
+
+static void
+handle_tbm_monitor_client_request_to_client(void *data, struct wl_tbm_monitor *wl_tbm_monitor,
+                               const char * options, const char * request_id)
+{
+       struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
+       char temp[1024];
+       char *argv[WL_TBM_MONITOR_ARGS_MAX] = {0};
+       int argc = 0;
+
+       char message[WL_TBM_MONITOR_REPLY_MSG_LEN] = {0,};
+       int len = sizeof(message);
+       char *reply = message;
+
+       char *end = NULL;
+       int i;
+
+       snprintf(temp, sizeof(temp), "%s", options);
+
+       argv[argc] = strtok_r(temp, " ", &end);
+       while (argv[argc]) {
+               argc++;
+               if (argc == WL_TBM_MONITOR_ARGS_MAX)
+                       break;
+               argv[argc] = strtok_r(NULL, " ", &end);
+       }
+
+#ifdef DEBUG_TRACE
+       WL_TBM_TRACE("receive request_id:%s argc:%d [%s %s] options:'%s'", request_id, argc, argv[0], argv[1], temp);
+#endif
+
+       if (argc > 0) {
+               for (i = 0; i < sizeof(option_proc) / sizeof(option_proc[0]); i++) {
+                       if (argv[0][0] == '-' && !strncmp(argv[0] + 1, option_proc[i].opt, 32)) {
+                               if (option_proc[i].func) {
+                                       option_proc[i].func(argc, argv, reply, &len, tbm_client);
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       wl_tbm_monitor_responce_to_server(tbm_monitor, message, request_id);
+}
+
+static const struct wl_tbm_monitor_listener wl_tbm_monitor_listener = {
+               handle_tbm_monitor_client_done,
+               handle_tbm_monitor_client_request_to_client,
+};
+
+int
+wayland_tbm_monitor_client_init(struct wayland_tbm_client *tbm_client,
+       struct wl_registry *registry, uint32_t name, uint32_t version)
+{
+       /*Create wl_monotor proxy by sington*/
+       if (tbm_monitor)
+               return 1;
+
+       tbm_monitor = wl_registry_bind(registry, name, &wl_tbm_monitor_interface, version);
+       WL_TBM_RETURN_VAL_IF_FAIL(tbm_monitor != NULL, 0);
+
+       wl_proxy_set_queue((struct wl_proxy *)tbm_monitor, NULL);
+
+       wl_tbm_monitor_add_listener(tbm_monitor, &wl_tbm_monitor_listener, tbm_client);
+
+       return 1;
+}
+
+void
+wayland_tbm_monitor_client_deinit(struct wayland_tbm_client *tbm_client)
+{
+       WL_TBM_RETURN_IF_FAIL(tbm_client);
+
+       if (tbm_monitor
+               && (tbm_client == wl_tbm_monitor_get_user_data(tbm_monitor))) {
+               wl_tbm_monitor_destroy(tbm_monitor);
+               tbm_monitor = NULL;
+       }
+}