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 **************************************************************************/
42 #include "tdm_private.h"
43 #include "tdm_helper.h"
46 #define TDM_DBG_SERVER_ARGS_MAX 32
48 static void _tdm_monitor_server_usage(char *app_name, char *reply, int *len);
51 _tdm_monitor_server_query(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
53 tdm_helper_get_display_information(dpy, reply, len);
57 _tdm_monitor_server_dpms(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
60 int output_idx, dpms_value;
66 _tdm_monitor_server_usage(argv[0], reply, len);
71 output_idx = strtol(arg, &end, 10);
73 TDM_SNPRINTF(reply, len, "failed: no onoff value\n");
78 dpms_value = strtol(arg, &end, 10);
80 output = tdm_display_get_output(dpy, output_idx, &ret);
81 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
83 ret = tdm_output_set_dpms(output, dpms_value);
84 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
86 TDM_SNPRINTF(reply, len, "done: DPMS %s\n", tdm_dpms_str(dpms_value));
90 _tdm_monitor_server_ttrace_vblank(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
92 int enable, output_id = 0;
94 const char *name = NULL;
101 _tdm_monitor_server_usage(argv[0], reply, len);
106 enable = strtol(arg, &end, 10);
110 output_id = strtol(arg, &end, 10);
113 output = tdm_display_get_output(dpy, output_id, NULL);
115 TDM_SNPRINTF(reply, len, "can't find the output_id(%d)\n", output_id);
119 ret = tdm_output_get_output_type(output, &type);
120 if (ret != TDM_ERROR_NONE) {
121 TDM_SNPRINTF(reply, len, "can't find the type of output_id(%d)\n", output_id);
125 tdm_output_get_model_info(output, NULL, NULL, &name);
127 tdm_display_enable_ttrace_vblank(dpy, output, enable);
129 TDM_SNPRINTF(reply, len, "%s ttrace vblank for '%s'\n",
130 (enable)?"enable":"disable", tdm_conn_str(type));
134 _tdm_monitor_server_debug(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
141 _tdm_monitor_server_usage(argv[0], reply, len);
146 level = strtol(arg, &end, 10);
148 tdm_log_set_debug_level(level);
149 TDM_SNPRINTF(reply, len, "debug level: %d\n", level);
154 tdm_display_enable_debug_module((const char *)arg);
156 TDM_SNPRINTF(reply, len, "debugging... '%s'\n", arg);
161 _tdm_monitor_server_log_path(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
163 static int old_stdout = -1;
164 char fd_name[TDM_PATH_LEN];
168 _tdm_monitor_server_usage(argv[0], reply, len);
172 if (old_stdout == -1)
173 old_stdout = dup(STDOUT_FILENO);
176 TDM_DBG_RETURN_IF_FAIL(path != NULL);
178 tdm_log_enable_dlog(0);
180 if (!strncmp(path, "dlog", 4)) {
181 tdm_log_enable_dlog(1);
183 } else if (!strncmp(path, "console", 7))
184 snprintf(fd_name, TDM_PATH_LEN, "/proc/%d/fd/1", pid);
187 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
190 snprintf(fd_name, TDM_PATH_LEN, "%s/%s", cwd, path);
192 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
194 tdm_log_enable_color(0);
197 if (tdm_display_enable_path((const char*)fd_name) != TDM_ERROR_NONE) {
198 TDM_SNPRINTF(reply, len, "failed: '%s'\n", path);
203 TDM_SNPRINTF(reply, len, "log path: '%s'\n", path);
207 _tdm_monitor_server_prop(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
210 tdm_output *layer = NULL;
211 int output_idx, layer_idx = -1;
212 int cnt, i, done = 0;
214 char temp[TDM_PATH_LEN];
219 const tdm_prop *props;
222 _tdm_monitor_server_usage(argv[0], reply, len);
226 snprintf(temp, TDM_PATH_LEN, "%s", argv[2]);
229 output_idx = strtol(arg, &end, 10);
232 layer_idx = strtol(arg, &end, 10);
236 TDM_SNPRINTF(reply, len, "failed: no prop_name\n");
241 prop_name = strtok_r(arg, ",", &end);
243 TDM_SNPRINTF(reply, len, "failed: get prop_name by strtok_r\n");
248 TDM_SNPRINTF(reply, len, "failed: no value\n");
252 arg = strtok_r(NULL, TDM_DELIM, &end);
254 TDM_SNPRINTF(reply, len, "failed: get arg by strtok_r\n");
257 value.u32 = strtol(arg, &end, 10);
259 output = tdm_display_get_output(dpy, output_idx, &ret);
260 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
262 if (layer_idx != -1) {
263 layer = tdm_output_get_layer(output, layer_idx, &ret);
264 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && layer != NULL);
268 ret = tdm_layer_get_available_properties(layer, &props, &cnt);
269 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
271 for (i = 0; i < cnt; i++) {
272 if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
273 ret = tdm_layer_set_property(layer, props[i].id, value);
274 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
280 ret = tdm_output_get_available_properties(output, &props, &cnt);
281 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
283 for (i = 0; i < cnt; i++) {
284 if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
285 ret = tdm_output_set_property(output, props[i].id, value);
286 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
294 TDM_SNPRINTF(reply, len, "done: %s:%d \n", prop_name, value.u32);
296 TDM_SNPRINTF(reply, len, "no '%s' propperty \n", prop_name);
300 _tdm_monitor_server_dump(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
303 _tdm_monitor_server_usage(argv[0], reply, len);
307 tdm_display_enable_dump(dpy, (const char*)argv[2], reply, len);
312 void (*func)(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy);
318 "info", _tdm_monitor_server_query,
319 "show tdm output, layer information", NULL, NULL
322 "dpms", _tdm_monitor_server_dpms,
323 "set output dpms", "<output_idx>:<dpms>", "0:3 or 0:0"
326 "ttrace_vblank", _tdm_monitor_server_ttrace_vblank,
327 "enable/disable the vblank for ttrace [0:disable 1:enable]",
328 "<enable>[@<output_idx>]", "0 or 1"
331 "debug", _tdm_monitor_server_debug,
332 "set the debug level and modules(module: none, mutex, buffer, thread, vblank)",
333 "<level>[@<module1>[,<module2>]]",
337 "log_path", _tdm_monitor_server_log_path,
338 "set the log path (console,dlog,filepath)",
343 "prop", _tdm_monitor_server_prop,
344 "set the property of a output or a layer",
345 "<output_idx>[,<layer_idx>]:<prop_name>,<value>",
349 "dump", _tdm_monitor_server_dump,
350 "dump buffers (type: none, layer, pp, capture, current)\n"
351 "\t\t layer, pp, capture - start to dump buffers of layer, pp, capture\n"
352 "\t\t none - stop to dump buffers\n"
353 "\t\t current - dump the current buffer of all layers",
354 "<object_type1>[,<object_type2>[,...]]@[<directory_path>]",
360 _tdm_monitor_server_usage(char *app_name, char *reply, int *len)
362 int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
365 TDM_SNPRINTF(reply, len, "usage: %s \n\n", app_name);
367 for (i = 0; i < opt_size; i++) {
368 TDM_SNPRINTF(reply, len, "\t-%s\t%s\n", option_proc[i].opt, option_proc[i].desc);
369 if (option_proc[i].arg)
370 TDM_SNPRINTF(reply, len, "\t\t %s\n", option_proc[i].arg);
371 if (option_proc[i].ex)
372 TDM_SNPRINTF(reply, len, "\t\t ex) %s\n", option_proc[i].ex);
373 TDM_SNPRINTF(reply, len, "\n");
378 _tdm_monitor_server_command(unsigned int pid, char *cwd, tdm_display *dpy, int argc, char *argv[], char *reply, int *len)
380 int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
384 _tdm_monitor_server_usage(argv[0], reply, len);
388 for (i = 0; i < opt_size; i++) {
389 if (argv[1][0] == '-' && !strncmp(argv[1] + 1, option_proc[i].opt, 32)) {
390 if (option_proc[i].func) {
391 option_proc[i].func(pid, cwd, argc, argv, reply, len, dpy);
394 TDM_SNPRINTF(reply, len, "'%s' not implemented.\n", argv[1]);
400 _tdm_monitor_server_usage(argv[0], reply, len);
406 tdm_monitor_server_command(tdm_display *dpy, const char *options, char *reply, int *len)
411 char *argv[TDM_DBG_SERVER_ARGS_MAX] = {0,};
414 char *end = NULL, *e;
416 snprintf(temp, sizeof(temp), "%s", options);
418 arg = strtok_r(temp, " ", &end);
420 TDM_SNPRINTF(reply, len, "no pid for tdm-monitor");
423 pid = strtol(arg, &e, 10);
425 arg = strtok_r(NULL, " ", &end);
427 TDM_SNPRINTF(reply, len, "no cwd for tdm-monitor");
430 snprintf(cwd, sizeof(cwd), "%s", arg);
432 TDM_DBG("pid(%d) cwd(%s)", pid, cwd);
434 argv[argc] = strtok_r(NULL, " ", &end);
437 if (argc == TDM_DBG_SERVER_ARGS_MAX) {
438 TDM_SNPRINTF(reply, len, "too many arguments for tdm-monitor");
441 argv[argc] = strtok_r(NULL, " ", &end);
444 _tdm_monitor_server_command(pid, cwd, dpy, argc, argv, reply, len);