virtual output: Add implementation for set_available_modes, connect and disconnect.
[platform/core/uifw/libtdm.git] / src / tdm_server.c
index d98339c..ed4ddff 100644 (file)
@@ -703,6 +703,132 @@ _tdm_server_cb_create_output(struct wl_client *client, struct wl_resource *resou
        }
 }
 
+typedef struct _tdm_server_voutput_info {
+       tdm_private_server *private_server;
+       tdm_output_conn_status status;
+       struct
+       {
+               int count;
+               tdm_output_mode *modes;
+       } available_modes;
+} tdm_server_voutput_info;
+
+static void _tdm_voutput_cb_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+       wl_resource_destroy(resource);
+}
+
+static void
+_tdm_voutput_cb_set_available_modes(struct wl_client *client,
+                                                                       struct wl_resource *resource,
+                                                                       uint32_t index,
+                                                                       uint32_t clock,
+                                                                       uint32_t hdisplay,
+                                                                       uint32_t hsync_start,
+                                                                       uint32_t hsync_end,
+                                                                       uint32_t htotal,
+                                                                       uint32_t hskew,
+                                                                       uint32_t vdisplay,
+                                                                       uint32_t vsync_start,
+                                                                       uint32_t vsync_end,
+                                                                       uint32_t vtotal,
+                                                                       uint32_t vscan,
+                                                                       uint32_t vrefresh,
+                                                                       uint32_t flags,
+                                                                       uint32_t type,
+                                                                       const char *name)
+{
+       tdm_server_voutput_info *voutput_info;
+       tdm_output_mode *tmp_modes, *old_modes;
+       tdm_output_mode *new_mode;
+       int count, len;
+
+       voutput_info = wl_resource_get_user_data(resource);
+
+       count = voutput_info->available_modes.count;
+       old_modes = voutput_info->available_modes.modes;
+       if (index >= count)
+       {
+               if (count > 0)
+               {
+                       tmp_modes = malloc(count * sizeof(*tmp_modes));
+                       memcpy(tmp_modes, old_modes, count * sizeof(tdm_output_mode));
+               }
+
+               voutput_info->available_modes.count = index + 1;
+               voutput_info->available_modes.modes =
+                       realloc(voutput_info->available_modes.modes,
+                                       sizeof(tdm_output_mode) * (index + 1));
+
+               if (count > 0)
+               {
+                       memcpy(voutput_info->available_modes.modes, tmp_modes, count * sizeof(tdm_output_mode));
+                       free(tmp_modes);
+               }
+       }
+
+       new_mode = &voutput_info->available_modes.modes[index];
+       new_mode->clock = clock;
+       new_mode->hdisplay = hdisplay;
+       new_mode->hsync_start = hsync_start;
+       new_mode->hsync_end = hsync_end;
+       new_mode->htotal = htotal;
+       new_mode->hskew= hskew;
+       new_mode->vdisplay= vdisplay;
+       new_mode->vsync_start= vsync_start;
+       new_mode->vsync_end = vsync_end;
+       new_mode->vtotal = vtotal;
+       new_mode->vscan = vscan;
+       new_mode->vrefresh = vrefresh;
+       new_mode->flags = flags;
+       new_mode->type = type;
+
+       len = strlen(name);
+       strncpy(new_mode->name, name, len);
+       new_mode->name[len] = '\0';
+}
+
+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;
+}
+
+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;
+}
+
+static const struct wl_tdm_voutput_interface tdm_voutput_implementation = {
+       _tdm_voutput_cb_destroy,
+       _tdm_voutput_cb_set_available_modes,
+       _tdm_voutput_cb_connect,
+       _tdm_voutput_cb_disconnect
+};
+
+void
+tdm_voutput_cb_resource_destroy(struct wl_resource *resource)
+{
+       tdm_server_voutput_info *voutput_info;
+
+       voutput_info = wl_resource_get_user_data(resource);
+
+       /* 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)
 {
@@ -758,10 +884,12 @@ _tdm_server_cb_create_virtual_output(struct wl_client *client, struct wl_resourc
        voutput_info->resource = voutput_resource;
        voutput_info->output = output;
        LIST_INITHEAD(&voutput_info->output_list);
-#if 0
-       wl_resource_set_implementation(voutput_resource, &tdm_voutput_implementation,
-                                                                  voutput_info, destroy_voutput_callback);
-#endif
+
+       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);
 }