aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/examples/ecore_idler_example.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/examples/ecore_idler_example.c')
-rw-r--r--libraries/ecore/src/examples/ecore_idler_example.c112
1 files changed, 0 insertions, 112 deletions
diff --git a/libraries/ecore/src/examples/ecore_idler_example.c b/libraries/ecore/src/examples/ecore_idler_example.c
deleted file mode 100644
index d19fce3..0000000
--- a/libraries/ecore/src/examples/ecore_idler_example.c
+++ /dev/null
@@ -1,112 +0,0 @@
1#include <Ecore.h>
2#include <unistd.h>
3
4struct context { // helper struct to give some context to the callbacks
5 int count;
6 Ecore_Idle_Enterer *enterer;
7 Ecore_Idler *idler;
8 Ecore_Idle_Exiter *exiter;
9 Ecore_Event_Handler *handler;
10 Ecore_Timer *timer;
11};
12
13static _event_type = 0; // a new type of event will be defined and stored here
14
15static Eina_Bool
16_enterer_cb(void *data) // the idle enterer callback
17{
18 printf("IDLE ENTERER: Ecore entering in idle state.\n");
19
20 return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
21}
22
23static Eina_Bool
24_exiter_cb(void *data) // the idle exiter callback
25{
26 printf("IDLE EXITER: Ecore exiting idle state.\n");
27
28 return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
29}
30
31static Eina_Bool
32_idler_cb(void *data) // the idler callback - ran while the mainloop is idle
33{
34 struct context *ctxt = data;
35 printf("IDLER: executing idler callback while in idle state.\n");
36
37 ctxt->count++;
38
39 /* each 10 times that the callback gets called, generate an event that
40 * will wake up the main loop, triggering idle enterers, exiters, etc. */
41 if ((ctxt->count % 10) == 0)
42 ecore_event_add(_event_type, NULL, NULL, NULL);
43
44 return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
45}
46
47static Eina_Bool
48_event_handler_cb(void *data, int type, void *event) // event callback
49{
50 struct context *ctxt = data;
51
52 printf("EVENT: processing callback for the event received.\n");
53
54 if (ctxt->count > 100)
55 {
56 ecore_idle_enterer_del(ctxt->enterer);
57 ecore_idle_exiter_del(ctxt->exiter);
58 ecore_idler_del(ctxt->idler);
59
60 ctxt->enterer = NULL;
61 ctxt->exiter = NULL;
62 ctxt->idler = NULL;
63
64 if (ctxt->timer)
65 {
66 ecore_timer_del(ctxt->timer);
67 ctxt->timer = NULL;
68 }
69
70 ecore_main_loop_quit();
71 }
72
73 return ECORE_CALLBACK_DONE; // same as EINA_FALSE
74}
75
76static Eina_Bool
77_timer_cb(void *data)
78{
79 struct context *ctxt = data;
80 printf("TIMER: timer callback called.\n");
81
82 if (ctxt->timer)
83 ctxt->timer = NULL;
84
85 return ECORE_CALLBACK_CANCEL; // same as EINA_TRUE
86}
87
88int main(int argc, char **argv)
89{
90 struct context ctxt = {0};
91
92 if (!ecore_init())
93 {
94 printf("ERROR: Cannot init Ecore!\n");
95 return -1;
96 }
97
98 _event_type = ecore_event_type_new();
99
100 ctxt.enterer = ecore_idle_enterer_add(_enterer_cb, &ctxt);
101 ctxt.exiter = ecore_idle_exiter_add(_exiter_cb, &ctxt);
102 ctxt.idler = ecore_idler_add(_idler_cb, &ctxt);
103 ctxt.handler = ecore_event_handler_add(_event_type,
104 _event_handler_cb,
105 &ctxt);
106 ctxt.timer = ecore_timer_add(0.0005, _timer_cb, &ctxt);
107
108 ecore_main_loop_begin();
109 ecore_shutdown();
110
111 return 0;
112}