ivi-shell: rework surface_add_notification API

The surface_add_notification API accepts a simple
wl_listener instead of a ivi-shell specific notification
function. Therefore, the API is renamed to surface_add_listener.

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.

This patch also remove two APIs which are not needed:
- ivi_layout_surface_remove_notification
- ivi_layout_surface_remove_notification_by_callback

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 0bd29b6a52
commit 706cb5aa7c
  1. 30
      ivi-shell/ivi-layout-export.h
  2. 80
      ivi-shell/ivi-layout.c
  3. 37
      tests/ivi_layout-test-plugin.c

@ -144,12 +144,6 @@ typedef void (*layer_property_notification_func)(
enum ivi_layout_notification_mask mask,
void *userdata);
typedef void (*surface_property_notification_func)(
struct ivi_layout_surface *ivisurf,
const struct ivi_layout_surface_properties *,
enum ivi_layout_notification_mask mask,
void *userdata);
typedef void (*layer_create_notification_func)(
struct ivi_layout_layer *ivilayer,
void *userdata);
@ -318,19 +312,18 @@ struct ivi_layout_interface {
enum wl_output_transform orientation);
/**
* \brief register for notification on property changes of ivi_surface
* \brief add a listener to listen property changes of ivi_surface
*
* When a property of the ivi_surface is changed, the property_changed
* signal is emitted to the listening controller plugins.
* The pointer of the ivi_surface is sent as the void *data argument
* to the wl_listener::notify callback function of the listener.
*
* \return IVI_SUCCEEDED if the method call was successful
* \return IVI_FAILED if the method call was failed
*/
int32_t (*surface_add_notification)(struct ivi_layout_surface *ivisurf,
surface_property_notification_func callback,
void *userdata);
/**
* \brief remove notification on property changes of ivi_surface
*/
void (*surface_remove_notification)(struct ivi_layout_surface *ivisurf);
int32_t (*surface_add_listener)(struct ivi_layout_surface *ivisurf,
struct wl_listener *listener);
/**
* \brief get weston_surface of ivi_surface
@ -604,13 +597,6 @@ struct ivi_layout_interface {
int32_t x, int32_t y,
int32_t width, int32_t height);
/**
* remove notification by callback on property changes of ivi_surface
*/
void (*surface_remove_notification_by_callback)(struct ivi_layout_surface *ivisurf,
surface_property_notification_func callback,
void *userdata);
/**
* \brief remove notification by callback on property changes of ivi_layer
*/

@ -201,30 +201,6 @@ remove_all_notification(struct wl_list *listener_list)
}
}
static void
ivi_layout_surface_remove_notification(struct ivi_layout_surface *ivisurf)
{
if (ivisurf == NULL) {
weston_log("ivi_layout_surface_remove_notification: invalid argument\n");
return;
}
remove_all_notification(&ivisurf->property_changed.listener_list);
}
static void
ivi_layout_surface_remove_notification_by_callback(struct ivi_layout_surface *ivisurf,
surface_property_notification_func callback,
void *userdata)
{
if (ivisurf == NULL) {
weston_log("ivi_layout_surface_remove_notification_by_callback: invalid argument\n");
return;
}
remove_notification(&ivisurf->property_changed.listener_list, callback, userdata);
}
/**
* Called at destruction of wl_surface/ivi_surface
*/
@ -247,8 +223,6 @@ ivi_layout_surface_destroy(struct ivi_layout_surface *ivisurf)
ivi_layout_remove_all_surface_transitions(ivisurf);
ivi_layout_surface_remove_notification(ivisurf);
free(ivisurf);
}
@ -1061,23 +1035,6 @@ surface_removed(struct wl_listener *listener, void *data)
(ivisurface, removed_callback->data);
}
static void
surface_prop_changed(struct wl_listener *listener, void *data)
{
struct ivi_layout_surface *ivisurf = data;
struct listener_layout_notification *layout_listener =
container_of(listener,
struct listener_layout_notification,
listener);
struct ivi_layout_notification_callback *prop_callback =
layout_listener->userdata;
((surface_property_notification_func)prop_callback->callback)
(ivisurf, &ivisurf->prop, ivisurf->prop.event_mask, prop_callback->data);
}
static void
surface_configure_changed(struct wl_listener *listener,
void *data)
@ -1360,38 +1317,15 @@ ivi_layout_get_surface_from_id(uint32_t id_surface)
}
static int32_t
ivi_layout_surface_add_notification(struct ivi_layout_surface *ivisurf,
surface_property_notification_func callback,
void *userdata)
ivi_layout_surface_add_listener(struct ivi_layout_surface *ivisurf,
struct wl_listener *listener)
{
struct listener_layout_notification* notification = NULL;
struct ivi_layout_notification_callback *prop_callback = NULL;
if (ivisurf == NULL || callback == NULL) {
weston_log("ivi_layout_surface_add_notification: invalid argument\n");
return IVI_FAILED;
}
notification = malloc(sizeof *notification);
if (notification == NULL) {
weston_log("fails to allocate memory\n");
if (ivisurf == NULL || listener == NULL) {
weston_log("ivi_layout_surface_add_listener: invalid argument\n");
return IVI_FAILED;
}
prop_callback = malloc(sizeof *prop_callback);
if (prop_callback == NULL) {
weston_log("fails to allocate memory\n");
free(notification);
return IVI_FAILED;
}
prop_callback->callback = callback;
prop_callback->data = userdata;
notification->listener.notify = surface_prop_changed;
notification->userdata = prop_callback;
wl_signal_add(&ivisurf->property_changed, &notification->listener);
wl_signal_add(&ivisurf->property_changed, listener);
return IVI_SUCCEEDED;
}
@ -2386,8 +2320,7 @@ static struct ivi_layout_interface ivi_layout_interface = {
.surface_set_source_rectangle = ivi_layout_surface_set_source_rectangle,
.surface_set_destination_rectangle = ivi_layout_surface_set_destination_rectangle,
.surface_set_orientation = ivi_layout_surface_set_orientation,
.surface_add_notification = ivi_layout_surface_add_notification,
.surface_remove_notification = ivi_layout_surface_remove_notification,
.surface_add_listener = ivi_layout_surface_add_listener,
.surface_get_weston_surface = ivi_layout_surface_get_weston_surface,
.surface_set_transition = ivi_layout_surface_set_transition,
.surface_set_transition_duration = ivi_layout_surface_set_transition_duration,
@ -2441,7 +2374,6 @@ static struct ivi_layout_interface ivi_layout_interface = {
/**
* remove notification by callback on property changes of ivi_surface/layer
*/
.surface_remove_notification_by_callback = ivi_layout_surface_remove_notification_by_callback,
.layer_remove_notification_by_callback = ivi_layout_layer_remove_notification_by_callback
};

@ -83,6 +83,8 @@ struct test_context {
const struct ivi_layout_interface *layout_interface;
struct wl_resource *runner_resource;
uint32_t user_flags;
struct wl_listener surface_property_changed;
};
static struct test_context static_context;
@ -809,13 +811,14 @@ RUNNER_TEST(cleanup_layer)
}
static void
test_surface_properties_changed_notification_callback(struct ivi_layout_surface *ivisurf,
const struct ivi_layout_surface_properties *prop,
enum ivi_layout_notification_mask mask,
void *userdata)
test_surface_properties_changed_notification_callback(struct wl_listener *listener, void *data)
{
struct test_context *ctx = userdata;
struct test_context *ctx =
container_of(listener, struct test_context,
surface_property_changed);
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));
@ -833,8 +836,10 @@ RUNNER_TEST(surface_properties_changed_notification)
ivisurf = lyt->get_surface_from_id(id_surface);
runner_assert(ivisurf != NULL);
runner_assert(lyt->surface_add_notification(
ivisurf, test_surface_properties_changed_notification_callback, ctx) == IVI_SUCCEEDED);
ctx->surface_property_changed.notify = test_surface_properties_changed_notification_callback;
runner_assert(lyt->surface_add_listener(
ivisurf, &ctx->surface_property_changed) == IVI_SUCCEEDED);
lyt->commit_changes();
@ -855,7 +860,8 @@ RUNNER_TEST(surface_properties_changed_notification)
runner_assert(ctx->user_flags == 0);
lyt->surface_remove_notification(ivisurf);
// remove surface property changed listener.
wl_list_remove(&ctx->surface_property_changed.link);
ctx->user_flags = 0;
runner_assert(lyt->surface_set_destination_rectangle(
ivisurf, 40, 50, 400, 500) == IVI_SUCCEEDED);
@ -981,10 +987,7 @@ RUNNER_TEST(surface_remove_notification_p3)
}
static void
test_surface_bad_properties_changed_notification_callback(struct ivi_layout_surface *ivisurf,
const struct ivi_layout_surface_properties *prop,
enum ivi_layout_notification_mask mask,
void *userdata)
test_surface_bad_properties_changed_notification_callback(struct wl_listener *listener, void *data)
{
}
@ -996,8 +999,10 @@ RUNNER_TEST(surface_bad_properties_changed_notification)
ivisurf = lyt->get_surface_from_id(IVI_TEST_SURFACE_ID(0));
runner_assert(ivisurf != NULL);
runner_assert(lyt->surface_add_notification(
NULL, test_surface_bad_properties_changed_notification_callback, NULL) == IVI_FAILED);
runner_assert(lyt->surface_add_notification(
ivisurf, NULL, NULL) == IVI_FAILED);
ctx->surface_property_changed.notify = test_surface_bad_properties_changed_notification_callback;
runner_assert(lyt->surface_add_listener(
NULL, &ctx->surface_property_changed) == IVI_FAILED);
runner_assert(lyt->surface_add_listener(
ivisurf, NULL) == IVI_FAILED);
}

Loading…
Cancel
Save