summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2016-06-20 10:37:02 +0100
committerTom Hacohen <tom@stosb.com>2016-06-20 18:02:00 +0100
commitd648eb5311585f7392d0290640ba133814b52589 (patch)
tree8a10a691218bfe1cbd08ba139a8feb22f23b9185
parent508ba2e249526b79d503c5867e3095952499580a (diff)
downloadefl-d648eb5311585f7392d0290640ba133814b52589.tar.gz
Eo event callbacks: Change the way callbacks are stopped.
Instead of using the return value, we now use eo_event_callback_stop() to stop calling other callbacks.
-rw-r--r--src/lib/eo/Eo.h14
-rw-r--r--src/lib/eo/eo_base.eo9
-rw-r--r--src/lib/eo/eo_base_class.c23
-rw-r--r--src/lib/eolian/database_type.c2
4 files changed, 29 insertions, 19 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index d5274a9712..ec14715e3b 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -1048,20 +1048,6 @@ EAPI const Eo_Event_Description *eo_base_legacy_only_event_description_get(const
#define EO_CALLBACK_PRIORITY_AFTER 100
/**
- * @def EO_CALLBACK_STOP
- * Stop calling callbacks for the even of which the callback was called for.
- * @see EO_CALLBACK_CONTINUE
- */
-#define EO_CALLBACK_STOP EINA_FALSE
-
-/**
- * @def EO_CALLBACK_CONTINUE
- * Continue calling callbacks for the even of which the callback was called for.
- * @see EO_CALLBACK_STOP
- */
-#define EO_CALLBACK_CONTINUE EINA_TRUE
-
-/**
* Helper for creating global callback arrays.
* The problem is on windows where you can't declare a static array with
* external symbols in it, because the addresses are only known at runtime.
diff --git a/src/lib/eo/eo_base.eo b/src/lib/eo/eo_base.eo
index 204c57bbee..d4e3bd655b 100644
--- a/src/lib/eo/eo_base.eo
+++ b/src/lib/eo/eo_base.eo
@@ -351,6 +351,15 @@ abstract Eo.Base ()
$true otherwise
]]
}
+ event_callback_stop {
+ [[Stop the current callback call.
+
+ This stops the current callback call. Any other callbacks for the
+ current event will not be called. This is useful when you want to
+ filter out events. You just add higher priority events and call this
+ on certain conditions to block a certain event.
+ ]]
+ }
event_callback_forwarder_add {
[[Add an event callback forwarder for an event and an object.]]
params {
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index e1865b3299..fe12067bd2 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -35,6 +35,7 @@ typedef struct
unsigned short walking_list;
unsigned short event_freeze_count;
Eina_Bool deletions_waiting : 1;
+ Eina_Bool callback_stopped : 1;
} Eo_Base_Data;
typedef enum {
@@ -1042,6 +1043,7 @@ _eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
const Eo_Event_Description *desc,
void *event_info)
{
+ Eina_Bool callback_already_stopped = pd->callback_stopped;
Eina_Bool ret = EINA_TRUE;
Eo_Callback_Description *cb;
Eo_Current_Callback_Description *lookup = NULL;
@@ -1100,8 +1102,9 @@ _eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
// Handle nested restart of walking list
if (lookup) lookup->current = cb->next;
+ it->func((void *) cb->func_data, &ev);
/* Abort callback calling if the func says so. */
- if (!it->func((void *) cb->func_data, &ev))
+ if (pd->callback_stopped)
{
ret = EINA_FALSE;
goto end;
@@ -1122,8 +1125,9 @@ _eo_base_event_callback_call(Eo *obj_id, Eo_Base_Data *pd,
// Handle nested restart of walking list
if (lookup) lookup->current = cb->next;
+ cb->items.item.func((void *) cb->func_data, &ev);
/* Abort callback calling if the func says so. */
- if (!cb->items.item.func((void *) cb->func_data, &ev))
+ if (pd->callback_stopped)
{
ret = EINA_FALSE;
goto end;
@@ -1147,10 +1151,18 @@ end:
pd->walking_list--;
_eo_callbacks_clear(pd);
+ pd->callback_stopped = callback_already_stopped;
+
return ret;
}
-static Eina_Bool
+EOLIAN static void
+_eo_base_event_callback_stop(Eo *obj EINA_UNUSED, Eo_Base_Data *pd)
+{
+ pd->callback_stopped = EINA_TRUE;
+}
+
+static void
_eo_event_forwarder_callback(void *data, const Eo_Event *event)
{
Eo *new_obj = (Eo *) data;
@@ -1158,7 +1170,10 @@ _eo_event_forwarder_callback(void *data, const Eo_Event *event)
ret = eo_event_callback_call(new_obj, event->desc, event->info);
- return ret;
+ if (!ret)
+ {
+ eo_event_callback_stop(event->object);
+ }
}
/* FIXME: Change default priority? Maybe call later? */
diff --git a/src/lib/eolian/database_type.c b/src/lib/eolian/database_type.c
index c9cc654761..ee1f11477d 100644
--- a/src/lib/eolian/database_type.c
+++ b/src/lib/eolian/database_type.c
@@ -203,7 +203,7 @@ _atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
if (tp->base_type->type == EOLIAN_TYPE_REGULAR &&
!strcmp(tp->base_type->name, "__builtin_event_cb"))
{
- eina_strbuf_append(buf, "Eina_Bool (*");
+ eina_strbuf_append(buf, "void (*");
_append_name(tp, buf);
eina_strbuf_append(buf, ")(void *data, const Eo_Event *event)");
return;