X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftdm_server.c;h=1bb5683597a01ea4efa937c8604d0b31eef195a0;hb=805e6f0b8f83dabebb8eb0ee21bad9e131dd33bb;hp=bb2a7c30cb88e49fe13c5cf9251248896c2ac638;hpb=da7ffd3c21144e76ac0a150948cb66d75419d50a;p=platform%2Fcore%2Fuifw%2Flibtdm.git diff --git a/src/tdm_server.c b/src/tdm_server.c index bb2a7c3..1bb5683 100644 --- a/src/tdm_server.c +++ b/src/tdm_server.c @@ -37,10 +37,9 @@ #include "config.h" #endif -#include "tdm.h" +#include + #include "tdm_private.h" -#include "tdm_list.h" -#include "tdm-server-protocol.h" /* CAUTION: * - tdm server doesn't care about thread things. @@ -63,16 +62,16 @@ typedef struct _tdm_server_output_info { struct wl_resource *resource; tdm_output *output; struct list_head vblank_list; + unsigned int watch_output_changes; } tdm_server_output_info; typedef struct _tdm_server_vblank_info { struct list_head link; - struct list_head valid_link; - tdm_server_output_info *output_info; struct wl_resource *resource; tdm_vblank *vblank; + unsigned int stamp; } tdm_server_vblank_info; typedef struct _tdm_server_wait_info { @@ -80,13 +79,48 @@ typedef struct _tdm_server_wait_info { tdm_server_vblank_info *vblank_info; unsigned int req_id; + double req_time; } tdm_server_wait_info; +typedef struct _tdm_server_client_info { + struct list_head link; + pid_t pid; + char name[TDM_NAME_LEN]; + struct wl_resource *resource; +} tdm_server_client_info; + static tdm_private_server *keep_private_server; -static struct list_head valid_vblank_list; +static struct list_head client_list; static void destroy_wait(tdm_server_wait_info *wait_info); +static void +_tdm_server_get_process_name(pid_t pid, char *name, unsigned int size) +{ + char proc[TDM_NAME_LEN], pname[TDM_NAME_LEN]; + FILE *h; + size_t len; + + snprintf(name, size, "Unknown"); + + snprintf(proc, TDM_NAME_LEN, "/proc/%d/cmdline", pid); + h = fopen(proc, "r"); + if (!h) + return; + + len = fread(pname, sizeof(char), TDM_NAME_LEN, h); + if (len == 0) { + char *p = strncpy(pname, "NO NAME", sizeof(pname) - 1); + len = p - pname; + } + pname[len - 1] = '\0'; + + strncpy(name, pname, size - 1); + name[size - 1] = '\0'; + + fclose(h); +} + static tdm_output* _tdm_server_find_output(tdm_private_server *private_server, const char *name) { @@ -126,6 +160,7 @@ _tdm_server_find_output(tdm_private_server *private_server, const char *name) return found; } +/* LCOV_EXCL_START */ static void _tdm_server_send_done(tdm_server_wait_info *wait_info, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec) @@ -133,53 +168,74 @@ _tdm_server_send_done(tdm_server_wait_info *wait_info, tdm_error error, tdm_server_wait_info *found; tdm_server_vblank_info *vblank_info; - if (!keep_private_server) - return; + TDM_RETURN_IF_FAIL(keep_private_server != NULL); LIST_FIND_ITEM(wait_info, &keep_private_server->wait_list, tdm_server_wait_info, link, found); if (!found) { - TDM_DBG("wait_info(%p) is destroyed", wait_info); + TDM_ERR("wait_info(%p) is destroyed", wait_info); return; } if (tdm_debug_module & TDM_DEBUG_VBLANK) - TDM_INFO("req_id(%d) done", wait_info->req_id); - - TDM_TRACE_COUNT(ServerDoneVBlank, wait_info->req_id); + TDM_DBG("req_id(%d) done", wait_info->req_id); vblank_info = wait_info->vblank_info; + + if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK) + TDM_TRACE_ASYNC_END((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); + wl_tdm_vblank_send_done(vblank_info->resource, wait_info->req_id, sequence, tv_sec, tv_usec, error); + destroy_wait(wait_info); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_cb_vblank(tdm_vblank *vblank, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data) { _tdm_server_send_done((tdm_server_wait_info*)user_data, error, sequence, tv_sec, tv_usec); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_cb_output_change(tdm_output *output, tdm_output_change_type type, tdm_value value, void *user_data) { tdm_server_output_info *output_info = user_data; + struct wl_client *client; + pid_t pid = 0; TDM_RETURN_IF_FAIL(output_info != NULL); + client = wl_resource_get_client(output_info->resource); + TDM_RETURN_IF_FAIL(client != NULL); + + wl_client_get_credentials(client, &pid, NULL, NULL); + + if (!output_info->watch_output_changes) { + TDM_DBG("skip sending the output changes: pid(%d)", (unsigned int)pid); + return; + } + + TDM_DBG("send the output changes: %d", (unsigned int)pid); + switch (type) { case TDM_OUTPUT_CHANGE_DPMS: - wl_tdm_output_send_dpms(output_info->resource, value.u32); + wl_tdm_output_send_dpms(output_info->resource, value.u32, TDM_ERROR_NONE); break; case TDM_OUTPUT_CHANGE_CONNECTION: - wl_tdm_output_send_connection(output_info->resource, value.u32); + wl_tdm_output_send_connection(output_info->resource, value.u32, TDM_ERROR_NONE); break; default: break; } } +/* LCOV_EXCL_STOP */ static void destroy_wait(tdm_server_wait_info *wait_info) @@ -196,6 +252,8 @@ destroy_vblank_callback(struct wl_resource *resource) TDM_RETURN_IF_FAIL(vblank_info != NULL); + LIST_DEL(&vblank_info->link); + if (vblank_info->vblank) tdm_vblank_destroy(vblank_info->vblank); @@ -204,18 +262,18 @@ destroy_vblank_callback(struct wl_resource *resource) destroy_wait(w); } - LIST_DEL(&vblank_info->link); - LIST_DEL(&vblank_info->valid_link); - free(vblank_info); } +/* LCOV_EXCL_START */ static void _tdm_server_vblank_cb_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_vblank_cb_set_name(struct wl_client *client, struct wl_resource *resource, const char *name) { @@ -223,7 +281,9 @@ _tdm_server_vblank_cb_set_name(struct wl_client *client, struct wl_resource *res tdm_vblank_set_name(vblank_info->vblank, name); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_vblank_cb_set_fps(struct wl_client *client, struct wl_resource *resource, uint32_t fps) { @@ -231,7 +291,9 @@ _tdm_server_vblank_cb_set_fps(struct wl_client *client, struct wl_resource *reso tdm_vblank_set_fps(vblank_info->vblank, fps); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_vblank_cb_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t offset) { @@ -239,6 +301,7 @@ _tdm_server_vblank_cb_set_offset(struct wl_client *client, struct wl_resource *r tdm_vblank_set_offset(vblank_info->vblank, offset); } +/* LCOV_EXCL_STOP */ static void _tdm_server_vblank_cb_set_enable_fake(struct wl_client *client, struct wl_resource *resource, uint32_t enable_fake) @@ -259,21 +322,27 @@ _tdm_server_vblank_cb_wait_vblank(struct wl_client *client, struct wl_resource * unsigned int enable_fake = 0; tdm_error ret; - TDM_TRACE_COUNT(ServerWaitVBlank, req_id); - wait_info = calloc(1, sizeof * wait_info); if (!wait_info) { + /* LCOV_EXCL_START */ + TDM_ERR("alloc failed"); ret = TDM_ERROR_OUT_OF_MEMORY; goto wait_failed; + + /* LCOV_EXCL_STOP */ } LIST_ADDTAIL(&wait_info->link, &private_server->wait_list); wait_info->vblank_info = vblank_info; wait_info->req_id = req_id; + wait_info->req_time = TDM_TIME(req_sec, req_usec); if (tdm_debug_module & TDM_DEBUG_VBLANK) - TDM_INFO("req_id(%d) wait", req_id); + TDM_DBG("req_id(%d) wait", req_id); + + if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK) + TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); ret = tdm_vblank_wait(vblank_info->vblank, req_sec, req_usec, interval, _tdm_server_cb_vblank, wait_info); @@ -285,9 +354,13 @@ _tdm_server_vblank_cb_wait_vblank(struct wl_client *client, struct wl_resource * return; wait_failed: + /* LCOV_EXCL_START */ + wl_tdm_vblank_send_done(vblank_info->resource, req_id, 0, 0, 0, ret); if (wait_info) destroy_wait(wait_info); + + /* LCOV_EXCL_STOP */ } static void @@ -301,21 +374,27 @@ _tdm_server_vblank_cb_wait_vblank_seq(struct wl_client *client, struct wl_resour unsigned int enable_fake = 0; tdm_error ret; - TDM_TRACE_COUNT(ServerWaitVBlank, req_id); - wait_info = calloc(1, sizeof * wait_info); if (!wait_info) { + /* LCOV_EXCL_START */ + TDM_ERR("alloc failed"); ret = TDM_ERROR_OUT_OF_MEMORY; goto wait_failed; + + /* LCOV_EXCL_STOP */ } LIST_ADDTAIL(&wait_info->link, &private_server->wait_list); wait_info->vblank_info = vblank_info; wait_info->req_id = req_id; + wait_info->req_time = TDM_TIME(req_sec, req_usec); if (tdm_debug_module & TDM_DEBUG_VBLANK) - TDM_INFO("req_id(%d) wait", req_id); + TDM_DBG("req_id(%d) wait", req_id); + + if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK) + TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); ret = tdm_vblank_wait_seq(vblank_info->vblank, req_sec, req_usec, sequence, _tdm_server_cb_vblank, wait_info); @@ -327,9 +406,13 @@ _tdm_server_vblank_cb_wait_vblank_seq(struct wl_client *client, struct wl_resour return; wait_failed: + /* LCOV_EXCL_START */ + wl_tdm_vblank_send_done(vblank_info->resource, req_id, 0, 0, 0, ret); if (wait_info) destroy_wait(wait_info); + + /* LCOV_EXCL_STOP */ } static const struct wl_tdm_vblank_interface tdm_vblank_implementation = { @@ -342,11 +425,13 @@ static const struct wl_tdm_vblank_interface tdm_vblank_implementation = { _tdm_server_vblank_cb_wait_vblank_seq, }; +/* LCOV_EXCL_START */ static void _tdm_server_output_cb_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); } +/* LCOV_EXCL_STOP */ static void _tdm_server_output_cb_create_vblank(struct wl_client *client, struct wl_resource *resource, uint32_t id) @@ -362,44 +447,162 @@ _tdm_server_output_cb_create_vblank(struct wl_client *client, struct wl_resource wl_resource_create(client, &wl_tdm_vblank_interface, wl_resource_get_version(resource), id); if (!vblank_resource) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); TDM_ERR("wl_resource_create failed"); return; + + /* LCOV_EXCL_STOP */ } vblank = tdm_vblank_create(private_loop->dpy, output_info->output, NULL); if (!vblank) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); wl_resource_destroy(vblank_resource); TDM_ERR("tdm_vblank_create failed"); return; + + /* LCOV_EXCL_STOP */ } vblank_info = calloc(1, sizeof * vblank_info); if (!vblank_info) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); wl_resource_destroy(vblank_resource); tdm_vblank_destroy(vblank); TDM_ERR("alloc failed"); return; + + /* LCOV_EXCL_STOP */ } LIST_ADDTAIL(&vblank_info->link, &output_info->vblank_list); - LIST_ADDTAIL(&vblank_info->valid_link, &valid_vblank_list); - vblank_info->output_info = output_info; vblank_info->resource = vblank_resource; vblank_info->vblank = vblank; + vblank_info->stamp = (unsigned int)tdm_vblank_get_stamp(vblank); + + tdm_vblank_set_resource(vblank, vblank_resource); wl_resource_set_implementation(vblank_resource, &tdm_vblank_implementation, vblank_info, destroy_vblank_callback); + wl_tdm_vblank_send_stamp(vblank_info->resource, vblank_info->stamp); + + if (tdm_ttrace_module & TDM_TTRACE_CLIENT_VBLANK) { + tdm_output *output = tdm_display_get_output(private_loop->dpy, tdm_ttrace_output, NULL); + if (output == output_info->output) + wl_tdm_vblank_send_ttrace(vblank_info->resource, 1); + } + + return; +} + +/* LCOV_EXCL_START */ +static void +_tdm_server_output_cb_watch_output_changes(struct wl_client *client, struct wl_resource *resource, unsigned int enable) +{ + tdm_server_output_info *output_info = wl_resource_get_user_data(resource); + + TDM_RETURN_IF_FAIL(output_info != NULL); + + output_info->watch_output_changes = enable; +} +/* LCOV_EXCL_STOP */ + +static void +_tdm_server_output_cb_get_connection(struct wl_client *client, struct wl_resource *resource) +{ + tdm_server_output_info *output_info = wl_resource_get_user_data(resource); + tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; + tdm_error ret; + + TDM_RETURN_IF_FAIL(output_info != NULL); + + ret = tdm_output_get_conn_status(output_info->output, &status); + TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + + wl_tdm_output_send_connection(output_info->resource, status, ret); + return; + +failed: + wl_tdm_output_send_connection(output_info->resource, TDM_OUTPUT_CONN_STATUS_DISCONNECTED, ret); +} + +static void +_tdm_server_output_cb_get_mode(struct wl_client *client, struct wl_resource *resource) +{ + tdm_server_output_info *output_info = wl_resource_get_user_data(resource); + tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; + tdm_error ret; + + TDM_RETURN_IF_FAIL(output_info != NULL); + + ret = tdm_output_get_conn_status(output_info->output, &status); + TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + + if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) { + const tdm_output_mode *mode = NULL; + unsigned int hdisplay, vdisplay, vrefresh; + + ret = tdm_output_get_mode(output_info->output, &mode); + TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + + hdisplay = (mode) ? mode->hdisplay : 0; + vdisplay = (mode) ? mode->vdisplay : 0; + vrefresh = (mode) ? mode->vrefresh : 0; + + wl_tdm_output_send_mode(output_info->resource, hdisplay, vdisplay, vrefresh, ret); + } else { + wl_tdm_output_send_mode(output_info->resource, 0, 0, 0, TDM_ERROR_OUTPUT_DISCONNECTED); + } + + return; +failed: + wl_tdm_output_send_mode(output_info->resource, 0, 0, 0, ret); +} + +static void +_tdm_server_output_cb_get_dpms(struct wl_client *client, struct wl_resource *resource) +{ + tdm_server_output_info *output_info = wl_resource_get_user_data(resource); + tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; + tdm_error ret; + + TDM_RETURN_IF_FAIL(output_info != NULL); + + ret = tdm_output_get_conn_status(output_info->output, &status); + TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + + if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) { + tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; + + ret = tdm_output_get_dpms(output_info->output, &dpms_value); + TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + + wl_tdm_output_send_dpms(output_info->resource, dpms_value, ret); + } else { + wl_tdm_output_send_dpms(output_info->resource, TDM_OUTPUT_DPMS_OFF, TDM_ERROR_OUTPUT_DISCONNECTED); + } + + return; +failed: + wl_tdm_output_send_dpms(output_info->resource, TDM_OUTPUT_DPMS_OFF, ret); } static const struct wl_tdm_output_interface tdm_output_implementation = { _tdm_server_output_cb_destroy, _tdm_server_output_cb_create_vblank, + _tdm_server_output_cb_watch_output_changes, + _tdm_server_output_cb_get_connection, + _tdm_server_output_cb_get_mode, + _tdm_server_output_cb_get_dpms, }; static void @@ -410,6 +613,8 @@ destroy_output_callback(struct wl_resource *resource) TDM_RETURN_IF_FAIL(output_info != NULL); + LIST_DEL(&output_info->link); + tdm_output_remove_change_handler(output_info->output, _tdm_server_cb_output_change, output_info); @@ -417,7 +622,6 @@ destroy_output_callback(struct wl_resource *resource) wl_resource_destroy(v->resource); } - LIST_DEL(&output_info->link); free(output_info); } @@ -429,44 +633,44 @@ _tdm_server_cb_create_output(struct wl_client *client, struct wl_resource *resou tdm_server_output_info *output_info; struct wl_resource *output_resource = NULL; tdm_output *output; - const tdm_output_mode *mode = NULL; - tdm_output_dpms dpms_value; - tdm_output_conn_status status; + tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; + tdm_error ret; output = _tdm_server_find_output(private_server, name); if (!output) { + /* LCOV_EXCL_START */ + TDM_ERR("There is no '%s' output", name); wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "There is no '%s' output", name); return; - } - tdm_output_get_mode(output, &mode); - if (!mode) { - TDM_ERR("no mode for '%s' output", name); - wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, - "no mode for '%s' output", name); - return; + /* LCOV_EXCL_STOP */ } - tdm_output_get_dpms(output, &dpms_value); - tdm_output_get_conn_status(output, &status); - output_resource = wl_resource_create(client, &wl_tdm_output_interface, wl_resource_get_version(resource), id); if (!output_resource) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); TDM_ERR("wl_resource_create failed"); return; + + /* LCOV_EXCL_STOP */ } output_info = calloc(1, sizeof * output_info); if (!output_info) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); wl_resource_destroy(output_resource); TDM_ERR("alloc failed"); return; + + /* LCOV_EXCL_STOP */ } LIST_ADDTAIL(&output_info->link, &private_server->output_list); @@ -480,61 +684,128 @@ _tdm_server_cb_create_output(struct wl_client *client, struct wl_resource *resou wl_resource_set_implementation(output_resource, &tdm_output_implementation, output_info, destroy_output_callback); - wl_tdm_output_send_mode(output_resource, mode->hdisplay, mode->vdisplay, mode->vrefresh); - wl_tdm_output_send_dpms(output_resource, dpms_value); - wl_tdm_output_send_connection(output_resource, status); + ret = tdm_output_get_conn_status(output, &status); + wl_tdm_output_send_connection(output_resource, status, ret); + + if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) { + tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; + const tdm_output_mode *mode = NULL; + unsigned int hdisplay, vdisplay, vrefresh; + + ret = tdm_output_get_mode(output, &mode); + hdisplay = (mode) ? mode->hdisplay : 0; + vdisplay = (mode) ? mode->vdisplay : 0; + vrefresh = (mode) ? mode->vrefresh : 0; + wl_tdm_output_send_mode(output_resource, hdisplay, vdisplay, vrefresh, ret); + + ret = tdm_output_get_dpms(output, &dpms_value); + wl_tdm_output_send_dpms(output_resource, dpms_value, ret); + } else { + wl_tdm_output_send_mode(output_resource, 0, 0, 0, TDM_ERROR_OUTPUT_DISCONNECTED); + wl_tdm_output_send_dpms(output_resource, TDM_OUTPUT_DPMS_OFF, TDM_ERROR_OUTPUT_DISCONNECTED); + } } +/* LCOV_EXCL_START */ static void _tdm_server_cb_debug(struct wl_client *client, struct wl_resource *resource, const char *options) { tdm_private_server *private_server = wl_resource_get_user_data(resource); tdm_private_loop *private_loop = private_server->private_loop; char message[TDM_SERVER_REPLY_MSG_LEN]; - int size = sizeof(message); + char *m; + int len = sizeof(message), size; uid_t uid; wl_client_get_credentials(client, NULL, &uid, NULL); if (uid != 0) { - snprintf(message, size, "tdm-monitor: SHOULD be a superuser.\n"); + snprintf(message, len, "tdm-monitor: SHOULD be a superuser.\n"); TDM_ERR("%s", message); } else { - tdm_monitor_server_command(private_loop->dpy, options, message, &size); + tdm_monitor_server_command(private_loop->dpy, options, message, &len); } - wl_tdm_send_debug_done(resource, message); -} + size = sizeof(message) - len; + m = message; -static void -_tdm_server_cb_set_client_vblank_fps(struct wl_client *client, struct wl_resource *resource, - unsigned int pid, const char *name, unsigned int fps) -{ - tdm_error ret = tdm_server_set_client_vblank_fps(pid, name, fps); - TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE); + wl_client_flush(client); + + while (size > 0) { + char buffer[TDM_DEBUG_REPLY_MSG_LEN]; + int copylen = TDM_MIN(size, sizeof(buffer) - 1); + + strncpy(buffer, m, copylen); + m += copylen; + size -= copylen; + + buffer[copylen] = '\0'; + + wl_tdm_send_debug_message(resource, buffer); + } - TDM_INFO("'%s' vblank fps(PID: '%u'): %u", name, pid, fps); + wl_tdm_send_debug_done(resource); } +/* LCOV_EXCL_STOP */ static const struct wl_tdm_interface tdm_implementation = { _tdm_server_cb_debug, _tdm_server_cb_create_output, - _tdm_server_cb_set_client_vblank_fps, }; static void +destroy_client(struct wl_resource *resource) +{ + tdm_server_client_info *c = NULL, *cc = NULL; + struct wl_client *client; + + client = wl_resource_get_client(resource); + TDM_RETURN_IF_FAIL(client != NULL); + + LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) { + if (c->resource == resource) { + LIST_DEL(&c->link); + free(c); + return; + } + } +} + +static void _tdm_server_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; + tdm_server_client_info *cinfo; resource = wl_resource_create(client, &wl_tdm_interface, version, id); if (!resource) { + /* LCOV_EXCL_START */ + + wl_client_post_no_memory(client); + return; + + /* LCOV_EXCL_STOP */ + } + + cinfo = calloc(1, sizeof(tdm_server_client_info)); + if (!cinfo) { + /* LCOV_EXCL_START */ + wl_client_post_no_memory(client); + wl_resource_destroy(resource); return; + + /* LCOV_EXCL_STOP */ } - wl_resource_set_implementation(resource, &tdm_implementation, data, NULL); + cinfo->resource = resource; + + LIST_ADDTAIL(&cinfo->link, &client_list); + wl_client_get_credentials(client, &cinfo->pid, NULL, NULL); + _tdm_server_get_process_name(cinfo->pid, cinfo->name, TDM_NAME_LEN); + + wl_resource_set_implementation(resource, &tdm_implementation, data, destroy_client); } INTERN tdm_error @@ -549,8 +820,12 @@ tdm_server_init(tdm_private_loop *private_loop) return TDM_ERROR_NONE; if (wl_display_add_socket(private_loop->wl_display, "tdm-socket")) { + /* LCOV_EXCL_START */ + TDM_ERR("createing a tdm-socket failed"); return TDM_ERROR_OPERATION_FAILED; + + /* LCOV_EXCL_STOP */ } private_server = calloc(1, sizeof * private_server); @@ -564,17 +839,21 @@ tdm_server_init(tdm_private_loop *private_loop) if (!wl_global_create(private_loop->wl_display, &wl_tdm_interface, 1, private_server, _tdm_server_bind)) { + /* LCOV_EXCL_START */ + TDM_ERR("creating a global resource failed"); free(private_server); return TDM_ERROR_OUT_OF_MEMORY; - } - LIST_INITHEAD(&valid_vblank_list); + /* LCOV_EXCL_STOP */ + } private_server->private_loop = private_loop; private_loop->private_server = private_server; keep_private_server = private_server; + LIST_INITHEAD(&client_list); + return TDM_ERROR_NONE; } @@ -583,6 +862,7 @@ tdm_server_deinit(tdm_private_loop *private_loop) { tdm_server_output_info *o = NULL, *oo = NULL; tdm_server_wait_info *w = NULL, *ww = NULL; + tdm_server_client_info *c = NULL, *cc = NULL; tdm_private_server *private_server; if (!private_loop->private_server) @@ -598,102 +878,51 @@ tdm_server_deinit(tdm_private_loop *private_loop) wl_resource_destroy(o->resource); } + LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) { + wl_resource_destroy(c->resource); + } + free(private_server); private_loop->private_server = NULL; keep_private_server = NULL; } -INTERN tdm_error -tdm_server_set_client_vblank_fps(unsigned int pid, const char *name, unsigned int fps) +/* LCOV_EXCL_START */ +INTERN const char* +tdm_server_get_client_name(pid_t pid) { - tdm_server_vblank_info *v; + tdm_server_client_info *c = NULL; - TDM_RETURN_VAL_IF_FAIL(pid > 0, TDM_ERROR_INVALID_PARAMETER); - TDM_RETURN_VAL_IF_FAIL(fps > 0, TDM_ERROR_INVALID_PARAMETER); - - LIST_FOR_EACH_ENTRY(v, &valid_vblank_list, valid_link) { - struct wl_client *client = wl_resource_get_client(v->resource); - pid_t client_pid = 0; - const char *vblank_name = NULL; - - if (!client) - continue; - - wl_client_get_credentials(client, &client_pid, NULL, NULL); - - if (client_pid != pid) - continue; - - if (name && strncmp(name, TDM_VBLANK_DEFAULT_NAME, TDM_NAME_LEN)) { - tdm_vblank_get_name(v->vblank, &vblank_name); - if (strncmp(vblank_name, name, TDM_NAME_LEN)) - continue; - } - - tdm_vblank_set_fps(v->vblank, fps); + LIST_FOR_EACH_ENTRY(c, &client_list, link) { + if (c->pid == pid) + return (const char*)c->name; } - return TDM_ERROR_NONE; + return NULL; } +/* LCOV_EXCL_STOP */ -static void -_tdm_server_get_process_name(pid_t pid, char *name, unsigned int size) +/* LCOV_EXCL_START */ +INTERN tdm_error +tdm_server_enable_ttrace_client_vblank(tdm_display *dpy, tdm_output *output, int enable) { - char proc[TDM_NAME_LEN], pname[TDM_NAME_LEN]; - FILE *h; - size_t len; - - snprintf(proc, TDM_NAME_LEN, "/proc/%d/cmdline", pid); - h = fopen(proc, "r"); - if (!h) - return; + tdm_private_server *private_server = keep_private_server; + tdm_server_output_info *output_info = NULL; - len = fread(pname, sizeof(char), TDM_NAME_LEN, h); - if (len == 0) { - char *p = strncpy(pname, "NO NAME", sizeof(pname) - 1); - len = p - pname; - } - pname[len - 1] = '\0'; + if (!keep_private_server) + return TDM_ERROR_NONE; - strncpy(name, pname, size - 1); - name[size - 1] = '\0'; + LIST_FOR_EACH_ENTRY(output_info, &private_server->output_list, link) { + tdm_server_vblank_info *vblank_info = NULL; - fclose(h); -} + if (output && output_info->output != output) + continue; -INTERN void -tdm_server_get_vblank_list_information(tdm_display *dpy, char *reply, int *len) -{ - tdm_server_vblank_info *v; - - TDM_SNPRINTF(reply, len, "[Client Vblank List]\n"); - TDM_SNPRINTF(reply, len, "---------------------------------------------------------------\n"); - TDM_SNPRINTF(reply, len, "name fps offset fake process\n"); - TDM_SNPRINTF(reply, len, "---------------------------------------------------------------\n"); - - LIST_FOR_EACH_ENTRY(v, &valid_vblank_list, valid_link) { - struct wl_client *client = wl_resource_get_client(v->resource); - const char *vbl_name = NULL; - char proc_name[TDM_NAME_LEN]; - unsigned int fps = 0, fake = 0; - int offset = 0; - pid_t pid = 0; - - tdm_vblank_get_name(v->vblank, &vbl_name); - tdm_vblank_get_fps(v->vblank, &fps); - tdm_vblank_get_offset(v->vblank, &offset); - tdm_vblank_get_enable_fake(v->vblank, &fake); - - snprintf(proc_name, TDM_NAME_LEN, "Unknown"); - if (client) { - wl_client_get_credentials(client, &pid, NULL, NULL); - _tdm_server_get_process_name(pid, proc_name, TDM_NAME_LEN); + LIST_FOR_EACH_ENTRY(vblank_info, &output_info->vblank_list, link) { + wl_tdm_vblank_send_ttrace(vblank_info->resource, enable); } - - TDM_SNPRINTF(reply, len, "%-12s %u %d %u %s (pid: %u)\n", - vbl_name, fps, offset, fake, proc_name, pid); } - TDM_SNPRINTF(reply, len, "\n"); + return TDM_ERROR_NONE; } - +/* LCOV_EXCL_STOP */