summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore/ecore_poll.c
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2012-10-10 08:19:58 +0000
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2012-10-10 08:19:58 +0000
commitdbda81582a7669044f61d22549727e4799e8184f (patch)
treeae265363db08486947116bce46b3faa20749a55c /legacy/ecore/src/lib/ecore/ecore_poll.c
parentfa1dd2b86ff0a8a6679d7b1de64dbe09b17afdce (diff)
Porting to Eo: Job, Animator, Idler, Idle_Enterer, Idle_Exiter, Timer, Ecore_Poll
Signed-off-by: Yakov Goldberg <yakov.g@samsung.com> SVN revision: 77722
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_poll.c226
1 files changed, 178 insertions, 48 deletions
diff --git a/legacy/ecore/src/lib/ecore/ecore_poll.c b/legacy/ecore/src/lib/ecore/ecore_poll.c
index 089212ef57..eabb05df22 100644
--- a/legacy/ecore/src/lib/ecore/ecore_poll.c
+++ b/legacy/ecore/src/lib/ecore/ecore_poll.c
@@ -7,16 +7,30 @@
7#include "Ecore.h" 7#include "Ecore.h"
8#include "ecore_private.h" 8#include "ecore_private.h"
9 9
10struct _Ecore_Poller 10#include "Eo.h"
11
12#define MY_CLASS ECORE_POLLER_CLASS
13
14#define MY_CLASS_NAME "ecore_poller"
15
16EAPI Eo_Op ECORE_POLLER_BASE_ID = EO_NOOP;
17
18#define ECORE_POLLER_CHECK(obj) \
19 if (!eo_isa((obj), ECORE_POLLER_CLASS)) \
20 return
21
22struct _Ecore_Poller_Private_Data
11{ 23{
12 EINA_INLIST; 24 EINA_INLIST;
13 ECORE_MAGIC; 25 ECORE_MAGIC;
26 Ecore_Poller *obj;
14 int ibit; 27 int ibit;
15 unsigned char delete_me : 1; 28 unsigned char delete_me : 1;
16 Ecore_Task_Cb func; 29 Ecore_Task_Cb func;
17 void *data; 30 void *data;
18}; 31};
19GENERIC_ALLOC_SIZE_DECLARE(Ecore_Poller); 32
33typedef struct _Ecore_Poller_Private_Data Ecore_Poller_Private_Data;
20 34
21static Ecore_Timer *timer = NULL; 35static Ecore_Timer *timer = NULL;
22static int min_interval = -1; 36static int min_interval = -1;
@@ -28,7 +42,7 @@ static int poller_walking = 0;
28static double poll_interval = 0.125; 42static double poll_interval = 0.125;
29static double poll_cur_interval = 0.0; 43static double poll_cur_interval = 0.0;
30static double last_tick = 0.0; 44static double last_tick = 0.0;
31static Ecore_Poller *pollers[16] = 45static Ecore_Poller_Private_Data *pollers[16] =
32{ 46{
33 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 47 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
34 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL 48 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
@@ -105,7 +119,7 @@ static Eina_Bool
105_ecore_poller_cb_timer(void *data __UNUSED__) 119_ecore_poller_cb_timer(void *data __UNUSED__)
106{ 120{
107 int i; 121 int i;
108 Ecore_Poller *poller, *l; 122 Ecore_Poller_Private_Data *poller, *l;
109 int changes = 0; 123 int changes = 0;
110 124
111 at_tick++; 125 at_tick++;
@@ -156,11 +170,17 @@ _ecore_poller_cb_timer(void *data __UNUSED__)
156 for (l = pollers[i]; l; ) 170 for (l = pollers[i]; l; )
157 { 171 {
158 poller = l; 172 poller = l;
159 l = (Ecore_Poller *)EINA_INLIST_GET(l)->next; 173 l = (Ecore_Poller_Private_Data *)EINA_INLIST_GET(l)->next;
160 if (poller->delete_me) 174 if (poller->delete_me)
161 { 175 {
162 pollers[i] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(poller)); 176 pollers[i] = (Ecore_Poller_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(poller));
163 ecore_poller_mp_free(poller); 177
178 eo_parent_set(poller->obj, NULL);
179 if (eo_destructed_is(poller->obj))
180 eo_manual_free(poller->obj);
181 else
182 eo_manual_free_set(poller->obj, EINA_FALSE);
183
164 poller_delete_count--; 184 poller_delete_count--;
165 changes++; 185 changes++;
166 if (poller_delete_count <= 0) break; 186 if (poller_delete_count <= 0) break;
@@ -212,6 +232,13 @@ ecore_poller_poll_interval_get(Ecore_Poller_Type type __UNUSED__)
212 return poll_interval; 232 return poll_interval;
213} 233}
214 234
235static void
236_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
237{
238 eo_error_set(obj);
239 ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
240}
241
215EAPI Ecore_Poller * 242EAPI Ecore_Poller *
216ecore_poller_add(Ecore_Poller_Type type __UNUSED__, 243ecore_poller_add(Ecore_Poller_Type type __UNUSED__,
217 int interval, 244 int interval,
@@ -219,15 +246,43 @@ ecore_poller_add(Ecore_Poller_Type type __UNUSED__,
219 const void *data) 246 const void *data)
220{ 247{
221 Ecore_Poller *poller; 248 Ecore_Poller *poller;
249 poller = eo_add_custom(MY_CLASS, _ecore_parent,
250 ecore_poller_constructor(type, interval, func, data));
251 eo_unref(poller);
252 return poller;
253}
254
255static void
256_poller_constructor(Eo *obj, void *_pd, va_list *list)
257{
258 Ecore_Poller_Type type = va_arg(*list, Ecore_Poller_Type);
259 (void)type;
260 int interval = va_arg(*list, int);
261 Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
262 const void *data = va_arg(*list, const void *);
263
264
265 Ecore_Poller_Private_Data *poller = _pd;
266 poller->obj = obj;
267
222 int ibit; 268 int ibit;
223 269
224 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 270 if (EINA_UNLIKELY(!eina_main_loop_is()))
225 if (!func) return NULL; 271 {
226 if (interval < 1) interval = 1; 272 eo_error_set(obj);
273 EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FLASE);
274 }
275
276 eo_do_super(obj, eo_constructor());
277 eo_manual_free_set(obj, EINA_TRUE);
278
279 if (!func)
280 {
281 eo_error_set(obj);
282 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
283 return;
284 }
227 285
228 poller = ecore_poller_calloc(1);
229 if (!poller) return NULL;
230 ECORE_MAGIC_SET(poller, ECORE_MAGIC_POLLER);
231 /* interval MUST be a power of 2, so enforce it */ 286 /* interval MUST be a power of 2, so enforce it */
232 if (interval < 1) interval = 1; 287 if (interval < 1) interval = 1;
233 ibit = -1; 288 ibit = -1;
@@ -242,27 +297,35 @@ ecore_poller_add(Ecore_Poller_Type type __UNUSED__,
242 poller->ibit = ibit; 297 poller->ibit = ibit;
243 poller->func = func; 298 poller->func = func;
244 poller->data = (void *)data; 299 poller->data = (void *)data;
245 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 300 pollers[poller->ibit] = (Ecore_Poller_Private_Data *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
246 if (poller_walking) 301 if (poller_walking)
247 just_added_poller++; 302 just_added_poller++;
248 else 303 else
249 _ecore_poller_next_tick_eval(); 304 _ecore_poller_next_tick_eval();
250 return poller;
251} 305}
252 306
253EAPI Eina_Bool 307EAPI Eina_Bool
254ecore_poller_poller_interval_set(Ecore_Poller *poller, 308ecore_poller_poller_interval_set(Ecore_Poller *obj,
255 int interval) 309 int interval)
256{ 310{
311 Eina_Bool ret;
312 ECORE_POLLER_CHECK(obj) EINA_FALSE;
313 eo_do(obj, ecore_poller_interval_set(interval, &ret));
314 return ret;
315}
316
317static void
318_poller_interval_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
319{
320 int interval = va_arg(*list, int);
321 Eina_Bool *ret = va_arg(*list, Eina_Bool *);
322 Eina_Bool int_ret;
323
324 EINA_MAIN_LOOP_CHECK_RETURN;
325
257 int ibit; 326 int ibit;
258 327
259 EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE); 328 Ecore_Poller_Private_Data *poller = _pd;
260 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER))
261 {
262 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER,
263 "ecore_poller_poller_interval_set");
264 return EINA_FALSE;
265 }
266 329
267 /* interval MUST be a power of 2, so enforce it */ 330 /* interval MUST be a power of 2, so enforce it */
268 if (interval < 1) interval = 1; 331 if (interval < 1) interval = 1;
@@ -276,29 +339,44 @@ ecore_poller_poller_interval_set(Ecore_Poller *poller,
276 if (ibit > 15) ibit = 15; 339 if (ibit > 15) ibit = 15;
277 /* if interval specified is the same as interval set, return true without wasting time */ 340 /* if interval specified is the same as interval set, return true without wasting time */
278 if (poller->ibit == ibit) 341 if (poller->ibit == ibit)
279 return EINA_TRUE; 342 {
280 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 343 int_ret = EINA_TRUE;
344 goto end;
345 }
346
347 pollers[poller->ibit] = (Ecore_Poller_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
281 poller->ibit = ibit; 348 poller->ibit = ibit;
282 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 349 pollers[poller->ibit] = (Ecore_Poller_Private_Data *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
283 if (poller_walking) 350 if (poller_walking)
284 just_added_poller++; 351 just_added_poller++;
285 else 352 else
286 _ecore_poller_next_tick_eval(); 353 _ecore_poller_next_tick_eval();
287 return EINA_TRUE; 354
355 int_ret = EINA_TRUE;
356
357end:
358 if (ret) *ret = int_ret;
288} 359}
289 360
290EAPI int 361EAPI int
291ecore_poller_poller_interval_get(Ecore_Poller *poller) 362ecore_poller_poller_interval_get(Ecore_Poller *obj)
292{ 363{
364 int ret;
365 ECORE_POLLER_CHECK(obj) EINA_FALSE;
366 eo_do(obj, ecore_poller_interval_get(&ret));
367 return ret;
368}
369
370static void
371_poller_interval_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
372{
373 int *ret = va_arg(*list, int *);
374 *ret =0;
375
293 int ibit, interval = 1; 376 int ibit, interval = 1;
294 377
295 EINA_MAIN_LOOP_CHECK_RETURN_VAL(0); 378 EINA_MAIN_LOOP_CHECK_RETURN;
296 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER)) 379 Ecore_Poller_Private_Data *poller = _pd;
297 {
298 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER,
299 "ecore_poller_poller_interval_get");
300 return 0;
301 }
302 380
303 ibit = poller->ibit; 381 ibit = poller->ibit;
304 while (ibit != 0) 382 while (ibit != 0)
@@ -306,21 +384,16 @@ ecore_poller_poller_interval_get(Ecore_Poller *poller)
306 ibit--; 384 ibit--;
307 interval <<= 1; 385 interval <<= 1;
308 } 386 }
309 return interval; 387 *ret = interval;
310} 388}
311 389
312EAPI void * 390EAPI void *
313ecore_poller_del(Ecore_Poller *poller) 391ecore_poller_del(Ecore_Poller *obj)
314{ 392{
315 void *data; 393 void *data;
316 394
317 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 395 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
318 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER)) 396 Ecore_Poller_Private_Data *poller = eo_data_get(obj, MY_CLASS);
319 {
320 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER,
321 "ecore_poller_del");
322 return NULL;
323 }
324 /* we are walking the poller list - a bad idea to remove from it while 397 /* we are walking the poller list - a bad idea to remove from it while
325 * walking it, so just flag it as delete_me and come back to it after 398 * walking it, so just flag it as delete_me and come back to it after
326 * the loop has finished */ 399 * the loop has finished */
@@ -332,12 +405,32 @@ ecore_poller_del(Ecore_Poller *poller)
332 } 405 }
333 /* not in loop so safe - delete immediately */ 406 /* not in loop so safe - delete immediately */
334 data = poller->data; 407 data = poller->data;
335 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 408 pollers[poller->ibit] = (Ecore_Poller_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
336 ecore_poller_mp_free(poller); 409
410 eo_parent_set(poller->obj, NULL);
411 if (eo_destructed_is(poller->obj))
412 eo_manual_free(obj);
413 else
414 eo_manual_free_set(obj, EINA_FALSE);
415
337 _ecore_poller_next_tick_eval(); 416 _ecore_poller_next_tick_eval();
338 return data; 417 return data;
339} 418}
340 419
420static void
421_destructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
422{
423 Ecore_Poller_Private_Data *pd = _pd;
424
425 if (!pd->delete_me)
426 {
427 pd->delete_me = 1;
428 poller_delete_count++;
429 }
430
431 eo_do_super(obj, eo_destructor());
432}
433
341/** 434/**
342 * @} 435 * @}
343 */ 436 */
@@ -346,15 +439,52 @@ void
346_ecore_poller_shutdown(void) 439_ecore_poller_shutdown(void)
347{ 440{
348 int i; 441 int i;
349 Ecore_Poller *poller; 442 Ecore_Poller_Private_Data *poller;
350 443
351 for (i = 0; i < 15; i++) 444 for (i = 0; i < 15; i++)
352 { 445 {
353 while ((poller = pollers[i])) 446 while ((poller = pollers[i]))
354 { 447 {
355 pollers[i] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(pollers[i])); 448 pollers[i] = (Ecore_Poller_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(pollers[i]));
356 ecore_poller_mp_free(poller); 449 eo_parent_set(poller->obj, NULL);
450 if (eo_destructed_is(poller->obj))
451 eo_manual_free(poller->obj);
452 else
453 eo_manual_free_set(poller->obj, EINA_FALSE);
357 } 454 }
358 } 455 }
359} 456}
360 457
458static void
459_class_constructor(Eo_Class *klass)
460{
461 const Eo_Op_Func_Description func_desc[] = {
462 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
463 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
464 EO_OP_FUNC(ECORE_POLLER_ID(ECORE_POLLER_SUB_ID_CONSTRUCTOR), _poller_constructor),
465 EO_OP_FUNC(ECORE_POLLER_ID(ECORE_POLLER_SUB_ID_INTERVAL_SET), _poller_interval_set),
466 EO_OP_FUNC(ECORE_POLLER_ID(ECORE_POLLER_SUB_ID_INTERVAL_GET), _poller_interval_get),
467 EO_OP_FUNC_SENTINEL
468 };
469
470 eo_class_funcs_set(klass, func_desc);
471}
472
473static const Eo_Op_Description op_desc[] = {
474 EO_OP_DESCRIPTION(ECORE_POLLER_SUB_ID_CONSTRUCTOR, "Add an idle enterer handler."),
475 EO_OP_DESCRIPTION(ECORE_POLLER_SUB_ID_INTERVAL_SET, "Changes the polling interval rate of poller."),
476 EO_OP_DESCRIPTION(ECORE_POLLER_SUB_ID_INTERVAL_GET, "Gets the polling interval rate of poller"),
477 EO_OP_DESCRIPTION_SENTINEL
478};
479static const Eo_Class_Description class_desc = {
480 EO_VERSION,
481 MY_CLASS_NAME,
482 EO_CLASS_TYPE_REGULAR,
483 EO_CLASS_DESCRIPTION_OPS(&ECORE_POLLER_BASE_ID, op_desc, ECORE_POLLER_SUB_ID_LAST),
484 NULL,
485 sizeof(Ecore_Poller_Private_Data),
486 _class_constructor,
487 NULL
488};
489
490EO_DEFINE_CLASS(ecore_poller_class_get, &class_desc, EO_BASE_CLASS, NULL)