client: use queue to handle internal events 26/168426/3
authorBoram Park <boram1288.park@samsung.com>
Fri, 26 Jan 2018 11:31:38 +0000 (20:31 +0900)
committerSangjin Lee <lsj119@samsung.com>
Fri, 26 Jan 2018 12:00:29 +0000 (12:00 +0000)
Change-Id: Id5fe565fcc177325661830ea5229515bab24c70e

client/tdm_client.c

index 79ed4bb..54ae817 100644 (file)
@@ -55,6 +55,7 @@ typedef struct _tdm_private_client_vblank tdm_private_client_vblank;
 
 typedef struct _tdm_private_client {
        struct wl_display *display;
+       struct wl_event_queue *queue;
        struct wl_registry *registry;
        struct wl_tdm *tdm;
        struct list_head output_list;
@@ -355,6 +356,9 @@ tdm_client_create(tdm_error *error)
        private_client->display = wl_display_connect("tdm-socket");
        TDM_GOTO_IF_FAIL(private_client->display != NULL, create_failed);
 
+       private_client->queue = wl_display_create_queue(private_client->display);
+       TDM_GOTO_IF_FAIL(private_client->queue != NULL, create_failed);
+
        private_client->registry = wl_display_get_registry(private_client->display);
        TDM_GOTO_IF_FAIL(private_client->registry != NULL, create_failed);
 
@@ -396,6 +400,8 @@ tdm_client_destroy(tdm_client *client)
                wl_tdm_destroy(private_client->tdm);
        if (private_client->registry)
                wl_registry_destroy(private_client->registry);
+       if (private_client->queue)
+               wl_event_queue_destroy(private_client->queue);
        if (private_client->display)
                wl_display_disconnect(private_client->display);
 
@@ -497,6 +503,7 @@ tdm_client_get_output(tdm_client *client, char *name, tdm_error *error)
 {
        tdm_private_client *private_client;
        tdm_private_client_output *private_output = NULL;
+       struct wl_proxy *wrapper;
 
        if (error)
                *error = TDM_ERROR_NONE;
@@ -518,8 +525,19 @@ tdm_client_get_output(tdm_client *client, char *name, tdm_error *error)
                        return (tdm_client_output*)private_output;
        }
 
+       wrapper = wl_proxy_create_wrapper(private_client->tdm);
+       if (!wrapper) {
+               TDM_ERR("create output_wrapper failed");
+               if (error)
+                       *error = TDM_ERROR_OUT_OF_MEMORY;
+               return NULL;
+       }
+
+       wl_proxy_set_queue(wrapper, private_client->queue);
+
        private_output = calloc(1, sizeof *private_output);
        if (!private_output) {
+               wl_proxy_wrapper_destroy(wrapper);
                TDM_ERR("alloc failed");
                if (error)
                        *error = TDM_ERROR_OUT_OF_MEMORY;
@@ -529,7 +547,8 @@ tdm_client_get_output(tdm_client *client, char *name, tdm_error *error)
        private_output->private_client = private_client;
 
        snprintf(private_output->name, TDM_NAME_LEN, "%s", name);
-       private_output->output = wl_tdm_create_output(private_client->tdm, private_output->name);
+       private_output->output = wl_tdm_create_output((struct wl_tdm *)wrapper, private_output->name);
+       wl_proxy_wrapper_destroy(wrapper);
        if (!private_output->output) {
                TDM_ERR("couldn't create output resource");
                free(private_output);
@@ -544,7 +563,9 @@ tdm_client_get_output(tdm_client *client, char *name, tdm_error *error)
 
        wl_tdm_output_add_listener(private_output->output,
                                                           &tdm_client_output_listener, private_output);
-       wl_display_roundtrip(private_client->display);
+       wl_display_roundtrip_queue(private_client->display, private_client->queue);
+
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL);
 
        return (tdm_client_output*)private_output;
 }
@@ -631,8 +652,10 @@ tdm_client_output_get_refresh_rate(tdm_client_output *output, unsigned int *refr
        private_client = private_output->private_client;
        TDM_RETURN_VAL_IF_FAIL(private_client != NULL, TDM_ERROR_INVALID_PARAMETER);
 
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, private_client->queue);
        wl_tdm_output_get_mode(private_output->output);
-       wl_display_roundtrip(private_client->display);
+       wl_display_roundtrip_queue(private_client->display, private_client->queue);
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL);
 
        *refresh = private_output->refresh;
 
@@ -658,8 +681,10 @@ tdm_client_output_get_conn_status(tdm_client_output *output, tdm_output_conn_sta
        private_client = private_output->private_client;
        TDM_RETURN_VAL_IF_FAIL(private_client != NULL, TDM_ERROR_INVALID_PARAMETER);
 
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, private_client->queue);
        wl_tdm_output_get_connection(private_output->output);
-       wl_display_roundtrip(private_client->display);
+       wl_display_roundtrip_queue(private_client->display, private_client->queue);
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL);
 
        *status = private_output->connection;
 
@@ -685,8 +710,10 @@ tdm_client_output_get_dpms(tdm_client_output *output, tdm_output_dpms *dpms)
        private_client = private_output->private_client;
        TDM_RETURN_VAL_IF_FAIL(private_client != NULL, TDM_ERROR_INVALID_PARAMETER);
 
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, private_client->queue);
        wl_tdm_output_get_dpms(private_output->output);
-       wl_display_roundtrip(private_client->display);
+       wl_display_roundtrip_queue(private_client->display, private_client->queue);
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL);
 
        *dpms = private_output->dpms;
 
@@ -699,6 +726,7 @@ tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error)
        tdm_private_client *private_client;
        tdm_private_client_output *private_output;
        tdm_private_client_vblank *private_vblank;
+       struct wl_proxy *wrapper;
 
        if (error)
                *error = TDM_ERROR_NONE;
@@ -720,9 +748,20 @@ tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error)
                return NULL;
        }
 
+       wrapper = wl_proxy_create_wrapper(private_output->output);
+       if (!wrapper) {
+               TDM_ERR("create output_wrapper failed");
+               if (error)
+                       *error = TDM_ERROR_OUT_OF_MEMORY;
+               return NULL;
+       }
+
+       wl_proxy_set_queue(wrapper, private_client->queue);
+
        private_vblank = calloc(1, sizeof *private_vblank);
        if (!private_vblank) {
                TDM_ERR("alloc failed");
+               wl_proxy_wrapper_destroy(wrapper);
                if (error)
                        *error = TDM_ERROR_OUT_OF_MEMORY;
                return NULL;
@@ -730,7 +769,8 @@ tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error)
 
        private_vblank->private_output = private_output;
 
-       private_vblank->vblank = wl_tdm_output_create_vblank(private_output->output);
+       private_vblank->vblank = wl_tdm_output_create_vblank((struct wl_tdm_output*)wrapper);
+       wl_proxy_wrapper_destroy(wrapper);
        if (!private_vblank->vblank) {
                TDM_ERR("couldn't create vblank resource");
                free(private_vblank);
@@ -749,7 +789,9 @@ tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error)
 
        wl_tdm_vblank_add_listener(private_vblank->vblank,
                                                           &tdm_client_vblank_listener, private_vblank);
-       wl_display_roundtrip(private_client->display);
+       wl_display_roundtrip_queue(private_client->display, private_client->queue);
+
+       wl_proxy_set_queue((struct wl_proxy *)private_vblank->vblank, NULL);
 
        return (tdm_client_vblank*)private_vblank;
 }