The add_notification_remove_surface API accepts a simple
wl_listener instead of a ivi-shell specific notification
function. Therefore, the API is renamed to add_listener_remove_surface.

This change has several advantages:
1. Code cleanup
2. No dynamic memory allocation. Listeners are allocated
   by controller plugins
3. Remove API is not needed. Controller plugins can easily
   remove the listener link.

Signed-off-by: Emre Ucan <[email protected]>
---
 ivi-shell/hmi-controller.c       |   14 ++++++++-----
 ivi-shell/ivi-layout-export.h    |    4 +---
 ivi-shell/ivi-layout.c           |   40 ++++++--------------------------------
 tests/ivi_layout-internal-test.c |    2 +-
 tests/ivi_layout-test-plugin.c   |   19 ++++++++++--------
 5 files changed, 28 insertions(+), 51 deletions(-)

diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index bd38717..49aba81 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -128,6 +128,7 @@ struct hmi_controller {
        struct wl_listener                  destroy_listener;
 
        struct wl_listener                  surface_created;
+       struct wl_listener                  surface_removed;
 
        struct wl_client                   *user_interface;
        struct ui_setting                   ui_setting;
@@ -600,10 +601,12 @@ set_notification_create_surface(struct wl_listener 
*listener, void *data)
 }
 
 static void
-set_notification_remove_surface(struct ivi_layout_surface *ivisurf,
-                               void *userdata)
+set_notification_remove_surface(struct wl_listener *listener, void *data)
 {
-       struct hmi_controller *hmi_ctrl = userdata;
+       struct hmi_controller *hmi_ctrl =
+                       wl_container_of(listener, hmi_ctrl,
+                                       surface_removed);
+       (void)data;
 
        switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
 }
@@ -840,8 +843,9 @@ hmi_controller_create(struct weston_compositor *ec)
 
        hmi_ctrl->surface_created.notify = set_notification_create_surface;
        
ivi_layout_interface->add_listener_create_surface(&hmi_ctrl->surface_created);
-       ivi_layout_interface->add_notification_remove_surface(
-               set_notification_remove_surface, hmi_ctrl);
+
+       hmi_ctrl->surface_removed.notify = set_notification_remove_surface;
+       
ivi_layout_interface->add_listener_remove_surface(&hmi_ctrl->surface_removed);
        ivi_layout_interface->add_notification_configure_surface(
                set_notification_configure_surface, hmi_ctrl);
 
diff --git a/ivi-shell/ivi-layout-export.h b/ivi-shell/ivi-layout-export.h
index 391df55..0aaf5b3 100644
--- a/ivi-shell/ivi-layout-export.h
+++ b/ivi-shell/ivi-layout-export.h
@@ -174,9 +174,7 @@ struct ivi_layout_interface {
        /**
         * \brief register/unregister for notification when ivi_surface is 
removed
         */
-       int32_t (*add_notification_remove_surface)(
-                               surface_remove_notification_func callback,
-                               void *userdata);
+       int32_t (*add_listener_remove_surface)(struct wl_listener *listener);
 
        void (*remove_notification_remove_surface)(
                                surface_remove_notification_func callback,
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index e7d6583..63983c5 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -931,23 +931,6 @@ clear_surface_order_list(struct ivi_layout_layer *ivilayer)
 }
 
 static void
-surface_removed(struct wl_listener *listener, void *data)
-{
-       struct ivi_layout_surface *ivisurface = data;
-
-       struct listener_layout_notification *notification =
-               container_of(listener,
-                            struct listener_layout_notification,
-                            listener);
-
-       struct ivi_layout_notification_callback *removed_callback =
-               notification->userdata;
-
-       ((surface_remove_notification_func)removed_callback->callback)
-               (ivisurface, removed_callback->data);
-}
-
-static void
 surface_configure_changed(struct wl_listener *listener,
                          void *data)
 {
@@ -1064,29 +1047,18 @@ ivi_layout_add_listener_create_surface(struct 
wl_listener *listener)
 }
 
 static int32_t
-ivi_layout_add_notification_remove_surface(surface_remove_notification_func 
callback,
-                                          void *userdata)
+ivi_layout_add_listener_remove_surface(struct wl_listener *listener)
 {
        struct ivi_layout *layout = get_instance();
-       struct ivi_layout_notification_callback *removed_callback = NULL;
-
-       if (callback == NULL) {
-               weston_log("ivi_layout_add_notification_remove_surface: invalid 
argument\n");
-               return IVI_FAILED;
-       }
 
-       removed_callback = malloc(sizeof *removed_callback);
-       if (removed_callback == NULL) {
-               weston_log("fails to allocate memory\n");
+       if (listener == NULL) {
+               weston_log("ivi_layout_add_listener_remove_surface: invalid 
argument\n");
                return IVI_FAILED;
        }
 
-       removed_callback->callback = callback;
-       removed_callback->data = userdata;
+       wl_signal_add(&layout->surface_notification.removed, listener);
 
-       return add_notification(&layout->surface_notification.removed,
-                               surface_removed,
-                               removed_callback);
+       return IVI_SUCCEEDED;
 }
 
 static void
@@ -2123,7 +2095,7 @@ static struct ivi_layout_interface ivi_layout_interface = 
{
         * surface controller interfaces
         */
        .add_listener_create_surface    = 
ivi_layout_add_listener_create_surface,
-       .add_notification_remove_surface        = 
ivi_layout_add_notification_remove_surface,
+       .add_listener_remove_surface    = 
ivi_layout_add_listener_remove_surface,
        .remove_notification_remove_surface     = 
ivi_layout_remove_notification_remove_surface,
        .add_notification_configure_surface     = 
ivi_layout_add_notification_configure_surface,
        .remove_notification_configure_surface  = 
ivi_layout_remove_notification_configure_surface,
diff --git a/tests/ivi_layout-internal-test.c b/tests/ivi_layout-internal-test.c
index 49a682a..72c045f 100644
--- a/tests/ivi_layout-internal-test.c
+++ b/tests/ivi_layout-internal-test.c
@@ -873,7 +873,7 @@ test_surface_bad_remove_notification(struct test_context 
*ctx)
 {
        const struct ivi_layout_interface *lyt = ctx->layout_interface;
 
-       iassert(lyt->add_notification_remove_surface(NULL, NULL) == IVI_FAILED);
+       iassert(lyt->add_listener_remove_surface(NULL) == IVI_FAILED);
 }
 
 /************************ tests end ********************************/
diff --git a/tests/ivi_layout-test-plugin.c b/tests/ivi_layout-test-plugin.c
index 32de740..f01a2d5 100644
--- a/tests/ivi_layout-test-plugin.c
+++ b/tests/ivi_layout-test-plugin.c
@@ -86,6 +86,7 @@ struct test_context {
 
        struct wl_listener surface_property_changed;
        struct wl_listener surface_created;
+       struct wl_listener surface_removed;
 };
 
 static struct test_context static_context;
@@ -952,11 +953,13 @@ RUNNER_TEST(surface_create_notification_p3)
 }
 
 static void
-test_surface_remove_notification_callback(struct ivi_layout_surface *ivisurf,
-                                         void *userdata)
+test_surface_remove_notification_callback(struct wl_listener *listener, void 
*data)
 {
-       struct test_context *ctx = userdata;
+       struct test_context *ctx =
+                       container_of(listener, struct test_context,
+                                       surface_removed);
        const struct ivi_layout_interface *lyt = ctx->layout_interface;
+       struct ivi_layout_surface *ivisurf = (struct ivi_layout_surface*) data;
 
        runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == 
IVI_TEST_SURFACE_ID(0));
 
@@ -967,19 +970,19 @@ RUNNER_TEST(surface_remove_notification_p1)
 {
        const struct ivi_layout_interface *lyt = ctx->layout_interface;
 
-       runner_assert(lyt->add_notification_remove_surface(
-                     test_surface_remove_notification_callback, ctx) == 
IVI_SUCCEEDED);
+       ctx->surface_removed.notify = test_surface_remove_notification_callback;
+       runner_assert(lyt->add_listener_remove_surface(&ctx->surface_removed)
+                       == IVI_SUCCEEDED);
 
        ctx->user_flags = 0;
 }
 
 RUNNER_TEST(surface_remove_notification_p2)
 {
-       const struct ivi_layout_interface *lyt = ctx->layout_interface;
-
        runner_assert(ctx->user_flags == 1);
 
-       
lyt->remove_notification_remove_surface(test_surface_remove_notification_callback,
 ctx);
+       // remove surface removed listener.
+       wl_list_remove(&ctx->surface_removed.link);
        ctx->user_flags = 0;
 }
 
-- 
1.7.9.5

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to