summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2017-06-02 15:38:25 -0700
committerCedric BAIL <cedric@osg.samsung.com>2017-06-02 16:28:28 -0700
commit88fc88a305bc09c1b543b62556e66bdb8fa21d78 (patch)
tree078c5fb7aee10010c8098ab35e478e49de1410b7 /src/lib/ecore
parente0a6eaeaa3896682a66615d17620d4852d9466ab (diff)
ecore: poller will be legacy only.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/Ecore_Eo.h12
-rw-r--r--src/lib/ecore/Ecore_Legacy.h26
-rw-r--r--src/lib/ecore/ecore_poller.c134
-rw-r--r--src/lib/ecore/ecore_poller.eo62
4 files changed, 72 insertions, 162 deletions
diff --git a/src/lib/ecore/Ecore_Eo.h b/src/lib/ecore/Ecore_Eo.h
index 2a250fca29..502f6419ec 100644
--- a/src/lib/ecore/Ecore_Eo.h
+++ b/src/lib/ecore/Ecore_Eo.h
@@ -6,18 +6,6 @@ extern "C" {
6#endif 6#endif
7 7
8/** 8/**
9 * @ingroup Ecore_Poller_Group
10 *
11 * @{
12 */
13
14#include "ecore_poller.eo.h"
15
16/**
17 * @}
18 */
19
20/**
21 * @ingroup Ecore_Timer_Group 9 * @ingroup Ecore_Timer_Group
22 * 10 *
23 * @{ 11 * @{
diff --git a/src/lib/ecore/Ecore_Legacy.h b/src/lib/ecore/Ecore_Legacy.h
index 6b950fa05b..e70c0a1b9b 100644
--- a/src/lib/ecore/Ecore_Legacy.h
+++ b/src/lib/ecore/Ecore_Legacy.h
@@ -7,8 +7,12 @@ extern "C" {
7 * 7 *
8 * @{ 8 * @{
9 */ 9 */
10typedef enum
11{
12 ECORE_POLLER_CORE = 0 /**< The core poller interval */
13} Ecore_Poller_Type;
10 14
11#include "ecore_poller.eo.legacy.h" 15typedef struct _Ecore_Poller Ecore_Poller;
12 16
13/** 17/**
14 * @brief Creates a poller to call the given function at a particular tick interval. 18 * @brief Creates a poller to call the given function at a particular tick interval.
@@ -68,6 +72,26 @@ EAPI void ecore_poller_poll_interval_set(Ecore_Poller_Type type, double poll_tim
68EAPI double ecore_poller_poll_interval_get(Ecore_Poller_Type type); 72EAPI double ecore_poller_poll_interval_get(Ecore_Poller_Type type);
69 73
70/** 74/**
75 * @brief Polling interval rate of the poller.
76 *
77 * @param[in] interval The tick interval; must be a power of 2 and <= 32768.
78 *
79 * @return @c true on success, @c false on failure.
80 *
81 * @ingroup Ecore_Poller
82 */
83EAPI Eina_Bool ecore_poller_poller_interval_set(Ecore_Poller *obj, int interval);
84
85/**
86 * @brief Polling interval rate of the poller.
87 *
88 * @return The tick interval; must be a power of 2 and <= 32768.
89 *
90 * @ingroup Ecore_Poller
91 */
92EAPI int ecore_poller_poller_interval_get(const Ecore_Poller *obj);
93
94/**
71 * @} 95 * @}
72 */ 96 */
73 97
diff --git a/src/lib/ecore/ecore_poller.c b/src/lib/ecore/ecore_poller.c
index ee4ebce767..b5567bc5e6 100644
--- a/src/lib/ecore/ecore_poller.c
+++ b/src/lib/ecore/ecore_poller.c
@@ -17,19 +17,16 @@
17 if (!efl_isa((obj), ECORE_POLLER_CLASS)) \ 17 if (!efl_isa((obj), ECORE_POLLER_CLASS)) \
18 return 18 return
19 19
20struct _Ecore_Poller_Data 20struct _Ecore_Poller
21{ 21{
22 EINA_INLIST; 22 EINA_INLIST;
23 ECORE_MAGIC; 23 ECORE_MAGIC;
24 Ecore_Poller *obj;
25 int ibit; 24 int ibit;
26 unsigned char delete_me : 1; 25 unsigned char delete_me : 1;
27 Ecore_Task_Cb func; 26 Ecore_Task_Cb func;
28 void *data; 27 void *data;
29}; 28};
30 29
31typedef struct _Ecore_Poller_Data Ecore_Poller_Data;
32
33static Ecore_Timer *timer = NULL; 30static Ecore_Timer *timer = NULL;
34static int min_interval = -1; 31static int min_interval = -1;
35static int interval_incr = 0; 32static int interval_incr = 0;
@@ -40,7 +37,7 @@ static int poller_walking = 0;
40static double poll_interval = 0.125; 37static double poll_interval = 0.125;
41static double poll_cur_interval = 0.0; 38static double poll_cur_interval = 0.0;
42static double last_tick = 0.0; 39static double last_tick = 0.0;
43static Ecore_Poller_Data *pollers[16] = 40static Ecore_Poller *pollers[16] =
44{ 41{
45 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 42 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
46 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL 43 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
@@ -54,6 +51,19 @@ static unsigned short poller_counters[16] =
54static void _ecore_poller_next_tick_eval(void); 51static void _ecore_poller_next_tick_eval(void);
55static Eina_Bool _ecore_poller_cb_timer(void *data); 52static Eina_Bool _ecore_poller_cb_timer(void *data);
56 53
54static void *
55_ecore_poller_cleanup(Ecore_Poller *poller)
56{
57 void *data;
58
59 data = poller->data;
60 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
61
62 free(poller);
63
64 return data;
65}
66
57static void 67static void
58_ecore_poller_next_tick_eval(void) 68_ecore_poller_next_tick_eval(void)
59{ 69{
@@ -116,8 +126,8 @@ _ecore_poller_next_tick_eval(void)
116static Eina_Bool 126static Eina_Bool
117_ecore_poller_cb_timer(void *data EINA_UNUSED) 127_ecore_poller_cb_timer(void *data EINA_UNUSED)
118{ 128{
129 Ecore_Poller *poller;
119 int i; 130 int i;
120 Ecore_Poller_Data *poller, *l;
121 int changes = 0; 131 int changes = 0;
122 132
123 at_tick++; 133 at_tick++;
@@ -165,19 +175,13 @@ _ecore_poller_cb_timer(void *data EINA_UNUSED)
165 /* FIXME: walk all pollers and remove deleted ones */ 175 /* FIXME: walk all pollers and remove deleted ones */
166 for (i = 0; i < 15; i++) 176 for (i = 0; i < 15; i++)
167 { 177 {
168 for (l = pollers[i]; l; ) 178 Eina_Inlist *l;
179
180 EINA_INLIST_FOREACH_SAFE(pollers[i], l, poller)
169 { 181 {
170 poller = l;
171 l = (Ecore_Poller_Data *)EINA_INLIST_GET(l)->next;
172 if (poller->delete_me) 182 if (poller->delete_me)
173 { 183 {
174 pollers[i] = (Ecore_Poller_Data *)eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(poller)); 184 _ecore_poller_cleanup(poller);
175
176 efl_parent_set(poller->obj, NULL);
177 if (efl_destructed_is(poller->obj))
178 efl_manual_free(poller->obj);
179 else
180 efl_manual_free_set(poller->obj, EINA_FALSE);
181 185
182 poller_delete_count--; 186 poller_delete_count--;
183 changes++; 187 changes++;
@@ -237,28 +241,20 @@ ecore_poller_add(Ecore_Poller_Type type EINA_UNUSED,
237 const void *data) 241 const void *data)
238{ 242{
239 Ecore_Poller *poller; 243 Ecore_Poller *poller;
240 poller = efl_add(MY_CLASS, _mainloop_singleton, ecore_poller_constructor(efl_added, type, interval, func, data));
241 return poller;
242}
243
244EOLIAN static void
245_ecore_poller_constructor(Eo *obj, Ecore_Poller_Data *poller, Ecore_Poller_Type type EINA_UNUSED, int interval, Ecore_Task_Cb func, const void *data)
246{
247 poller->obj = obj;
248
249 int ibit; 244 int ibit;
250 245
251 if (EINA_UNLIKELY(!eina_main_loop_is())) 246 poller = calloc(1, sizeof (Ecore_Poller));
252 { 247 if (!poller) return NULL;
253 EINA_MAIN_LOOP_CHECK_RETURN;
254 }
255 248
256 efl_manual_free_set(obj, EINA_TRUE); 249 if (EINA_UNLIKELY(!eina_main_loop_is()))
250 {
251 EINA_MAIN_LOOP_CHECK_RETURN;
252 }
257 253
258 if (!func) 254 if (!func)
259 { 255 {
260 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME); 256 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
261 return; 257 return NULL;
262 } 258 }
263 259
264 /* interval MUST be a power of 2, so enforce it */ 260 /* interval MUST be a power of 2, so enforce it */
@@ -275,20 +271,23 @@ _ecore_poller_constructor(Eo *obj, Ecore_Poller_Data *poller, Ecore_Poller_Type
275 poller->ibit = ibit; 271 poller->ibit = ibit;
276 poller->func = func; 272 poller->func = func;
277 poller->data = (void *)data; 273 poller->data = (void *)data;
278 pollers[poller->ibit] = (Ecore_Poller_Data *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 274 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
279 if (poller_walking) 275 if (poller_walking)
280 just_added_poller++; 276 just_added_poller++;
281 else 277 else
282 _ecore_poller_next_tick_eval(); 278 _ecore_poller_next_tick_eval();
279
280 return poller;
283} 281}
284 282
285EOLIAN static Eina_Bool 283EAPI Eina_Bool
286_ecore_poller_interval_set(Eo *obj EINA_UNUSED, Ecore_Poller_Data *poller, int interval) 284ecore_poller_poller_interval_set(Ecore_Poller *poller, int interval)
287{ 285{
288 EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
289
290 int ibit; 286 int ibit;
291 287
288 if (!poller) return EINA_FALSE;
289 EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
290
292 /* interval MUST be a power of 2, so enforce it */ 291 /* interval MUST be a power of 2, so enforce it */
293 if (interval < 1) interval = 1; 292 if (interval < 1) interval = 1;
294 ibit = -1; 293 ibit = -1;
@@ -302,9 +301,9 @@ _ecore_poller_interval_set(Eo *obj EINA_UNUSED, Ecore_Poller_Data *poller, int i
302 /* if interval specified is the same as interval set, return true without wasting time */ 301 /* if interval specified is the same as interval set, return true without wasting time */
303 if (poller->ibit == ibit) return EINA_TRUE; 302 if (poller->ibit == ibit) return EINA_TRUE;
304 303
305 pollers[poller->ibit] = (Ecore_Poller_Data *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 304 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
306 poller->ibit = ibit; 305 poller->ibit = ibit;
307 pollers[poller->ibit] = (Ecore_Poller_Data *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 306 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
308 if (poller_walking) 307 if (poller_walking)
309 just_added_poller++; 308 just_added_poller++;
310 else 309 else
@@ -313,11 +312,12 @@ _ecore_poller_interval_set(Eo *obj EINA_UNUSED, Ecore_Poller_Data *poller, int i
313 return EINA_TRUE; 312 return EINA_TRUE;
314} 313}
315 314
316EOLIAN static int 315EAPI int
317_ecore_poller_interval_get(Eo *obj EINA_UNUSED, Ecore_Poller_Data *poller) 316ecore_poller_poller_interval_get(const Ecore_Poller *poller)
318{ 317{
319 int ibit, interval = 1; 318 int ibit, interval = 1;
320 319
320 if (!poller) return -1;
321 EINA_MAIN_LOOP_CHECK_RETURN_VAL(interval); 321 EINA_MAIN_LOOP_CHECK_RETURN_VAL(interval);
322 322
323 ibit = poller->ibit; 323 ibit = poller->ibit;
@@ -326,19 +326,17 @@ _ecore_poller_interval_get(Eo *obj EINA_UNUSED, Ecore_Poller_Data *poller)
326 ibit--; 326 ibit--;
327 interval <<= 1; 327 interval <<= 1;
328 } 328 }
329 329
330 return interval; 330 return interval;
331} 331}
332 332
333EAPI void * 333EAPI void *
334ecore_poller_del(Ecore_Poller *obj) 334ecore_poller_del(Ecore_Poller *poller)
335{ 335{
336 void *data; 336 void *data;
337 337
338 if (!obj) return NULL;
339 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
340 Ecore_Poller_Data *poller = efl_data_scope_get(obj, MY_CLASS);
341 if (!poller) return NULL; 338 if (!poller) return NULL;
339 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
342 /* we are walking the poller list - a bad idea to remove from it while 340 /* we are walking the poller list - a bad idea to remove from it while
343 * walking it, so just flag it as delete_me and come back to it after 341 * walking it, so just flag it as delete_me and come back to it after
344 * the loop has finished */ 342 * the loop has finished */
@@ -349,60 +347,22 @@ ecore_poller_del(Ecore_Poller *obj)
349 return poller->data; 347 return poller->data;
350 } 348 }
351 /* not in loop so safe - delete immediately */ 349 /* not in loop so safe - delete immediately */
352 data = poller->data; 350 data = _ecore_poller_cleanup(poller);
353 pollers[poller->ibit] = (Ecore_Poller_Data *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
354
355 efl_parent_set(poller->obj, NULL);
356 if (efl_destructed_is(poller->obj))
357 efl_manual_free(obj);
358 else
359 efl_manual_free_set(obj, EINA_FALSE);
360 351
361 _ecore_poller_next_tick_eval(); 352 _ecore_poller_next_tick_eval();
362 return data;
363}
364 353
365EOLIAN static void 354 return data;
366_ecore_poller_efl_object_destructor(Eo *obj, Ecore_Poller_Data *pd)
367{
368 if (!pd->delete_me)
369 {
370 pd->delete_me = 1;
371 poller_delete_count++;
372 }
373
374 efl_destructor(efl_super(obj, MY_CLASS));
375}
376
377EOLIAN static Eo *
378_ecore_poller_efl_object_finalize(Eo *obj, Ecore_Poller_Data *pd)
379{
380 if (!pd->func)
381 {
382 return NULL;
383 }
384
385 return efl_finalize(efl_super(obj, MY_CLASS));
386} 355}
387 356
388void 357void
389_ecore_poller_shutdown(void) 358_ecore_poller_shutdown(void)
390{ 359{
360 Ecore_Poller *poller;
391 int i; 361 int i;
392 Ecore_Poller_Data *poller;
393 362
394 for (i = 0; i < 15; i++) 363 for (i = 0; i < 15; i++)
395 { 364 {
396 while ((poller = pollers[i])) 365 while ((poller = pollers[i]))
397 { 366 _ecore_poller_cleanup(poller);
398 pollers[i] = (Ecore_Poller_Data *)eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(pollers[i]));
399 efl_parent_set(poller->obj, NULL);
400 if (efl_destructed_is(poller->obj))
401 efl_manual_free(poller->obj);
402 else
403 efl_manual_free_set(poller->obj, EINA_FALSE);
404 }
405 } 367 }
406} 368}
407
408#include "ecore_poller.eo.c"
diff --git a/src/lib/ecore/ecore_poller.eo b/src/lib/ecore/ecore_poller.eo
deleted file mode 100644
index c5ef3d76f5..0000000000
--- a/src/lib/ecore/ecore_poller.eo
+++ /dev/null
@@ -1,62 +0,0 @@
1type @extern Ecore_Task_Cb: __undefined_type; [[Ecore task callback type]]
2
3enum Ecore.Poller_Type
4{
5 [[Defines the frequency of ticks for the poller.]]
6 legacy: ecore_poller;
7 core = 0 [[The core poller interval]]
8}
9
10class Ecore.Poller (Efl.Object)
11{
12 [[Ecore poller provides infrastructure for the creation of pollers.
13
14 Pollers are, in essence, callbacks that share a single timer per type. Because
15 not all pollers need to be called at the same frequency the user may specify
16 the frequency in ticks(each expiration of the shared timer is called a tick,
17 in ecore poller parlance) for each added poller. Ecore pollers should only be
18 used when the poller doesn't have specific requirements on the exact times to
19 poll.
20
21 This architecture means that the main loop is only woken up once to handle
22 all pollers of that type, this will save power as the CPU has more of a
23 chance to go into a low power state the longer it is asleep for, so this
24 should be used in situations where power usage is a concern.
25
26 For now only 1 core poller type is supported: ECORE_POLLER_CORE, the default
27 interval for ECORE_POLLER_CORE is 0.125(or 1/8th) second.
28 ]]
29 methods {
30 constructor {
31 [[Constructor with parameters for Ecore Poller.]]
32 legacy: null;
33 params {
34 @in type: Ecore.Poller_Type; [[Ecore poller type which defines the frequency of ticks
35 for the poller.]]
36 @in interval: int; [[The tick interval; must be a power of 2 and <= 32768.]]
37 @in func: Ecore_Task_Cb; [[Ecore poller callback function.]]
38 @in data: const(void_ptr); [[Private data passed to callback function.]]
39 }
40 }
41 @property interval {
42 [[Polling interval rate of the poller.]]
43 set {
44 legacy: ecore_poller_poller_interval_set;
45 return: bool; [[$true on success, $false on failure.]]
46 }
47 get {
48 legacy: ecore_poller_poller_interval_get;
49 }
50 values {
51 interval: int; [[The tick interval; must be a power of 2 and <= 32768.]]
52 }
53 }
54 }
55 implements {
56 Efl.Object.destructor;
57 Efl.Object.finalize;
58 }
59 constructors {
60 .constructor;
61 }
62}