mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-05-05 05:18:01 +02:00
ivi-shell: rework remove_layer notification
The add_notification_remove_layer API accepts a simple wl_listener instead of a ivi-shell specific notification function. Therefore, the API is renamed to add_listener_remove_layer. 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_layer Signed-off-by: Emre Ucan <eucan@de.adit-jv.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
parent
c98f2cf16b
commit
562f2ecb0c
3 changed files with 25 additions and 61 deletions
|
|
@ -138,10 +138,6 @@ enum ivi_layout_transition_type{
|
|||
IVI_LAYOUT_TRANSITION_MAX,
|
||||
};
|
||||
|
||||
typedef void (*layer_remove_notification_func)(
|
||||
struct ivi_layout_layer *ivilayer,
|
||||
void *userdata);
|
||||
|
||||
typedef void (*surface_remove_notification_func)(
|
||||
struct ivi_layout_surface *ivisurf,
|
||||
void *userdata);
|
||||
|
|
@ -345,15 +341,14 @@ struct ivi_layout_interface {
|
|||
int32_t (*add_listener_create_layer)(struct wl_listener *listener);
|
||||
|
||||
/**
|
||||
* \brief register/unregister for notification when ivi_layer is removed
|
||||
* \brief add a listener for notification when ivi_layer is removed
|
||||
*
|
||||
* When an ivi_layer is removed, a signal is emitted
|
||||
* to the listening controller plugins.
|
||||
* The pointer of the removed ivi_layer is sent as the void *data argument
|
||||
* to the wl_listener::notify callback function of the listener.
|
||||
*/
|
||||
int32_t (*add_notification_remove_layer)(
|
||||
layer_remove_notification_func callback,
|
||||
void *userdata);
|
||||
|
||||
void (*remove_notification_remove_layer)(
|
||||
layer_remove_notification_func callback,
|
||||
void *userdata);
|
||||
int32_t (*add_listener_remove_layer)(struct wl_listener *listener);
|
||||
|
||||
/**
|
||||
* \brief Create a ivi_layer which should be managed by the service
|
||||
|
|
|
|||
|
|
@ -930,23 +930,6 @@ clear_surface_order_list(struct ivi_layout_layer *ivilayer)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
layer_removed(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct ivi_layout_layer *ivilayer = data;
|
||||
|
||||
struct listener_layout_notification *notification =
|
||||
container_of(listener,
|
||||
struct listener_layout_notification,
|
||||
listener);
|
||||
|
||||
struct ivi_layout_notification_callback *removed_callback =
|
||||
notification->userdata;
|
||||
|
||||
((layer_remove_notification_func)removed_callback->callback)
|
||||
(ivilayer, removed_callback->data);
|
||||
}
|
||||
|
||||
static void
|
||||
surface_removed(struct wl_listener *listener, void *data)
|
||||
{
|
||||
|
|
@ -1051,36 +1034,18 @@ ivi_layout_add_listener_create_layer(struct wl_listener *listener)
|
|||
}
|
||||
|
||||
static int32_t
|
||||
ivi_layout_add_notification_remove_layer(layer_remove_notification_func callback,
|
||||
void *userdata)
|
||||
ivi_layout_add_listener_remove_layer(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_layer: invalid argument\n");
|
||||
if (listener == NULL) {
|
||||
weston_log("ivi_layout_add_listener_remove_layer: invalid argument\n");
|
||||
return IVI_FAILED;
|
||||
}
|
||||
|
||||
removed_callback = malloc(sizeof *removed_callback);
|
||||
if (removed_callback == NULL) {
|
||||
weston_log("fails to allocate memory\n");
|
||||
return IVI_FAILED;
|
||||
}
|
||||
wl_signal_add(&layout->layer_notification.removed, listener);
|
||||
|
||||
removed_callback->callback = callback;
|
||||
removed_callback->data = userdata;
|
||||
return add_notification(&layout->layer_notification.removed,
|
||||
layer_removed,
|
||||
removed_callback);
|
||||
}
|
||||
|
||||
static void
|
||||
ivi_layout_remove_notification_remove_layer(layer_remove_notification_func callback,
|
||||
void *userdata)
|
||||
{
|
||||
struct ivi_layout *layout = get_instance();
|
||||
remove_notification(&layout->layer_notification.removed.listener_list, callback, userdata);
|
||||
return IVI_SUCCEEDED;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
|
|
@ -2181,8 +2146,7 @@ static struct ivi_layout_interface ivi_layout_interface = {
|
|||
* layer controller interfaces
|
||||
*/
|
||||
.add_listener_create_layer = ivi_layout_add_listener_create_layer,
|
||||
.add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
|
||||
.remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
|
||||
.add_listener_remove_layer = ivi_layout_add_listener_remove_layer,
|
||||
.layer_create_with_dimension = ivi_layout_layer_create_with_dimension,
|
||||
.layer_destroy = ivi_layout_layer_destroy,
|
||||
.get_layers = ivi_layout_get_layers,
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ struct test_context {
|
|||
|
||||
struct wl_listener layer_property_changed;
|
||||
struct wl_listener layer_created;
|
||||
struct wl_listener layer_removed;
|
||||
};
|
||||
|
||||
static void
|
||||
|
|
@ -767,11 +768,13 @@ test_layer_create_notification(struct test_context *ctx)
|
|||
}
|
||||
|
||||
static void
|
||||
test_layer_remove_notification_callback(struct ivi_layout_layer *ivilayer,
|
||||
void *userdata)
|
||||
test_layer_remove_notification_callback(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct test_context *ctx = userdata;
|
||||
struct test_context *ctx =
|
||||
container_of(listener, struct test_context,
|
||||
layer_removed);
|
||||
const struct ivi_layout_interface *lyt = ctx->layout_interface;
|
||||
struct ivi_layout_layer *ivilayer = data;
|
||||
const struct ivi_layout_layer_properties *prop =
|
||||
lyt->get_properties_of_layer(ivilayer);
|
||||
|
||||
|
|
@ -793,17 +796,19 @@ test_layer_remove_notification(struct test_context *ctx)
|
|||
struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
|
||||
|
||||
ctx->user_flags = 0;
|
||||
ctx->layer_removed.notify = test_layer_remove_notification_callback;
|
||||
|
||||
ivilayers[0] = lyt->layer_create_with_dimension(layers[0], 200, 300);
|
||||
iassert(lyt->add_notification_remove_layer(
|
||||
test_layer_remove_notification_callback, ctx) == IVI_SUCCEEDED);
|
||||
iassert(lyt->add_listener_remove_layer(&ctx->layer_removed) == IVI_SUCCEEDED);
|
||||
lyt->layer_destroy(ivilayers[0]);
|
||||
|
||||
iassert(ctx->user_flags == 1);
|
||||
|
||||
ctx->user_flags = 0;
|
||||
ivilayers[1] = lyt->layer_create_with_dimension(layers[1], 250, 350);
|
||||
lyt->remove_notification_remove_layer(test_layer_remove_notification_callback, ctx);
|
||||
|
||||
// remove layer property changed listener.
|
||||
wl_list_remove(&ctx->layer_removed.link);
|
||||
lyt->layer_destroy(ivilayers[1]);
|
||||
|
||||
iassert(ctx->user_flags == 0);
|
||||
|
|
@ -860,7 +865,7 @@ test_layer_bad_remove_notification(struct test_context *ctx)
|
|||
{
|
||||
const struct ivi_layout_interface *lyt = ctx->layout_interface;
|
||||
|
||||
iassert(lyt->add_notification_remove_layer(NULL, NULL) == IVI_FAILED);
|
||||
iassert(lyt->add_listener_remove_layer(NULL) == IVI_FAILED);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue