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 **************************************************************************/
40 #include <tdm-server-protocol.h>
42 #include "tdm_private.h"
45 * - tdm server doesn't care about thread things.
46 * - DO NOT use the TDM internal functions here.
47 * However, the internal function which does lock/unlock the mutex of
48 * private_display in itself can be called.
49 * - DO NOT use the tdm_private_display structure here.
50 * - The callback function things can be called in main thread.
53 struct _tdm_private_server {
54 tdm_private_loop *private_loop;
55 struct list_head output_list;
56 struct list_head wait_list;
59 typedef struct _tdm_server_output_info {
60 struct list_head link;
61 tdm_private_server *private_server;
62 struct wl_resource *resource;
64 struct list_head vblank_list;
65 unsigned int watch_output_changes;
66 } tdm_server_output_info;
68 typedef struct _tdm_server_vblank_info {
69 struct list_head link;
70 tdm_server_output_info *output_info;
71 struct wl_resource *resource;
75 } tdm_server_vblank_info;
77 typedef struct _tdm_server_wait_info {
78 struct list_head link;
79 tdm_server_vblank_info *vblank_info;
83 } tdm_server_wait_info;
85 typedef struct _tdm_server_client_info {
86 struct list_head link;
88 char name[TDM_NAME_LEN];
89 struct wl_resource *resource;
90 } tdm_server_client_info;
92 static tdm_private_server *keep_private_server;
93 static struct list_head client_list;
95 static void destroy_wait(tdm_server_wait_info *wait_info);
98 _tdm_server_get_process_name(pid_t pid, char *name, unsigned int size)
100 char proc[TDM_NAME_LEN], pname[TDM_NAME_LEN];
104 snprintf(name, size, "Unknown");
106 snprintf(proc, TDM_NAME_LEN, "/proc/%d/cmdline", pid);
107 h = fopen(proc, "r");
111 len = fread(pname, sizeof(char), TDM_NAME_LEN, h);
113 char *p = strncpy(pname, "NO NAME", sizeof(pname) - 1);
116 pname[len - 1] = '\0';
118 strncpy(name, pname, size - 1);
119 name[size - 1] = '\0';
124 /* LCOV_EXCL_START */
126 _tdm_server_send_done(tdm_server_wait_info *wait_info, tdm_error error,
127 unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec)
129 tdm_server_wait_info *found;
130 tdm_server_vblank_info *vblank_info;
132 TDM_RETURN_IF_FAIL(keep_private_server != NULL);
134 LIST_FIND_ITEM(wait_info, &keep_private_server->wait_list,
135 tdm_server_wait_info, link, found);
137 TDM_ERR("wait_info(%p) is destroyed", wait_info);
141 if (tdm_debug_module & TDM_DEBUG_VBLANK)
142 TDM_DBG("req_id(%d) done", wait_info->req_id);
144 vblank_info = wait_info->vblank_info;
146 if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK)
147 TDM_TRACE_ASYNC_END((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp);
149 wl_tdm_vblank_send_done(vblank_info->resource, wait_info->req_id,
150 sequence, tv_sec, tv_usec, error);
152 destroy_wait(wait_info);
156 /* LCOV_EXCL_START */
158 _tdm_server_cb_vblank(tdm_vblank *vblank, tdm_error error, unsigned int sequence,
159 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
161 _tdm_server_send_done((tdm_server_wait_info*)user_data, error, sequence, tv_sec, tv_usec);
165 /* LCOV_EXCL_START */
167 _tdm_server_cb_output_change(tdm_output *output, tdm_output_change_type type,
168 tdm_value value, void *user_data)
170 tdm_server_output_info *output_info = user_data;
171 struct wl_client *client;
174 TDM_RETURN_IF_FAIL(output_info != NULL);
176 client = wl_resource_get_client(output_info->resource);
177 TDM_RETURN_IF_FAIL(client != NULL);
179 wl_client_get_credentials(client, &pid, NULL, NULL);
181 if (!output_info->watch_output_changes) {
182 TDM_DBG("skip sending the output changes: pid(%d)", (unsigned int)pid);
186 TDM_DBG("send the output changes: %d", (unsigned int)pid);
189 case TDM_OUTPUT_CHANGE_DPMS:
190 wl_tdm_output_send_dpms(output_info->resource, value.u32, TDM_ERROR_NONE);
192 case TDM_OUTPUT_CHANGE_CONNECTION:
193 wl_tdm_output_send_connection(output_info->resource, value.u32, TDM_ERROR_NONE);
202 destroy_wait(tdm_server_wait_info *wait_info)
204 LIST_DEL(&wait_info->link);
209 destroy_vblank_callback(struct wl_resource *resource)
211 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
212 tdm_server_wait_info *w = NULL, *ww = NULL;
214 TDM_RETURN_IF_FAIL(vblank_info != NULL);
216 LIST_DEL(&vblank_info->link);
218 if (vblank_info->vblank)
219 tdm_vblank_destroy(vblank_info->vblank);
221 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &keep_private_server->wait_list, link) {
222 if (w->vblank_info == vblank_info)
229 /* LCOV_EXCL_START */
231 _tdm_server_vblank_cb_destroy(struct wl_client *client, struct wl_resource *resource)
233 wl_resource_destroy(resource);
237 /* LCOV_EXCL_START */
239 _tdm_server_vblank_cb_set_name(struct wl_client *client, struct wl_resource *resource, const char *name)
241 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
243 tdm_vblank_set_name(vblank_info->vblank, name);
247 /* LCOV_EXCL_START */
249 _tdm_server_vblank_cb_set_fps(struct wl_client *client, struct wl_resource *resource, uint32_t fps)
251 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
253 tdm_vblank_set_fps(vblank_info->vblank, fps);
257 /* LCOV_EXCL_START */
259 _tdm_server_vblank_cb_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t offset)
261 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
263 tdm_vblank_set_offset(vblank_info->vblank, offset);
268 _tdm_server_vblank_cb_set_enable_fake(struct wl_client *client, struct wl_resource *resource, uint32_t enable_fake)
270 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
272 tdm_vblank_set_enable_fake(vblank_info->vblank, enable_fake);
276 _tdm_server_vblank_cb_wait_vblank(struct wl_client *client, struct wl_resource *resource,
277 uint32_t interval, uint32_t req_id, uint32_t req_sec, uint32_t req_usec)
279 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
280 tdm_server_output_info *output_info = vblank_info->output_info;
281 tdm_private_server *private_server = output_info->private_server;
282 tdm_server_wait_info *wait_info;
283 unsigned int enable_fake = 0;
286 wait_info = calloc(1, sizeof * wait_info);
288 /* LCOV_EXCL_START */
290 TDM_ERR("alloc failed");
291 ret = TDM_ERROR_OUT_OF_MEMORY;
297 LIST_ADDTAIL(&wait_info->link, &private_server->wait_list);
298 wait_info->vblank_info = vblank_info;
299 wait_info->req_id = req_id;
300 wait_info->req_time = TDM_TIME(req_sec, req_usec);
302 if (tdm_debug_module & TDM_DEBUG_VBLANK)
303 TDM_DBG("req_id(%d) wait", req_id);
305 if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK)
306 TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp);
308 ret = tdm_vblank_wait(vblank_info->vblank, req_sec, req_usec, interval, _tdm_server_cb_vblank, wait_info);
310 tdm_vblank_get_enable_fake(vblank_info->vblank, &enable_fake);
311 if (!enable_fake && ret == TDM_ERROR_DPMS_OFF)
314 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
318 /* LCOV_EXCL_START */
320 wl_tdm_vblank_send_done(vblank_info->resource, req_id, 0, 0, 0, ret);
322 destroy_wait(wait_info);
328 _tdm_server_vblank_cb_wait_vblank_seq(struct wl_client *client, struct wl_resource *resource,
329 uint32_t sequence, uint32_t req_id, uint32_t req_sec, uint32_t req_usec)
331 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
332 tdm_server_output_info *output_info = vblank_info->output_info;
333 tdm_private_server *private_server = output_info->private_server;
334 tdm_server_wait_info *wait_info;
335 unsigned int enable_fake = 0;
338 wait_info = calloc(1, sizeof * wait_info);
340 /* LCOV_EXCL_START */
342 TDM_ERR("alloc failed");
343 ret = TDM_ERROR_OUT_OF_MEMORY;
349 LIST_ADDTAIL(&wait_info->link, &private_server->wait_list);
350 wait_info->vblank_info = vblank_info;
351 wait_info->req_id = req_id;
352 wait_info->req_time = TDM_TIME(req_sec, req_usec);
354 if (tdm_debug_module & TDM_DEBUG_VBLANK)
355 TDM_DBG("req_id(%d) wait", req_id);
357 if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK)
358 TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp);
360 ret = tdm_vblank_wait_seq(vblank_info->vblank, req_sec, req_usec, sequence, _tdm_server_cb_vblank, wait_info);
362 tdm_vblank_get_enable_fake(vblank_info->vblank, &enable_fake);
363 if (!enable_fake && ret == TDM_ERROR_DPMS_OFF)
366 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
370 /* LCOV_EXCL_START */
372 wl_tdm_vblank_send_done(vblank_info->resource, req_id, 0, 0, 0, ret);
374 destroy_wait(wait_info);
379 static const struct wl_tdm_vblank_interface tdm_vblank_implementation = {
380 _tdm_server_vblank_cb_destroy,
381 _tdm_server_vblank_cb_set_name,
382 _tdm_server_vblank_cb_set_fps,
383 _tdm_server_vblank_cb_set_offset,
384 _tdm_server_vblank_cb_set_enable_fake,
385 _tdm_server_vblank_cb_wait_vblank,
386 _tdm_server_vblank_cb_wait_vblank_seq,
389 /* LCOV_EXCL_START */
391 _tdm_server_output_cb_destroy(struct wl_client *client, struct wl_resource *resource)
393 wl_resource_destroy(resource);
398 _tdm_server_output_cb_create_vblank(struct wl_client *client, struct wl_resource *resource, uint32_t id)
400 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
401 tdm_private_server *private_server = output_info->private_server;
402 tdm_private_loop *private_loop = private_server->private_loop;
403 struct wl_resource *vblank_resource;
405 tdm_server_vblank_info *vblank_info;
408 wl_resource_create(client, &wl_tdm_vblank_interface,
409 wl_resource_get_version(resource), id);
410 if (!vblank_resource) {
411 /* LCOV_EXCL_START */
413 wl_resource_post_no_memory(resource);
414 TDM_ERR("wl_resource_create failed");
420 vblank = tdm_vblank_create(private_loop->dpy, output_info->output, NULL);
422 /* LCOV_EXCL_START */
424 wl_resource_post_no_memory(resource);
425 wl_resource_destroy(vblank_resource);
426 TDM_ERR("tdm_vblank_create failed");
432 vblank_info = calloc(1, sizeof * vblank_info);
434 /* LCOV_EXCL_START */
436 wl_resource_post_no_memory(resource);
437 wl_resource_destroy(vblank_resource);
438 tdm_vblank_destroy(vblank);
439 TDM_ERR("alloc failed");
445 LIST_ADDTAIL(&vblank_info->link, &output_info->vblank_list);
446 vblank_info->output_info = output_info;
447 vblank_info->resource = vblank_resource;
448 vblank_info->vblank = vblank;
449 vblank_info->stamp = (unsigned int)tdm_vblank_get_stamp(vblank);
451 tdm_vblank_set_resource(vblank, vblank_resource);
453 wl_resource_set_implementation(vblank_resource, &tdm_vblank_implementation,
454 vblank_info, destroy_vblank_callback);
456 wl_tdm_vblank_send_stamp(vblank_info->resource, vblank_info->stamp);
458 if (tdm_ttrace_module & TDM_TTRACE_CLIENT_VBLANK) {
459 tdm_output *output = tdm_display_get_output(private_loop->dpy, tdm_ttrace_output, NULL);
460 if (output == output_info->output)
461 wl_tdm_vblank_send_ttrace(vblank_info->resource, 1);
467 /* LCOV_EXCL_START */
469 _tdm_server_output_cb_watch_output_changes(struct wl_client *client, struct wl_resource *resource, unsigned int enable)
471 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
473 TDM_RETURN_IF_FAIL(output_info != NULL);
475 output_info->watch_output_changes = enable;
480 _tdm_server_output_cb_get_connection(struct wl_client *client, struct wl_resource *resource)
482 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
483 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
486 TDM_RETURN_IF_FAIL(output_info != NULL);
488 ret = tdm_output_get_conn_status(output_info->output, &status);
489 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
491 wl_tdm_output_send_connection(output_info->resource, status, ret);
496 wl_tdm_output_send_connection(output_info->resource, TDM_OUTPUT_CONN_STATUS_DISCONNECTED, ret);
500 _tdm_server_output_cb_get_mode(struct wl_client *client, struct wl_resource *resource)
502 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
503 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
506 TDM_RETURN_IF_FAIL(output_info != NULL);
508 ret = tdm_output_get_conn_status(output_info->output, &status);
509 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
511 if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
512 const tdm_output_mode *mode = NULL;
513 unsigned int hdisplay, vdisplay, vrefresh;
515 ret = tdm_output_get_mode(output_info->output, &mode);
516 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
518 hdisplay = (mode) ? mode->hdisplay : 0;
519 vdisplay = (mode) ? mode->vdisplay : 0;
520 vrefresh = (mode) ? mode->vrefresh : 0;
522 wl_tdm_output_send_mode(output_info->resource, hdisplay, vdisplay, vrefresh, ret);
524 wl_tdm_output_send_mode(output_info->resource, 0, 0, 0, TDM_ERROR_OUTPUT_DISCONNECTED);
529 wl_tdm_output_send_mode(output_info->resource, 0, 0, 0, ret);
533 _tdm_server_output_cb_get_dpms(struct wl_client *client, struct wl_resource *resource)
535 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
536 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
539 TDM_RETURN_IF_FAIL(output_info != NULL);
541 ret = tdm_output_get_conn_status(output_info->output, &status);
542 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
544 if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
545 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
547 ret = tdm_output_get_dpms(output_info->output, &dpms_value);
548 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
550 wl_tdm_output_send_dpms(output_info->resource, dpms_value, ret);
552 wl_tdm_output_send_dpms(output_info->resource, TDM_OUTPUT_DPMS_OFF, TDM_ERROR_OUTPUT_DISCONNECTED);
557 wl_tdm_output_send_dpms(output_info->resource, TDM_OUTPUT_DPMS_OFF, ret);
560 static const struct wl_tdm_output_interface tdm_output_implementation = {
561 _tdm_server_output_cb_destroy,
562 _tdm_server_output_cb_create_vblank,
563 _tdm_server_output_cb_watch_output_changes,
564 _tdm_server_output_cb_get_connection,
565 _tdm_server_output_cb_get_mode,
566 _tdm_server_output_cb_get_dpms,
570 destroy_output_callback(struct wl_resource *resource)
572 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
573 tdm_server_vblank_info *v = NULL, *vv = NULL;
575 TDM_RETURN_IF_FAIL(output_info != NULL);
577 LIST_DEL(&output_info->link);
579 tdm_output_remove_change_handler(output_info->output,
580 _tdm_server_cb_output_change, output_info);
582 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &output_info->vblank_list, link) {
583 wl_resource_destroy(v->resource);
590 _tdm_server_cb_create_output(struct wl_client *client, struct wl_resource *resource,
591 const char *name, uint32_t id)
593 tdm_private_server *private_server = wl_resource_get_user_data(resource);
594 tdm_server_output_info *output_info;
595 struct wl_resource *output_resource = NULL;
597 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
600 output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL);
602 /* LCOV_EXCL_START */
604 TDM_ERR("There is no '%s' output", name);
605 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
606 "There is no '%s' output", name);
613 wl_resource_create(client, &wl_tdm_output_interface,
614 wl_resource_get_version(resource), id);
615 if (!output_resource) {
616 /* LCOV_EXCL_START */
618 wl_resource_post_no_memory(resource);
619 TDM_ERR("wl_resource_create failed");
625 output_info = calloc(1, sizeof * output_info);
627 /* LCOV_EXCL_START */
629 wl_resource_post_no_memory(resource);
630 wl_resource_destroy(output_resource);
631 TDM_ERR("alloc failed");
637 ret = tdm_output_add_change_handler(output, _tdm_server_cb_output_change, output_info);
638 if (ret != TDM_ERROR_NONE) {
639 wl_resource_post_no_memory(resource);
640 wl_resource_destroy(output_resource);
642 TDM_ERR("tdm_output_add_change_handler failed");
646 LIST_ADDTAIL(&output_info->link, &private_server->output_list);
647 output_info->private_server = private_server;
648 output_info->resource = output_resource;
649 output_info->output = output;
650 LIST_INITHEAD(&output_info->vblank_list);
652 wl_resource_set_implementation(output_resource, &tdm_output_implementation,
653 output_info, destroy_output_callback);
655 ret = tdm_output_get_conn_status(output, &status);
656 wl_tdm_output_send_connection(output_resource, status, ret);
658 if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
659 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
660 const tdm_output_mode *mode = NULL;
661 unsigned int hdisplay, vdisplay, vrefresh;
663 ret = tdm_output_get_mode(output, &mode);
664 hdisplay = (mode) ? mode->hdisplay : 0;
665 vdisplay = (mode) ? mode->vdisplay : 0;
666 vrefresh = (mode) ? mode->vrefresh : 0;
667 wl_tdm_output_send_mode(output_resource, hdisplay, vdisplay, vrefresh, ret);
669 ret = tdm_output_get_dpms(output, &dpms_value);
670 wl_tdm_output_send_dpms(output_resource, dpms_value, ret);
672 wl_tdm_output_send_mode(output_resource, 0, 0, 0, TDM_ERROR_OUTPUT_DISCONNECTED);
673 wl_tdm_output_send_dpms(output_resource, TDM_OUTPUT_DPMS_OFF, TDM_ERROR_OUTPUT_DISCONNECTED);
677 /* LCOV_EXCL_START */
679 _tdm_server_cb_debug(struct wl_client *client, struct wl_resource *resource, const char *options)
681 tdm_private_server *private_server = wl_resource_get_user_data(resource);
682 tdm_private_loop *private_loop = private_server->private_loop;
683 char message[TDM_SERVER_REPLY_MSG_LEN];
685 int len = sizeof(message), size;
688 wl_client_get_credentials(client, NULL, &uid, NULL);
691 snprintf(message, len, "tdm-monitor: SHOULD be a superuser.\n");
692 TDM_ERR("%s", message);
694 tdm_monitor_server_command(private_loop->dpy, options, message, &len);
697 size = sizeof(message) - len;
700 wl_client_flush(client);
703 char buffer[TDM_DEBUG_REPLY_MSG_LEN];
704 int copylen = TDM_MIN(size, sizeof(buffer) - 1);
706 strncpy(buffer, m, copylen);
710 buffer[copylen] = '\0';
712 wl_tdm_send_debug_message(resource, buffer);
715 wl_tdm_send_debug_done(resource);
719 static const struct wl_tdm_interface tdm_implementation = {
720 _tdm_server_cb_debug,
721 _tdm_server_cb_create_output,
725 destroy_client(struct wl_resource *resource)
727 tdm_server_client_info *c = NULL, *cc = NULL;
728 struct wl_client *client;
730 client = wl_resource_get_client(resource);
731 TDM_RETURN_IF_FAIL(client != NULL);
733 LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) {
734 if (c->resource == resource) {
743 _tdm_server_bind(struct wl_client *client, void *data,
744 uint32_t version, uint32_t id)
746 struct wl_resource *resource;
747 tdm_server_client_info *cinfo;
749 resource = wl_resource_create(client, &wl_tdm_interface, version, id);
751 /* LCOV_EXCL_START */
753 wl_client_post_no_memory(client);
759 cinfo = calloc(1, sizeof(tdm_server_client_info));
761 /* LCOV_EXCL_START */
763 wl_client_post_no_memory(client);
764 wl_resource_destroy(resource);
770 cinfo->resource = resource;
772 LIST_ADDTAIL(&cinfo->link, &client_list);
773 wl_client_get_credentials(client, &cinfo->pid, NULL, NULL);
774 _tdm_server_get_process_name(cinfo->pid, cinfo->name, TDM_NAME_LEN);
776 wl_resource_set_implementation(resource, &tdm_implementation, data, destroy_client);
780 tdm_server_init(tdm_private_loop *private_loop)
782 tdm_private_server *private_server;
784 TDM_RETURN_VAL_IF_FAIL(private_loop, TDM_ERROR_OPERATION_FAILED);
785 TDM_RETURN_VAL_IF_FAIL(private_loop->wl_display, TDM_ERROR_OPERATION_FAILED);
787 if (private_loop->private_server)
788 return TDM_ERROR_NONE;
790 if (wl_display_add_socket(private_loop->wl_display, "tdm-socket")) {
791 /* LCOV_EXCL_START */
793 TDM_ERR("createing a tdm-socket failed");
794 return TDM_ERROR_OPERATION_FAILED;
799 private_server = calloc(1, sizeof * private_server);
800 if (!private_server) {
801 TDM_ERR("alloc failed");
802 return TDM_ERROR_OUT_OF_MEMORY;
805 LIST_INITHEAD(&private_server->output_list);
806 LIST_INITHEAD(&private_server->wait_list);
808 if (!wl_global_create(private_loop->wl_display, &wl_tdm_interface, 1,
809 private_server, _tdm_server_bind)) {
810 /* LCOV_EXCL_START */
812 TDM_ERR("creating a global resource failed");
813 free(private_server);
814 return TDM_ERROR_OUT_OF_MEMORY;
819 private_server->private_loop = private_loop;
820 private_loop->private_server = private_server;
821 keep_private_server = private_server;
823 LIST_INITHEAD(&client_list);
825 return TDM_ERROR_NONE;
829 tdm_server_deinit(tdm_private_loop *private_loop)
831 tdm_server_output_info *o = NULL, *oo = NULL;
832 tdm_server_wait_info *w = NULL, *ww = NULL;
833 tdm_server_client_info *c = NULL, *cc = NULL;
834 tdm_private_server *private_server;
836 if (!private_loop->private_server)
839 private_server = private_loop->private_server;
841 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &private_server->wait_list, link) {
845 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &private_server->output_list, link) {
846 wl_resource_destroy(o->resource);
849 LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) {
850 wl_resource_destroy(c->resource);
853 free(private_server);
854 private_loop->private_server = NULL;
855 keep_private_server = NULL;
858 /* LCOV_EXCL_START */
860 tdm_server_get_client_name(pid_t pid)
862 tdm_server_client_info *c = NULL;
864 LIST_FOR_EACH_ENTRY(c, &client_list, link) {
866 return (const char*)c->name;
873 /* LCOV_EXCL_START */
875 tdm_server_enable_ttrace_client_vblank(tdm_display *dpy, tdm_output *output, int enable)
877 tdm_private_server *private_server = keep_private_server;
878 tdm_server_output_info *output_info = NULL;
880 if (!keep_private_server)
881 return TDM_ERROR_NONE;
883 LIST_FOR_EACH_ENTRY(output_info, &private_server->output_list, link) {
884 tdm_server_vblank_info *vblank_info = NULL;
886 if (output && output_info->output != output)
889 LIST_FOR_EACH_ENTRY(vblank_info, &output_info->vblank_list, link) {
890 wl_tdm_vblank_send_ttrace(vblank_info->resource, enable);
894 return TDM_ERROR_NONE;