ilmControl: rewrite sync_and_acquire_instance
authorMarcus Fritzsch <marcus.fritzsch@xse.de>
Tue, 5 Aug 2014 11:36:38 +0000 (13:36 +0200)
committerNobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>
Mon, 1 Sep 2014 06:55:43 +0000 (15:55 +0900)
* Moved all of the code to impl_sync_and_acquire_instance
* The macro still allows for ILM_FAILED return if instance is not
  correctly initialized or the wayland display connection broke.

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

index faf8b99..6016e1a 100644 (file)
@@ -168,7 +168,8 @@ static inline void unlock_context(struct ilm_control_context *ctx)
 
 static int init_control(void);
 
-static struct ilm_control_context* sync_and_acquire_instance(void);
+static ilmErrorTypes impl_sync_and_acquire_instance(struct ilm_control_context *ctx);
+
 static struct surface_context* get_surface_context(struct wayland_context *, uint32_t);
 
 static void release_instance(void);
@@ -1195,7 +1196,7 @@ init_control(void)
 
     if (! wl->controller)
     {
-        fputs("ivi_controller not available\n", stderr);
+        fprintf(stderr, "ivi_controller not available\n");
         return -1;
     }
 
@@ -1219,14 +1220,33 @@ init_control(void)
     return 0;
 }
 
+static ilmErrorTypes impl_sync_and_acquire_instance(struct ilm_control_context *ctx)
+{
+    if (! ctx->initialized) {
+        fprintf(stderr, "Not initialized\n");
+        return ILM_FAILED;
+    }
+
+    lock_context(ctx);
+
+    if (display_roundtrip_queue(ctx->wl.display, ctx->wl.queue) == -1) {
+        int err = wl_display_get_error(ctx->wl.display);
+        fprintf(stderr, "Error communicating with wayland: %s\n", strerror(err));
+        unlock_context(ctx);
+        return ILM_FAILED;
+    }
+
+    return ILM_SUCCESS;
+}
+
 #define sync_and_acquire_instance() ({ \
     struct ilm_control_context *ctx = &ilm_context; \
-    if (! ctx->initialized) { \
-        fputs("Not initialized\n", stderr); \
-        return ILM_FAILED; \
+    { \
+        ilmErrorTypes status = impl_sync_and_acquire_instance(ctx); \
+        if (status != ILM_SUCCESS) { \
+            return status; \
+        } \
     } \
-    lock_context(ctx); \
-    display_roundtrip_queue(ctx->wl.display, ctx->wl.queue); \
     ctx; \
 })