2009-01-31 10:33:39 -08:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
static Ecore_Idler *idlers = NULL;
|
|
|
|
static int idlers_delete_me = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an idler handler.
|
2004-05-07 21:44:04 -07:00
|
|
|
* @param func The function to call when idling.
|
|
|
|
* @param data The data to be passed to this @p func call.
|
|
|
|
* @return A idler handle if successfully added. NULL otherwise.
|
|
|
|
* @ingroup Idle_Group
|
2006-12-27 19:31:44 -08:00
|
|
|
*
|
|
|
|
* Add an idler handle to the event loop, returning a handle on success and
|
|
|
|
* NULL otherwise. The function @p func will be called repeatedly while
|
2008-11-29 03:23:17 -08:00
|
|
|
* no other events are ready to be processed, as long as it returns 1
|
|
|
|
* (or ECORE_CALLBACK_RENEW). A return of 0 (or ECORE_CALLBACK_CANCEL) deletes
|
2008-01-25 10:28:16 -08:00
|
|
|
* the idler.
|
2006-12-27 19:31:44 -08:00
|
|
|
*
|
|
|
|
* Idlers are useful for progressively prossessing data without blocking.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI Ecore_Idler *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_idler_add(int (*func) (void *data), const void *data)
|
|
|
|
{
|
|
|
|
Ecore_Idler *ie;
|
|
|
|
|
|
|
|
if (!func) return NULL;
|
|
|
|
ie = calloc(1, sizeof(Ecore_Idler));
|
|
|
|
if (!ie) return NULL;
|
|
|
|
ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLER);
|
|
|
|
ie->func = func;
|
|
|
|
ie->data = (void *)data;
|
2009-06-17 04:39:37 -07:00
|
|
|
idlers = (Ecore_Idler *) eina_inlist_append(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
|
2003-09-23 01:09:32 -07:00
|
|
|
return ie;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-05-07 21:44:04 -07:00
|
|
|
* Delete an idler callback from the list to be executed.
|
|
|
|
* @param idler The handle of the idler callback to delete
|
|
|
|
* @return The data pointer passed to the idler callback on success. NULL
|
|
|
|
* otherwise.
|
|
|
|
* @ingroup Idle_Group
|
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_idler_del(Ecore_Idler *idler)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(idler, ECORE_MAGIC_IDLER))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(idler, ECORE_MAGIC_IDLER,
|
|
|
|
"ecore_idler_del");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
idler->delete_me = 1;
|
|
|
|
idlers_delete_me = 1;
|
|
|
|
return idler->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_idler_shutdown(void)
|
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
Ecore_Idler *ie;
|
|
|
|
while ((ie = idlers))
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
idlers = (Ecore_Idler *) eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(idlers));
|
2003-09-23 01:09:32 -07:00
|
|
|
ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
|
|
|
|
free(ie);
|
|
|
|
}
|
|
|
|
idlers_delete_me = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_ecore_idler_call(void)
|
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
Ecore_Idler *ie;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2009-06-17 04:39:37 -07:00
|
|
|
EINA_INLIST_FOREACH(idlers, ie)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
if (!ie->delete_me)
|
|
|
|
{
|
|
|
|
if (!ie->func(ie->data)) ecore_idler_del(ie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idlers_delete_me)
|
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
Ecore_Idler *l;
|
|
|
|
for (l = idlers; l;)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
ie = l;
|
|
|
|
l = (Ecore_Idler *) EINA_INLIST_GET(l)->next;
|
2003-09-23 01:09:32 -07:00
|
|
|
if (ie->delete_me)
|
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
idlers = (Ecore_Idler *) eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
|
2003-09-23 01:09:32 -07:00
|
|
|
ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
|
|
|
|
free(ie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
idlers_delete_me = 0;
|
|
|
|
}
|
|
|
|
if (idlers) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_ecore_idler_exist(void)
|
|
|
|
{
|
|
|
|
if (idlers) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|