summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2018-01-29 13:56:28 -0500
committerMike Blumenkrantz <zmike@osg.samsung.com>2018-01-30 13:02:07 -0500
commitda9eef6027489fd0555e61860646fc9ca91f5695 (patch)
treed36a6293ccb3fff5a5156091299da9778e389fcc
parent5651b2e586e9a9836ebe4f50f9223e237099cf86 (diff)
ecore: add function for prepending an event handler
@feature
-rw-r--r--src/lib/ecore/Ecore_Common.h23
-rw-r--r--src/lib/ecore/ecore_event_message_handler.c32
-rw-r--r--src/lib/ecore/ecore_event_message_handler.eo9
-rw-r--r--src/lib/ecore/ecore_events.c9
4 files changed, 66 insertions, 7 deletions
diff --git a/src/lib/ecore/Ecore_Common.h b/src/lib/ecore/Ecore_Common.h
index 6102341446..90df3cb02a 100644
--- a/src/lib/ecore/Ecore_Common.h
+++ b/src/lib/ecore/Ecore_Common.h
@@ -698,6 +698,19 @@ struct _Ecore_Event_Signal_Realtime
698EAPI Ecore_Event_Handler *ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void *data); 698EAPI Ecore_Event_Handler *ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void *data);
699 699
700/** 700/**
701 * @brief Adds an event handler to the beginning of the handler list.
702 * @param type The type of the event this handler will get called for
703 * @param func The function to call when the event is found in the queue
704 * @param data A data pointer to pass to the called function @p func
705 * @return A new Event handler, or @c NULL on failure.
706 *
707 * This function is identical to ecore_event_handler_add() except that it
708 * creates the handler at the start of the list. Do not use this function.
709 * @since 1.21
710 */
711EAPI Ecore_Event_Handler *ecore_event_handler_prepend(int type, Ecore_Event_Handler_Cb func, const void *data);
712
713/**
701 * @brief Deletes an event handler. 714 * @brief Deletes an event handler.
702 * @param event_handler Event handler handle to delete 715 * @param event_handler Event handler handle to delete
703 * @return Data passed to handler 716 * @return Data passed to handler
@@ -1597,9 +1610,9 @@ EAPI double ecore_loop_time_get(void);
1597 1610
1598/** 1611/**
1599 * Sets the loop time. 1612 * Sets the loop time.
1600 * 1613 *
1601 * @param t The new loop time 1614 * @param t The new loop time
1602 * 1615 *
1603 * You should never need/call this, unless you are implementing a custom 1616 * You should never need/call this, unless you are implementing a custom
1604 * tick source for an ecore animator. Only then inside your function that 1617 * tick source for an ecore animator. Only then inside your function that
1605 * calls ecore_animator_custom_tick(), just before it, if you are able to 1618 * calls ecore_animator_custom_tick(), just before it, if you are able to
@@ -1611,7 +1624,7 @@ EAPI double ecore_loop_time_get(void);
1611 * you get from ecore_time_get() and ecore_loop_time_get() (same 0 point). 1624 * you get from ecore_time_get() and ecore_loop_time_get() (same 0 point).
1612 * What this point is is undefined, sou unless your source uses the same 1625 * What this point is is undefined, sou unless your source uses the same
1613 * 0 time, then you may have to adjust and do some guessing. 1626 * 0 time, then you may have to adjust and do some guessing.
1614 * 1627 *
1615 * @see ecore_animator_custom_tick() 1628 * @see ecore_animator_custom_tick()
1616 * @see ecore_loop_time_get() 1629 * @see ecore_loop_time_get()
1617 * @since 1.11 1630 * @since 1.11
@@ -2402,14 +2415,14 @@ EAPI Ecore_Pipe *ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data);
2402 2415
2403/** 2416/**
2404 * Creates a pipe with more parameters. 2417 * Creates a pipe with more parameters.
2405 * 2418 *
2406 * @param handler Same as ecore_pipe_add() 2419 * @param handler Same as ecore_pipe_add()
2407 * @param data Same as ecore_pipe_add() 2420 * @param data Same as ecore_pipe_add()
2408 * @param fd_read An fd to use for reading or @c -1 otherwise 2421 * @param fd_read An fd to use for reading or @c -1 otherwise
2409 * @param fd_write An fd to use for writing or @c -1 otherwise 2422 * @param fd_write An fd to use for writing or @c -1 otherwise
2410 * @param read_survive_fork Should read fd survive a fork 2423 * @param read_survive_fork Should read fd survive a fork
2411 * @param write_survive_fork Should write fd survive a fork 2424 * @param write_survive_fork Should write fd survive a fork
2412 * 2425 *
2413 * This is the same as ecore_pipe_add() but with some added parameters. 2426 * This is the same as ecore_pipe_add() but with some added parameters.
2414 * 2427 *
2415 * @return A pointer to the new Ecore_Pipe object on success, else NULL. 2428 * @return A pointer to the new Ecore_Pipe object on success, else NULL.
diff --git a/src/lib/ecore/ecore_event_message_handler.c b/src/lib/ecore/ecore_event_message_handler.c
index cab87a1743..39f5dfe5a8 100644
--- a/src/lib/ecore/ecore_event_message_handler.c
+++ b/src/lib/ecore/ecore_event_message_handler.c
@@ -21,6 +21,7 @@ struct _Handler
21 int type; 21 int type;
22 Eina_Bool delete_me : 1; 22 Eina_Bool delete_me : 1;
23 Eina_Bool to_add : 1; 23 Eina_Bool to_add : 1;
24 Eina_Bool prepend : 1;
24}; 25};
25 26
26struct _Filter 27struct _Filter
@@ -161,6 +162,29 @@ _ecore_event_message_handler_handler_add(Eo *obj EINA_UNUSED, Ecore_Event_Messag
161} 162}
162 163
163EOLIAN static void * 164EOLIAN static void *
165_ecore_event_message_handler_handler_prepend(Eo *obj EINA_UNUSED, Ecore_Event_Message_Handler_Data *pd, int type, void *func, void *data)
166{
167 Handler *h;
168
169 if ((type < 0) || (type > pd->event_type_count) || (!func)) return NULL;
170 h = calloc(1, sizeof(Handler));
171 if (!h) return NULL;
172 h->func = func;
173 h->data = data;
174 h->type = type;
175 if (pd->current_event_type == type)
176 {
177 h->to_add = EINA_TRUE;
178 h->prepend = EINA_TRUE;
179 pd->handlers_add = eina_list_append(pd->handlers_add, h);
180 }
181 else
182 pd->handlers[type] = eina_inlist_prepend(pd->handlers[type],
183 EINA_INLIST_GET(h));
184 return h;
185}
186
187EOLIAN static void *
164_ecore_event_message_handler_handler_del(Eo *obj EINA_UNUSED, Ecore_Event_Message_Handler_Data *pd, void *handler) 188_ecore_event_message_handler_handler_del(Eo *obj EINA_UNUSED, Ecore_Event_Message_Handler_Data *pd, void *handler)
165{ 189{
166 Handler *h = handler; 190 Handler *h = handler;
@@ -344,8 +368,12 @@ _ecore_event_message_handler_efl_loop_message_handler_message_call(Eo *obj, Ecor
344 h->to_add = EINA_FALSE; 368 h->to_add = EINA_FALSE;
345 pd->handlers_add = 369 pd->handlers_add =
346 eina_list_remove_list(pd->handlers_add, l); 370 eina_list_remove_list(pd->handlers_add, l);
347 pd->handlers[type] = 371 if (h->prepend)
348 eina_inlist_append(pd->handlers[type], EINA_INLIST_GET(h)); 372 pd->handlers[type] =
373 eina_inlist_prepend(pd->handlers[type], EINA_INLIST_GET(h));
374 else
375 pd->handlers[type] =
376 eina_inlist_append(pd->handlers[type], EINA_INLIST_GET(h));
349 } 377 }
350 } 378 }
351 if (pd->handlers_walking == 0) 379 if (pd->handlers_walking == 0)
diff --git a/src/lib/ecore/ecore_event_message_handler.eo b/src/lib/ecore/ecore_event_message_handler.eo
index 78047164ca..7854c4113c 100644
--- a/src/lib/ecore/ecore_event_message_handler.eo
+++ b/src/lib/ecore/ecore_event_message_handler.eo
@@ -28,6 +28,15 @@ class Ecore.Event.Message.Handler (Efl.Loop.Message.Handler)
28 } 28 }
29 return: void_ptr; [[ Lazy return handle ]] 29 return: void_ptr; [[ Lazy return handle ]]
30 } 30 }
31 handler_prepend {
32 [[ Legacy list of callback handlers so they can return false ]]
33 params {
34 type: int;
35 func: void_ptr;
36 data: void_ptr;
37 }
38 return: void_ptr; [[ Lazy return handle ]]
39 }
31 handler_del { 40 handler_del {
32 params { 41 params {
33 handler: void_ptr; [[ handler returned from handler_add() ]] 42 handler: void_ptr; [[ handler returned from handler_add() ]]
diff --git a/src/lib/ecore/ecore_events.c b/src/lib/ecore/ecore_events.c
index 3911abeb67..de0f16dfb7 100644
--- a/src/lib/ecore/ecore_events.c
+++ b/src/lib/ecore/ecore_events.c
@@ -36,6 +36,15 @@ ecore_event_handler_add(int type,
36 type, func, (void *)data); 36 type, func, (void *)data);
37} 37}
38 38
39EAPI Ecore_Event_Handler *
40ecore_event_handler_prepend(int type,
41 Ecore_Event_Handler_Cb func,
42 const void *data)
43{
44 return ecore_event_message_handler_prepend(_event_msg_handler,
45 type, func, (void *)data);
46}
47
39EAPI void * 48EAPI void *
40ecore_event_handler_del(Ecore_Event_Handler *event_handler) 49ecore_event_handler_del(Ecore_Event_Handler *event_handler)
41{ 50{