1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <boram1288.park@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
41 #include "tdm_macro.h"
43 #include "tdm-client-protocol.h"
46 #define exit_if_fail(cond) { \
48 printf("'%s' failed. (line:%d)\n", #cond, __LINE__); \
53 typedef struct _tdm_monitor_info {
54 struct wl_display *display;
55 struct wl_registry *registry;
60 char message[TDM_SERVER_REPLY_MSG_LEN];
67 static tdm_monitor_info td_info;
70 _tdm_monitor_cb_debug_message(void *data, struct wl_tdm *wl_tdm, const char *message)
72 tdm_monitor_info *info = data;
73 TDM_SNPRINTF(info->debug.m, info->debug.l, "%s", message);
77 _tdm_monitor_cb_debug_done(void *data, struct wl_tdm *wl_tdm)
79 tdm_monitor_info *info = data;
81 *(info->debug.m) = '\0';
82 printf("%s", info->debug.message);
85 static const struct wl_tdm_listener tdm_monitor_listener = {
86 _tdm_monitor_cb_debug_message,
87 _tdm_monitor_cb_debug_done,
91 _tdm_monitor_cb_global(void *data, struct wl_registry *registry,
92 uint32_t name, const char *interface,
95 tdm_monitor_info *info = data;
97 if (strncmp(interface, "wl_tdm", 6) == 0) {
98 info->tdm = wl_registry_bind(registry, name, &wl_tdm_interface, version);
99 exit_if_fail(info->tdm != NULL);
100 wl_tdm_add_listener(info->tdm, &tdm_monitor_listener, info);
101 wl_display_flush(info->display);
106 _tdm_monitor_cb_global_remove(void *data, struct wl_registry *registry, uint32_t name)
110 static const struct wl_registry_listener tdm_monitor_registry_listener = {
111 _tdm_monitor_cb_global,
112 _tdm_monitor_cb_global_remove
116 main(int argc, char ** argv)
118 tdm_monitor_info *info = &td_info;
122 int bufsize = sizeof(options);
123 char *str_buf = options;
124 int *len_buf = &bufsize;
127 xdg = (const char*)getenv("XDG_RUNTIME_DIR");
130 snprintf(buf, sizeof(buf), "/run");
132 ret = setenv("XDG_RUNTIME_DIR", (const char*)buf, 1);
133 exit_if_fail(ret == 0);
136 info->display = wl_display_connect("tdm-socket");
137 exit_if_fail(info->display != NULL);
139 info->registry = wl_display_get_registry(info->display);
140 exit_if_fail(info->registry != NULL);
142 wl_registry_add_listener(info->registry,
143 &tdm_monitor_registry_listener, info);
144 wl_display_roundtrip(info->display);
145 exit_if_fail(info->tdm != NULL);
147 TDM_SNPRINTF(str_buf, len_buf, "%d ", getpid());
149 if (!getcwd(cwd, sizeof(cwd)))
150 snprintf(cwd, sizeof(cwd), "/tmp");
151 TDM_SNPRINTF(str_buf, len_buf, "%s ", cwd);
153 for (i = 0; i < argc; i++)
154 TDM_SNPRINTF(str_buf, len_buf, "%s ", argv[i]);
156 info->debug.done = 0;
157 info->debug.message[0] = '\0';
158 info->debug.len = sizeof(info->debug.message);
159 info->debug.m = info->debug.message;
160 info->debug.l = &info->debug.len;
162 wl_tdm_debug(info->tdm, options);
164 while (!info->debug.done && ret >= 0)
165 ret = wl_display_dispatch(info->display);
167 wl_tdm_destroy(info->tdm);
168 wl_registry_destroy(info->registry);
169 wl_display_disconnect(info->display);