ivi-shell: rework create_layer_notification

The add_notification_layer_surface API accepts a simple
wl_listener instead of a ivi-shell specific notification
function. Therefore, the API is renamed to add_listener_layer_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_create_layer

Signed-off-by: Emre Ucan <eucan@de.adit-jv.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
dev
Ucan, Emre (ADITG/SW1) 9 years ago committed by Pekka Paalanen
parent 970f831588
commit c98f2cf16b
  1. 19
      ivi-shell/ivi-layout-export.h
  2. 49
      ivi-shell/ivi-layout.c
  3. 18
      tests/ivi_layout-internal-test.c

@ -138,10 +138,6 @@ enum ivi_layout_transition_type{
IVI_LAYOUT_TRANSITION_MAX, IVI_LAYOUT_TRANSITION_MAX,
}; };
typedef void (*layer_create_notification_func)(
struct ivi_layout_layer *ivilayer,
void *userdata);
typedef void (*layer_remove_notification_func)( typedef void (*layer_remove_notification_func)(
struct ivi_layout_layer *ivilayer, struct ivi_layout_layer *ivilayer,
void *userdata); void *userdata);
@ -339,15 +335,14 @@ struct ivi_layout_interface {
*/ */
/** /**
* \brief register/unregister for notification when ivi_layer is created * \brief add a listener for notification when ivi_layer is created
*
* When an ivi_layer is created, a signal is emitted
* to the listening controller plugins.
* The pointer of the created ivi_layer is sent as the void *data argument
* to the wl_listener::notify callback function of the listener.
*/ */
int32_t (*add_notification_create_layer)( int32_t (*add_listener_create_layer)(struct wl_listener *listener);
layer_create_notification_func callback,
void *userdata);
void (*remove_notification_create_layer)(
layer_create_notification_func callback,
void *userdata);
/** /**
* \brief register/unregister for notification when ivi_layer is removed * \brief register/unregister for notification when ivi_layer is removed

@ -930,23 +930,6 @@ clear_surface_order_list(struct ivi_layout_layer *ivilayer)
} }
} }
static void
layer_created(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 *created_callback =
notification->userdata;
((layer_create_notification_func)created_callback->callback)
(ivilayer, created_callback->data);
}
static void static void
layer_removed(struct wl_listener *listener, void *data) layer_removed(struct wl_listener *listener, void *data)
{ {
@ -1053,37 +1036,18 @@ remove_notification(struct wl_list *listener_list, void *callback, void *userdat
* Brief of APIs is described in ivi-layout-export.h. * Brief of APIs is described in ivi-layout-export.h.
*/ */
static int32_t static int32_t
ivi_layout_add_notification_create_layer(layer_create_notification_func callback, ivi_layout_add_listener_create_layer(struct wl_listener *listener)
void *userdata)
{ {
struct ivi_layout *layout = get_instance(); struct ivi_layout *layout = get_instance();
struct ivi_layout_notification_callback *created_callback = NULL;
if (callback == NULL) { if (listener == NULL) {
weston_log("ivi_layout_add_notification_create_layer: invalid argument\n"); weston_log("ivi_layout_add_listener_create_layer: 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; return IVI_FAILED;
} }
created_callback->callback = callback; wl_signal_add(&layout->layer_notification.created, listener);
created_callback->data = userdata;
return add_notification(&layout->layer_notification.created, return IVI_SUCCEEDED;
layer_created,
created_callback);
}
static void
ivi_layout_remove_notification_create_layer(layer_create_notification_func callback,
void *userdata)
{
struct ivi_layout *layout = get_instance();
remove_notification(&layout->layer_notification.created.listener_list, callback, userdata);
} }
static int32_t static int32_t
@ -2216,8 +2180,7 @@ static struct ivi_layout_interface ivi_layout_interface = {
/** /**
* layer controller interfaces * layer controller interfaces
*/ */
.add_notification_create_layer = ivi_layout_add_notification_create_layer, .add_listener_create_layer = ivi_layout_add_listener_create_layer,
.remove_notification_create_layer = ivi_layout_remove_notification_create_layer,
.add_notification_remove_layer = ivi_layout_add_notification_remove_layer, .add_notification_remove_layer = ivi_layout_add_notification_remove_layer,
.remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer, .remove_notification_remove_layer = ivi_layout_remove_notification_remove_layer,
.layer_create_with_dimension = ivi_layout_layer_create_with_dimension, .layer_create_with_dimension = ivi_layout_layer_create_with_dimension,

@ -43,6 +43,7 @@ struct test_context {
uint32_t user_flags; uint32_t user_flags;
struct wl_listener layer_property_changed; struct wl_listener layer_property_changed;
struct wl_listener layer_created;
}; };
static void static void
@ -718,11 +719,13 @@ test_layer_properties_changed_notification(struct test_context *ctx)
} }
static void static void
test_layer_create_notification_callback(struct ivi_layout_layer *ivilayer, test_layer_create_notification_callback(struct wl_listener *listener, void *data)
void *userdata)
{ {
struct test_context *ctx = userdata; struct test_context *ctx =
container_of(listener, struct test_context,
layer_created);
const struct ivi_layout_interface *lyt = ctx->layout_interface; 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); 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(lyt->get_id_of_layer(ivilayer) == IVI_TEST_LAYER_ID(0));
@ -743,15 +746,16 @@ test_layer_create_notification(struct test_context *ctx)
struct ivi_layout_layer *ivilayers[LAYER_NUM] = {}; struct ivi_layout_layer *ivilayers[LAYER_NUM] = {};
ctx->user_flags = 0; ctx->user_flags = 0;
ctx->layer_created.notify = test_layer_create_notification_callback;
iassert(lyt->add_notification_create_layer( iassert(lyt->add_listener_create_layer(&ctx->layer_created) == IVI_SUCCEEDED);
test_layer_create_notification_callback, ctx) == IVI_SUCCEEDED);
ivilayers[0] = lyt->layer_create_with_dimension(layers[0], 200, 300); ivilayers[0] = lyt->layer_create_with_dimension(layers[0], 200, 300);
iassert(ctx->user_flags == 1); iassert(ctx->user_flags == 1);
ctx->user_flags = 0; ctx->user_flags = 0;
lyt->remove_notification_create_layer(test_layer_create_notification_callback, ctx); // remove layer created listener.
wl_list_remove(&ctx->layer_created.link);
ivilayers[1] = lyt->layer_create_with_dimension(layers[1], 400, 500); ivilayers[1] = lyt->layer_create_with_dimension(layers[1], 400, 500);
@ -840,7 +844,7 @@ test_layer_bad_create_notification(struct test_context *ctx)
{ {
const struct ivi_layout_interface *lyt = ctx->layout_interface; const struct ivi_layout_interface *lyt = ctx->layout_interface;
iassert(lyt->add_notification_create_layer(NULL, NULL) == IVI_FAILED); iassert(lyt->add_listener_create_layer(NULL) == IVI_FAILED);
} }
static void static void

Loading…
Cancel
Save