summaryrefslogtreecommitdiff
path: root/ivi-shell
diff options
context:
space:
mode:
authorUcan, Emre (ADITG/SW1) <eucan@de.adit-jv.com>2016-04-04 08:05:18 +0000
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2016-04-05 11:53:48 +0300
commit67f0aa87674c573fbf68a1aaa1e0b75a2f4c7c62 (patch)
tree77ff8818ddd5b843a23686fd4a6d1fcda337813f /ivi-shell
parent562f2ecb0cb49aba1c26b3c01d406752165c279e (diff)
downloadweston-67f0aa87674c573fbf68a1aaa1e0b75a2f4c7c62.tar.gz
ivi-shell: rework remove_surface notification
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. The remove API is removed too: - ivi_layout_remove_notification_remove_surface Signed-off-by: Emre Ucan <eucan@de.adit-jv.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'ivi-shell')
-rw-r--r--ivi-shell/hmi-controller.c14
-rw-r--r--ivi-shell/ivi-layout-export.h19
-rw-r--r--ivi-shell/ivi-layout.c49
3 files changed, 22 insertions, 60 deletions
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index b6716f3f..b27f87b2 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 2ed1e766..1485d3f3 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_remove_notification_func)(
- struct ivi_layout_surface *ivisurf,
- void *userdata);
-
typedef void (*surface_configure_notification_func)(
struct ivi_layout_surface *ivisurf,
void *userdata);
@@ -172,15 +168,14 @@ struct ivi_layout_interface {
int32_t (*add_listener_create_surface)(struct wl_listener *listener);
/**
- * \brief register/unregister for notification when ivi_surface is removed
+ * \brief add a listener for notification when ivi_surface is removed
+ *
+ * When an ivi_surface is removed, a signal is emitted
+ * to the listening controller plugins.
+ * The pointer of the removed ivi_surface is sent as the void *data argument
+ * to the wl_listener::notify callback function of the listener.
*/
- int32_t (*add_notification_remove_surface)(
- surface_remove_notification_func callback,
- void *userdata);
-
- void (*remove_notification_remove_surface)(
- surface_remove_notification_func callback,
- void *userdata);
+ int32_t (*add_listener_remove_surface)(struct wl_listener *listener);
/**
* \brief register/unregister for notification when ivi_surface is configured
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index 82a6d559..23f23120 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,37 +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);
-}
-
-static void
-ivi_layout_remove_notification_remove_surface(surface_remove_notification_func callback,
- void *userdata)
-{
- struct ivi_layout *layout = get_instance();
- remove_notification(&layout->surface_notification.removed.listener_list, callback, userdata);
+ return IVI_SUCCEEDED;
}
static int32_t
@@ -2123,8 +2087,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,
- .remove_notification_remove_surface = ivi_layout_remove_notification_remove_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,
.get_surfaces = ivi_layout_get_surfaces,