* Taeheon Kim <th908.kim@samsung.com>,
* YoungJun Cho <yj44.cho@samsung.com>,
* SooChan Lim <sc1.lim@samsung.com>,
- * Boram Park <sc1.lim@samsung.com>
+ * Boram Park <boram1288.park@samsung.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
struct _tdm_private_server {
tdm_private_loop *private_loop;
struct list_head output_list;
+ struct list_head voutput_list;
struct list_head wait_list;
};
unsigned int watch_output_changes;
} tdm_server_output_info;
+typedef struct _tdm_server_voutput_info {
+ struct list_head link;
+ tdm_private_server *private_server;
+ struct wl_resource *resource;
+ tdm_output *output;
+ struct list_head output_list;
+
+ tdm_output_conn_status status;
+ struct
+ {
+ int count;
+ tdm_output_mode *modes;
+ } available_modes;
+
+ unsigned int mmwidth;
+ unsigned int mmheight;
+} tdm_server_voutput_info;
+
typedef struct _tdm_server_vblank_info {
struct list_head link;
tdm_server_output_info *output_info;
fclose(h);
}
-static tdm_output*
-_tdm_server_find_output(tdm_private_server *private_server, const char *name)
-{
- tdm_private_loop *private_loop = private_server->private_loop;
- tdm_output *found = NULL;
-
- if (!strncasecmp(name, "primary", 7) || !strncasecmp(name, "default", 7))
- found = tdm_display_get_output(private_loop->dpy, 0, NULL);
-
- if (!found) {
- int count = 0, i;
-
- tdm_display_get_output_count(private_loop->dpy, &count);
-
- for (i = 0; i < count; i++) {
- tdm_output *output = tdm_display_get_output(private_loop->dpy, i, NULL);
- tdm_output_conn_status status;
- const char *model = NULL;
- tdm_error ret;
-
- ret = tdm_output_get_conn_status(output, &status);
- if (ret || status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
- continue;
-
- ret = tdm_output_get_model_info(output, NULL, &model, NULL);
- if (ret || !model)
- continue;
-
- if (strncmp(model, name, TDM_NAME_LEN))
- continue;
-
- found = output;
- break;
- }
- }
-
- return found;
-}
-
/* LCOV_EXCL_START */
static void
_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;
}
_tdm_server_vblank_cb_set_name(struct wl_client *client, struct wl_resource *resource, const char *name)
{
tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
+ tdm_error ret;
- tdm_vblank_set_name(vblank_info->vblank, name);
+ ret = tdm_vblank_set_name(vblank_info->vblank, name);
+ TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
}
/* LCOV_EXCL_STOP */
_tdm_server_vblank_cb_set_fps(struct wl_client *client, struct wl_resource *resource, uint32_t fps)
{
tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
+ tdm_error ret;
- tdm_vblank_set_fps(vblank_info->vblank, fps);
+ ret = tdm_vblank_set_fps(vblank_info->vblank, fps);
+ TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
}
/* LCOV_EXCL_STOP */
_tdm_server_vblank_cb_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t offset)
{
tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
+ tdm_error ret;
- tdm_vblank_set_offset(vblank_info->vblank, offset);
+ ret = tdm_vblank_set_offset(vblank_info->vblank, offset);
+ TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
}
/* LCOV_EXCL_STOP */
_tdm_server_vblank_cb_set_enable_fake(struct wl_client *client, struct wl_resource *resource, uint32_t enable_fake)
{
tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
+ tdm_error ret;
- tdm_vblank_set_enable_fake(vblank_info->vblank, enable_fake);
+ ret = tdm_vblank_set_enable_fake(vblank_info->vblank, enable_fake);
+ TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
}
static void
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);
+ TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
wl_tdm_output_send_connection(output_info->resource, status, 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);
+ 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);
+ TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
hdisplay = (mode) ? mode->hdisplay : 0;
vdisplay = (mode) ? mode->vdisplay : 0;
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);
+ 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);
+ TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
wl_tdm_output_send_dpms(output_info->resource, dpms_value, ret);
} else {
tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
tdm_error ret;
- output = _tdm_server_find_output(private_server, name);
+ output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL);
if (!output) {
/* LCOV_EXCL_START */
/* LCOV_EXCL_STOP */
}
+ ret = tdm_output_add_change_handler(output, _tdm_server_cb_output_change, output_info);
+ if (ret != TDM_ERROR_NONE) {
+ wl_resource_post_no_memory(resource);
+ wl_resource_destroy(output_resource);
+ free(output_info);
+ TDM_ERR("tdm_output_add_change_handler failed");
+ return;
+ }
+
LIST_ADDTAIL(&output_info->link, &private_server->output_list);
output_info->private_server = private_server;
output_info->resource = output_resource;
output_info->output = output;
LIST_INITHEAD(&output_info->vblank_list);
- tdm_output_add_change_handler(output, _tdm_server_cb_output_change, output_info);
-
wl_resource_set_implementation(output_resource, &tdm_output_implementation,
output_info, destroy_output_callback);
}
}
+static void _tdm_voutput_cb_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+ tdm_server_voutput_info *voutput_info;
+ tdm_private_server *private_server;
+ tdm_output *output;
+ tdm_error ret = TDM_ERROR_NONE;
+
+ voutput_info = wl_resource_get_user_data(resource);
+
+ private_server = voutput_info->private_server;
+ output = voutput_info->output;
+
+ if (output)
+ ret = tdm_display_destroy_output(private_server->private_loop->dpy, output);
+
+ if (ret != TDM_ERROR_NONE)
+ TDM_ERR("_tdm_voutput_cb_destroy fail");
+
+ wl_resource_destroy(resource);
+}
+
+static void
+_tdm_voutput_cb_set_available_modes(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_array *modes)
+{
+ tdm_server_voutput_info *voutput_info;
+ tdm_output_mode *mode;
+ int size, count = 0, i = 0;
+
+ voutput_info = wl_resource_get_user_data(resource);
+
+ voutput_info->available_modes.count = 0;
+ if (voutput_info->available_modes.modes)
+ free(voutput_info->available_modes.modes);
+
+ wl_array_for_each(mode, modes)
+ count++;
+ size = sizeof(tdm_output_mode);
+
+ voutput_info->available_modes.modes = malloc(count * size);
+ voutput_info->available_modes.count = count;
+
+ wl_array_for_each(mode, modes)
+ memcpy(&voutput_info->available_modes.modes[i++], mode, size);
+}
+
+static void
+_tdm_voutput_cb_set_physical_size(struct wl_client *client, struct wl_resource *resource,
+ unsigned int mmwidth, unsigned int mmheight)
+{
+ tdm_server_voutput_info *voutput_info;
+
+ voutput_info = wl_resource_get_user_data(resource);
+
+ voutput_info->mmwidth = mmwidth;
+ voutput_info->mmheight = mmheight;
+}
+
+static void
+_tdm_voutput_cb_connect(struct wl_client *client, struct wl_resource *resource)
+{
+ tdm_server_voutput_info *voutput_info;
+
+ voutput_info = wl_resource_get_user_data(resource);
+ voutput_info->status = TDM_OUTPUT_CONN_STATUS_CONNECTED;
+
+ tdm_output_set_physical_size(voutput_info->output, voutput_info->mmwidth, voutput_info->mmheight);
+ tdm_output_set_available_mode(voutput_info->output, voutput_info->available_modes.modes, voutput_info->available_modes.count);
+ tdm_output_set_connect(voutput_info->output);
+}
+
+static void
+_tdm_voutput_cb_disconnect(struct wl_client *client, struct wl_resource *resource)
+{
+ tdm_server_voutput_info *voutput_info;
+
+ voutput_info = wl_resource_get_user_data(resource);
+ voutput_info->status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
+
+ /* Do free resources when it's being disconnected */
+ free(voutput_info->available_modes.modes);
+ voutput_info->available_modes.modes = NULL;
+ voutput_info->available_modes.count = 0;
+ voutput_info->mmwidth = 0;
+ voutput_info->mmheight = 0;
+
+ tdm_output_set_disconnect(voutput_info->output);
+}
+
+static void
+_tdm_voutput_cb_commit_done(struct wl_client *client, struct wl_resource *resource)
+{
+ tdm_server_voutput_info *voutput_info;
+
+ voutput_info = wl_resource_get_user_data(resource);
+ if (voutput_info->status != TDM_OUTPUT_CONN_STATUS_CONNECTED)
+ {
+ // handle error
+ return;
+ }
+}
+
+static const struct wl_tdm_voutput_interface tdm_voutput_implementation = {
+ _tdm_voutput_cb_destroy,
+ _tdm_voutput_cb_set_available_modes,
+ _tdm_voutput_cb_set_physical_size,
+ _tdm_voutput_cb_connect,
+ _tdm_voutput_cb_disconnect,
+ _tdm_voutput_cb_commit_done
+};
+
+void
+tdm_voutput_cb_resource_destroy(struct wl_resource *resource)
+{
+ tdm_server_voutput_info *voutput_info = wl_resource_get_user_data(resource);
+
+ TDM_RETURN_IF_FAIL(voutput_info != NULL);
+
+ LIST_DEL(&voutput_info->link);
+
+ /* Do free your own resource */
+ free(voutput_info);
+}
+
+static void
+_tdm_server_cb_create_virtual_output(struct wl_client *client, struct wl_resource *resource, const char *name, uint32_t id)
+{
+ struct wl_resource *voutput_resource = NULL;
+ tdm_private_server *private_server = wl_resource_get_user_data(resource);
+ tdm_server_voutput_info *voutput_info;
+ tdm_output *output;
+ tdm_error ret;
+
+ output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL);
+ if (output) {
+ TDM_ERR("There is '%s' output, cannot create.", name);
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "There is '%s' output", name);
+ return;
+ }
+
+ output = tdm_display_create_output(private_server->private_loop->dpy, name, &ret);
+ if (!output) {
+ TDM_ERR("output creation fail(%s)(%d).", name, ret);
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_NO_MEMORY,
+ "%s output creation fail", name);
+ return;
+ }
+
+ voutput_resource =
+ wl_resource_create(client, &wl_tdm_voutput_interface,
+ wl_resource_get_version(resource), id);
+ if (!voutput_resource) {
+ /* LCOV_EXCL_START */
+
+ wl_resource_post_no_memory(resource);
+ TDM_ERR("wl_resource_create failed");
+ return;
+
+ /* LCOV_EXCL_STOP */
+ }
+
+ voutput_info = calloc(1, sizeof * voutput_info);
+ if (!voutput_info) {
+ /* LCOV_EXCL_START */
+
+ wl_resource_post_no_memory(resource);
+ wl_resource_destroy(voutput_resource);
+ TDM_ERR("alloc failed");
+ return;
+
+ /* LCOV_EXCL_STOP */
+ }
+
+ LIST_ADDTAIL(&voutput_info->link, &private_server->voutput_list);
+ voutput_info->private_server = private_server;
+ voutput_info->resource = voutput_resource;
+ voutput_info->output = output;
+ LIST_INITHEAD(&voutput_info->output_list);
+
+ wl_resource_set_implementation(voutput_resource,
+ &tdm_voutput_implementation,
+ voutput_info,
+ tdm_voutput_cb_resource_destroy);
+
+ wl_tdm_voutput_send_ack_message(voutput_resource, WL_TDM_VOUTPUT_MESSAGE_ADDED);
+}
+
/* LCOV_EXCL_START */
static void
_tdm_server_cb_debug(struct wl_client *client, struct wl_resource *resource, const char *options)
static const struct wl_tdm_interface tdm_implementation = {
_tdm_server_cb_debug,
_tdm_server_cb_create_output,
+ _tdm_server_cb_create_virtual_output
};
static void
wl_resource_set_implementation(resource, &tdm_implementation, data, destroy_client);
}
-static int
-_tdm_getgrnam_r(const char *name)
-{
- struct group *grp = NULL;
- struct group *grp_res = NULL;
- char* buf = NULL;
- size_t buf_len;
- int ret;
- int id;
-
- buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
- if (buf_len == -1)
- buf_len = 2048;
-
- buf = calloc(1, buf_len * sizeof(char));
- if (!buf) {
- TDM_ERR("creating buffer failed");
- goto failed;
- }
-
- grp = calloc(1, sizeof(struct group));
- if (!grp) {
- TDM_ERR("creating group failed");
- goto failed;
- }
-
- ret = getgrnam_r(name, grp, buf, buf_len, &grp_res);
- if (ret < 0) {
- TDM_ERR("getgrnam_r failed errno:%d(%m)", ret);
- goto failed;
- }
-
- if (grp_res == NULL) {
- TDM_ERR("finding name:%s group failed", name);
- goto failed;
- }
-
- id = grp->gr_gid;
- free(buf);
- free(grp);
-
- return id;
-
-failed:
- /* LCOV_EXCL_START */
-
- if (buf)
- free(buf);
- if (grp)
- free(grp);
-
- return -1;
-
- /* LCOV_EXCL_STOP */
-}
-
-static void
-_tdm_socket_init(tdm_private_loop *private_loop)
-{
- const char *dir = NULL;
- char socket_path[TDM_NAME_LEN * 2];
- int ret = -1, len;
- uid_t uid;
- gid_t gid;
-
- dir = getenv("XDG_RUNTIME_DIR");
- if (!dir) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("getting XDG_RUNTIME_DIR failed");
- return;
-
- /* LCOV_EXCL_STOP */
- }
-
- len = strlen(dir);
- if (len > TDM_NAME_LEN - 1) {
- TDM_ERR("XDG_RUNTIME_DIR is too long\n");
- return;
- }
-
- strncpy(socket_path, dir, TDM_NAME_LEN - 1);
- socket_path[TDM_NAME_LEN - 1] = '\0';
-
- strncat(socket_path, "/tdm-socket", 11);
- socket_path[TDM_NAME_LEN + 10] = '\0';
-
- ret = chmod(socket_path, 509);
- if (ret < 0) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("changing modes of socket file failed:%s (%m)", socket_path);
- return;
-
- /* LCOV_EXCL_STOP */
- }
-
- ret = _tdm_getgrnam_r("root");
- if (ret < 0) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("getting uid failed");
- return;
-
- /* LCOV_EXCL_STOP */
- }
- uid = ret;
-
- ret = _tdm_getgrnam_r("display");
- if (ret < 0) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("getting gid failed");
- return;
-
- /* LCOV_EXCL_STOP */
- }
- gid = ret;
-
- ret = chown(socket_path, uid, gid);
- if (ret < 0) {
- /* LCOV_EXCL_START */
-
- TDM_WRN("changing owner of socket file failed:%s (%m)", socket_path);
- return;
-
- /* LCOV_EXCL_STOP */
- }
-}
-
INTERN tdm_error
tdm_server_init(tdm_private_loop *private_loop)
{
/* LCOV_EXCL_STOP */
}
- _tdm_socket_init(private_loop);
-
private_server = calloc(1, sizeof * private_server);
if (!private_server) {
TDM_ERR("alloc failed");
}
LIST_INITHEAD(&private_server->output_list);
+ LIST_INITHEAD(&private_server->voutput_list);
LIST_INITHEAD(&private_server->wait_list);
if (!wl_global_create(private_loop->wl_display, &wl_tdm_interface, 1,
tdm_server_deinit(tdm_private_loop *private_loop)
{
tdm_server_output_info *o = NULL, *oo = NULL;
+// tdm_server_voutput_info *vo = NULL, *voo = NULL;
tdm_server_wait_info *w = NULL, *ww = NULL;
tdm_server_client_info *c = NULL, *cc = NULL;
tdm_private_server *private_server;
LIST_FOR_EACH_ENTRY_SAFE(o, oo, &private_server->output_list, link) {
wl_resource_destroy(o->resource);
}
-
+#if 0
+ LIST_FOR_EACH_ENTRY_SAFE(vo, voo, &private_server->voutput_list, link) {
+ wl_resource_destroy(vo->resource);
+ }
+#endif
LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) {
wl_resource_destroy(c->resource);
}