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 <sc1.lim@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;
59 static tdm_monitor_info td_info;
63 _tdm_monitor_cb_debug_done(void *data, struct wl_tdm *wl_tdm, const char *message)
65 printf("%s", message);
70 static const struct wl_tdm_listener tdm_monitor_listener = {
71 _tdm_monitor_cb_debug_done,
75 _tdm_monitor_cb_global(void *data, struct wl_registry *registry,
76 uint32_t name, const char *interface,
79 tdm_monitor_info *info = data;
81 if (strncmp(interface, "wl_tdm", 6) == 0) {
82 info->tdm = wl_registry_bind(registry, name, &wl_tdm_interface, version);
83 exit_if_fail(info->tdm != NULL);
84 wl_tdm_add_listener(info->tdm, &tdm_monitor_listener, info);
85 wl_display_flush(info->display);
90 _tdm_monitor_cb_global_remove(void *data, struct wl_registry *registry, uint32_t name)
94 static const struct wl_registry_listener tdm_monitor_registry_listener = {
95 _tdm_monitor_cb_global,
96 _tdm_monitor_cb_global_remove
100 main(int argc, char ** argv)
102 tdm_monitor_info *info = &td_info;
106 int bufsize = sizeof(options);
107 char *str_buf = options;
108 int *len_buf = &bufsize;
111 xdg = (const char*)getenv("XDG_RUNTIME_DIR");
114 snprintf(buf, sizeof(buf), "/run");
116 ret = setenv("XDG_RUNTIME_DIR", (const char*)buf, 1);
117 exit_if_fail(ret == 0);
120 info->display = wl_display_connect("tdm-socket");
121 exit_if_fail(info->display != NULL);
123 info->registry = wl_display_get_registry(info->display);
124 exit_if_fail(info->registry != NULL);
126 wl_registry_add_listener(info->registry,
127 &tdm_monitor_registry_listener, info);
128 wl_display_roundtrip(info->display);
129 exit_if_fail(info->tdm != NULL);
131 TDM_SNPRINTF(str_buf, len_buf, "%d ", getpid());
133 if (!getcwd(cwd, sizeof(cwd)))
134 snprintf(cwd, sizeof(cwd), "/tmp");
135 TDM_SNPRINTF(str_buf, len_buf, "%s ", cwd);
137 for (i = 0; i < argc; i++)
138 TDM_SNPRINTF(str_buf, len_buf, "%s ", argv[i]);
142 wl_tdm_debug(info->tdm, options);
144 while (!done && ret >= 0)
145 ret = wl_display_dispatch(info->display);
148 wl_tdm_destroy(info->tdm);
150 wl_registry_destroy(info->registry);
152 wl_display_disconnect(info->display);