[PATCH weston v2 7/7] ivi-shell: rework configure_surface notification
Ucan, Emre (ADITG/SW1)
eucan at de.adit-jv.com
Mon Apr 4 08:05:20 UTC 2016
The add_notification_configure_surface API accepts a simple
wl_listener instead of a ivi-shell specific notification
function. Therefore, the API is renamed to
add_listener_configure_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.
The remove API is removed too:
- ivi_layout_remove_notification_configure_surface
Signed-off-by: Emre Ucan <eucan at de.adit-jv.com>
---
ivi-shell/hmi-controller.c | 14 +++--
ivi-shell/ivi-layout-export.h | 19 +++----
ivi-shell/ivi-layout.c | 111 +++-----------------------------------
tests/ivi_layout-internal-test.c | 2 +-
tests/ivi_layout-test-plugin.c | 17 +++---
5 files changed, 33 insertions(+), 130 deletions(-)
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index b27f87b..97f78af 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -129,6 +129,7 @@ struct hmi_controller {
struct wl_listener surface_created;
struct wl_listener surface_removed;
+ struct wl_listener surface_configured;
struct wl_client *user_interface;
struct ui_setting ui_setting;
@@ -612,10 +613,12 @@ set_notification_remove_surface(struct wl_listener *listener, void *data)
}
static void
-set_notification_configure_surface(struct ivi_layout_surface *ivisurf,
- void *userdata)
+set_notification_configure_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_configured);
+ struct ivi_layout_surface *ivisurf = data;
struct hmi_controller_layer *layer_link = NULL;
struct ivi_layout_layer *application_layer = NULL;
struct weston_surface *surface;
@@ -846,8 +849,9 @@ hmi_controller_create(struct weston_compositor *ec)
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);
+
+ hmi_ctrl->surface_configured.notify = set_notification_configure_surface;
+ ivi_layout_interface->add_listener_configure_surface(&hmi_ctrl->surface_configured);
hmi_ctrl->destroy_listener.notify = hmi_controller_destroy;
wl_signal_add(&hmi_ctrl->compositor->destroy_signal,
diff --git a/ivi-shell/ivi-layout-export.h b/ivi-shell/ivi-layout-export.h
index 1485d3f..9c5225c 100644
--- a/ivi-shell/ivi-layout-export.h
+++ b/ivi-shell/ivi-layout-export.h
@@ -138,10 +138,6 @@ enum ivi_layout_transition_type{
IVI_LAYOUT_TRANSITION_MAX,
};
-typedef void (*surface_configure_notification_func)(
- struct ivi_layout_surface *ivisurf,
- void *userdata);
-
struct ivi_layout_interface {
/**
@@ -178,15 +174,14 @@ struct ivi_layout_interface {
int32_t (*add_listener_remove_surface)(struct wl_listener *listener);
/**
- * \brief register/unregister for notification when ivi_surface is configured
+ * \brief add a listener for notification when ivi_surface is configured
+ *
+ * When an ivi_surface is configured, a signal is emitted
+ * to the listening controller plugins.
+ * The pointer of the configured ivi_surface is sent as the void *data argument
+ * to the wl_listener::notify callback function of the listener.
*/
- int32_t (*add_notification_configure_surface)(
- surface_configure_notification_func callback,
- void *userdata);
-
- void (*remove_notification_configure_surface)(
- surface_configure_notification_func callback,
- void *userdata);
+ int32_t (*add_listener_configure_surface)(struct wl_listener *listener);
/**
* \brief Get all ivi_surfaces which are currently registered and managed
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index 23f2312..e3452d2 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -71,11 +71,6 @@
#define max(a, b) ((a) > (b) ? (a) : (b))
-struct listener_layout_notification {
- void *userdata;
- struct wl_listener listener;
-};
-
struct ivi_layout;
struct ivi_layout_screen {
@@ -96,11 +91,6 @@ struct ivi_layout_screen {
} order;
};
-struct ivi_layout_notification_callback {
- void *callback;
- void *data;
-};
-
struct ivi_rectangle
{
int32_t x;
@@ -109,9 +99,6 @@ struct ivi_rectangle
int32_t height;
};
-static void
-remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
-
static struct ivi_layout ivilayout = {0};
struct ivi_layout *
@@ -930,73 +917,6 @@ clear_surface_order_list(struct ivi_layout_layer *ivilayer)
}
}
-static void
-surface_configure_changed(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 *configure_changed_callback =
- notification->userdata;
-
- ((surface_configure_notification_func)configure_changed_callback->callback)
- (ivisurface, configure_changed_callback->data);
-}
-
-static int32_t
-add_notification(struct wl_signal *signal,
- wl_notify_func_t callback,
- void *userdata)
-{
- struct listener_layout_notification *notification = NULL;
-
- notification = malloc(sizeof *notification);
- if (notification == NULL) {
- weston_log("fails to allocate memory\n");
- free(userdata);
- return IVI_FAILED;
- }
-
- notification->listener.notify = callback;
- notification->userdata = userdata;
-
- wl_signal_add(signal, ¬ification->listener);
-
- return IVI_SUCCEEDED;
-}
-
-static void
-remove_notification(struct wl_list *listener_list, void *callback, void *userdata)
-{
- struct wl_listener *listener = NULL;
- struct wl_listener *next = NULL;
-
- wl_list_for_each_safe(listener, next, listener_list, link) {
- struct listener_layout_notification *notification =
- container_of(listener,
- struct listener_layout_notification,
- listener);
-
- struct ivi_layout_notification_callback *notification_callback =
- notification->userdata;
-
- if ((notification_callback->callback != callback) ||
- (notification_callback->data != userdata)) {
- continue;
- }
-
- wl_list_remove(&listener->link);
-
- free(notification->userdata);
- free(notification);
- }
-}
-
/**
* Exported APIs of ivi-layout library are implemented from here.
* Brief of APIs is described in ivi-layout-export.h.
@@ -1062,36 +982,18 @@ ivi_layout_add_listener_remove_surface(struct wl_listener *listener)
}
static int32_t
-ivi_layout_add_notification_configure_surface(surface_configure_notification_func callback,
- void *userdata)
+ivi_layout_add_listener_configure_surface(struct wl_listener *listener)
{
struct ivi_layout *layout = get_instance();
- struct ivi_layout_notification_callback *configure_changed_callback = NULL;
- if (callback == NULL) {
- weston_log("ivi_layout_add_notification_configure_surface: invalid argument\n");
- return IVI_FAILED;
- }
- configure_changed_callback = malloc(sizeof *configure_changed_callback);
- if (configure_changed_callback == NULL) {
- weston_log("fails to allocate memory\n");
+ if (listener == NULL) {
+ weston_log("ivi_layout_add_listener_configure_surface: invalid argument\n");
return IVI_FAILED;
}
- configure_changed_callback->callback = callback;
- configure_changed_callback->data = userdata;
+ wl_signal_add(&layout->surface_notification.configure_changed, listener);
- return add_notification(&layout->surface_notification.configure_changed,
- surface_configure_changed,
- configure_changed_callback);
-}
-
-static void
-ivi_layout_remove_notification_configure_surface(surface_configure_notification_func callback,
- void *userdata)
-{
- struct ivi_layout *layout = get_instance();
- remove_notification(&layout->surface_notification.configure_changed.listener_list, callback, userdata);
+ return IVI_SUCCEEDED;
}
uint32_t
@@ -2088,8 +1990,7 @@ static struct ivi_layout_interface ivi_layout_interface = {
*/
.add_listener_create_surface = ivi_layout_add_listener_create_surface,
.add_listener_remove_surface = ivi_layout_add_listener_remove_surface,
- .add_notification_configure_surface = ivi_layout_add_notification_configure_surface,
- .remove_notification_configure_surface = ivi_layout_remove_notification_configure_surface,
+ .add_listener_configure_surface = ivi_layout_add_listener_configure_surface,
.get_surfaces = ivi_layout_get_surfaces,
.get_id_of_surface = ivi_layout_get_id_of_surface,
.get_surface_from_id = ivi_layout_get_surface_from_id,
diff --git a/tests/ivi_layout-internal-test.c b/tests/ivi_layout-internal-test.c
index 4e17357..f5e296c 100644
--- a/tests/ivi_layout-internal-test.c
+++ b/tests/ivi_layout-internal-test.c
@@ -841,7 +841,7 @@ test_surface_bad_configure_notification(struct test_context *ctx)
{
const struct ivi_layout_interface *lyt = ctx->layout_interface;
- iassert(lyt->add_notification_configure_surface(NULL, NULL) == IVI_FAILED);
+ iassert(lyt->add_listener_configure_surface(NULL) == IVI_FAILED);
}
static void
diff --git a/tests/ivi_layout-test-plugin.c b/tests/ivi_layout-test-plugin.c
index 6796b33..80fcdf7 100644
--- a/tests/ivi_layout-test-plugin.c
+++ b/tests/ivi_layout-test-plugin.c
@@ -87,6 +87,7 @@ struct test_context {
struct wl_listener surface_property_changed;
struct wl_listener surface_created;
struct wl_listener surface_removed;
+ struct wl_listener surface_configured;
};
static struct test_context static_context;
@@ -874,11 +875,13 @@ RUNNER_TEST(surface_properties_changed_notification)
}
static void
-test_surface_configure_notification_callback(struct ivi_layout_surface *ivisurf,
- void *userdata)
+test_surface_configure_notification_callback(struct wl_listener *listener, void *data)
{
- struct test_context *ctx = userdata;
+ struct test_context *ctx =
+ container_of(listener, struct test_context,
+ surface_configured);
const struct ivi_layout_interface *lyt = ctx->layout_interface;
+ struct ivi_layout_surface *ivisurf = data;
runner_assert_or_return(lyt->get_id_of_surface(ivisurf) == IVI_TEST_SURFACE_ID(0));
@@ -889,7 +892,8 @@ RUNNER_TEST(surface_configure_notification_p1)
{
const struct ivi_layout_interface *lyt = ctx->layout_interface;
- runner_assert(IVI_SUCCEEDED == lyt->add_notification_configure_surface(test_surface_configure_notification_callback, ctx));
+ ctx->surface_configured.notify = test_surface_configure_notification_callback;
+ runner_assert(IVI_SUCCEEDED == lyt->add_listener_configure_surface(&ctx->surface_configured));
lyt->commit_changes();
ctx->user_flags = 0;
@@ -897,11 +901,10 @@ RUNNER_TEST(surface_configure_notification_p1)
RUNNER_TEST(surface_configure_notification_p2)
{
- const struct ivi_layout_interface *lyt = ctx->layout_interface;
-
runner_assert(ctx->user_flags == 1);
- lyt->remove_notification_configure_surface(test_surface_configure_notification_callback, ctx);
+ // remove surface configured listener.
+ wl_list_remove(&ctx->surface_configured.link);
ctx->user_flags = 0;
}
--
1.7.9.5
More information about the wayland-devel
mailing list