discomfitor pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=8f510bc228e35a015a8857d5320ccb92b03c2523

commit 8f510bc228e35a015a8857d5320ccb92b03c2523
Author: Mike Blumenkrantz <zm...@osg.samsung.com>
Date:   Fri Jan 22 16:38:15 2016 -0500

    add macros for creating and binding wayland globals in extensions file
    
    wayland requires a ton of boilerplate code. anything that can be done to
    reduce the amount of work (copy/pasting) required to handle extension adding
    is a plus
---
 src/bin/e_comp_wl_extensions.c | 81 ++++++++++++++++++------------------------
 1 file changed, 35 insertions(+), 46 deletions(-)

diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index 803fbea..cb53c7f 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -10,27 +10,6 @@ _e_comp_wl_sr_cb_provide_uuid(struct wl_client *client 
EINA_UNUSED, struct wl_re
    DBG("Provide UUID callback called for UUID: %s", uuid);
 }
 
-static const struct zwp_e_session_recovery_interface 
_e_session_recovery_interface =
-{
-   _e_comp_wl_sr_cb_provide_uuid,
-};
-
-static void
-_e_comp_wl_session_recovery_cb_bind(struct wl_client *client, void *data 
EINA_UNUSED, uint32_t version EINA_UNUSED, uint32_t id)
-{
-   struct wl_resource *res;
-
-   if (!(res = wl_resource_create(client, &zwp_e_session_recovery_interface, 
1, id)))
-     {
-        ERR("Could not create session_recovery interface");
-        wl_client_post_no_memory(client);
-        return;
-     }
-
-   /* set implementation on resource */
-   wl_resource_set_implementation(res, &_e_session_recovery_interface, e_comp, 
NULL);
-}
-
 static void
 _e_comp_wl_screenshooter_cb_shoot(struct wl_client *client EINA_UNUSED, struct 
wl_resource *resource, struct wl_resource *output_resource, struct wl_resource 
*buffer_resource)
 {
@@ -91,44 +70,54 @@ _e_comp_wl_screenshooter_cb_shoot(struct wl_client *client 
EINA_UNUSED, struct w
    screenshooter_send_done(resource);
 }
 
+static const struct zwp_e_session_recovery_interface 
_e_session_recovery_interface =
+{
+   _e_comp_wl_sr_cb_provide_uuid,
+};
+
 static const struct screenshooter_interface _e_screenshooter_interface =
 {
    _e_comp_wl_screenshooter_cb_shoot
 };
 
-static void
-_e_comp_wl_screenshooter_cb_bind(struct wl_client *client, void *data, 
uint32_t version EINA_UNUSED, uint32_t id)
-{
-   struct wl_resource *res;
+#define GLOBAL_BIND_CB(NAME, IFACE) \
+static void \
+_e_comp_wl_##NAME##_cb_bind(struct wl_client *client, void *data EINA_UNUSED, 
uint32_t version EINA_UNUSED, uint32_t id) \
+{ \
+   struct wl_resource *res; \
+\
+   if (!(res = wl_resource_create(client, &(IFACE), 1, id))) \
+     { \
+        ERR("Could not create %s interface", #NAME);\
+        wl_client_post_no_memory(client);\
+        return;\
+     }\
+\
+   wl_resource_set_implementation(res, &_e_##NAME##_interface, NULL, NULL);\
+}
 
-   res = wl_resource_create(client, &screenshooter_interface, 1, id);
-   if (!res)
-     {
-        ERR("Could not create screenshooter resource");
-        wl_client_post_no_memory(client);
-        return;
-     }
+GLOBAL_BIND_CB(session_recovery, zwp_e_session_recovery_interface)
+GLOBAL_BIND_CB(screenshooter, screenshooter_interface)
+
+
+#define GLOBAL_CREATE_OR_RETURN(NAME, IFACE) \
+   do { \
+      if (!wl_global_create(e_comp_wl->wl.disp, &(IFACE), 1, \
+                            NULL, _e_comp_wl_##NAME##_cb_bind)) \
+        { \
+           ERR("Could not add %s to wayland globals", #IFACE); \
+           return EINA_FALSE; \
+        } \
+   } while (0)
 
-   wl_resource_set_implementation(res, &_e_screenshooter_interface, data, 
NULL);
-}
 
 EINTERN Eina_Bool
 e_comp_wl_extensions_init(void)
 {
    /* try to add session_recovery to wayland globals */
-   if (!wl_global_create(e_comp_wl->wl.disp, 
&zwp_e_session_recovery_interface, 1,
-                         e_comp, _e_comp_wl_session_recovery_cb_bind))
-     {
-        ERR("Could not add session_recovery to wayland globals");
-        return EINA_FALSE;
-     }
+   GLOBAL_CREATE_OR_RETURN(session_recovery, zwp_e_session_recovery_interface);
+   GLOBAL_CREATE_OR_RETURN(screenshooter, screenshooter_interface);
 
-   if (!wl_global_create(e_comp_wl->wl.disp, &screenshooter_interface, 1,
-                      e_comp, _e_comp_wl_screenshooter_cb_bind))
-     {
-        ERR("Could not create screenshooter global");
-        return EINA_FALSE;
-     }
    e_comp_wl->extensions = E_NEW(E_Comp_Wl_Extension_Data, 1);
    return EINA_TRUE;
 }

-- 


Reply via email to