[PATCH weston 06/16] ivi-shell: rework create_surface notification
Ucan, Emre (ADITG/SW1)
eucan at de.adit-jv.com
Thu Mar 31 11:09:18 UTC 2016
The add_notification_create_surface API accepts a simple
wl_listener instead of a ivi-shell specific notification
function. Therefore, the API is renamed to add_listener_create_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 <eucan at de.adit-jv.com>
---
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 | 20 ++++++++++---------
5 files changed, 28 insertions(+), 52 deletions(-)
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index 1ef008d..bd38717 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -127,6 +127,8 @@ struct hmi_controller {
struct weston_compositor *compositor;
struct wl_listener destroy_listener;
+ struct wl_listener surface_created;
+
struct wl_client *user_interface;
struct ui_setting ui_setting;
@@ -576,10 +578,12 @@ create_layer(struct weston_output *output,
* Internal set notification
*/
static void
-set_notification_create_surface(struct ivi_layout_surface *ivisurf,
- void *userdata)
+set_notification_create_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_created);
+ struct ivi_layout_surface *ivisurf = (struct ivi_layout_surface*) data;
struct hmi_controller_layer *layer_link =
wl_container_of(hmi_ctrl->application_layer_list.prev,
layer_link,
@@ -834,8 +838,8 @@ hmi_controller_create(struct weston_compositor *ec)
wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
&tmp_link_layer->link);
- ivi_layout_interface->add_notification_create_surface(
- set_notification_create_surface, hmi_ctrl);
+ 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);
ivi_layout_interface->add_notification_configure_surface(
diff --git a/ivi-shell/ivi-layout-export.h b/ivi-shell/ivi-layout-export.h
index f8d29da..7f5e785 100644
--- a/ivi-shell/ivi-layout-export.h
+++ b/ivi-shell/ivi-layout-export.h
@@ -181,9 +181,7 @@ struct ivi_layout_interface {
/**
* \brief register/unregister for notification when ivi_surface is created
*/
- int32_t (*add_notification_create_surface)(
- surface_create_notification_func callback,
- void *userdata);
+ int32_t (*add_listener_create_surface)(struct wl_listener *listener);
void (*remove_notification_create_surface)(
surface_create_notification_func callback,
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index 80f8496..ac86049 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -965,23 +965,6 @@ layer_removed(struct wl_listener *listener, void *data)
}
static void
-surface_created(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 *created_callback =
- notification->userdata;
-
- ((surface_create_notification_func)created_callback->callback)
- (ivisurface, created_callback->data);
-}
-
-static void
surface_removed(struct wl_listener *listener, void *data)
{
struct ivi_layout_surface *ivisurface = data;
@@ -1137,29 +1120,18 @@ ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callb
}
static int32_t
-ivi_layout_add_notification_create_surface(surface_create_notification_func callback,
- void *userdata)
+ivi_layout_add_listener_create_surface(struct wl_listener *listener)
{
struct ivi_layout *layout = get_instance();
- struct ivi_layout_notification_callback *created_callback = NULL;
- if (callback == NULL) {
- weston_log("ivi_layout_add_notification_create_surface: invalid argument\n");
+ if (listener == NULL) {
+ weston_log("ivi_layout_add_listener_create_surface: invalid argument\n");
return IVI_FAILED;
}
- created_callback = malloc(sizeof *created_callback);
- if (created_callback == NULL) {
- weston_log("fails to allocate memory\n");
- return IVI_FAILED;
- }
-
- created_callback->callback = callback;
- created_callback->data = userdata;
+ wl_signal_add(&layout->surface_notification.created, listener);
- return add_notification(&layout->surface_notification.created,
- surface_created,
- created_callback);
+ return IVI_SUCCEEDED;
}
static void
@@ -2229,7 +2201,7 @@ static struct ivi_layout_interface ivi_layout_interface = {
/**
* surface controller interfaces
*/
- .add_notification_create_surface = ivi_layout_add_notification_create_surface,
+ .add_listener_create_surface = ivi_layout_add_listener_create_surface,
.remove_notification_create_surface = ivi_layout_remove_notification_create_surface,
.add_notification_remove_surface = ivi_layout_add_notification_remove_surface,
.remove_notification_remove_surface = ivi_layout_remove_notification_remove_surface,
diff --git a/tests/ivi_layout-internal-test.c b/tests/ivi_layout-internal-test.c
index 1cd6c3f..f95c9e3 100644
--- a/tests/ivi_layout-internal-test.c
+++ b/tests/ivi_layout-internal-test.c
@@ -848,7 +848,7 @@ test_surface_bad_create_notification(struct test_context *ctx)
{
const struct ivi_layout_interface *lyt = ctx->layout_interface;
- iassert(lyt->add_notification_create_surface(NULL, NULL) == IVI_FAILED);
+ iassert(lyt->add_listener_create_surface(NULL) == IVI_FAILED);
}
static void
diff --git a/tests/ivi_layout-test-plugin.c b/tests/ivi_layout-test-plugin.c
index 839a0f6..32de740 100644
--- a/tests/ivi_layout-test-plugin.c
+++ b/tests/ivi_layout-test-plugin.c
@@ -85,6 +85,7 @@ struct test_context {
uint32_t user_flags;
struct wl_listener surface_property_changed;
+ struct wl_listener surface_created;
};
static struct test_context static_context;
@@ -912,11 +913,13 @@ RUNNER_TEST(surface_configure_notification_p3)
}
static void
-test_surface_create_notification_callback(struct ivi_layout_surface *ivisurf,
- void *userdata)
+test_surface_create_notification_callback(struct wl_listener *listener, void *data)
{
- struct test_context *ctx = userdata;
+ struct test_context *ctx =
+ container_of(listener, struct test_context,
+ surface_created);
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));
@@ -927,20 +930,19 @@ RUNNER_TEST(surface_create_notification_p1)
{
const struct ivi_layout_interface *lyt = ctx->layout_interface;
- runner_assert(lyt->add_notification_create_surface(
- test_surface_create_notification_callback, ctx) == IVI_SUCCEEDED);
+ ctx->surface_created.notify = test_surface_create_notification_callback;
+ runner_assert(lyt->add_listener_create_surface(
+ &ctx->surface_created) == IVI_SUCCEEDED);
ctx->user_flags = 0;
}
RUNNER_TEST(surface_create_notification_p2)
{
- const struct ivi_layout_interface *lyt = ctx->layout_interface;
-
runner_assert(ctx->user_flags == 1);
- lyt->remove_notification_create_surface(
- test_surface_create_notification_callback, ctx);
+ // remove surface created listener.
+ wl_list_remove(&ctx->surface_created.link);
ctx->user_flags = 0;
}
--
1.7.9.5
More information about the wayland-devel
mailing list