2009-01-31 10:33:39 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-11-18 22:26:48 -08:00
|
|
|
#include <Eo.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
|
|
|
|
2016-04-21 13:40:33 -07:00
|
|
|
struct _Ecore_Factorized_Idle
|
2011-12-11 00:29:35 -08:00
|
|
|
{
|
|
|
|
Ecore_Task_Cb func;
|
|
|
|
void *data;
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
const Efl_Callback_Array_Item *desc;
|
2016-04-21 22:13:02 -07:00
|
|
|
|
|
|
|
short references;
|
|
|
|
Eina_Bool delete_me : 1;
|
2016-04-21 13:40:33 -07:00
|
|
|
};
|
2011-07-28 05:01:16 -07:00
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
void
|
2016-04-21 13:40:33 -07:00
|
|
|
_ecore_factorized_idle_event_del(void *data, const Eo_Event *event EINA_UNUSED)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-04-21 13:40:33 -07:00
|
|
|
_ecore_factorized_idle_del(data);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
void
|
2016-04-21 13:40:33 -07:00
|
|
|
_ecore_factorized_idle_process(void *data, const Eo_Event *event EINA_UNUSED)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
2016-04-21 13:40:33 -07:00
|
|
|
Ecore_Factorized_Idle *idler = data;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-04-21 22:13:02 -07:00
|
|
|
idler->references++;
|
2016-04-21 11:57:14 -07:00
|
|
|
if (!_ecore_call_task_cb(idler->func, idler->data))
|
2016-04-21 22:13:02 -07:00
|
|
|
idler->delete_me = EINA_TRUE;
|
|
|
|
idler->references--;
|
|
|
|
|
|
|
|
if (idler->delete_me &&
|
|
|
|
idler->references == 0)
|
2016-04-21 13:40:33 -07:00
|
|
|
_ecore_factorized_idle_del(idler);
|
2012-10-10 01:19:58 -07:00
|
|
|
}
|
|
|
|
|
2016-04-21 13:40:33 -07:00
|
|
|
void *
|
|
|
|
_ecore_factorized_idle_del(Ecore_Idler *idler)
|
2011-07-28 05:01:16 -07:00
|
|
|
{
|
2016-04-21 11:57:14 -07:00
|
|
|
void *data;
|
|
|
|
|
2015-03-27 23:43:50 -07:00
|
|
|
if (!idler) return NULL;
|
2016-04-21 13:40:33 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
|
2011-07-28 05:01:16 -07:00
|
|
|
|
2016-04-21 22:13:02 -07:00
|
|
|
if (idler->references > 0)
|
|
|
|
{
|
|
|
|
idler->delete_me = EINA_TRUE;
|
|
|
|
return idler->data;
|
|
|
|
}
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_array_del(_mainloop_singleton, idler->desc, idler);
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-04-21 11:57:14 -07:00
|
|
|
data = idler->data;
|
|
|
|
free(idler);
|
|
|
|
return data;
|
2012-10-10 01:19:58 -07:00
|
|
|
}
|
|
|
|
|
2016-04-21 13:40:33 -07:00
|
|
|
Ecore_Factorized_Idle *
|
2016-08-10 07:23:04 -07:00
|
|
|
_ecore_factorized_idle_add(const Efl_Callback_Array_Item *desc,
|
2016-04-21 13:40:33 -07:00
|
|
|
Ecore_Task_Cb func,
|
|
|
|
const void *data)
|
2015-05-20 06:56:45 -07:00
|
|
|
{
|
2016-04-21 13:40:33 -07:00
|
|
|
Ecore_Factorized_Idle *ret;
|
2016-04-21 11:57:14 -07:00
|
|
|
|
|
|
|
if (EINA_UNLIKELY(!eina_main_loop_is()))
|
2015-05-20 06:56:45 -07:00
|
|
|
{
|
2016-04-21 11:57:14 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!func)
|
|
|
|
{
|
|
|
|
ERR("callback function must be set up for an object of Ecore_Idler.");
|
2015-05-20 06:56:45 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-21 11:57:14 -07:00
|
|
|
ret = malloc(sizeof (Ecore_Idler));
|
|
|
|
if (!ret) return NULL;
|
|
|
|
|
|
|
|
ret->func = func;
|
|
|
|
ret->data = (void*) data;
|
2016-04-21 13:40:33 -07:00
|
|
|
ret->desc = desc;
|
2016-04-21 22:13:02 -07:00
|
|
|
ret->references = 0;
|
|
|
|
ret->delete_me = EINA_FALSE;
|
2016-04-21 11:57:14 -07:00
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_array_add(_mainloop_singleton, desc, ret);
|
2016-04-21 11:57:14 -07:00
|
|
|
|
|
|
|
return ret;
|
2015-05-20 06:56:45 -07:00
|
|
|
}
|
|
|
|
|
2016-04-21 13:40:33 -07:00
|
|
|
/* Specific to Ecore_Idler implementation */
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
EFL_CALLBACKS_ARRAY_DEFINE(ecore_idler_callbacks,
|
2016-04-21 15:11:32 -07:00
|
|
|
{ EFL_LOOP_EVENT_IDLE, _ecore_factorized_idle_process },
|
2016-08-10 07:23:04 -07:00
|
|
|
{ EFL_EVENT_DEL, _ecore_factorized_idle_event_del });
|
2016-04-21 13:40:33 -07:00
|
|
|
|
|
|
|
EAPI Ecore_Idler *
|
|
|
|
ecore_idler_add(Ecore_Task_Cb func,
|
|
|
|
const void *data)
|
|
|
|
{
|
|
|
|
return _ecore_factorized_idle_add(ecore_idler_callbacks(), func, data);
|
|
|
|
}
|
|
|
|
|
2016-04-21 11:57:14 -07:00
|
|
|
EAPI void *
|
|
|
|
ecore_idler_del(Ecore_Idler *idler)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-04-21 13:40:33 -07:00
|
|
|
return _ecore_factorized_idle_del(idler);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2016-04-21 11:57:14 -07:00
|
|
|
void
|
|
|
|
_ecore_idler_all_call(Eo *loop)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-22 15:40:39 -07:00
|
|
|
efl_event_callback_legacy_call(loop, EFL_LOOP_EVENT_IDLE, NULL);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-04-21 11:57:14 -07:00
|
|
|
_ecore_idler_exist(Eo *loop)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Loop_Data *dt = efl_data_scope_get(loop, EFL_LOOP_CLASS);
|
2011-10-20 22:40:39 -07:00
|
|
|
|
2016-04-21 11:57:14 -07:00
|
|
|
return dt->idlers;
|
|
|
|
}
|