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

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/ivi-layout-export.h  |    5 ++--
 ivi-shell/ivi-layout.c         |   52 +++++-----------------------------------
 tests/ivi_layout-test-plugin.c |   37 ++++++++++++++++------------
 3 files changed, 30 insertions(+), 64 deletions(-)

diff --git a/ivi-shell/ivi-layout-export.h b/ivi-shell/ivi-layout-export.h
index 7a3fbb7..8dc32cb 100644
--- a/ivi-shell/ivi-layout-export.h
+++ b/ivi-shell/ivi-layout-export.h
@@ -328,9 +328,8 @@ struct ivi_layout_interface {
         * \return IVI_SUCCEEDED if the method call was successful
         * \return IVI_FAILED if the method call was failed
         */
-       int32_t (*surface_add_notification)(struct ivi_layout_surface *ivisurf,
-                                           surface_property_notification_func 
callback,
-                                           void *userdata);
+       int32_t (*surface_add_listener)(struct ivi_layout_surface *ivisurf,
+                                           struct wl_listener *listener);
 
        /**
         * \brief remove notification on property changes of ivi_surface
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index 5c0e8f4..8a95a11 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -1062,23 +1062,6 @@ surface_removed(struct wl_listener *listener, void *data)
 }
 
 static void
-surface_prop_changed(struct wl_listener *listener, void *data)
-{
-       struct ivi_layout_surface *ivisurf = data;
-
-       struct listener_layout_notification *layout_listener =
-               container_of(listener,
-                            struct listener_layout_notification,
-                            listener);
-
-       struct ivi_layout_notification_callback *prop_callback =
-               layout_listener->userdata;
-
-       ((surface_property_notification_func)prop_callback->callback)
-               (ivisurf, &ivisurf->prop, ivisurf->prop.event_mask, 
prop_callback->data);
-}
-
-static void
 surface_configure_changed(struct wl_listener *listener,
                          void *data)
 {
@@ -1360,38 +1343,15 @@ ivi_layout_get_surface_from_id(uint32_t id_surface)
 }
 
 static int32_t
-ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
-                                   surface_property_notification_func callback,
-                                   void *userdata)
+ivi_layout_surface_add_listener(struct ivi_layout_surface *ivisurf,
+                                   struct wl_listener *listener)
 {
-       struct listener_layout_notification* notification = NULL;
-       struct ivi_layout_notification_callback *prop_callback = NULL;
-
-       if (ivisurf == NULL || callback == NULL) {
-               weston_log("ivi_layout_surface_add_notification: invalid 
argument\n");
-               return IVI_FAILED;
-       }
-
-       notification = malloc(sizeof *notification);
-       if (notification == NULL) {
-               weston_log("fails to allocate memory\n");
-               return IVI_FAILED;
-       }
-
-       prop_callback = malloc(sizeof *prop_callback);
-       if (prop_callback == NULL) {
-               weston_log("fails to allocate memory\n");
-               free(notification);
+       if (ivisurf == NULL || listener == NULL) {
+               weston_log("ivi_layout_surface_add_listener: invalid 
argument\n");
                return IVI_FAILED;
        }
 
-       prop_callback->callback = callback;
-       prop_callback->data = userdata;
-
-       notification->listener.notify = surface_prop_changed;
-       notification->userdata = prop_callback;
-
-       wl_signal_add(&ivisurf->property_changed, &notification->listener);
+       wl_signal_add(&ivisurf->property_changed, listener);
 
        return IVI_SUCCEEDED;
 }
@@ -2386,7 +2346,7 @@ static struct ivi_layout_interface ivi_layout_interface = 
{
        .surface_set_source_rectangle           = 
ivi_layout_surface_set_source_rectangle,
        .surface_set_destination_rectangle      = 
ivi_layout_surface_set_destination_rectangle,
        .surface_set_orientation                = 
ivi_layout_surface_set_orientation,
-       .surface_add_notification               = 
ivi_layout_surface_add_notification,
+       .surface_add_listener                   = 
ivi_layout_surface_add_listener,
        .surface_remove_notification            = 
ivi_layout_surface_remove_notification,
        .surface_get_weston_surface             = 
ivi_layout_surface_get_weston_surface,
        .surface_set_transition                 = 
ivi_layout_surface_set_transition,
diff --git a/tests/ivi_layout-test-plugin.c b/tests/ivi_layout-test-plugin.c
index 7c72c36..5cdc203 100644
--- a/tests/ivi_layout-test-plugin.c
+++ b/tests/ivi_layout-test-plugin.c
@@ -83,6 +83,8 @@ struct test_context {
        const struct ivi_layout_interface *layout_interface;
        struct wl_resource *runner_resource;
        uint32_t user_flags;
+
+       struct wl_listener surface_property_changed;
 };
 
 static struct test_context static_context;
@@ -809,13 +811,14 @@ RUNNER_TEST(cleanup_layer)
 }
 
 static void
-test_surface_properties_changed_notification_callback(struct 
ivi_layout_surface *ivisurf,
-                                                     const struct 
ivi_layout_surface_properties *prop,
-                                                     enum 
ivi_layout_notification_mask mask,
-                                                     void *userdata)
+test_surface_properties_changed_notification_callback(struct wl_listener 
*listener, void *data)
+
 {
-       struct test_context *ctx = userdata;
+       struct test_context *ctx =
+                       container_of(listener, struct test_context,
+                                       surface_property_changed);
        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));
 
@@ -833,8 +836,10 @@ RUNNER_TEST(surface_properties_changed_notification)
        ivisurf = lyt->get_surface_from_id(id_surface);
        runner_assert(ivisurf != NULL);
 
-       runner_assert(lyt->surface_add_notification(
-                     ivisurf, 
test_surface_properties_changed_notification_callback, ctx) == IVI_SUCCEEDED);
+       ctx->surface_property_changed.notify = 
test_surface_properties_changed_notification_callback;
+
+       runner_assert(lyt->surface_add_listener(
+                     ivisurf, &ctx->surface_property_changed) == 
IVI_SUCCEEDED);
 
        lyt->commit_changes();
 
@@ -863,6 +868,9 @@ RUNNER_TEST(surface_properties_changed_notification)
        lyt->commit_changes();
 
        runner_assert(ctx->user_flags == 0);
+
+       // remove surface property changed listener.
+       wl_list_remove(&ctx->surface_property_changed.link);
 }
 
 static void
@@ -981,10 +989,7 @@ RUNNER_TEST(surface_remove_notification_p3)
 }
 
 static void
-test_surface_bad_properties_changed_notification_callback(struct 
ivi_layout_surface *ivisurf,
-                                                         const struct 
ivi_layout_surface_properties *prop,
-                                                         enum 
ivi_layout_notification_mask mask,
-                                                         void *userdata)
+test_surface_bad_properties_changed_notification_callback(struct wl_listener 
*listener, void *data)
 {
 }
 
@@ -996,8 +1001,10 @@ RUNNER_TEST(surface_bad_properties_changed_notification)
        ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
        runner_assert(ivisurf != NULL);
 
-       runner_assert(lyt->surface_add_notification(
-                     NULL, 
test_surface_bad_properties_changed_notification_callback, NULL) == IVI_FAILED);
-       runner_assert(lyt->surface_add_notification(
-                     ivisurf, NULL, NULL) == IVI_FAILED);
+       ctx->surface_property_changed.notify = 
test_surface_bad_properties_changed_notification_callback;
+
+       runner_assert(lyt->surface_add_listener(
+                     NULL, &ctx->surface_property_changed) == IVI_FAILED);
+       runner_assert(lyt->surface_add_listener(
+                     ivisurf, NULL) == IVI_FAILED);
 }
-- 
1.7.9.5

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

Reply via email to