2009-01-31 10:33:39 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
#include "Ecore.h"
|
2009-12-22 13:15:12 -08:00
|
|
|
#include "ecore_private.h"
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2017-08-08 14:10:36 -07:00
|
|
|
typedef struct _Ecore_Future_Schedule_Entry
|
|
|
|
{
|
|
|
|
Eina_Future_Schedule_Entry base;
|
|
|
|
Eina_Future_Scheduler_Cb cb;
|
|
|
|
Eina_Future *future;
|
|
|
|
Eina_Value value;
|
|
|
|
} Ecore_Future_Schedule_Entry;
|
|
|
|
|
2017-11-08 22:59:04 -08:00
|
|
|
//////
|
|
|
|
// XXX: still using legacy ecore events
|
|
|
|
static Eina_Bool shutting_down = EINA_FALSE;
|
|
|
|
static Eina_Mempool *mp_future_schedule_entry = NULL;
|
|
|
|
//
|
|
|
|
//////
|
|
|
|
|
|
|
|
static Ecore_Event_Message_Handler *_event_msg_handler = NULL;
|
2010-02-23 17:16:00 -08:00
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI Ecore_Event_Handler *
|
2011-10-20 22:40:39 -07:00
|
|
|
ecore_event_handler_add(int type,
|
|
|
|
Ecore_Event_Handler_Cb func,
|
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_add(_event_msg_handler,
|
|
|
|
type, func, (void *)data);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2018-01-29 10:56:28 -08:00
|
|
|
EAPI Ecore_Event_Handler *
|
|
|
|
ecore_event_handler_prepend(int type,
|
|
|
|
Ecore_Event_Handler_Cb func,
|
|
|
|
const void *data)
|
|
|
|
{
|
|
|
|
return ecore_event_message_handler_prepend(_event_msg_handler,
|
|
|
|
type, func, (void *)data);
|
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_event_handler_del(Ecore_Event_Handler *event_handler)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_del(_event_msg_handler,
|
|
|
|
event_handler);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2010-11-04 13:51:17 -07:00
|
|
|
EAPI void *
|
|
|
|
ecore_event_handler_data_get(Ecore_Event_Handler *eh)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_data_get(_event_msg_handler, eh);
|
2010-11-04 13:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void *
|
2011-10-20 22:40:39 -07:00
|
|
|
ecore_event_handler_data_set(Ecore_Event_Handler *eh,
|
|
|
|
const void *data)
|
2010-11-04 13:51:17 -07:00
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_data_set(_event_msg_handler, eh,
|
|
|
|
(void *)data);
|
2004-05-09 00:54:00 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI Ecore_Event *
|
2011-10-20 22:40:39 -07:00
|
|
|
ecore_event_add(int type,
|
|
|
|
void *ev,
|
|
|
|
Ecore_End_Cb func_free,
|
|
|
|
void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
Ecore_Event_Message *msg;
|
2018-01-31 01:53:09 -08:00
|
|
|
if (type <= ECORE_EVENT_NONE) return NULL;
|
2011-07-28 05:01:16 -07:00
|
|
|
|
2017-11-08 22:59:04 -08:00
|
|
|
msg = ecore_event_message_handler_message_type_add(_event_msg_handler);
|
2018-01-31 01:53:09 -08:00
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
ecore_event_message_data_set(msg, type, ev, func_free, data);
|
|
|
|
efl_loop_message_handler_message_send(_event_msg_handler, msg);
|
|
|
|
}
|
2017-11-08 22:59:04 -08:00
|
|
|
return (Ecore_Event *)msg;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_event_del(Ecore_Event *event)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
void *data = NULL;
|
2017-12-18 02:04:56 -08:00
|
|
|
if (!event) return data;
|
2018-02-06 20:50:24 -08:00
|
|
|
ecore_event_message_data_get((Eo *)event, NULL, NULL, NULL, &data);
|
2017-11-08 22:59:04 -08:00
|
|
|
_efl_loop_message_unsend((Eo *)event);
|
|
|
|
return data;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_event_type_new(void)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_type_new(_event_msg_handler);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI Ecore_Event_Filter *
|
2011-10-20 22:40:39 -07:00
|
|
|
ecore_event_filter_add(Ecore_Data_Cb func_start,
|
|
|
|
Ecore_Filter_Cb func_filter,
|
|
|
|
Ecore_End_Cb func_end,
|
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_filter_add(_event_msg_handler,
|
|
|
|
func_start, func_filter,
|
|
|
|
func_end, (void *)data);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_event_filter_del(Ecore_Event_Filter *ef)
|
2008-11-29 03:23:17 -08:00
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_filter_del(_event_msg_handler, ef);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_event_current_type_get(void)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_current_type_get(_event_msg_handler);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_event_current_event_get(void)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return ecore_event_message_handler_current_event_get(_event_msg_handler);
|
2011-08-11 22:22:16 -07:00
|
|
|
}
|
|
|
|
|
2019-03-28 17:18:08 -07:00
|
|
|
static void _future_dispatch_cb(void *data, const Efl_Event *ev EINA_UNUSED);
|
|
|
|
static void _event_del_cb(void *data, const Efl_Event *ev);
|
2017-12-17 06:38:19 -08:00
|
|
|
|
2019-03-28 17:18:08 -07:00
|
|
|
EFL_CALLBACKS_ARRAY_DEFINE(ecore_future_callbacks,
|
|
|
|
{ EFL_LOOP_EVENT_IDLE_ENTER, _future_dispatch_cb },
|
|
|
|
{ EFL_LOOP_EVENT_IDLE, _future_dispatch_cb },
|
|
|
|
{ EFL_EVENT_DEL, _event_del_cb });
|
2017-08-08 14:10:36 -07:00
|
|
|
|
|
|
|
static void
|
2019-03-28 17:18:08 -07:00
|
|
|
_future_dispatch_cb(void *data, const Efl_Event *ev EINA_UNUSED)
|
2017-08-08 14:10:36 -07:00
|
|
|
{
|
2019-03-28 17:18:08 -07:00
|
|
|
Efl_Loop_Future_Scheduler *loopsched = data;
|
|
|
|
Eina_List *entries = loopsched->future_entries;
|
|
|
|
Ecore_Future_Schedule_Entry *entry;
|
|
|
|
|
|
|
|
loopsched->future_entries = NULL;
|
|
|
|
efl_event_callback_array_del((Eo *) loopsched->loop, ecore_future_callbacks(), loopsched);
|
|
|
|
|
|
|
|
EINA_LIST_FREE(entries, entry)
|
2017-08-08 14:10:36 -07:00
|
|
|
{
|
2019-03-28 17:18:08 -07:00
|
|
|
entry->cb(entry->future, entry->value);
|
|
|
|
eina_mempool_free(mp_future_schedule_entry, entry);
|
2017-08-08 14:10:36 -07:00
|
|
|
}
|
|
|
|
}
|
2017-12-27 08:19:52 -08:00
|
|
|
|
|
|
|
static void
|
2019-03-28 17:18:08 -07:00
|
|
|
_event_del_cb(void *data, const Efl_Event *ev EINA_UNUSED)
|
2017-12-27 08:19:52 -08:00
|
|
|
{
|
2019-03-28 17:18:08 -07:00
|
|
|
Efl_Loop_Future_Scheduler *loopsched = data;
|
|
|
|
Eina_List *entries = loopsched->future_entries;
|
|
|
|
Ecore_Future_Schedule_Entry *entry;
|
2017-12-27 08:19:52 -08:00
|
|
|
|
2019-03-28 17:18:08 -07:00
|
|
|
loopsched->future_entries = NULL;
|
|
|
|
efl_event_callback_array_del((Eo *) loopsched->loop, ecore_future_callbacks(), loopsched);
|
|
|
|
|
|
|
|
EINA_LIST_FREE(entries, entry)
|
2017-12-27 08:19:52 -08:00
|
|
|
{
|
|
|
|
eina_future_cancel(entry->future);
|
|
|
|
eina_value_flush(&entry->value);
|
2019-03-28 17:18:08 -07:00
|
|
|
eina_mempool_free(mp_future_schedule_entry, entry);
|
2017-12-27 08:19:52 -08:00
|
|
|
}
|
|
|
|
}
|
2017-08-08 14:10:36 -07:00
|
|
|
|
|
|
|
static Eina_Future_Schedule_Entry *
|
2017-12-27 08:19:52 -08:00
|
|
|
ecore_future_schedule(Eina_Future_Scheduler *sched,
|
|
|
|
Eina_Future_Scheduler_Cb cb,
|
|
|
|
Eina_Future *future,
|
|
|
|
Eina_Value value)
|
2017-08-08 14:10:36 -07:00
|
|
|
{
|
2017-12-27 08:19:52 -08:00
|
|
|
Efl_Loop_Future_Scheduler *loopsched = (Efl_Loop_Future_Scheduler *)sched;
|
2017-12-18 02:04:56 -08:00
|
|
|
Ecore_Future_Schedule_Entry *entry;
|
|
|
|
|
|
|
|
entry = eina_mempool_malloc(mp_future_schedule_entry, sizeof(*entry));
|
2017-08-08 14:10:36 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(entry, NULL);
|
|
|
|
entry->base.scheduler = sched;
|
|
|
|
entry->cb = cb;
|
|
|
|
entry->future = future;
|
|
|
|
entry->value = value;
|
|
|
|
|
2019-03-28 17:18:08 -07:00
|
|
|
if (!loopsched->future_entries)
|
|
|
|
efl_event_callback_array_add((Eo *) loopsched->loop, ecore_future_callbacks(), loopsched);
|
|
|
|
|
|
|
|
loopsched->future_entries = eina_list_append(loopsched->future_entries, entry);
|
|
|
|
return &entry->base;
|
2017-08-08 14:10:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ecore_future_recall(Eina_Future_Schedule_Entry *s_entry)
|
|
|
|
{
|
2019-03-28 17:18:08 -07:00
|
|
|
Ecore_Future_Schedule_Entry *entry = (Ecore_Future_Schedule_Entry *)s_entry;
|
|
|
|
Efl_Loop_Future_Scheduler *loopsched;
|
|
|
|
Eina_List *lookup;
|
2017-12-27 08:19:52 -08:00
|
|
|
|
2017-08-08 14:10:36 -07:00
|
|
|
if (shutting_down) return;
|
2019-03-28 17:18:08 -07:00
|
|
|
|
|
|
|
loopsched = (Efl_Loop_Future_Scheduler *) entry->base.scheduler;
|
|
|
|
|
|
|
|
lookup = eina_list_data_find_list(loopsched->future_entries, entry);
|
|
|
|
if (!lookup) return;
|
|
|
|
|
|
|
|
loopsched->future_entries = eina_list_remove_list(loopsched->future_entries, lookup);
|
|
|
|
if (!loopsched->future_entries)
|
|
|
|
efl_event_callback_array_del((Eo *) loopsched->loop, ecore_future_callbacks(), loopsched);
|
|
|
|
|
2017-08-08 14:10:36 -07:00
|
|
|
eina_value_flush(&entry->value);
|
2019-03-28 17:18:08 -07:00
|
|
|
eina_mempool_free(mp_future_schedule_entry, entry);
|
|
|
|
|
2017-08-08 14:10:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Future_Scheduler ecore_future_scheduler = {
|
|
|
|
.schedule = ecore_future_schedule,
|
|
|
|
.recall = ecore_future_recall,
|
|
|
|
};
|
|
|
|
|
|
|
|
Eina_Future_Scheduler *
|
|
|
|
_ecore_event_future_scheduler_get(void)
|
|
|
|
{
|
|
|
|
return &ecore_future_scheduler;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
_ecore_event_init(void)
|
|
|
|
{
|
|
|
|
const char *choice = getenv("EINA_MEMPOOL");
|
|
|
|
if ((!choice) || (!choice[0])) choice = "chained_mempool";
|
|
|
|
|
2019-02-21 09:56:00 -08:00
|
|
|
_event_msg_handler = efl_add(ECORE_EVENT_MESSAGE_HANDLER_CLASS, _mainloop_singleton);
|
|
|
|
efl_loop_register(_mainloop_singleton, ECORE_EVENT_MESSAGE_HANDLER_CLASS, _event_msg_handler);
|
|
|
|
|
2017-11-08 22:59:04 -08:00
|
|
|
if (!_event_msg_handler)
|
|
|
|
{
|
|
|
|
ERR("Cannot create legacy ecore event message handler");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
// init some core legacy event types in t he same order and numbering as before
|
|
|
|
// ECORE_EVENT_NONE 0
|
|
|
|
// no need to do as ev types start at 1
|
|
|
|
|
|
|
|
// ECORE_EVENT_SIGNAL_USER 1
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_SIGNAL_HUP 2
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_SIGNAL_EXIT 3
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_SIGNAL_POWER 4
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_SIGNAL_REALTIME 5
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_MEMORY_STATE 6
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_POWER_STATE 7
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_LOCALE_CHANGED 8
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_HOSTNAME_CHANGED 9
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED 10
|
|
|
|
ecore_event_message_handler_type_new(_event_msg_handler);
|
|
|
|
// ECORE_EVENT_COUNT 11
|
|
|
|
// no need to do as it was a count, nto an event
|
|
|
|
|
|
|
|
//////
|
|
|
|
// XXX: ecore future still using legacy...
|
2017-08-08 14:10:36 -07:00
|
|
|
shutting_down = EINA_FALSE;
|
2017-12-27 08:19:52 -08:00
|
|
|
// ECORE_EV_FUTURE_ID = ecore_event_type_new();
|
|
|
|
// future_handler = ecore_event_handler_add(ECORE_EV_FUTURE_ID, ecore_future_dispatched, NULL);
|
|
|
|
// EINA_SAFETY_ON_NULL_GOTO(future_handler, err_handler);
|
2017-08-08 14:10:36 -07:00
|
|
|
//FIXME: Is 512 too high?
|
2017-12-27 08:19:52 -08:00
|
|
|
if (!mp_future_schedule_entry)
|
|
|
|
{
|
|
|
|
mp_future_schedule_entry = eina_mempool_add
|
|
|
|
(choice, "Ecore_Future_Event", NULL,
|
|
|
|
sizeof(Ecore_Future_Schedule_Entry), 512);
|
|
|
|
EINA_SAFETY_ON_NULL_GOTO(mp_future_schedule_entry, err_pool);
|
|
|
|
}
|
2017-11-08 22:59:04 -08:00
|
|
|
//
|
|
|
|
//////
|
2017-08-08 14:10:36 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
err_pool:
|
2017-12-27 08:19:52 -08:00
|
|
|
// XXX:
|
|
|
|
// ecore_event_handler_del(future_handler);
|
|
|
|
// future_handler = NULL;
|
|
|
|
// err_handler:
|
|
|
|
// ECORE_EV_FUTURE_ID = -1;
|
2017-08-08 14:10:36 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
void
|
|
|
|
_ecore_event_shutdown(void)
|
|
|
|
{
|
2017-08-08 14:10:36 -07:00
|
|
|
shutting_down = EINA_TRUE;
|
2017-11-08 22:59:04 -08:00
|
|
|
|
|
|
|
//////
|
|
|
|
// XXX: ecore future still using legacy...
|
2017-12-27 08:19:52 -08:00
|
|
|
// ecore_event_handler_del(future_handler);
|
|
|
|
// future_handler = NULL;
|
|
|
|
// ECORE_EV_FUTURE_ID = -1;
|
2017-11-08 22:59:04 -08:00
|
|
|
//
|
|
|
|
//////
|
2010-02-23 17:16:00 -08:00
|
|
|
|
2017-11-08 22:59:04 -08:00
|
|
|
efl_loop_message_handler_message_clear(_event_msg_handler);
|
|
|
|
_event_msg_handler = NULL;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2012-04-13 08:36:42 -07:00
|
|
|
void *
|
2003-09-23 01:09:32 -07:00
|
|
|
_ecore_event_signal_user_new(void)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return calloc(1, sizeof(Ecore_Event_Signal_User));
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
_ecore_event_signal_hup_new(void)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return calloc(1, sizeof(Ecore_Event_Signal_Hup));
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
_ecore_event_signal_exit_new(void)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return calloc(1, sizeof(Ecore_Event_Signal_Exit));
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
_ecore_event_signal_power_new(void)
|
|
|
|
{
|
2017-11-08 22:59:04 -08:00
|
|
|
return calloc(1, sizeof(Ecore_Event_Signal_Power));
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2004-04-04 12:53:19 -07:00
|
|
|
void *
|
|
|
|
_ecore_event_signal_realtime_new(void)
|
|
|
|
{
|
|
|
|
return calloc(1, sizeof(Ecore_Event_Signal_Realtime));
|
|
|
|
}
|
2017-03-03 08:55:44 -08:00
|
|
|
|
2017-03-09 15:51:00 -08:00
|
|
|
EAPI void
|
|
|
|
ecore_event_type_flush_internal(int type, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2017-07-26 02:57:37 -07:00
|
|
|
if (type == ECORE_EVENT_NONE) return;
|
2017-11-08 22:59:04 -08:00
|
|
|
ecore_event_message_handler_type_flush(_event_msg_handler, type);
|
2017-03-09 15:51:00 -08:00
|
|
|
|
|
|
|
va_start(args, type);
|
2017-11-08 22:59:04 -08:00
|
|
|
for (;;)
|
2017-03-09 15:51:00 -08:00
|
|
|
{
|
|
|
|
type = va_arg(args, int);
|
2017-11-08 22:59:04 -08:00
|
|
|
if (type == ECORE_EVENT_NONE) break;
|
|
|
|
ecore_event_message_handler_type_flush(_event_msg_handler, type);
|
2017-03-09 15:51:00 -08:00
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|