2
// gcc -o ecore_timer_example ecore_timer_example.c `pkg-config --libs --cflags ecore`
7
#define TIMEOUT_1 1.0 // interval for timer1
8
#define TIMEOUT_2 3.0 // timer2 - delay timer1
9
#define TIMEOUT_3 8.2 // timer3 - pause timer1
10
#define TIMEOUT_4 11.0 // timer4 - resume timer1
11
#define TIMEOUT_5 14.0 // timer5 - change interval of timer1
12
#define TIMEOUT_6 18.0 // top timer1 and start timer7 and timer8 with changed precision
13
#define TIMEOUT_7 1.1 // interval for timer7
14
#define TIMEOUT_8 1.2 // interval for timer8
15
#define DELAY_1 3.0 // delay time for timer1 - used by timer2
16
#define INTERVAL1 2.0 // new interval for timer1 - used by timer5
18
static double _initial_time = 0;
20
struct context // helper struct to give some context to the callbacks
33
_get_current_time(void)
35
return ecore_time_get() - _initial_time;
39
_timer1_cb(void *data EINA_UNUSED)
41
printf("Timer1 expired after %0.3f seconds.\n", _get_current_time());
42
return ECORE_CALLBACK_RENEW;
48
struct context *ctxt = data;
49
printf("Timer2 expired after %0.3f seconds. "
50
"Adding delay of %0.3f seconds to timer1.\n",
51
_get_current_time(), DELAY_1);
53
ecore_timer_delay(ctxt->timer1, DELAY_1);
56
return ECORE_CALLBACK_CANCEL;
62
struct context *ctxt = data;
63
printf("Timer3 expired after %0.3f seconds. "
64
"Freezing timer1.\n", _get_current_time());
66
ecore_timer_freeze(ctxt->timer1);
69
return ECORE_CALLBACK_CANCEL;
75
struct context *ctxt = data;
76
printf("Timer4 expired after %0.3f seconds. "
77
"Resuming timer1, which has %0.3f seconds left to expire.\n",
78
_get_current_time(), ecore_timer_pending_get(ctxt->timer1));
80
ecore_timer_thaw(ctxt->timer1);
83
return ECORE_CALLBACK_CANCEL;
89
struct context *ctxt = data;
90
double interval = ecore_timer_interval_get(ctxt->timer1);
92
printf("Timer5 expired after %0.3f seconds. "
93
"Changing interval of timer1 from %0.3f to %0.3f seconds.\n",
94
_get_current_time(), interval, INTERVAL1);
96
ecore_timer_interval_set(ctxt->timer1, INTERVAL1);
99
return ECORE_CALLBACK_CANCEL;
103
_timer7_cb(void *data)
105
struct context *ctxt = data;
106
printf("Timer7 expired after %0.3f seconds.\n", _get_current_time());
109
return ECORE_CALLBACK_CANCEL;
113
_timer8_cb(void *data)
115
struct context *ctxt = data;
116
printf("Timer8 expired after %0.3f seconds.\n", _get_current_time());
119
return ECORE_CALLBACK_CANCEL;
123
_timer6_cb(void *data)
125
struct context *ctxt = data;
126
printf("Timer6 expired after %0.3f seconds.\n", _get_current_time());
128
printf("Stopping timer1.\n");
130
ecore_timer_del(ctxt->timer1);
133
printf("Starting timer7 (%0.3fs) and timer8 (%0.3fs).\n",
134
TIMEOUT_7, TIMEOUT_8);
136
ctxt->timer7 = ecore_timer_add(TIMEOUT_7, _timer7_cb, ctxt);
137
ctxt->timer8 = ecore_timer_add(TIMEOUT_8, _timer8_cb, ctxt);
139
ecore_timer_precision_set(0.2);
142
return ECORE_CALLBACK_CANCEL;
148
struct context ctxt = {0};
152
printf("ERROR: Cannot init Ecore!\n");
156
_initial_time = ecore_time_get();
158
ctxt.timer1 = ecore_timer_add(TIMEOUT_1, _timer1_cb, &ctxt);
159
ctxt.timer2 = ecore_timer_add(TIMEOUT_2, _timer2_cb, &ctxt);
160
ctxt.timer3 = ecore_timer_add(TIMEOUT_3, _timer3_cb, &ctxt);
161
ctxt.timer4 = ecore_timer_add(TIMEOUT_4, _timer4_cb, &ctxt);
162
ctxt.timer5 = ecore_timer_add(TIMEOUT_5, _timer5_cb, &ctxt);
163
ctxt.timer6 = ecore_timer_add(TIMEOUT_6, _timer6_cb, &ctxt);
165
printf("start the main loop.\n");
167
ecore_main_loop_begin();
170
ecore_timer_del(ctxt.timer1);
172
ecore_timer_del(ctxt.timer2);
174
ecore_timer_del(ctxt.timer3);
176
ecore_timer_del(ctxt.timer4);
178
ecore_timer_del(ctxt.timer5);
180
ecore_timer_del(ctxt.timer6);
182
ecore_timer_del(ctxt.timer7);
184
ecore_timer_del(ctxt.timer8);