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>
|
|
|
|
|
2004-03-16 21:44:17 -08:00
|
|
|
#include "Ecore.h"
|
2009-12-22 13:15:12 -08:00
|
|
|
#include "ecore_private.h"
|
2004-03-16 21:44:17 -08:00
|
|
|
|
2010-01-03 13:55:50 -08:00
|
|
|
|
|
|
|
struct _Ecore_Idle_Exiter
|
|
|
|
{
|
|
|
|
EINA_INLIST;
|
|
|
|
ECORE_MAGIC;
|
|
|
|
int delete_me : 1;
|
|
|
|
int (*func) (void *data);
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-03-16 21:44:17 -08:00
|
|
|
static Ecore_Idle_Exiter *idle_exiters = NULL;
|
2006-06-22 23:40:26 -07:00
|
|
|
static int idle_exiters_delete_me = 0;
|
2004-03-16 21:44:17 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an idle exiter handler.
|
|
|
|
* @param func The function to call when exiting an idle state.
|
|
|
|
* @param data The data to be passed to the @p func call
|
2004-05-07 21:44:04 -07:00
|
|
|
* @return A handle to the idle exiter callback on success. NULL otherwise.
|
|
|
|
* @ingroup Idle_Group
|
2004-03-16 21:44:17 -08:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI Ecore_Idle_Exiter *
|
2004-03-16 21:44:17 -08:00
|
|
|
ecore_idle_exiter_add(int (*func) (void *data), const void *data)
|
|
|
|
{
|
|
|
|
Ecore_Idle_Exiter *ie;
|
|
|
|
|
|
|
|
if (!func) return NULL;
|
|
|
|
ie = calloc(1, sizeof(Ecore_Idle_Exiter));
|
|
|
|
if (!ie) return NULL;
|
|
|
|
ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLE_EXITER);
|
|
|
|
ie->func = func;
|
|
|
|
ie->data = (void *)data;
|
2009-06-17 04:39:37 -07:00
|
|
|
idle_exiters = (Ecore_Idle_Exiter *) eina_inlist_append(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(ie));
|
2004-03-16 21:44:17 -08:00
|
|
|
return ie;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-05-07 21:44:04 -07:00
|
|
|
* Delete an idle exiter handler from the list to be run on exiting idle state.
|
2004-03-16 21:44:17 -08:00
|
|
|
* @param idle_exiter The idle exiter to delete
|
2004-05-07 21:44:04 -07:00
|
|
|
* @return The data pointer that was being being passed to the handler if
|
|
|
|
* successful. NULL otherwise.
|
|
|
|
* @ingroup Idle_Group
|
2004-03-16 21:44:17 -08:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2004-03-16 21:44:17 -08:00
|
|
|
ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(idle_exiter, ECORE_MAGIC_IDLE_EXITER))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(idle_exiter, ECORE_MAGIC_IDLE_EXITER,
|
|
|
|
"ecore_idle_exiter_del");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
idle_exiter->delete_me = 1;
|
|
|
|
idle_exiters_delete_me = 1;
|
|
|
|
return idle_exiter->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_idle_exiter_shutdown(void)
|
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
Ecore_Idle_Exiter *ie;
|
|
|
|
while ((ie = idle_exiters))
|
2004-03-16 21:44:17 -08:00
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
idle_exiters = (Ecore_Idle_Exiter *) eina_inlist_remove(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(idle_exiters));
|
2004-03-16 21:44:17 -08:00
|
|
|
ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
|
|
|
|
free(ie);
|
|
|
|
}
|
|
|
|
idle_exiters_delete_me = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_idle_exiter_call(void)
|
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
Ecore_Idle_Exiter *ie;
|
2008-11-29 03:23:17 -08:00
|
|
|
|
2009-06-17 04:39:37 -07:00
|
|
|
EINA_INLIST_FOREACH(idle_exiters, ie)
|
2004-03-16 21:44:17 -08:00
|
|
|
{
|
|
|
|
if (!ie->delete_me)
|
|
|
|
{
|
|
|
|
if (!ie->func(ie->data)) ecore_idle_exiter_del(ie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idle_exiters_delete_me)
|
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
Ecore_Idle_Exiter *l;
|
|
|
|
for (l = idle_exiters; l;)
|
2004-03-16 21:44:17 -08:00
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
ie = l;
|
2008-11-29 03:23:17 -08:00
|
|
|
|
2009-06-17 04:39:37 -07:00
|
|
|
l = (Ecore_Idle_Exiter *) EINA_INLIST_GET(l)->next;
|
2004-03-16 21:44:17 -08:00
|
|
|
if (ie->delete_me)
|
|
|
|
{
|
2009-06-17 04:39:37 -07:00
|
|
|
idle_exiters = (Ecore_Idle_Exiter *) eina_inlist_remove(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(ie));
|
2004-03-16 21:44:17 -08:00
|
|
|
ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
|
|
|
|
free(ie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
idle_exiters_delete_me = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_ecore_idle_exiter_exist(void)
|
|
|
|
{
|
|
|
|
if (idle_exiters) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|