ilmCommon: manage ownership of display connection
authorMarcus Fritzsch <marcus.fritzsch@xse.de>
Mon, 21 Jul 2014 11:43:52 +0000 (13:43 +0200)
committerNobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>
Tue, 12 Aug 2014 13:15:12 +0000 (22:15 +0900)
Introduced a new flag 'disconnect_display' separate from
valid, as adding bits to valid would change its scope and
entail changes to all usages of it.

Signed-off-by: Marcus Fritzsch <marcus.fritzsch@xse.de>
ivi-layermanagement-api/ilmCommon/src/ilm_common_wayland_platform.c

index b8fd975..fd20b27 100644 (file)
@@ -50,10 +50,11 @@ extern char *__progname;
 
 struct ilm_common_context {
     int32_t valid;
+    int32_t disconnect_display;
     struct wl_display *display;
 };
 
-static struct ilm_common_context ilm_context = {0, 0};
+static struct ilm_common_context ilm_context = {0};
 
 static ilmErrorTypes
 wayland_init(t_ilm_nativedisplay nativedisplay)
@@ -62,8 +63,10 @@ wayland_init(t_ilm_nativedisplay nativedisplay)
 
     if (nativedisplay != 0) {
         ctx->display = (struct wl_display*)nativedisplay;
+        ctx->disconnect_display = 0;
     } else {
         ctx->display = wl_display_connect(NULL);
+        ctx->disconnect_display = 1;
         if (ctx->display == NULL) {
             fprintf(stderr, "Failed to connect display in libilmCommon\n");
             return ILM_FAILED;
@@ -102,5 +105,13 @@ wayland_destroy(void)
 
     ctx->valid = 0;
 
+    // we own the display, act like it.
+    if (ctx->disconnect_display)
+    {
+       wl_display_roundtrip(ctx->display);
+       wl_display_disconnect(ctx->display);
+       ctx->display = NULL;
+    }
+
     return ILM_SUCCESS;
 }