[PATCH weston 04/16] ivi-shell: rework layer_add_notification API

Ucan, Emre (ADITG/SW1) eucan at de.adit-jv.com
Thu Mar 31 11:09:08 UTC 2016


The layer_add_notification API accepts a simple
wl_listener instead of a ivi-shell specific notification
function. Therefore, the API is renamed to layer_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 <eucan at de.adit-jv.com>
---
 ivi-shell/ivi-layout-export.h    |    5 ++---
 ivi-shell/ivi-layout.c           |   43 +++++++-------------------------------
 tests/ivi_layout-internal-test.c |   33 ++++++++++++++++-------------
 3 files changed, 28 insertions(+), 53 deletions(-)

diff --git a/ivi-shell/ivi-layout-export.h b/ivi-shell/ivi-layout-export.h
index 7a25825..9db18e0 100644
--- a/ivi-shell/ivi-layout-export.h
+++ b/ivi-shell/ivi-layout-export.h
@@ -527,9 +527,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 (*layer_add_notification)(struct ivi_layout_layer *ivilayer,
-					  layer_property_notification_func callback,
-					  void *userdata);
+	int32_t (*layer_add_listener)(struct ivi_layout_layer *ivilayer,
+					  struct wl_listener *listener);
 
 	/**
 	 * \brief remove notification on property changes of ivi_layer
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index 013e096..25df1f9 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -985,23 +985,6 @@ layer_removed(struct wl_listener *listener, void *data)
 }
 
 static void
-layer_prop_changed(struct wl_listener *listener, void *data)
-{
-	struct ivi_layout_layer *ivilayer = 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;
-
-	((layer_property_notification_func)prop_callback->callback)
-		(ivilayer, &ivilayer->prop, ivilayer->prop.event_mask, prop_callback->data);
-}
-
-static void
 surface_created(struct wl_listener *listener, void *data)
 {
 	struct ivi_layout_surface *ivisurface = data;
@@ -1983,29 +1966,17 @@ ivi_layout_surface_get_size(struct ivi_layout_surface *ivisurf,
 }
 
 static int32_t
-ivi_layout_layer_add_notification(struct ivi_layout_layer *ivilayer,
-				  layer_property_notification_func callback,
-				  void *userdata)
+ivi_layout_layer_add_listener(struct ivi_layout_layer *ivilayer,
+				  struct wl_listener *listener)
 {
-	struct ivi_layout_notification_callback *prop_callback = NULL;
-
-	if (ivilayer == NULL || callback == NULL) {
-		weston_log("ivi_layout_layer_add_notification: invalid argument\n");
-		return IVI_FAILED;
-	}
-
-	prop_callback = malloc(sizeof *prop_callback);
-	if (prop_callback == NULL) {
-		weston_log("fails to allocate memory\n");
+	if (ivilayer == NULL || listener == NULL) {
+		weston_log("ivi_layout_layer_add_listener: invalid argument\n");
 		return IVI_FAILED;
 	}
 
-	prop_callback->callback = callback;
-	prop_callback->data = userdata;
+	wl_signal_add(&ivilayer->property_changed, listener);
 
-	return add_notification(&ivilayer->property_changed,
-				layer_prop_changed,
-				prop_callback);
+	return IVI_SUCCEEDED;
 }
 
 static const struct ivi_layout_surface_properties *
@@ -2348,7 +2319,7 @@ static struct ivi_layout_interface ivi_layout_interface = {
 	.layer_add_surface			= ivi_layout_layer_add_surface,
 	.layer_remove_surface			= ivi_layout_layer_remove_surface,
 	.layer_set_render_order			= ivi_layout_layer_set_render_order,
-	.layer_add_notification			= ivi_layout_layer_add_notification,
+	.layer_add_listener			= ivi_layout_layer_add_listener,
 	.layer_remove_notification		= ivi_layout_layer_remove_notification,
 	.layer_set_transition			= ivi_layout_layer_set_transition,
 
diff --git a/tests/ivi_layout-internal-test.c b/tests/ivi_layout-internal-test.c
index 99d10a4..1cd6c3f 100644
--- a/tests/ivi_layout-internal-test.c
+++ b/tests/ivi_layout-internal-test.c
@@ -35,11 +35,14 @@
 #include "ivi-shell/ivi-layout-export.h"
 #include "ivi-shell/ivi-layout-private.h"
 #include "ivi-test.h"
+#include "shared/helpers.h"
 
 struct test_context {
 	struct weston_compositor *compositor;
 	const struct ivi_layout_interface *layout_interface;
 	uint32_t user_flags;
+
+	struct wl_listener layer_property_changed;
 };
 
 static void
@@ -652,13 +655,14 @@ test_commit_changes_after_render_order_set_layer_destroy(
 }
 
 static void
-test_layer_properties_changed_notification_callback(struct ivi_layout_layer *ivilayer,
-						    const struct ivi_layout_layer_properties *prop,
-						    enum ivi_layout_notification_mask mask,
-						    void *userdata)
+test_layer_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,
+					layer_property_changed);
 	const struct ivi_layout_interface *lyt = ctx->layout_interface;
+	struct ivi_layout_layer *ivilayer = (struct ivi_layout_layer*) data;
+	const struct ivi_layout_layer_properties *prop = lyt->get_properties_of_layer(ivilayer);
 
 	iassert(lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
 	iassert(prop->source_width == 200);
@@ -679,7 +683,9 @@ test_layer_properties_changed_notification(struct test_context *ctx)
 
 	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
 
-	iassert(lyt->layer_add_notification(ivilayer, test_layer_properties_changed_notification_callback, ctx) == IVI_SUCCEEDED);
+	ctx->layer_property_changed.notify = test_layer_properties_changed_notification_callback;
+
+	iassert(lyt->layer_add_listener(ivilayer, &ctx->layer_property_changed) == IVI_SUCCEEDED);
 
 	lyt->commit_changes();
 
@@ -700,7 +706,8 @@ test_layer_properties_changed_notification(struct test_context *ctx)
 
 	iassert(ctx->user_flags == 0);
 
-	lyt->layer_remove_notification(ivilayer);
+	// remove layer property changed listener.
+	wl_list_remove(&ctx->layer_property_changed.link);
 
 	ctx->user_flags = 0;
 	lyt->commit_changes();
@@ -800,10 +807,7 @@ test_layer_remove_notification(struct test_context *ctx)
 }
 
 static void
-test_layer_bad_properties_changed_notification_callback(struct ivi_layout_layer *ivilayer,
-							const struct ivi_layout_layer_properties *prop,
-							enum ivi_layout_notification_mask mask,
-							void *userdata)
+test_layer_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
 {
 }
 
@@ -815,9 +819,10 @@ test_layer_bad_properties_changed_notification(struct test_context *ctx)
 
 	ivilayer = lyt->layer_create_with_dimension(IVI_TEST_LAYER_ID(0), 200, 300);
 
-	iassert(lyt->layer_add_notification(
-		    NULL, test_layer_bad_properties_changed_notification_callback, NULL) == IVI_FAILED);
-	iassert(lyt->layer_add_notification(ivilayer, NULL, NULL) == IVI_FAILED);
+	ctx->layer_property_changed.notify = test_layer_bad_properties_changed_notification_callback;
+
+	iassert(lyt->layer_add_listener(NULL, &ctx->layer_property_changed) == IVI_FAILED);
+	iassert(lyt->layer_add_listener(ivilayer, NULL) == IVI_FAILED);
 
 	lyt->layer_destroy(ivilayer);
 }
-- 
1.7.9.5



More information about the wayland-devel mailing list