[UI Sample] Idler Sample Overview
The Idler sample demonstrates how to operate the idler functionalities in Ecore. It allows for callbacks to be called when the program is not handling events, timers or fd handlers.
The following log shows the result of the Idler sample.
Figure: Idler log
Implementation
The following code snippet shows the struct for dealing with the idler. It is a helper struct that gives some context to the callbacks.
struct context { int count; Ecore_Idle_Enterer *enterer; Ecore_Idler *idler; Ecore_Idle_Exiter *exiter; };
The following code snippet shows how to register the idle enterer, the idle exiter, and the idler callbacks.
struct context ctx = {0}; ctx.enterer = ecore_idle_enterer_add(_enterer_cb, &ctx); ctx.exiter = ecore_idle_exiter_add(_exiter_cb, &ctx); ctx.idler = ecore_idler_add(_idler_cb, &ctx);
The following code snippet defines the callback functions to be called.
static Eina_Bool _enterer_cb(void *data EINA_UNUSED) { dlog_print(DLOG_DEBUG, LOG_TAG, "IDLE ENTERER: Ecore entering in idle state."); return ECORE_CALLBACK_RENEW; } static Eina_Bool _exiter_cb(void *data EINA_UNUSED) { dlog_print(DLOG_DEBUG, LOG_TAG, "IDLE EXITER: Ecore exiting idle state."); return ECORE_CALLBACK_RENEW; } static Eina_Bool _idler_cb(void *data) { struct context *ctx = data; dlog_print(DLOG_DEBUG, LOG_TAG, "IDLER: executing idler callback while in idle state. (count : %d)", ctx->count); ctx->count++; if ((ctx->count % 10) == 0) ecore_event_add(_event_type, NULL, NULL, NULL); return ECORE_CALLBACK_RENEW; }