summaryrefslogtreecommitdiff
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
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
-rw-r--r--legacy/ecore/ChangeLog3
-rw-r--r--legacy/ecore/NEWS2
-rw-r--r--legacy/ecore/configure.ac7
-rw-r--r--legacy/ecore/src/examples/ecore_idler_example.c6
-rw-r--r--legacy/ecore/src/examples/ecore_poller_example.c35
-rw-r--r--legacy/ecore/src/lib/ecore/Ecore.h164
-rw-r--r--legacy/ecore/src/lib/ecore/ecore.c24
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_alloc.c42
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_anim.c221
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_idle_enterer.c200
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_idle_exiter.c163
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_idler.c156
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_job.c123
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_poll.c226
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_private.h18
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_timer.c497
16 files changed, 1432 insertions, 455 deletions
diff --git a/legacy/ecore/ChangeLog b/legacy/ecore/ChangeLog
index d9f5d9b39c..e1db999616 100644
--- a/legacy/ecore/ChangeLog
+++ b/legacy/ecore/ChangeLog
@@ -1,3 +1,6 @@
12012-10-10 Daniel Zaoui and Yaakov Goldberg
2 * Porting of Ecore to Eo
3
12011-01-29 Carsten Haitzler (The Rasterman) 42011-01-29 Carsten Haitzler (The Rasterman)
2 5
3 1.0.0 release 6 1.0.0 release
diff --git a/legacy/ecore/NEWS b/legacy/ecore/NEWS
index f08395dfe0..a34205f14f 100644
--- a/legacy/ecore/NEWS
+++ b/legacy/ecore/NEWS
@@ -4,6 +4,8 @@ Changes since Ecore 1.7.0:
4-------------------------- 4--------------------------
5 5
6Additions: 6Additions:
7 * ecore:
8 - porting to Eo
7 * ecore_con: 9 * ecore_con:
8 - Add Ecore_Con_Eet API to help using Eet_Data with Ecore_Con. 10 - Add Ecore_Con_Eet API to help using Eet_Data with Ecore_Con.
9 * ecore_x: 11 * ecore_x:
diff --git a/legacy/ecore/configure.ac b/legacy/ecore/configure.ac
index fa8ae0ae37..6b14164b88 100644
--- a/legacy/ecore/configure.ac
+++ b/legacy/ecore/configure.ac
@@ -565,6 +565,13 @@ requirements_ecore_win32="ecore >= 1.6.99 eina >= 1.6.99 ${requirements_ecore_wi
565requirements_ecore_wince="ecore >= 1.6.99 eina >= 1.6.99 ${requirements_ecore_wince}" 565requirements_ecore_wince="ecore >= 1.6.99 eina >= 1.6.99 ${requirements_ecore_wince}"
566requirements_ecore_x="ecore >= 1.6.99 eina >= 1.6.99 ${requirements_ecore_x}" 566requirements_ecore_x="ecore >= 1.6.99 eina >= 1.6.99 ${requirements_ecore_x}"
567 567
568# Eo
569
570PKG_CHECK_MODULES([EO], [eo])
571requirements_ecore="eo ${requirements_ecore}"
572
573EINA_CFLAGS="$EINA_CFLAGS $EO_CFLAGS"
574EINA_LIBS="$EINA_LIBS $EO_LIBS"
568 575
569# glib support (main loop integration) 576# glib support (main loop integration)
570AC_ARG_ENABLE([glib], 577AC_ARG_ENABLE([glib],
diff --git a/legacy/ecore/src/examples/ecore_idler_example.c b/legacy/ecore/src/examples/ecore_idler_example.c
index 11b3397820..37de393ffe 100644
--- a/legacy/ecore/src/examples/ecore_idler_example.c
+++ b/legacy/ecore/src/examples/ecore_idler_example.c
@@ -56,7 +56,8 @@ _event_handler_cb(void *data, int type, void *event) // event callback
56 { 56 {
57 ecore_idle_enterer_del(ctxt->enterer); 57 ecore_idle_enterer_del(ctxt->enterer);
58 ecore_idle_exiter_del(ctxt->exiter); 58 ecore_idle_exiter_del(ctxt->exiter);
59 ecore_idler_del(ctxt->idler); 59// ecore_idler_del(ctxt->idler);
60 eo_unref(ctxt->idler);
60 61
61 ctxt->enterer = NULL; 62 ctxt->enterer = NULL;
62 ctxt->exiter = NULL; 63 ctxt->exiter = NULL;
@@ -101,7 +102,8 @@ main(int argc, char **argv)
101 102
102 ctxt.enterer = ecore_idle_enterer_add(_enterer_cb, &ctxt); 103 ctxt.enterer = ecore_idle_enterer_add(_enterer_cb, &ctxt);
103 ctxt.exiter = ecore_idle_exiter_add(_exiter_cb, &ctxt); 104 ctxt.exiter = ecore_idle_exiter_add(_exiter_cb, &ctxt);
104 ctxt.idler = ecore_idler_add(_idler_cb, &ctxt); 105// ctxt.idler = ecore_idler_add(_idler_cb, &ctxt);
106 ctxt.idler = eo_add_custom(ECORE_IDLER_CLASS, NULL, ecore_idler_constructor(_idler_cb, &ctxt));
105 ctxt.handler = ecore_event_handler_add(_event_type, 107 ctxt.handler = ecore_event_handler_add(_event_type,
106 _event_handler_cb, 108 _event_handler_cb,
107 &ctxt); 109 &ctxt);
diff --git a/legacy/ecore/src/examples/ecore_poller_example.c b/legacy/ecore/src/examples/ecore_poller_example.c
index 0e246dee7a..ccd1c2e355 100644
--- a/legacy/ecore/src/examples/ecore_poller_example.c
+++ b/legacy/ecore/src/examples/ecore_poller_example.c
@@ -13,13 +13,22 @@ _poller_print_cb(void *data)
13 return ECORE_CALLBACK_RENEW; 13 return ECORE_CALLBACK_RENEW;
14} 14}
15 15
16static Eina_Bool
17_poller_quit_cb(void *data)
18{
19
20 ecore_main_loop_quit();
21 return EINA_TRUE;
22}
23
16int 24int
17main(int argc, char **argv) 25main(int argc, char **argv)
18{ 26{
19 double interval = 0.3; // tick each 0.3 seconds 27 double interval = 0.3; // tick each 0.3 seconds
20 Ecore_Poller *poller1, *poller2; 28 Ecore_Poller *poller1, *poller2, *poller3;
21 char *str1 = "poller1"; 29 char *str1 = "poller1";
22 char *str2 = "poller2"; 30 char *str2 = "poller2";
31 char *str3 = "poller3";
23 32
24 if (!ecore_init()) 33 if (!ecore_init())
25 { 34 {
@@ -31,18 +40,32 @@ main(int argc, char **argv)
31 40
32 ecore_poller_poll_interval_set(ECORE_POLLER_CORE, interval); 41 ecore_poller_poll_interval_set(ECORE_POLLER_CORE, interval);
33 42
34 poller1 = ecore_poller_add(ECORE_POLLER_CORE, 4, _poller_print_cb, str1); 43// poller1 = ecore_poller_add(ECORE_POLLER_CORE, 4, _poller_print_cb, str1);
35 poller2 = ecore_poller_add(ECORE_POLLER_CORE, 8, _poller_print_cb, str2); 44// poller2 = ecore_poller_add(ECORE_POLLER_CORE, 8, _poller_print_cb, str2);
45 // poller3 = ecore_poller_add(ECORE_POLLER_CORE, 30, _poller_quit_cb, str3);
46
47 poller1 = eo_add_custom(ECORE_POLLER_CLASS, NULL,
48 ecore_poller_constructor(ECORE_POLLER_CORE, 4, _poller_print_cb, str1));
49 poller2 = eo_add_custom(ECORE_POLLER_CLASS, NULL,
50 ecore_poller_constructor(ECORE_POLLER_CORE, 8, _poller_print_cb, str2));
51 poller3 = eo_add_custom(ECORE_POLLER_CLASS, NULL,
52 ecore_poller_constructor(ECORE_POLLER_CORE, 20, _poller_quit_cb, str3));
53
36 54
37 ecore_main_loop_begin(); 55 ecore_main_loop_begin();
38 56
39 printf("changing poller2 interval to 16\n"); 57 printf("changing poller2 interval to 16\n");
40 58
41 ecore_poller_poller_interval_set(poller2, 16); 59// ecore_poller_poller_interval_set(poller2, 16);
60 eo_do(poller2, ecore_poller_interval_set(16, NULL));
42 ecore_main_loop_begin(); 61 ecore_main_loop_begin();
43 62
44 ecore_poller_del(poller1); 63 eo_unref(poller1);
45 ecore_poller_del(poller2); 64 eo_unref(poller2);
65 eo_unref(poller3);
66// ecore_poller_del(poller1);
67// ecore_poller_del(poller2);
68// ecore_poller_del(poller3);
46 69
47 ecore_shutdown(); 70 ecore_shutdown();
48} 71}
diff --git a/legacy/ecore/src/lib/ecore/Ecore.h b/legacy/ecore/src/lib/ecore/Ecore.h
index d47c24d101..3610af4c68 100644
--- a/legacy/ecore/src/lib/ecore/Ecore.h
+++ b/legacy/ecore/src/lib/ecore/Ecore.h
@@ -328,6 +328,9 @@ sudo make install
328 328
329#include <Eina.h> 329#include <Eina.h>
330 330
331/* This include has been added to support Eo in Ecore */
332#include <Eo.h>
333
331#ifdef EAPI 334#ifdef EAPI
332# undef EAPI 335# undef EAPI
333#endif 336#endif
@@ -1253,7 +1256,31 @@ enum _Ecore_Poller_Type /* Poller types */
1253}; 1256};
1254typedef enum _Ecore_Poller_Type Ecore_Poller_Type; 1257typedef enum _Ecore_Poller_Type Ecore_Poller_Type;
1255 1258
1256typedef struct _Ecore_Poller Ecore_Poller; /**< A handle for pollers */ 1259/*
1260 * @since 1.8
1261 */
1262
1263typedef Eo Ecore_Poller; /**< A handle for pollers */
1264
1265#define ECORE_POLLER_CLASS ecore_poller_class_get()
1266const Eo_Class *ecore_poller_class_get(void) EINA_CONST;
1267extern EAPI Eo_Op ECORE_POLLER_BASE_ID;
1268
1269enum
1270{
1271 ECORE_POLLER_SUB_ID_CONSTRUCTOR,
1272 ECORE_POLLER_SUB_ID_INTERVAL_SET,
1273 ECORE_POLLER_SUB_ID_INTERVAL_GET,
1274 ECORE_POLLER_SUB_ID_LAST,
1275};
1276
1277#define ECORE_POLLER_ID(sub_id) (ECORE_POLLER_BASE_ID + sub_id)
1278
1279#define ecore_poller_constructor(type, interval, func, data) ECORE_POLLER_ID(ECORE_POLLER_SUB_ID_CONSTRUCTOR), EO_TYPECHECK(Ecore_Poller_Type, type), EO_TYPECHECK(int, interval), EO_TYPECHECK(Ecore_Task_Cb, func), EO_TYPECHECK(const void *, data)
1280
1281#define ecore_poller_interval_set(interval, ret) ECORE_POLLER_ID(ECORE_POLLER_SUB_ID_INTERVAL_SET), EO_TYPECHECK(int, interval), EO_TYPECHECK(Eina_Bool *, ret)
1282#define ecore_poller_interval_get(ret) ECORE_POLLER_ID(ECORE_POLLER_SUB_ID_INTERVAL_GET), EO_TYPECHECK(int *, ret)
1283
1257 1284
1258/** 1285/**
1259 * @brief Sets the time(in seconds) between ticks for the given poller type. 1286 * @brief Sets the time(in seconds) between ticks for the given poller type.
@@ -1368,7 +1395,27 @@ EAPI void *ecore_poller_del(Ecore_Poller *poller);
1368 * @{ 1395 * @{
1369 */ 1396 */
1370 1397
1371typedef struct _Ecore_Animator Ecore_Animator; /**< A handle for animators */ 1398/*
1399 * @since 1.8
1400 */
1401typedef Eo Ecore_Animator; /**< A handle for animators */
1402#define ECORE_ANIMATOR_CLASS ecore_animator_class_get()
1403const Eo_Class *ecore_animator_class_get(void) EINA_CONST;
1404
1405extern EAPI Eo_Op ECORE_ANIMATOR_BASE_ID;
1406
1407enum
1408{
1409 ECORE_ANIMATOR_SUB_ID_CONSTRUCTOR,
1410 ECORE_ANIMATOR_SUB_ID_TIMELINE_CONSTRUCTOR,
1411 ECORE_ANIMATOR_SUB_ID_LAST
1412};
1413
1414#define ECORE_ANIMATOR_ID(sub_id) (ECORE_ANIMATOR_BASE_ID + sub_id)
1415
1416#define ecore_animator_constructor(func, data) ECORE_ANIMATOR_ID(ECORE_ANIMATOR_SUB_ID_CONSTRUCTOR), EO_TYPECHECK(Ecore_Task_Cb, func), EO_TYPECHECK(const void *, data)
1417
1418#define ecore_animator_timeline_constructor(runtime, func, data) ECORE_ANIMATOR_ID(ECORE_ANIMATOR_SUB_ID_TIMELINE_CONSTRUCTOR), EO_TYPECHECK(double, runtime), EO_TYPECHECK(Ecore_Timeline_Cb, func), EO_TYPECHECK(const void *, data)
1372 1419
1373/** 1420/**
1374 * @enum _Ecore_Pos_Map 1421 * @enum _Ecore_Pos_Map
@@ -1711,7 +1758,37 @@ EAPI double ecore_loop_time_get(void);
1711 * @{ 1758 * @{
1712 */ 1759 */
1713 1760
1714typedef struct _Ecore_Timer Ecore_Timer; /**< A handle for timers */ 1761/*
1762 * @since 1.8
1763 */
1764typedef Eo Ecore_Timer; /**< A handle for timers */
1765
1766#define ECORE_TIMER_CLASS ecore_timer_class_get()
1767const Eo_Class *ecore_timer_class_get(void) EINA_CONST;
1768extern EAPI Eo_Op ECORE_TIMER_BASE_ID;
1769
1770enum
1771{
1772 ECORE_TIMER_SUB_ID_CONSTRUCTOR,
1773 ECORE_TIMER_SUB_ID_LOOP_CONSTRUCTOR,
1774 ECORE_TIMER_SUB_ID_INTERVAL_SET,
1775 ECORE_TIMER_SUB_ID_INTERVAL_GET,
1776 ECORE_TIMER_SUB_ID_DELAY,
1777 ECORE_TIMER_SUB_ID_RESET,
1778 ECORE_TIMER_SUB_ID_PENDING_GET,
1779 ECORE_TIMER_SUB_ID_LAST,
1780};
1781
1782#define ECORE_TIMER_ID(sub_id) (ECORE_TIMER_BASE_ID + sub_id)
1783
1784#define ecore_timer_constructor(in, func, data) ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_CONSTRUCTOR), EO_TYPECHECK(double, in), EO_TYPECHECK(Ecore_Task_Cb, func), EO_TYPECHECK(const void *, data)
1785#define ecore_timer_loop_constructor(in, func, data) ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_LOOP_CONSTRUCTOR), EO_TYPECHECK(double, in), EO_TYPECHECK(Ecore_Task_Cb, func), EO_TYPECHECK(const void *, data)
1786
1787#define ecore_obj_timer_interval_set(in) ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_INTERVAL_SET), EO_TYPECHECK(double, in)
1788#define ecore_obj_timer_interval_get(ret) ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_INTERVAL_GET), EO_TYPECHECK(double *, ret)
1789#define ecore_obj_timer_delay(add) ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_DELAY), EO_TYPECHECK(double, add)
1790#define ecore_obj_timer_reset() ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_RESET)
1791#define ecore_obj_timer_pending_get(ret) ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_PENDING_GET), EO_TYPECHECK(double *, ret)
1715 1792
1716EAPI Ecore_Timer *ecore_timer_add(double in, Ecore_Task_Cb func, const void *data); 1793EAPI Ecore_Timer *ecore_timer_add(double in, Ecore_Task_Cb func, const void *data);
1717EAPI Ecore_Timer *ecore_timer_loop_add(double in, Ecore_Task_Cb func, const void *data); 1794EAPI Ecore_Timer *ecore_timer_loop_add(double in, Ecore_Task_Cb func, const void *data);
@@ -1776,9 +1853,66 @@ EAPI char *ecore_timer_dump(void);
1776 * @{ 1853 * @{
1777 */ 1854 */
1778 1855
1779typedef struct _Ecore_Idler Ecore_Idler; /**< A handle for idlers */ 1856/*
1780typedef struct _Ecore_Idle_Enterer Ecore_Idle_Enterer; /**< A handle for idle enterers */ 1857 * @since 1.8
1781typedef struct _Ecore_Idle_Exiter Ecore_Idle_Exiter; /**< A handle for idle exiters */ 1858 */
1859typedef Eo Ecore_Idler; /**< A handle for idlers */
1860#define ECORE_IDLER_CLASS ecore_idler_class_get()
1861const Eo_Class *ecore_idler_class_get(void) EINA_CONST;
1862
1863extern EAPI Eo_Op ECORE_IDLER_BASE_ID;
1864
1865enum
1866{
1867 ECORE_IDLER_SUB_ID_CONSTRUCTOR,
1868 ECORE_IDLER_SUB_ID_LAST
1869};
1870
1871#define ECORE_IDLER_ID(sub_id) (ECORE_IDLER_BASE_ID + sub_id)
1872#define ecore_idler_constructor(func, data) ECORE_IDLER_ID(ECORE_IDLER_SUB_ID_CONSTRUCTOR), EO_TYPECHECK(Ecore_Task_Cb, func), EO_TYPECHECK(const void *, data)
1873
1874/**
1875 *
1876 */
1877
1878typedef Eo Ecore_Idle_Enterer; /**< A handle for idle enterers */
1879#define ECORE_IDLE_ENTERER_CLASS ecore_idle_enterer_class_get()
1880const Eo_Class *ecore_idle_enterer_class_get(void) EINA_CONST;
1881
1882extern EAPI Eo_Op ECORE_IDLE_ENTERER_BASE_ID;
1883
1884enum
1885{
1886 ECORE_IDLE_ENTERER_SUB_ID_AFTER_CONSTRUCTOR,
1887 ECORE_IDLE_ENTERER_SUB_ID_BEFORE_CONSTRUCTOR,
1888 ECORE_IDLE_ENTERER_SUB_ID_LAST
1889};
1890
1891#define ECORE_IDLE_ENTERER_ID(sub_id) (ECORE_IDLE_ENTERER_BASE_ID + sub_id)
1892#define ecore_idle_enterer_after_constructor(func, data) ECORE_IDLE_ENTERER_ID(ECORE_IDLE_ENTERER_SUB_ID_AFTER_CONSTRUCTOR), EO_TYPECHECK(Ecore_Task_Cb, func), EO_TYPECHECK(const void *, data)
1893#define ecore_idle_enterer_before_constructor(func, data) ECORE_IDLE_ENTERER_ID(ECORE_IDLE_ENTERER_SUB_ID_BEFORE_CONSTRUCTOR), EO_TYPECHECK(Ecore_Task_Cb, func), EO_TYPECHECK(const void *, data)
1894
1895/**
1896 *
1897 */
1898
1899/*
1900 * @since 1.8
1901 */
1902typedef Eo Ecore_Idle_Exiter; /**< A handle for idle exiters */
1903#define ECORE_IDLE_EXITER_CLASS ecore_idle_exiter_class_get()
1904const Eo_Class *ecore_idle_exiter_class_get(void) EINA_CONST;
1905
1906extern EAPI Eo_Op ECORE_IDLE_EXITER_BASE_ID;
1907
1908enum
1909{
1910 ECORE_IDLE_EXITER_SUB_ID_CONSTRUCTOR,
1911 ECORE_IDLE_EXITER_SUB_ID_LAST
1912};
1913
1914#define ECORE_IDLE_EXITER_ID(sub_id) (ECORE_IDLE_EXITER_BASE_ID + sub_id)
1915#define ecore_idle_exiter_constructor(func, data) ECORE_IDLE_EXITER_ID(ECORE_IDLE_EXITER_SUB_ID_CONSTRUCTOR), EO_TYPECHECK(Ecore_Task_Cb, func), EO_TYPECHECK(const void *, data)
1782 1916
1783/** 1917/**
1784 * Add an idler handler. 1918 * Add an idler handler.
@@ -2575,7 +2709,23 @@ EAPI int ecore_pipe_wait(Ecore_Pipe *p, int message_count, double wait);
2575 * @{ 2709 * @{
2576 */ 2710 */
2577 2711
2578typedef struct _Ecore_Job Ecore_Job; /**< A job handle */ 2712/*
2713 * @since 1.8
2714 */
2715typedef Eo Ecore_Job; /**< A job handle */
2716#define ECORE_JOB_CLASS ecore_job_class_get()
2717const Eo_Class *ecore_job_class_get(void) EINA_CONST;
2718
2719extern EAPI Eo_Op ECORE_JOB_BASE_ID;
2720
2721enum
2722{
2723 ECORE_JOB_SUB_ID_CONSTRUCTOR,
2724 ECORE_JOB_SUB_ID_LAST
2725};
2726
2727#define ECORE_JOB_ID(sub_id) (ECORE_JOB_BASE_ID + sub_id)
2728#define ecore_job_constructor(func, data) ECORE_JOB_ID(ECORE_JOB_SUB_ID_CONSTRUCTOR), EO_TYPECHECK(Ecore_Cb, func), EO_TYPECHECK(const void *, data)
2579 2729
2580EAPI Ecore_Job *ecore_job_add(Ecore_Cb func, const void *data); 2730EAPI Ecore_Job *ecore_job_add(Ecore_Cb func, const void *data);
2581EAPI void *ecore_job_del(Ecore_Job *job); 2731EAPI void *ecore_job_del(Ecore_Job *job);
diff --git a/legacy/ecore/src/lib/ecore/ecore.c b/legacy/ecore/src/lib/ecore/ecore.c
index 0df319b593..35c548679b 100644
--- a/legacy/ecore/src/lib/ecore/ecore.c
+++ b/legacy/ecore/src/lib/ecore/ecore.c
@@ -36,6 +36,9 @@
36#if HAVE_MALLINFO 36#if HAVE_MALLINFO
37#include <malloc.h> 37#include <malloc.h>
38 38
39
40EAPI Eo *_ecore_parent = NULL;
41
39static Ecore_Version _version = { VERS_MAJ, VERS_MIN, VERS_MIC, VERS_REV }; 42static Ecore_Version _version = { VERS_MAJ, VERS_MIN, VERS_MIC, VERS_REV };
40EAPI Ecore_Version *ecore_version = &_version; 43EAPI Ecore_Version *ecore_version = &_version;
41 44
@@ -138,6 +141,8 @@ ecore_init(void)
138 if (++_ecore_init_count != 1) 141 if (++_ecore_init_count != 1)
139 return _ecore_init_count; 142 return _ecore_init_count;
140 143
144 eo_init();
145
141#ifdef HAVE_LOCALE_H 146#ifdef HAVE_LOCALE_H
142 setlocale(LC_CTYPE, ""); 147 setlocale(LC_CTYPE, "");
143#endif 148#endif
@@ -194,6 +199,7 @@ ecore_init(void)
194#if defined(GLIB_INTEGRATION_ALWAYS) 199#if defined(GLIB_INTEGRATION_ALWAYS)
195 if (_ecore_glib_always_integrate) ecore_main_loop_glib_integrate(); 200 if (_ecore_glib_always_integrate) ecore_main_loop_glib_integrate();
196#endif 201#endif
202 _ecore_parent = eo_add(ECORE_PARENT_CLASS, NULL);
197 203
198 return _ecore_init_count; 204 return _ecore_init_count;
199 205
@@ -205,6 +211,9 @@ shutdown_evil:
205#ifdef HAVE_EVIL 211#ifdef HAVE_EVIL
206 evil_shutdown(); 212 evil_shutdown();
207#endif 213#endif
214
215 eo_shutdown();
216
208 return --_ecore_init_count; 217 return --_ecore_init_count;
209} 218}
210 219
@@ -299,6 +308,9 @@ ecore_shutdown(void)
299#ifdef HAVE_EVIL 308#ifdef HAVE_EVIL
300 evil_shutdown(); 309 evil_shutdown();
301#endif 310#endif
311
312 eo_unref(_ecore_parent);
313 eo_shutdown();
302unlock: 314unlock:
303 _ecore_unlock(); 315 _ecore_unlock();
304 316
@@ -852,3 +864,15 @@ _thread_callback(void *data __UNUSED__,
852 _ecore_main_call_flush(); 864 _ecore_main_call_flush();
853} 865}
854 866
867static const Eo_Class_Description parent_class_desc = {
868 EO_VERSION,
869 "ecore_parent",
870 EO_CLASS_TYPE_REGULAR,
871 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
872 NULL,
873 0,
874 NULL,
875 NULL
876};
877
878EO_DEFINE_CLASS(ecore_parent_class_get, &parent_class_desc, EO_BASE_CLASS, NULL);
diff --git a/legacy/ecore/src/lib/ecore/ecore_alloc.c b/legacy/ecore/src/lib/ecore/ecore_alloc.c
index 58aa131ddc..bec66ef0d5 100644
--- a/legacy/ecore/src/lib/ecore/ecore_alloc.c
+++ b/legacy/ecore/src/lib/ecore/ecore_alloc.c
@@ -32,16 +32,16 @@ struct _Ecore_Mempool
32 eina_mempool_free(Type##_mp.mp, e); \ 32 eina_mempool_free(Type##_mp.mp, e); \
33 } 33 }
34 34
35GENERIC_ALLOC_FREE(Ecore_Animator, ecore_animator); 35//GENERIC_ALLOC_FREE(Ecore_Animator, ecore_animator);
36GENERIC_ALLOC_FREE(Ecore_Event_Handler, ecore_event_handler); 36GENERIC_ALLOC_FREE(Ecore_Event_Handler, ecore_event_handler);
37GENERIC_ALLOC_FREE(Ecore_Event_Filter, ecore_event_filter); 37GENERIC_ALLOC_FREE(Ecore_Event_Filter, ecore_event_filter);
38GENERIC_ALLOC_FREE(Ecore_Event, ecore_event); 38GENERIC_ALLOC_FREE(Ecore_Event, ecore_event);
39GENERIC_ALLOC_FREE(Ecore_Idle_Exiter, ecore_idle_exiter); 39//GENERIC_ALLOC_FREE(Ecore_Idle_Exiter, ecore_idle_exiter);
40GENERIC_ALLOC_FREE(Ecore_Idle_Enterer, ecore_idle_enterer); 40//GENERIC_ALLOC_FREE(Ecore_Idle_Enterer, ecore_idle_enterer);
41GENERIC_ALLOC_FREE(Ecore_Idler, ecore_idler); 41//GENERIC_ALLOC_FREE(Ecore_Idler, ecore_idler);
42GENERIC_ALLOC_FREE(Ecore_Job, ecore_job); 42//GENERIC_ALLOC_FREE(Ecore_Job, ecore_job);
43GENERIC_ALLOC_FREE(Ecore_Timer, ecore_timer); 43//GENERIC_ALLOC_FREE(Ecore_Timer, ecore_timer);
44GENERIC_ALLOC_FREE(Ecore_Poller, ecore_poller); 44//GENERIC_ALLOC_FREE(Ecore_Poller, ecore_poller);
45GENERIC_ALLOC_FREE(Ecore_Pipe, ecore_pipe); 45GENERIC_ALLOC_FREE(Ecore_Pipe, ecore_pipe);
46GENERIC_ALLOC_FREE(Ecore_Fd_Handler, ecore_fd_handler); 46GENERIC_ALLOC_FREE(Ecore_Fd_Handler, ecore_fd_handler);
47#ifdef _WIN32 47#ifdef _WIN32
@@ -49,16 +49,16 @@ GENERIC_ALLOC_FREE(Ecore_Win32_Handler, ecore_win32_handler);
49#endif 49#endif
50 50
51static Ecore_Mempool *mempool_array[] = { 51static Ecore_Mempool *mempool_array[] = {
52 &ecore_animator_mp, 52// &ecore_animator_mp,
53 &ecore_event_handler_mp, 53 &ecore_event_handler_mp,
54 &ecore_event_filter_mp, 54 &ecore_event_filter_mp,
55 &ecore_event_mp, 55 &ecore_event_mp,
56 &ecore_idle_exiter_mp, 56// &ecore_idle_exiter_mp,
57 &ecore_idle_enterer_mp, 57// &ecore_idle_enterer_mp,
58 &ecore_idler_mp, 58// &ecore_idler_mp,
59 &ecore_job_mp, 59// &ecore_job_mp,
60 &ecore_timer_mp, 60// &ecore_timer_mp,
61 &ecore_poller_mp, 61// &ecore_poller_mp,
62 &ecore_pipe_mp, 62 &ecore_pipe_mp,
63 &ecore_fd_handler_mp, 63 &ecore_fd_handler_mp,
64#ifdef _WIN32 64#ifdef _WIN32
@@ -75,16 +75,16 @@ ecore_mempool_init(void)
75#define MP_SIZE_INIT(TYPE, Type) \ 75#define MP_SIZE_INIT(TYPE, Type) \
76 Type##_mp.size = _ecore_sizeof_##TYPE 76 Type##_mp.size = _ecore_sizeof_##TYPE
77 77
78 MP_SIZE_INIT(Ecore_Animator, ecore_animator); 78// MP_SIZE_INIT(Ecore_Animator, ecore_animator);
79 MP_SIZE_INIT(Ecore_Event_Handler, ecore_event_handler); 79 MP_SIZE_INIT(Ecore_Event_Handler, ecore_event_handler);
80 MP_SIZE_INIT(Ecore_Event_Filter, ecore_event_filter); 80 MP_SIZE_INIT(Ecore_Event_Filter, ecore_event_filter);
81 MP_SIZE_INIT(Ecore_Event, ecore_event); 81 MP_SIZE_INIT(Ecore_Event, ecore_event);
82 MP_SIZE_INIT(Ecore_Idle_Exiter, ecore_idle_exiter); 82// MP_SIZE_INIT(Ecore_Idle_Exiter, ecore_idle_exiter);
83 MP_SIZE_INIT(Ecore_Idle_Enterer, ecore_idle_enterer); 83// MP_SIZE_INIT(Ecore_Idle_Enterer, ecore_idle_enterer);
84 MP_SIZE_INIT(Ecore_Idler, ecore_idler); 84// MP_SIZE_INIT(Ecore_Idler, ecore_idler);
85 MP_SIZE_INIT(Ecore_Job, ecore_job); 85// MP_SIZE_INIT(Ecore_Job, ecore_job);
86 MP_SIZE_INIT(Ecore_Timer, ecore_timer); 86// MP_SIZE_INIT(Ecore_Timer, ecore_timer);
87 MP_SIZE_INIT(Ecore_Poller, ecore_poller); 87// MP_SIZE_INIT(Ecore_Poller, ecore_poller);
88 MP_SIZE_INIT(Ecore_Pipe, ecore_pipe); 88 MP_SIZE_INIT(Ecore_Pipe, ecore_pipe);
89 MP_SIZE_INIT(Ecore_Fd_Handler, ecore_fd_handler); 89 MP_SIZE_INIT(Ecore_Fd_Handler, ecore_fd_handler);
90#ifdef _WIN32 90#ifdef _WIN32
diff --git a/legacy/ecore/src/lib/ecore/ecore_anim.c b/legacy/ecore/src/lib/ecore/ecore_anim.c
index 67bf8b11e8..ac798f4120 100644
--- a/legacy/ecore/src/lib/ecore/ecore_anim.c
+++ b/legacy/ecore/src/lib/ecore/ecore_anim.c
@@ -8,10 +8,22 @@
8#include "Ecore.h" 8#include "Ecore.h"
9#include "ecore_private.h" 9#include "ecore_private.h"
10 10
11struct _Ecore_Animator 11#include "Eo.h"
12
13#define MY_CLASS ECORE_ANIMATOR_CLASS
14
15#define MY_CLASS_NAME "ecore_animator"
16
17#define ECORE_ANIMATOR_CHECK(obj) \
18 if (!eo_isa((obj), ECORE_ANIMATOR_CLASS)) \
19 return
20
21EAPI Eo_Op ECORE_ANIMATOR_BASE_ID = EO_NOOP;
22
23struct _Ecore_Animator_Private_Data
12{ 24{
13 EINA_INLIST; 25 EINA_INLIST;
14 ECORE_MAGIC; 26 Ecore_Animator *obj;
15 27
16 Ecore_Task_Cb func; 28 Ecore_Task_Cb func;
17 void *data; 29 void *data;
@@ -25,13 +37,13 @@ struct _Ecore_Animator
25 Eina_Bool just_added : 1; 37 Eina_Bool just_added : 1;
26}; 38};
27 39
28GENERIC_ALLOC_SIZE_DECLARE(Ecore_Animator); 40typedef struct _Ecore_Animator_Private_Data Ecore_Animator_Private_Data;
29 41
30static Eina_Bool _ecore_animator_run(void *data); 42static Eina_Bool _ecore_animator_run(void *data);
31static Eina_Bool _ecore_animator(void *data); 43static Eina_Bool _ecore_animator(void *data);
32 44
33static int animators_delete_me = 0; 45static int animators_delete_me = 0;
34static Ecore_Animator *animators = NULL; 46static Ecore_Animator_Private_Data *animators = NULL;
35static double animators_frametime = 1.0 / 30.0; 47static double animators_frametime = 1.0 / 30.0;
36 48
37static Ecore_Animator_Source src = ECORE_ANIMATOR_SOURCE_TIMER; 49static Ecore_Animator_Source src = ECORE_ANIMATOR_SOURCE_TIMER;
@@ -98,7 +110,7 @@ _end_tick(void)
98static Eina_Bool 110static Eina_Bool
99_do_tick(void) 111_do_tick(void)
100{ 112{
101 Ecore_Animator *animator; 113 Ecore_Animator_Private_Data *animator;
102 114
103 EINA_INLIST_FOREACH(animators, animator) 115 EINA_INLIST_FOREACH(animators, animator)
104 { 116 {
@@ -120,18 +132,23 @@ _do_tick(void)
120 } 132 }
121 if (animators_delete_me) 133 if (animators_delete_me)
122 { 134 {
123 Ecore_Animator *l; 135 Ecore_Animator_Private_Data *l;
124 for (l = animators; l; ) 136 for (l = animators; l; )
125 { 137 {
126 animator = l; 138 animator = l;
127 l = (Ecore_Animator *)EINA_INLIST_GET(l)->next; 139 l = (Ecore_Animator_Private_Data *)EINA_INLIST_GET(l)->next;
128 if (animator->delete_me) 140 if (animator->delete_me)
129 { 141 {
130 animators = (Ecore_Animator *) 142 animators = (Ecore_Animator_Private_Data *)
131 eina_inlist_remove(EINA_INLIST_GET(animators), 143 eina_inlist_remove(EINA_INLIST_GET(animators),
132 EINA_INLIST_GET(animator)); 144 EINA_INLIST_GET(animator));
133 ECORE_MAGIC_SET(animator, ECORE_MAGIC_NONE); 145
134 ecore_animator_mp_free(animator); 146 eo_parent_set(animator->obj, NULL);
147 if (eo_destructed_is(animator->obj))
148 eo_manual_free(animator->obj);
149 else
150 eo_manual_free_set(animator->obj, EINA_FALSE);
151
135 animators_delete_me--; 152 animators_delete_me--;
136 if (animators_delete_me == 0) break; 153 if (animators_delete_me == 0) break;
137 } 154 }
@@ -145,36 +162,66 @@ _do_tick(void)
145 return ECORE_CALLBACK_RENEW; 162 return ECORE_CALLBACK_RENEW;
146} 163}
147 164
148static Ecore_Animator * 165static Eina_Bool
149_ecore_animator_add(Ecore_Task_Cb func, 166_ecore_animator_add(Ecore_Animator *obj,
167 Ecore_Animator_Private_Data *animator,
168 Ecore_Task_Cb func,
150 const void *data) 169 const void *data)
151{ 170{
152 Ecore_Animator *animator = NULL; 171 if (EINA_UNLIKELY(!eina_main_loop_is()))
172 {
173 eo_error_set(obj);
174 EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
175 }
176
177 animator->obj = obj;
178 eo_do_super(obj, eo_constructor());
179 eo_manual_free_set(obj, EINA_TRUE);
180
181 if (!func)
182 {
183 eo_error_set(obj);
184 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
185 return EINA_FALSE;
186 }
153 187
154 if (!func) return animator;
155 animator = ecore_animator_calloc(1);
156 if (!animator) return animator;
157 ECORE_MAGIC_SET(animator, ECORE_MAGIC_ANIMATOR);
158 animator->func = func; 188 animator->func = func;
159 animator->data = (void *)data; 189 animator->data = (void *)data;
160 animator->just_added = EINA_TRUE; 190 animator->just_added = EINA_TRUE;
161 animators = (Ecore_Animator *)eina_inlist_append(EINA_INLIST_GET(animators), EINA_INLIST_GET(animator)); 191 animators = (Ecore_Animator_Private_Data *)eina_inlist_append(EINA_INLIST_GET(animators), EINA_INLIST_GET(animator));
162 _begin_tick(); 192 _begin_tick();
163 return animator; 193 return EINA_TRUE;
194}
195
196static void
197_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
198{
199 eo_error_set(obj);
200 ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
164} 201}
165 202
166EAPI Ecore_Animator * 203EAPI Ecore_Animator *
167ecore_animator_add(Ecore_Task_Cb func, 204ecore_animator_add(Ecore_Task_Cb func,
168 const void *data) 205 const void *data)
169{ 206{
170 Ecore_Animator *animator; 207 Ecore_Animator *animator = NULL;
208
209 animator = eo_add_custom(MY_CLASS, _ecore_parent,
210 ecore_animator_constructor(func, data));
211 eo_unref(animator);
212 return animator;
213}
214
215static void
216_animator_constructor(Eo *obj, void *_pd, va_list *list)
217{
218 Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
219 const void *data = va_arg(*list, const void *);
171 220
172 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
173 _ecore_lock(); 221 _ecore_lock();
174 animator = _ecore_animator_add(func, data); 222 Ecore_Animator_Private_Data *animator = _pd;
223 _ecore_animator_add(obj, animator, func, data);
175 _ecore_unlock(); 224 _ecore_unlock();
176
177 return animator;
178} 225}
179 226
180EAPI Ecore_Animator * 227EAPI Ecore_Animator *
@@ -183,18 +230,32 @@ ecore_animator_timeline_add(double runtime,
183 const void *data) 230 const void *data)
184{ 231{
185 Ecore_Animator *animator; 232 Ecore_Animator *animator;
233 animator = eo_add_custom(MY_CLASS, _ecore_parent,
234 ecore_animator_timeline_constructor(runtime, func, data));
235 eo_unref(animator);
236 return animator;
237}
186 238
187 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 239static void
240_animator_timeline_constructor(Eo *obj, void *_pd, va_list *list)
241{
188 _ecore_lock(); 242 _ecore_lock();
243 double runtime = va_arg(*list, double);
189 if (runtime <= 0.0) runtime = 0.0; 244 if (runtime <= 0.0) runtime = 0.0;
190 animator = _ecore_animator_add(_ecore_animator_run, NULL); 245 Ecore_Timeline_Cb func = va_arg(*list, Ecore_Timeline_Cb);
191 animator->data = animator; 246 const void *data = va_arg(*list, const void *);
247
248 Ecore_Animator_Private_Data *animator = _pd;
249 if (!_ecore_animator_add(obj, animator, _ecore_animator_run, NULL)) goto unlock;
250
251 animator->data = obj;
192 animator->run_func = func; 252 animator->run_func = func;
193 animator->run_data = (void *)data; 253 animator->run_data = (void *)data;
194 animator->start = ecore_loop_time_get(); 254 animator->start = ecore_loop_time_get();
195 animator->run = runtime; 255 animator->run = runtime;
256
257unlock:
196 _ecore_unlock(); 258 _ecore_unlock();
197 return animator;
198} 259}
199 260
200static double 261static double
@@ -333,18 +394,14 @@ ecore_animator_pos_map(double pos,
333} 394}
334 395
335EAPI void * 396EAPI void *
336ecore_animator_del(Ecore_Animator *animator) 397ecore_animator_del(Ecore_Animator *obj)
337{ 398{
338 void *data = NULL; 399 void *data = NULL;
339 400
340 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 401 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
402 Ecore_Animator_Private_Data *animator = eo_data_get(obj, MY_CLASS);
341 _ecore_lock(); 403 _ecore_lock();
342 if (!ECORE_MAGIC_CHECK(animator, ECORE_MAGIC_ANIMATOR)) 404
343 {
344 ECORE_MAGIC_FAIL(animator, ECORE_MAGIC_ANIMATOR,
345 "ecore_animator_del");
346 goto unlock;
347 }
348 if (animator->delete_me) 405 if (animator->delete_me)
349 { 406 {
350 data = animator->data; 407 data = animator->data;
@@ -361,6 +418,17 @@ unlock:
361 return data; 418 return data;
362} 419}
363 420
421static void
422_destructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
423{
424 Ecore_Animator_Private_Data *pd = _pd;
425
426 pd->delete_me = EINA_TRUE;
427 animators_delete_me++;
428
429 eo_do_super(obj, eo_destructor());
430}
431
364EAPI void 432EAPI void
365ecore_animator_frametime_set(double frametime) 433ecore_animator_frametime_set(double frametime)
366{ 434{
@@ -385,14 +453,18 @@ ecore_animator_frametime_get(void)
385EAPI void 453EAPI void
386ecore_animator_freeze(Ecore_Animator *animator) 454ecore_animator_freeze(Ecore_Animator *animator)
387{ 455{
456 ECORE_ANIMATOR_CHECK(animator);
457 eo_do(animator, eo_event_freeze());
458}
459
460static void
461_ecore_animator_freeze(Eo *obj EINA_UNUSED, void *_pd,
462 va_list *list EINA_UNUSED)
463{
388 EINA_MAIN_LOOP_CHECK_RETURN; 464 EINA_MAIN_LOOP_CHECK_RETURN;
389 _ecore_lock(); 465 _ecore_lock();
390 if (!ECORE_MAGIC_CHECK(animator, ECORE_MAGIC_ANIMATOR)) 466 Ecore_Animator_Private_Data *animator = _pd;
391 { 467
392 ECORE_MAGIC_FAIL(animator, ECORE_MAGIC_ANIMATOR,
393 "ecore_animator_del");
394 goto unlock;
395 }
396 if (animator->delete_me) goto unlock; 468 if (animator->delete_me) goto unlock;
397 animator->suspended = EINA_TRUE; 469 animator->suspended = EINA_TRUE;
398unlock: 470unlock:
@@ -402,14 +474,18 @@ unlock:
402EAPI void 474EAPI void
403ecore_animator_thaw(Ecore_Animator *animator) 475ecore_animator_thaw(Ecore_Animator *animator)
404{ 476{
477 ECORE_ANIMATOR_CHECK(animator);
478 eo_do(animator, eo_event_thaw());
479}
480
481static void
482_ecore_animator_thaw(Eo *obj EINA_UNUSED, void *_pd,
483 va_list *list EINA_UNUSED)
484{
405 EINA_MAIN_LOOP_CHECK_RETURN; 485 EINA_MAIN_LOOP_CHECK_RETURN;
486 Ecore_Animator_Private_Data *animator = _pd;
487
406 _ecore_lock(); 488 _ecore_lock();
407 if (!ECORE_MAGIC_CHECK(animator, ECORE_MAGIC_ANIMATOR))
408 {
409 ECORE_MAGIC_FAIL(animator, ECORE_MAGIC_ANIMATOR,
410 "ecore_animator_del");
411 goto unlock;
412 }
413 if (animator->delete_me) goto unlock; 489 if (animator->delete_me) goto unlock;
414 animator->suspended = EINA_FALSE; 490 animator->suspended = EINA_FALSE;
415unlock: 491unlock:
@@ -475,19 +551,25 @@ _ecore_animator_shutdown(void)
475 _end_tick(); 551 _end_tick();
476 while (animators) 552 while (animators)
477 { 553 {
478 Ecore_Animator *animator; 554 Ecore_Animator_Private_Data *animator;
479 555
480 animator = animators; 556 animator = animators;
481 animators = (Ecore_Animator *)eina_inlist_remove(EINA_INLIST_GET(animators), EINA_INLIST_GET(animators)); 557 animators = (Ecore_Animator_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(animators), EINA_INLIST_GET(animators));
482 ECORE_MAGIC_SET(animator, ECORE_MAGIC_NONE); 558
483 ecore_animator_mp_free(animator); 559 eo_parent_set(animator->obj, NULL);
560 if (eo_destructed_is(animator->obj))
561 eo_manual_free(animator->obj);
562 else
563 eo_manual_free_set(animator->obj, EINA_FALSE);
484 } 564 }
485} 565}
486 566
487static Eina_Bool 567static Eina_Bool
488_ecore_animator_run(void *data) 568_ecore_animator_run(void *data)
489{ 569{
490 Ecore_Animator *animator = data; 570 Ecore_Animator *obj = data;
571 Ecore_Animator_Private_Data *animator = eo_data_get(obj, MY_CLASS);
572
491 double pos = 0.0, t; 573 double pos = 0.0, t;
492 Eina_Bool run_ret; 574 Eina_Bool run_ret;
493 575
@@ -514,3 +596,38 @@ _ecore_animator(void *data __UNUSED__)
514 return r; 596 return r;
515} 597}
516 598
599static void
600_class_constructor(Eo_Class *klass)
601{
602 const Eo_Op_Func_Description func_desc[] = {
603 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
604 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
605 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE), _ecore_animator_freeze),
606 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_THAW), _ecore_animator_thaw),
607
608 EO_OP_FUNC(ECORE_ANIMATOR_ID(ECORE_ANIMATOR_SUB_ID_CONSTRUCTOR), _animator_constructor),
609 EO_OP_FUNC(ECORE_ANIMATOR_ID(ECORE_ANIMATOR_SUB_ID_TIMELINE_CONSTRUCTOR), _animator_timeline_constructor),
610 EO_OP_FUNC_SENTINEL
611 };
612
613 eo_class_funcs_set(klass, func_desc);
614}
615
616static const Eo_Op_Description op_desc[] = {
617 EO_OP_DESCRIPTION(ECORE_ANIMATOR_SUB_ID_CONSTRUCTOR, "Add an animator to call func at every animation tick during main loop execution."),
618 EO_OP_DESCRIPTION(ECORE_ANIMATOR_SUB_ID_TIMELINE_CONSTRUCTOR, "Add an animator that runs for a limited time"),
619 EO_OP_DESCRIPTION_SENTINEL
620};
621
622static const Eo_Class_Description class_desc = {
623 EO_VERSION,
624 MY_CLASS_NAME,
625 EO_CLASS_TYPE_REGULAR,
626 EO_CLASS_DESCRIPTION_OPS(&ECORE_ANIMATOR_BASE_ID, op_desc, ECORE_ANIMATOR_SUB_ID_LAST),
627 NULL,
628 sizeof(Ecore_Animator_Private_Data),
629 _class_constructor,
630 NULL
631};
632
633EO_DEFINE_CLASS(ecore_animator_class_get, &class_desc, EO_BASE_CLASS, NULL)
diff --git a/legacy/ecore/src/lib/ecore/ecore_idle_enterer.c b/legacy/ecore/src/lib/ecore/ecore_idle_enterer.c
index 73e72cbf85..e71a0f9db7 100644
--- a/legacy/ecore/src/lib/ecore/ecore_idle_enterer.c
+++ b/legacy/ecore/src/lib/ecore/ecore_idle_enterer.c
@@ -7,19 +7,27 @@
7#include "Ecore.h" 7#include "Ecore.h"
8#include "ecore_private.h" 8#include "ecore_private.h"
9 9
10struct _Ecore_Idle_Enterer 10#include "Eo.h"
11
12#define MY_CLASS ECORE_IDLE_ENTERER_CLASS
13
14#define MY_CLASS_NAME "ecore_idle_enterer"
15
16EAPI Eo_Op ECORE_IDLE_ENTERER_BASE_ID = EO_NOOP;
17
18struct _Ecore_Idle_Enterer_Private_Data
11{ 19{
12 EINA_INLIST; 20 EINA_INLIST;
13 ECORE_MAGIC; 21 Ecore_Idle_Enterer *obj;
14 Ecore_Task_Cb func; 22 Ecore_Task_Cb func;
15 void *data; 23 void *data;
16 int references; 24 int references;
17 Eina_Bool delete_me : 1; 25 Eina_Bool delete_me : 1;
18}; 26};
19GENERIC_ALLOC_SIZE_DECLARE(Ecore_Idle_Enterer); 27typedef struct _Ecore_Idle_Enterer_Private_Data Ecore_Idle_Enterer_Private_Data;
20 28
21static Ecore_Idle_Enterer *idle_enterers = NULL; 29static Ecore_Idle_Enterer_Private_Data *idle_enterers = NULL;
22static Ecore_Idle_Enterer *idle_enterer_current = NULL; 30static Ecore_Idle_Enterer_Private_Data *idle_enterer_current = NULL;
23static int idle_enterers_delete_me = 0; 31static int idle_enterers_delete_me = 0;
24 32
25static void * 33static void *
@@ -31,6 +39,34 @@ _ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer);
31 * @{ 39 * @{
32 */ 40 */
33 41
42static Eina_Bool
43_ecore_idle_enterer_add(Ecore_Idle_Enterer *obj,
44 Ecore_Idle_Enterer_Private_Data *ie,
45 Ecore_Task_Cb func,
46 const void *data)
47{
48 if (EINA_UNLIKELY(!eina_main_loop_is()))
49 {
50 eo_error_set(obj);
51 EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FLASE);
52 }
53
54 ie->obj = obj;
55 eo_do_super(obj, eo_constructor());
56 eo_manual_free_set(obj, EINA_TRUE);
57
58 if (!func)
59 {
60 eo_error_set(obj);
61 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
62 return EINA_FALSE;
63 }
64
65 ie->func = func;
66 ie->data = (void *)data;
67 return EINA_TRUE;
68}
69
34/** 70/**
35 * Add an idle enterer handler. 71 * Add an idle enterer handler.
36 * @param func The function to call when entering an idle state. 72 * @param func The function to call when entering an idle state.
@@ -46,20 +82,25 @@ ecore_idle_enterer_add(Ecore_Task_Cb func,
46 const void *data) 82 const void *data)
47{ 83{
48 Ecore_Idle_Enterer *ie = NULL; 84 Ecore_Idle_Enterer *ie = NULL;
85 ie = eo_add_custom(MY_CLASS, _ecore_parent, ecore_idle_enterer_after_constructor(func, data));
86 eo_unref(ie);
87 return ie;
88}
89
90static void
91_idle_enterer_after_constructor(Eo *obj, void *_pd, va_list *list)
92{
93 Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
94 const void *data = va_arg(*list, const void *);
49 95
50 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
51 _ecore_lock(); 96 _ecore_lock();
97 Ecore_Idle_Enterer_Private_Data *ie = _pd;
98 if (!_ecore_idle_enterer_add(obj, ie, func, data)) goto unlock;
99
100 idle_enterers = (Ecore_Idle_Enterer_Private_Data *)eina_inlist_append(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie));
52 101
53 if (!func) goto unlock;
54 ie = ecore_idle_enterer_calloc(1);
55 if (!ie) goto unlock;
56 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLE_ENTERER);
57 ie->func = func;
58 ie->data = (void *)data;
59 idle_enterers = (Ecore_Idle_Enterer *)eina_inlist_append(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie));
60unlock: 102unlock:
61 _ecore_unlock(); 103 _ecore_unlock();
62 return ie;
63} 104}
64 105
65/** 106/**
@@ -77,20 +118,32 @@ ecore_idle_enterer_before_add(Ecore_Task_Cb func,
77 const void *data) 118 const void *data)
78{ 119{
79 Ecore_Idle_Enterer *ie = NULL; 120 Ecore_Idle_Enterer *ie = NULL;
121 ie = eo_add_custom(MY_CLASS, _ecore_parent, ecore_idle_enterer_before_constructor(func, data));
122 eo_unref(ie);
123 return ie;
124}
125
126static void
127_idle_enterer_before_constructor(Eo *obj, void *_pd, va_list *list)
128{
129 Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
130 const void *data = va_arg(*list, const void *);
80 131
81 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
82 _ecore_lock(); 132 _ecore_lock();
133 Ecore_Idle_Enterer_Private_Data *ie = _pd;
134 if (!_ecore_idle_enterer_add(obj, ie, func, data)) goto unlock;
135
136 idle_enterers = (Ecore_Idle_Enterer_Private_Data *)eina_inlist_prepend(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie));
83 137
84 if (!func) goto unlock;
85 ie = ecore_idle_enterer_calloc(1);
86 if (!ie) goto unlock;
87 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLE_ENTERER);
88 ie->func = func;
89 ie->data = (void *)data;
90 idle_enterers = (Ecore_Idle_Enterer *)eina_inlist_prepend(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie));
91unlock: 138unlock:
92 _ecore_unlock(); 139 _ecore_unlock();
93 return ie; 140}
141
142static void
143_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
144{
145 eo_error_set(obj);
146 ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
94} 147}
95 148
96/** 149/**
@@ -102,15 +155,10 @@ unlock:
102EAPI void * 155EAPI void *
103ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer) 156ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer)
104{ 157{
105 void *data; 158 void *data = NULL;
106 159
107 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 160 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
108 if (!ECORE_MAGIC_CHECK(idle_enterer, ECORE_MAGIC_IDLE_ENTERER)) 161
109 {
110 ECORE_MAGIC_FAIL(idle_enterer, ECORE_MAGIC_IDLE_ENTERER,
111 "ecore_idle_enterer_del");
112 return NULL;
113 }
114 _ecore_lock(); 162 _ecore_lock();
115 data = _ecore_idle_enterer_del(idle_enterer); 163 data = _ecore_idle_enterer_del(idle_enterer);
116 _ecore_unlock(); 164 _ecore_unlock();
@@ -121,24 +169,42 @@ ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer)
121 * @} 169 * @}
122 */ 170 */
123 171
172
124static void * 173static void *
125_ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer) 174_ecore_idle_enterer_del(Ecore_Idle_Enterer *obj)
126{ 175{
176 Ecore_Idle_Enterer_Private_Data *idle_enterer = eo_data_get(obj, MY_CLASS);
177
127 EINA_SAFETY_ON_TRUE_RETURN_VAL(idle_enterer->delete_me, NULL); 178 EINA_SAFETY_ON_TRUE_RETURN_VAL(idle_enterer->delete_me, NULL);
128 idle_enterer->delete_me = 1; 179 idle_enterer->delete_me = 1;
129 idle_enterers_delete_me = 1; 180 idle_enterers_delete_me = 1;
130 return idle_enterer->data; 181 return idle_enterer->data;
131} 182}
132 183
184static void
185_destructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
186{
187 Ecore_Idle_Enterer_Private_Data *idle_enterer = _pd;
188
189 idle_enterer->delete_me = 1;
190 idle_enterers_delete_me = 1;
191
192 eo_do_super(obj, eo_destructor());
193}
194
133void 195void
134_ecore_idle_enterer_shutdown(void) 196_ecore_idle_enterer_shutdown(void)
135{ 197{
136 Ecore_Idle_Enterer *ie; 198 Ecore_Idle_Enterer_Private_Data *ie;
137 while ((ie = idle_enterers)) 199 while ((ie = idle_enterers))
138 { 200 {
139 idle_enterers = (Ecore_Idle_Enterer *)eina_inlist_remove(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(idle_enterers)); 201 idle_enterers = (Ecore_Idle_Enterer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(idle_enterers));
140 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE); 202
141 ecore_idle_enterer_mp_free(ie); 203 eo_parent_set(ie->obj, NULL);
204 if (eo_destructed_is(ie->obj))
205 eo_manual_free(ie->obj);
206 else
207 eo_manual_free_set(ie->obj, EINA_FALSE);
142 } 208 }
143 idle_enterers_delete_me = 0; 209 idle_enterers_delete_me = 0;
144 idle_enterer_current = NULL; 210 idle_enterer_current = NULL;
@@ -156,34 +222,34 @@ _ecore_idle_enterer_call(void)
156 { 222 {
157 /* recursive main loop, continue from where we were */ 223 /* recursive main loop, continue from where we were */
158 idle_enterer_current = 224 idle_enterer_current =
159 (Ecore_Idle_Enterer *)EINA_INLIST_GET(idle_enterer_current)->next; 225 (Ecore_Idle_Enterer_Private_Data *)EINA_INLIST_GET(idle_enterer_current)->next;
160 } 226 }
161 227
162 while (idle_enterer_current) 228 while (idle_enterer_current)
163 { 229 {
164 Ecore_Idle_Enterer *ie = (Ecore_Idle_Enterer *)idle_enterer_current; 230 Ecore_Idle_Enterer_Private_Data *ie = (Ecore_Idle_Enterer_Private_Data *)idle_enterer_current;
165 if (!ie->delete_me) 231 if (!ie->delete_me)
166 { 232 {
167 ie->references++; 233 ie->references++;
168 if (!_ecore_call_task_cb(ie->func, ie->data)) 234 if (!_ecore_call_task_cb(ie->func, ie->data))
169 { 235 {
170 if (!ie->delete_me) _ecore_idle_enterer_del(ie); 236 if (!ie->delete_me) _ecore_idle_enterer_del(ie->obj);
171 } 237 }
172 ie->references--; 238 ie->references--;
173 } 239 }
174 if (idle_enterer_current) /* may have changed in recursive main loops */ 240 if (idle_enterer_current) /* may have changed in recursive main loops */
175 idle_enterer_current = 241 idle_enterer_current =
176 (Ecore_Idle_Enterer *)EINA_INLIST_GET(idle_enterer_current)->next; 242 (Ecore_Idle_Enterer_Private_Data *)EINA_INLIST_GET(idle_enterer_current)->next;
177 } 243 }
178 if (idle_enterers_delete_me) 244 if (idle_enterers_delete_me)
179 { 245 {
180 Ecore_Idle_Enterer *l; 246 Ecore_Idle_Enterer_Private_Data *l;
181 int deleted_idler_enterers_in_use = 0; 247 int deleted_idler_enterers_in_use = 0;
182 248
183 for (l = idle_enterers; l; ) 249 for (l = idle_enterers; l; )
184 { 250 {
185 Ecore_Idle_Enterer *ie = l; 251 Ecore_Idle_Enterer_Private_Data *ie = l;
186 l = (Ecore_Idle_Enterer *)EINA_INLIST_GET(l)->next; 252 l = (Ecore_Idle_Enterer_Private_Data *)EINA_INLIST_GET(l)->next;
187 if (ie->delete_me) 253 if (ie->delete_me)
188 { 254 {
189 if (ie->references) 255 if (ie->references)
@@ -192,9 +258,13 @@ _ecore_idle_enterer_call(void)
192 continue; 258 continue;
193 } 259 }
194 260
195 idle_enterers = (Ecore_Idle_Enterer *)eina_inlist_remove(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie)); 261 idle_enterers = (Ecore_Idle_Enterer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(idle_enterers), EINA_INLIST_GET(ie));
196 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE); 262
197 ecore_idle_enterer_mp_free(ie); 263 eo_parent_set(ie->obj, NULL);
264 if (eo_destructed_is(ie->obj))
265 eo_manual_free(ie->obj);
266 else
267 eo_manual_free_set(ie->obj, EINA_FALSE);
198 } 268 }
199 } 269 }
200 if (!deleted_idler_enterers_in_use) 270 if (!deleted_idler_enterers_in_use)
@@ -209,3 +279,35 @@ _ecore_idle_enterer_exist(void)
209 return 0; 279 return 0;
210} 280}
211 281
282static void
283_class_constructor(Eo_Class *klass)
284{
285 const Eo_Op_Func_Description func_desc[] = {
286 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
287 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
288
289 EO_OP_FUNC(ECORE_IDLE_ENTERER_ID(ECORE_IDLE_ENTERER_SUB_ID_AFTER_CONSTRUCTOR), _idle_enterer_after_constructor),
290 EO_OP_FUNC(ECORE_IDLE_ENTERER_ID(ECORE_IDLE_ENTERER_SUB_ID_BEFORE_CONSTRUCTOR), _idle_enterer_before_constructor),
291 EO_OP_FUNC_SENTINEL
292 };
293
294 eo_class_funcs_set(klass, func_desc);
295}
296
297static const Eo_Op_Description op_desc[] = {
298 EO_OP_DESCRIPTION(ECORE_IDLE_ENTERER_SUB_ID_AFTER_CONSTRUCTOR, "Add an idle enterer handler."),
299 EO_OP_DESCRIPTION(ECORE_IDLE_ENTERER_SUB_ID_BEFORE_CONSTRUCTOR, "Add an idle enterer handler at the start of the list so it gets called earlier than others."),
300 EO_OP_DESCRIPTION_SENTINEL
301};
302static const Eo_Class_Description class_desc = {
303 EO_VERSION,
304 MY_CLASS_NAME,
305 EO_CLASS_TYPE_REGULAR,
306 EO_CLASS_DESCRIPTION_OPS(&ECORE_IDLE_ENTERER_BASE_ID, op_desc, ECORE_IDLE_ENTERER_SUB_ID_LAST),
307 NULL,
308 sizeof(Ecore_Idle_Enterer_Private_Data),
309 _class_constructor,
310 NULL
311};
312
313EO_DEFINE_CLASS(ecore_idle_enterer_class_get, &class_desc, EO_BASE_CLASS, NULL)
diff --git a/legacy/ecore/src/lib/ecore/ecore_idle_exiter.c b/legacy/ecore/src/lib/ecore/ecore_idle_exiter.c
index 0086bb63b7..dd411cbcbd 100644
--- a/legacy/ecore/src/lib/ecore/ecore_idle_exiter.c
+++ b/legacy/ecore/src/lib/ecore/ecore_idle_exiter.c
@@ -7,19 +7,28 @@
7#include "Ecore.h" 7#include "Ecore.h"
8#include "ecore_private.h" 8#include "ecore_private.h"
9 9
10struct _Ecore_Idle_Exiter 10#include "Eo.h"
11
12#define MY_CLASS ECORE_IDLE_EXITER_CLASS
13
14#define MY_CLASS_NAME "ecore_idle_exitier"
15
16EAPI Eo_Op ECORE_IDLE_EXITER_BASE_ID = EO_NOOP;
17
18struct _Ecore_Idle_Exiter_Private_Data
11{ 19{
12 EINA_INLIST; 20 EINA_INLIST;
13 ECORE_MAGIC; 21 Ecore_Idle_Exiter *obj;
14 Ecore_Task_Cb func; 22 Ecore_Task_Cb func;
15 void *data; 23 void *data;
16 int references; 24 int references;
17 Eina_Bool delete_me : 1; 25 Eina_Bool delete_me : 1;
18}; 26};
19GENERIC_ALLOC_SIZE_DECLARE(Ecore_Idle_Exiter);
20 27
21static Ecore_Idle_Exiter *idle_exiters = NULL; 28typedef struct _Ecore_Idle_Exiter_Private_Data Ecore_Idle_Exiter_Private_Data;
22static Ecore_Idle_Exiter *idle_exiter_current = NULL; 29
30static Ecore_Idle_Exiter_Private_Data *idle_exiters = NULL;
31static Ecore_Idle_Exiter_Private_Data *idle_exiter_current = NULL;
23static int idle_exiters_delete_me = 0; 32static int idle_exiters_delete_me = 0;
24 33
25static void * 34static void *
@@ -45,19 +54,49 @@ ecore_idle_exiter_add(Ecore_Task_Cb func,
45 const void *data) 54 const void *data)
46{ 55{
47 Ecore_Idle_Exiter *ie = NULL; 56 Ecore_Idle_Exiter *ie = NULL;
57 ie = eo_add_custom(MY_CLASS, _ecore_parent, ecore_idle_exiter_constructor(func, data));
58 eo_unref(ie);
59 return ie;
60}
61
62static void
63_idle_exiter_constructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
64{
65 Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
66 const void *data = va_arg(*list, const void *);
48 67
49 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
50 _ecore_lock(); 68 _ecore_lock();
51 if (!func) goto unlock; 69 if (EINA_UNLIKELY(!eina_main_loop_is()))
52 ie = ecore_idle_exiter_calloc(1); 70 {
53 if (!ie) goto unlock; 71 eo_error_set(obj);
54 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLE_EXITER); 72 EINA_MAIN_LOOP_CHECK_RETURN;
73 }
74
75 Ecore_Idle_Exiter_Private_Data *ie = _pd;
76
77 ie->obj = obj;
78 eo_do_super(obj, eo_constructor());
79 eo_manual_free_set(obj, EINA_TRUE);
80
81 if (!func)
82 {
83 eo_error_set(obj);
84 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
85 return;
86 }
87
55 ie->func = func; 88 ie->func = func;
56 ie->data = (void *)data; 89 ie->data = (void *)data;
57 idle_exiters = (Ecore_Idle_Exiter *)eina_inlist_append(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(ie)); 90
58unlock: 91 idle_exiters = (Ecore_Idle_Exiter_Private_Data *)eina_inlist_append(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(ie));
59 _ecore_unlock(); 92 _ecore_unlock();
60 return ie; 93}
94
95static void
96_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
97{
98 eo_error_set(obj);
99 ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
61} 100}
62 101
63/** 102/**
@@ -72,12 +111,7 @@ ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter)
72 void *data; 111 void *data;
73 112
74 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 113 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
75 if (!ECORE_MAGIC_CHECK(idle_exiter, ECORE_MAGIC_IDLE_EXITER)) 114
76 {
77 ECORE_MAGIC_FAIL(idle_exiter, ECORE_MAGIC_IDLE_EXITER,
78 "ecore_idle_exiter_del");
79 return NULL;
80 }
81 _ecore_lock(); 115 _ecore_lock();
82 data = _ecore_idle_exiter_del(idle_exiter); 116 data = _ecore_idle_exiter_del(idle_exiter);
83 _ecore_unlock(); 117 _ecore_unlock();
@@ -87,25 +121,41 @@ ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter)
87/** 121/**
88 * @} 122 * @}
89 */ 123 */
90
91static void * 124static void *
92_ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter) 125_ecore_idle_exiter_del(Ecore_Idle_Exiter *obj)
93{ 126{
127 Ecore_Idle_Exiter_Private_Data *idle_exiter = eo_data_get(obj, MY_CLASS);
94 EINA_SAFETY_ON_TRUE_RETURN_VAL(idle_exiter->delete_me, NULL); 128 EINA_SAFETY_ON_TRUE_RETURN_VAL(idle_exiter->delete_me, NULL);
95 idle_exiter->delete_me = 1; 129 idle_exiter->delete_me = 1;
96 idle_exiters_delete_me = 1; 130 idle_exiters_delete_me = 1;
97 return idle_exiter->data; 131 return idle_exiter->data;
98} 132}
99 133
134
135static void
136_destructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
137{
138 Ecore_Idle_Exiter_Private_Data *idle_exiter = _pd;
139
140 idle_exiter->delete_me = 1;
141 idle_exiters_delete_me = 1;
142
143 eo_do_super(obj, eo_destructor());
144}
145
100void 146void
101_ecore_idle_exiter_shutdown(void) 147_ecore_idle_exiter_shutdown(void)
102{ 148{
103 Ecore_Idle_Exiter *ie; 149 Ecore_Idle_Exiter_Private_Data *ie;
104 while ((ie = idle_exiters)) 150 while ((ie = idle_exiters))
105 { 151 {
106 idle_exiters = (Ecore_Idle_Exiter *)eina_inlist_remove(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(idle_exiters)); 152 idle_exiters = (Ecore_Idle_Exiter_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(idle_exiters));
107 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE); 153
108 ecore_idle_exiter_mp_free(ie); 154 eo_parent_set(ie->obj, NULL);
155 if (eo_destructed_is(ie->obj))
156 eo_manual_free(ie->obj);
157 else
158 eo_manual_free_set(ie->obj, EINA_FALSE);
109 } 159 }
110 idle_exiters_delete_me = 0; 160 idle_exiters_delete_me = 0;
111 idle_exiter_current = NULL; 161 idle_exiter_current = NULL;
@@ -123,35 +173,35 @@ _ecore_idle_exiter_call(void)
123 { 173 {
124 /* recursive main loop, continue from where we were */ 174 /* recursive main loop, continue from where we were */
125 idle_exiter_current = 175 idle_exiter_current =
126 (Ecore_Idle_Exiter *)EINA_INLIST_GET(idle_exiter_current)->next; 176 (Ecore_Idle_Exiter_Private_Data *)EINA_INLIST_GET(idle_exiter_current)->next;
127 } 177 }
128 178
129 while (idle_exiter_current) 179 while (idle_exiter_current)
130 { 180 {
131 Ecore_Idle_Exiter *ie = (Ecore_Idle_Exiter *)idle_exiter_current; 181 Ecore_Idle_Exiter_Private_Data *ie = (Ecore_Idle_Exiter_Private_Data *)idle_exiter_current;
132 if (!ie->delete_me) 182 if (!ie->delete_me)
133 { 183 {
134 ie->references++; 184 ie->references++;
135 if (!_ecore_call_task_cb(ie->func, ie->data)) 185 if (!_ecore_call_task_cb(ie->func, ie->data))
136 { 186 {
137 if (!ie->delete_me) _ecore_idle_exiter_del(ie); 187 if (!ie->delete_me) _ecore_idle_exiter_del(ie->obj);
138 } 188 }
139 ie->references--; 189 ie->references--;
140 } 190 }
141 if (idle_exiter_current) /* may have changed in recursive main loops */ 191 if (idle_exiter_current) /* may have changed in recursive main loops */
142 idle_exiter_current = 192 idle_exiter_current =
143 (Ecore_Idle_Exiter *)EINA_INLIST_GET(idle_exiter_current)->next; 193 (Ecore_Idle_Exiter_Private_Data *)EINA_INLIST_GET(idle_exiter_current)->next;
144 } 194 }
145 if (idle_exiters_delete_me) 195 if (idle_exiters_delete_me)
146 { 196 {
147 Ecore_Idle_Exiter *l; 197 Ecore_Idle_Exiter_Private_Data *l;
148 int deleted_idler_exiters_in_use = 0; 198 int deleted_idler_exiters_in_use = 0;
149 199
150 for (l = idle_exiters; l; ) 200 for (l = idle_exiters; l; )
151 { 201 {
152 Ecore_Idle_Exiter *ie = l; 202 Ecore_Idle_Exiter_Private_Data *ie = l;
153 203
154 l = (Ecore_Idle_Exiter *)EINA_INLIST_GET(l)->next; 204 l = (Ecore_Idle_Exiter_Private_Data *)EINA_INLIST_GET(l)->next;
155 if (ie->delete_me) 205 if (ie->delete_me)
156 { 206 {
157 if (ie->references) 207 if (ie->references)
@@ -160,9 +210,13 @@ _ecore_idle_exiter_call(void)
160 continue; 210 continue;
161 } 211 }
162 212
163 idle_exiters = (Ecore_Idle_Exiter *)eina_inlist_remove(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(ie)); 213 idle_exiters = (Ecore_Idle_Exiter_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(idle_exiters), EINA_INLIST_GET(ie));
164 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE); 214
165 ecore_idle_exiter_mp_free(ie); 215 eo_parent_set(ie->obj, NULL);
216 if (eo_destructed_is(ie->obj))
217 eo_manual_free(ie->obj);
218 else
219 eo_manual_free_set(ie->obj, EINA_FALSE);
166 } 220 }
167 } 221 }
168 if (!deleted_idler_exiters_in_use) 222 if (!deleted_idler_exiters_in_use)
@@ -177,3 +231,34 @@ _ecore_idle_exiter_exist(void)
177 return 0; 231 return 0;
178} 232}
179 233
234static void
235_class_constructor(Eo_Class *klass)
236{
237 const Eo_Op_Func_Description func_desc[] = {
238 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
239 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
240
241 EO_OP_FUNC(ECORE_IDLE_EXITER_ID(ECORE_IDLE_EXITER_SUB_ID_CONSTRUCTOR), _idle_exiter_constructor),
242 EO_OP_FUNC_SENTINEL
243 };
244
245 eo_class_funcs_set(klass, func_desc);
246}
247
248static const Eo_Op_Description op_desc[] = {
249 EO_OP_DESCRIPTION(ECORE_IDLE_EXITER_SUB_ID_CONSTRUCTOR, "Add an idle exiter handler."),
250 EO_OP_DESCRIPTION_SENTINEL
251};
252
253static const Eo_Class_Description class_desc = {
254 EO_VERSION,
255 MY_CLASS_NAME,
256 EO_CLASS_TYPE_REGULAR,
257 EO_CLASS_DESCRIPTION_OPS(&ECORE_IDLE_EXITER_BASE_ID, op_desc, ECORE_IDLE_EXITER_SUB_ID_LAST),
258 NULL,
259 sizeof(Ecore_Idle_Exiter_Private_Data),
260 _class_constructor,
261 NULL
262};
263
264EO_DEFINE_CLASS(ecore_idle_exiter_class_get, &class_desc, EO_BASE_CLASS, NULL)
diff --git a/legacy/ecore/src/lib/ecore/ecore_idler.c b/legacy/ecore/src/lib/ecore/ecore_idler.c
index 62998b6ff1..e47b210bb1 100644
--- a/legacy/ecore/src/lib/ecore/ecore_idler.c
+++ b/legacy/ecore/src/lib/ecore/ecore_idler.c
@@ -7,19 +7,27 @@
7#include "Ecore.h" 7#include "Ecore.h"
8#include "ecore_private.h" 8#include "ecore_private.h"
9 9
10struct _Ecore_Idler 10#include "Eo.h"
11
12#define MY_CLASS ECORE_IDLER_CLASS
13
14#define MY_CLASS_NAME "ecore_idler"
15
16EAPI Eo_Op ECORE_IDLER_BASE_ID = EO_NOOP;
17
18struct _Ecore_Idler_Private_Data
11{ 19{
12 EINA_INLIST; 20 EINA_INLIST;
13 ECORE_MAGIC; 21 Ecore_Idler *obj;
14 Ecore_Task_Cb func; 22 Ecore_Task_Cb func;
15 void *data; 23 void *data;
16 int references; 24 int references;
17 Eina_Bool delete_me : 1; 25 Eina_Bool delete_me : 1;
18}; 26};
19GENERIC_ALLOC_SIZE_DECLARE(Ecore_Idler);
20 27
21static Ecore_Idler *idlers = NULL; 28typedef struct _Ecore_Idler_Private_Data Ecore_Idler_Private_Data;
22static Ecore_Idler *idler_current = NULL; 29static Ecore_Idler_Private_Data *idlers = NULL;
30static Ecore_Idler_Private_Data *idler_current = NULL;
23static int idlers_delete_me = 0; 31static int idlers_delete_me = 0;
24 32
25static void * 33static void *
@@ -31,32 +39,59 @@ ecore_idler_add(Ecore_Task_Cb func,
31{ 39{
32 Ecore_Idler *ie = NULL; 40 Ecore_Idler *ie = NULL;
33 41
34 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
35 _ecore_lock(); 42 _ecore_lock();
36 if (!func) goto unlock; 43
37 ie = ecore_idler_calloc(1); 44 ie = eo_add_custom(MY_CLASS, _ecore_parent, ecore_idler_constructor(func, data));
38 if (!ie) goto unlock; 45 eo_unref(ie);
39 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLER); 46
40 ie->func = func;
41 ie->data = (void *)data;
42 idlers = (Ecore_Idler *)eina_inlist_append(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
43unlock:
44 _ecore_unlock(); 47 _ecore_unlock();
45 return ie; 48 return ie;
46} 49}
47 50
51static void
52_idler_constructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
53{
54 Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
55 const void *data = va_arg(*list, const void *);
56
57 if (EINA_UNLIKELY(!eina_main_loop_is()))
58 {
59 eo_error_set(obj);
60 EINA_MAIN_LOOP_CHECK_RETURN;
61 }
62
63 Ecore_Idler_Private_Data *ie = _pd;
64
65 ie->obj = obj;
66 eo_do_super(obj, eo_constructor());
67 eo_manual_free_set(obj, EINA_TRUE);
68
69 if (!func)
70 {
71 eo_error_set(obj);
72 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
73 return;
74 }
75
76 ie->func = func;
77 ie->data = (void *)data;
78 idlers = (Ecore_Idler_Private_Data *)eina_inlist_append(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
79}
80
81
82static void
83_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
84{
85 eo_error_set(obj);
86 ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
87}
88
48EAPI void * 89EAPI void *
49ecore_idler_del(Ecore_Idler *idler) 90ecore_idler_del(Ecore_Idler *idler)
50{ 91{
51 void *data = NULL; 92 void *data = NULL;
52 93
53 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 94 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
54 if (!ECORE_MAGIC_CHECK(idler, ECORE_MAGIC_IDLER))
55 {
56 ECORE_MAGIC_FAIL(idler, ECORE_MAGIC_IDLER,
57 "ecore_idler_del");
58 return NULL;
59 }
60 95
61 _ecore_lock(); 96 _ecore_lock();
62 data = _ecore_idler_del(idler); 97 data = _ecore_idler_del(idler);
@@ -73,23 +108,39 @@ ecore_idler_del(Ecore_Idler *idler)
73 */ 108 */
74 109
75static void * 110static void *
76_ecore_idler_del(Ecore_Idler *idler) 111_ecore_idler_del(Ecore_Idler *obj)
77{ 112{
113 Ecore_Idler_Private_Data *idler = eo_data_get(obj, MY_CLASS);
78 EINA_SAFETY_ON_TRUE_RETURN_VAL(idler->delete_me, NULL); 114 EINA_SAFETY_ON_TRUE_RETURN_VAL(idler->delete_me, NULL);
79 idler->delete_me = 1; 115 idler->delete_me = 1;
80 idlers_delete_me = 1; 116 idlers_delete_me = 1;
81 return idler->data; 117 return idler->data;
82} 118}
83 119
120static void
121_destructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
122{
123 Ecore_Idler_Private_Data *idler = _pd;
124
125 idler->delete_me = 1;
126 idlers_delete_me = 1;
127
128 eo_do_super(obj, eo_destructor());
129}
130
84void 131void
85_ecore_idler_shutdown(void) 132_ecore_idler_shutdown(void)
86{ 133{
87 Ecore_Idler *ie; 134 Ecore_Idler_Private_Data *ie;
88 while ((ie = idlers)) 135 while ((ie = idlers))
89 { 136 {
90 idlers = (Ecore_Idler *)eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(idlers)); 137 idlers = (Ecore_Idler_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(idlers));
91 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE); 138
92 ecore_idler_mp_free(ie); 139 eo_parent_set(ie->obj, NULL);
140 if (eo_destructed_is(ie->obj))
141 eo_manual_free(ie->obj);
142 else
143 eo_manual_free_set(ie->obj, EINA_FALSE);
93 } 144 }
94 idlers_delete_me = 0; 145 idlers_delete_me = 0;
95 idler_current = NULL; 146 idler_current = NULL;
@@ -106,32 +157,32 @@ _ecore_idler_all_call(void)
106 else 157 else
107 { 158 {
108 /* recursive main loop, continue from where we were */ 159 /* recursive main loop, continue from where we were */
109 idler_current = (Ecore_Idler *)EINA_INLIST_GET(idler_current)->next; 160 idler_current = (Ecore_Idler_Private_Data *)EINA_INLIST_GET(idler_current)->next;
110 } 161 }
111 162
112 while (idler_current) 163 while (idler_current)
113 { 164 {
114 Ecore_Idler *ie = (Ecore_Idler *)idler_current; 165 Ecore_Idler_Private_Data *ie = (Ecore_Idler_Private_Data *)idler_current;
115 if (!ie->delete_me) 166 if (!ie->delete_me)
116 { 167 {
117 ie->references++; 168 ie->references++;
118 if (!_ecore_call_task_cb(ie->func, ie->data)) 169 if (!_ecore_call_task_cb(ie->func, ie->data))
119 { 170 {
120 if (!ie->delete_me) _ecore_idler_del(ie); 171 if (!ie->delete_me) _ecore_idler_del(ie->obj);
121 } 172 }
122 ie->references--; 173 ie->references--;
123 } 174 }
124 if (idler_current) /* may have changed in recursive main loops */ 175 if (idler_current) /* may have changed in recursive main loops */
125 idler_current = (Ecore_Idler *)EINA_INLIST_GET(idler_current)->next; 176 idler_current = (Ecore_Idler_Private_Data *)EINA_INLIST_GET(idler_current)->next;
126 } 177 }
127 if (idlers_delete_me) 178 if (idlers_delete_me)
128 { 179 {
129 Ecore_Idler *l; 180 Ecore_Idler_Private_Data *l;
130 int deleted_idlers_in_use = 0; 181 int deleted_idlers_in_use = 0;
131 for (l = idlers; l; ) 182 for (l = idlers; l; )
132 { 183 {
133 Ecore_Idler *ie = l; 184 Ecore_Idler_Private_Data *ie = l;
134 l = (Ecore_Idler *)EINA_INLIST_GET(l)->next; 185 l = (Ecore_Idler_Private_Data *)EINA_INLIST_GET(l)->next;
135 if (ie->delete_me) 186 if (ie->delete_me)
136 { 187 {
137 if (ie->references) 188 if (ie->references)
@@ -140,9 +191,13 @@ _ecore_idler_all_call(void)
140 continue; 191 continue;
141 } 192 }
142 193
143 idlers = (Ecore_Idler *)eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie)); 194 idlers = (Ecore_Idler_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
144 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE); 195
145 ecore_idler_mp_free(ie); 196 eo_parent_set(ie->obj, NULL);
197 if (eo_destructed_is(ie->obj))
198 eo_manual_free(ie->obj);
199 else
200 eo_manual_free_set(ie->obj, EINA_FALSE);
146 } 201 }
147 } 202 }
148 if (!deleted_idlers_in_use) 203 if (!deleted_idlers_in_use)
@@ -159,3 +214,34 @@ _ecore_idler_exist(void)
159 return 0; 214 return 0;
160} 215}
161 216
217static void
218_class_constructor(Eo_Class *klass)
219{
220 const Eo_Op_Func_Description func_desc[] = {
221 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
222 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
223
224 EO_OP_FUNC(ECORE_IDLER_ID(ECORE_IDLER_SUB_ID_CONSTRUCTOR), _idler_constructor),
225 EO_OP_FUNC_SENTINEL
226 };
227
228 eo_class_funcs_set(klass, func_desc);
229}
230
231static const Eo_Op_Description op_desc[] = {
232 EO_OP_DESCRIPTION(ECORE_IDLER_SUB_ID_CONSTRUCTOR, "Add an idler handler."),
233 EO_OP_DESCRIPTION_SENTINEL
234};
235
236static const Eo_Class_Description class_desc = {
237 EO_VERSION,
238 MY_CLASS_NAME,
239 EO_CLASS_TYPE_REGULAR,
240 EO_CLASS_DESCRIPTION_OPS(&ECORE_IDLER_BASE_ID, op_desc, ECORE_IDLER_SUB_ID_LAST),
241 NULL,
242 sizeof(Ecore_Idler_Private_Data),
243 _class_constructor,
244 NULL
245};
246
247EO_DEFINE_CLASS(ecore_idler_class_get, &class_desc, EO_BASE_CLASS, NULL)
diff --git a/legacy/ecore/src/lib/ecore/ecore_job.c b/legacy/ecore/src/lib/ecore/ecore_job.c
index 93852a3ffe..3b45f0d554 100644
--- a/legacy/ecore/src/lib/ecore/ecore_job.c
+++ b/legacy/ecore/src/lib/ecore/ecore_job.c
@@ -2,11 +2,19 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <Eo.h>
6
5#include <stdlib.h> 7#include <stdlib.h>
6 8
7#include "Ecore.h" 9#include "Ecore.h"
8#include "ecore_private.h" 10#include "ecore_private.h"
9 11
12#define MY_CLASS ECORE_JOB_CLASS
13
14#define MY_CLASS_NAME "ecore_job"
15
16EAPI Eo_Op ECORE_JOB_BASE_ID = EO_NOOP;
17
10static Eina_Bool _ecore_job_event_handler(void *data, 18static Eina_Bool _ecore_job_event_handler(void *data,
11 int type, 19 int type,
12 void *ev); 20 void *ev);
@@ -16,14 +24,14 @@ static void _ecore_job_event_free(void *data,
16static int ecore_event_job_type = 0; 24static int ecore_event_job_type = 0;
17static Ecore_Event_Handler *_ecore_job_handler = NULL; 25static Ecore_Event_Handler *_ecore_job_handler = NULL;
18 26
19struct _Ecore_Job 27typedef struct _Ecore_Job_Private_Data Ecore_Job_Private_Data;
28
29struct _Ecore_Job_Private_Data
20{ 30{
21 ECORE_MAGIC;
22 Ecore_Event *event; 31 Ecore_Event *event;
23 Ecore_Cb func; 32 Ecore_Cb func;
24 void *data; 33 void *data;
25}; 34};
26GENERIC_ALLOC_SIZE_DECLARE(Ecore_Job);
27 35
28void 36void
29_ecore_job_init(void) 37_ecore_job_init(void)
@@ -58,23 +66,50 @@ EAPI Ecore_Job *
58ecore_job_add(Ecore_Cb func, 66ecore_job_add(Ecore_Cb func,
59 const void *data) 67 const void *data)
60{ 68{
61 Ecore_Job *job; 69 Ecore_Job *job = eo_add_custom(MY_CLASS, _ecore_parent, ecore_job_constructor(func, data));
70 eo_unref(job);
71 return job;
72}
62 73
63 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 74static void
64 if (!func) return NULL; 75_job_constructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
76{
77 Ecore_Cb func = va_arg(*list, Ecore_Cb);
78 const void *data = va_arg(*list, const void *);
65 79
66 job = ecore_job_calloc(1); 80 if (EINA_UNLIKELY(!eina_main_loop_is()))
67 if (!job) return NULL; 81 {
68 ECORE_MAGIC_SET(job, ECORE_MAGIC_JOB); 82 eo_error_set(obj);
69 job->event = ecore_event_add(ecore_event_job_type, job, _ecore_job_event_free, NULL); 83 EINA_MAIN_LOOP_CHECK_RETURN;
84 }
85 eo_do_super(obj, eo_constructor());
86 eo_manual_free_set(obj, EINA_TRUE);
87
88 if (!func)
89 {
90 eo_error_set(obj);
91 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
92 return;
93 }
94
95 Ecore_Job_Private_Data *job = _pd;
96
97 job->event = ecore_event_add(ecore_event_job_type, job, _ecore_job_event_free, obj);
70 if (!job->event) 98 if (!job->event)
71 { 99 {
72 ecore_job_mp_free(job); 100 eo_error_set(obj);
73 return NULL; 101 ERR("no event was assigned to object '%p' of class '%s'", obj, MY_CLASS_NAME);
102 return;
74 } 103 }
75 job->func = func; 104 job->func = func;
76 job->data = (void *)data; 105 job->data = (void *)data;
77 return job; 106}
107
108static void
109_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
110{
111 eo_error_set(obj);
112 ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
78} 113}
79 114
80/** 115/**
@@ -83,23 +118,25 @@ ecore_job_add(Ecore_Cb func,
83 * @return The data pointer that was to be passed to the job. 118 * @return The data pointer that was to be passed to the job.
84 */ 119 */
85EAPI void * 120EAPI void *
86ecore_job_del(Ecore_Job *job) 121ecore_job_del(Ecore_Job *obj)
87{ 122{
88 void *data; 123 void *data;
89 124
90 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 125 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
91 if (!ECORE_MAGIC_CHECK(job, ECORE_MAGIC_JOB)) 126 Ecore_Job_Private_Data *job = eo_data_get(obj, MY_CLASS);
92 {
93 ECORE_MAGIC_FAIL(job, ECORE_MAGIC_JOB,
94 "ecore_job_del");
95 return NULL;
96 }
97 data = job->data; 127 data = job->data;
98 ECORE_MAGIC_SET(job, ECORE_MAGIC_NONE);
99 ecore_event_del(job->event); 128 ecore_event_del(job->event);
129 eo_parent_set(obj, NULL);
100 return data; 130 return data;
101} 131}
102 132
133static void
134_destructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
135{
136 /*FIXME: check if ecore_event_del should be called from here*/
137 eo_do_super(obj, eo_destructor());
138}
139
103/** 140/**
104 * @} 141 * @}
105 */ 142 */
@@ -109,7 +146,7 @@ _ecore_job_event_handler(void *data __UNUSED__,
109 int type __UNUSED__, 146 int type __UNUSED__,
110 void *ev) 147 void *ev)
111{ 148{
112 Ecore_Job *job; 149 Ecore_Job_Private_Data *job;
113 150
114 job = ev; 151 job = ev;
115 job->func(job->data); 152 job->func(job->data);
@@ -117,9 +154,45 @@ _ecore_job_event_handler(void *data __UNUSED__,
117} 154}
118 155
119static void 156static void
120_ecore_job_event_free(void *data __UNUSED__, 157_ecore_job_event_free(void *data,
121 void *job) 158 void *job __UNUSED__)
122{ 159{
123 ecore_job_mp_free(job); 160 eo_parent_set(data, NULL);
161
162 Ecore_Job *obj = data;
163
164 if (eo_destructed_is(obj))
165 eo_manual_free(obj);
166 else
167 eo_manual_free_set(obj, EINA_FALSE);
124} 168}
125 169
170static void
171_class_constructor(Eo_Class *klass)
172{
173 const Eo_Op_Func_Description func_desc[] = {
174 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
175 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
176 EO_OP_FUNC(ECORE_JOB_ID(ECORE_JOB_SUB_ID_CONSTRUCTOR), _job_constructor),
177 EO_OP_FUNC_SENTINEL
178 };
179
180 eo_class_funcs_set(klass, func_desc);
181}
182
183static const Eo_Op_Description op_desc[] = {
184 EO_OP_DESCRIPTION(ECORE_JOB_SUB_ID_CONSTRUCTOR, "Add a job to the event queue."),
185 EO_OP_DESCRIPTION_SENTINEL
186};
187static const Eo_Class_Description class_desc = {
188 EO_VERSION,
189 MY_CLASS_NAME,
190 EO_CLASS_TYPE_REGULAR,
191 EO_CLASS_DESCRIPTION_OPS(&ECORE_JOB_BASE_ID, op_desc, ECORE_JOB_SUB_ID_LAST),
192 NULL,
193 sizeof(Ecore_Job_Private_Data),
194 _class_constructor,
195 NULL
196};
197
198EO_DEFINE_CLASS(ecore_job_class_get, &class_desc, EO_BASE_CLASS, NULL);
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)
diff --git a/legacy/ecore/src/lib/ecore/ecore_private.h b/legacy/ecore/src/lib/ecore/ecore_private.h
index d812e3a349..048d1041d7 100644
--- a/legacy/ecore/src/lib/ecore/ecore_private.h
+++ b/legacy/ecore/src/lib/ecore/ecore_private.h
@@ -359,16 +359,16 @@ void ecore_mempool_shutdown(void);
359#define GENERIC_ALLOC_SIZE_DECLARE(TYPE) \ 359#define GENERIC_ALLOC_SIZE_DECLARE(TYPE) \
360 size_t _ecore_sizeof_##TYPE = sizeof (TYPE); 360 size_t _ecore_sizeof_##TYPE = sizeof (TYPE);
361 361
362GENERIC_ALLOC_FREE_HEADER(Ecore_Animator, ecore_animator); 362//GENERIC_ALLOC_FREE_HEADER(Ecore_Animator, ecore_animator);
363GENERIC_ALLOC_FREE_HEADER(Ecore_Event_Handler, ecore_event_handler); 363GENERIC_ALLOC_FREE_HEADER(Ecore_Event_Handler, ecore_event_handler);
364GENERIC_ALLOC_FREE_HEADER(Ecore_Event_Filter, ecore_event_filter); 364GENERIC_ALLOC_FREE_HEADER(Ecore_Event_Filter, ecore_event_filter);
365GENERIC_ALLOC_FREE_HEADER(Ecore_Event, ecore_event); 365GENERIC_ALLOC_FREE_HEADER(Ecore_Event, ecore_event);
366GENERIC_ALLOC_FREE_HEADER(Ecore_Idle_Exiter, ecore_idle_exiter); 366//GENERIC_ALLOC_FREE_HEADER(Ecore_Idle_Exiter, ecore_idle_exiter);
367GENERIC_ALLOC_FREE_HEADER(Ecore_Idle_Enterer, ecore_idle_enterer); 367//GENERIC_ALLOC_FREE_HEADER(Ecore_Idle_Enterer, ecore_idle_enterer);
368GENERIC_ALLOC_FREE_HEADER(Ecore_Idler, ecore_idler); 368//GENERIC_ALLOC_FREE_HEADER(Ecore_Idler, ecore_idler);
369GENERIC_ALLOC_FREE_HEADER(Ecore_Job, ecore_job); 369//GENERIC_ALLOC_FREE_HEADER(Ecore_Job, ecore_job);
370GENERIC_ALLOC_FREE_HEADER(Ecore_Timer, ecore_timer); 370//GENERIC_ALLOC_FREE_HEADER(Ecore_Timer, ecore_timer);
371GENERIC_ALLOC_FREE_HEADER(Ecore_Poller, ecore_poller); 371//GENERIC_ALLOC_FREE_HEADER(Ecore_Poller, ecore_poller);
372GENERIC_ALLOC_FREE_HEADER(Ecore_Pipe, ecore_pipe); 372GENERIC_ALLOC_FREE_HEADER(Ecore_Pipe, ecore_pipe);
373GENERIC_ALLOC_FREE_HEADER(Ecore_Fd_Handler, ecore_fd_handler); 373GENERIC_ALLOC_FREE_HEADER(Ecore_Fd_Handler, ecore_fd_handler);
374#ifdef _WIN32 374#ifdef _WIN32
@@ -377,4 +377,8 @@ GENERIC_ALLOC_FREE_HEADER(Ecore_Win32_Handler, ecore_win32_handler);
377 377
378#undef GENERIC_ALLOC_FREE_HEADER 378#undef GENERIC_ALLOC_FREE_HEADER
379 379
380EAPI extern Eo *_ecore_parent;
381#define ECORE_PARENT_CLASS ecore_parent_class_get()
382const Eo_Class *ecore_parent_class_get(void) EINA_CONST;
383
380#endif 384#endif
diff --git a/legacy/ecore/src/lib/ecore/ecore_timer.c b/legacy/ecore/src/lib/ecore/ecore_timer.c
index 343c89f571..0ab4230dbe 100644
--- a/legacy/ecore/src/lib/ecore/ecore_timer.c
+++ b/legacy/ecore/src/lib/ecore/ecore_timer.c
@@ -8,6 +8,17 @@
8#include "Ecore.h" 8#include "Ecore.h"
9#include "ecore_private.h" 9#include "ecore_private.h"
10 10
11#include "Eo.h"
12
13#define MY_CLASS ECORE_TIMER_CLASS
14#define MY_CLASS_NAME "ecore_timer"
15
16EAPI Eo_Op ECORE_TIMER_BASE_ID = EO_NOOP;
17
18#define ECORE_TIMER_CHECK(obj) \
19 if (!eo_isa((obj), ECORE_TIMER_CLASS)) \
20 return
21
11#ifdef WANT_ECORE_TIMER_DUMP 22#ifdef WANT_ECORE_TIMER_DUMP
12# include <string.h> 23# include <string.h>
13# include <execinfo.h> 24# include <execinfo.h>
@@ -15,10 +26,10 @@
15typedef void (*Ecore_Timer_Bt_Func)(); 26typedef void (*Ecore_Timer_Bt_Func)();
16#endif 27#endif
17 28
18struct _Ecore_Timer 29struct _Ecore_Timer_Private_Data
19{ 30{
20 EINA_INLIST; 31 EINA_INLIST;
21 ECORE_MAGIC; 32 Ecore_Timer *obj;
22 double in; 33 double in;
23 double at; 34 double at;
24 double pending; 35 double pending;
@@ -35,9 +46,10 @@ struct _Ecore_Timer
35 unsigned char just_added : 1; 46 unsigned char just_added : 1;
36 unsigned char frozen : 1; 47 unsigned char frozen : 1;
37}; 48};
38GENERIC_ALLOC_SIZE_DECLARE(Ecore_Timer);
39 49
40static void _ecore_timer_set(Ecore_Timer *timer, 50typedef struct _Ecore_Timer_Private_Data Ecore_Timer_Private_Data;
51
52static void _ecore_timer_set(Ecore_Timer *timer,
41 double at, 53 double at,
42 double in, 54 double in,
43 Ecore_Task_Cb func, 55 Ecore_Task_Cb func,
@@ -49,9 +61,9 @@ static int _ecore_timer_cmp(const void *d1,
49 61
50static int timers_added = 0; 62static int timers_added = 0;
51static int timers_delete_me = 0; 63static int timers_delete_me = 0;
52static Ecore_Timer *timers = NULL; 64static Ecore_Timer_Private_Data *timers = NULL;
53static Ecore_Timer *timer_current = NULL; 65static Ecore_Timer_Private_Data *timer_current = NULL;
54static Ecore_Timer *suspended = NULL; 66static Ecore_Timer_Private_Data *suspended = NULL;
55static double last_check = 0.0; 67static double last_check = 0.0;
56static double precision = 10.0 / 1000000.0; 68static double precision = 10.0 / 1000000.0;
57 69
@@ -138,29 +150,89 @@ ecore_timer_add(double in,
138 Ecore_Task_Cb func, 150 Ecore_Task_Cb func,
139 const void *data) 151 const void *data)
140{ 152{
141 double now;
142 Ecore_Timer *timer = NULL; 153 Ecore_Timer *timer = NULL;
143 154
144 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 155 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
145 _ecore_lock(); 156 timer = eo_add_custom(MY_CLASS, _ecore_parent, ecore_timer_constructor(in, func, data));
146 if (!func) goto unlock; 157 eo_unref(timer);
158 return timer;
159}
160
161static Eina_Bool
162_ecore_timer_add(Ecore_Timer *obj,
163 Ecore_Timer_Private_Data *timer,
164 double now,
165 double in,
166 Ecore_Task_Cb func,
167 const void *data)
168{
169
170 if (EINA_UNLIKELY(!eina_main_loop_is()))
171 {
172 eo_error_set(obj);
173 EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
174 }
175
176 timer->obj = obj;
177 eo_do_super(obj, eo_constructor());
178 eo_manual_free_set(obj, EINA_TRUE);
179
180 if (!func)
181 {
182 eo_error_set(obj);
183 ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
184 return EINA_FALSE;
185 }
186
147 if (in < 0.0) in = 0.0; 187 if (in < 0.0) in = 0.0;
148 timer = ecore_timer_calloc(1);
149 if (!timer) goto unlock;
150 ECORE_MAGIC_SET(timer, ECORE_MAGIC_TIMER);
151 now = ecore_time_get();
152 188
153#ifdef WANT_ECORE_TIMER_DUMP 189#ifdef WANT_ECORE_TIMER_DUMP
154 timer->timer_bt_num = backtrace((void **)(timer->timer_bt), 190 timer->timer_bt_num = backtrace((void **)(timer->timer_bt),
155 ECORE_TIMER_DEBUG_BT_NUM); 191 ECORE_TIMER_DEBUG_BT_NUM);
156#endif 192#endif
193 _ecore_timer_set(obj, now + in, in, func, (void *)data);
194 return EINA_TRUE;
195}
157 196
158 _ecore_timer_set(timer, now + in, in, func, (void *)data); 197static void
159unlock: 198_timer_constructor(Eo *obj, void *_pd, va_list *list)
199{
200 double in = va_arg(*list, double);
201 Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
202 const void *data = va_arg(*list, const void *);
203 double now;
204
205 _ecore_lock();
206 now = ecore_time_get();
207
208 Ecore_Timer_Private_Data *timer = _pd;
209 _ecore_timer_add(obj, timer, now, in, func, data);
160 _ecore_unlock(); 210 _ecore_unlock();
161 return timer;
162} 211}
163 212
213static void
214_timer_loop_constructor(Eo *obj, void *_pd, va_list *list)
215{
216 double in = va_arg(*list, double);
217 Ecore_Task_Cb func = va_arg(*list, Ecore_Task_Cb);
218 const void *data = va_arg(*list, const void *);
219 double now;
220
221 _ecore_lock();
222 now = ecore_loop_time_get();
223
224 Ecore_Timer_Private_Data *timer = _pd;
225 _ecore_timer_add(obj, timer, now, in, func, data);
226}
227
228static void
229_constructor(Eo *obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
230{
231 eo_error_set(obj);
232 ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
233}
234
235
164/** 236/**
165 * Creates a timer to call the given function in the given period of time. 237 * Creates a timer to call the given function in the given period of time.
166 * @param in The interval in seconds from current loop time. 238 * @param in The interval in seconds from current loop time.
@@ -180,7 +252,6 @@ ecore_timer_loop_add(double in,
180{ 252{
181 Ecore_Timer *timer; 253 Ecore_Timer *timer;
182 254
183 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
184 _ecore_lock(); 255 _ecore_lock();
185 timer = _ecore_timer_loop_add(in, func, data); 256 timer = _ecore_timer_loop_add(in, func, data);
186 _ecore_unlock(); 257 _ecore_unlock();
@@ -205,16 +276,8 @@ ecore_timer_del(Ecore_Timer *timer)
205 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); 276 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
206 _ecore_lock(); 277 _ecore_lock();
207 278
208 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER))
209 {
210 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER,
211 "ecore_timer_del");
212 goto unlock;
213 }
214
215 data = _ecore_timer_del(timer); 279 data = _ecore_timer_del(timer);
216 280
217unlock:
218 _ecore_unlock(); 281 _ecore_unlock();
219 return data; 282 return data;
220} 283}
@@ -230,17 +293,20 @@ EAPI void
230ecore_timer_interval_set(Ecore_Timer *timer, 293ecore_timer_interval_set(Ecore_Timer *timer,
231 double in) 294 double in)
232{ 295{
296 ECORE_TIMER_CHECK(timer);
297 eo_do(timer, ecore_obj_timer_interval_set(in));
298}
299
300static void
301_timer_interval_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
302{
233 EINA_MAIN_LOOP_CHECK_RETURN; 303 EINA_MAIN_LOOP_CHECK_RETURN;
234 _ecore_lock(); 304 double in = va_arg(*list, double);
235 if (in < 0.0) in = 0.0; 305 if (in < 0.0) in = 0.0;
236 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER)) 306 Ecore_Timer_Private_Data *timer = _pd;
237 { 307
238 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER, 308 _ecore_lock();
239 "ecore_timer_interval_set");
240 goto unlock;
241 }
242 timer->in = in; 309 timer->in = in;
243unlock:
244 _ecore_unlock(); 310 _ecore_unlock();
245} 311}
246 312
@@ -253,23 +319,24 @@ unlock:
253EAPI double 319EAPI double
254ecore_timer_interval_get(Ecore_Timer *timer) 320ecore_timer_interval_get(Ecore_Timer *timer)
255{ 321{
256 double interval; 322 double interval = -1.0;
257 323
258 EINA_MAIN_LOOP_CHECK_RETURN_VAL(0.0); 324 ECORE_TIMER_CHECK(timer) interval;
259 _ecore_lock(); 325 eo_do(timer, ecore_obj_timer_interval_get(&interval));
326 return interval;
327}
260 328
261 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER)) 329static void
262 { 330_timer_interval_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
263 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER, 331{
264 "ecore_timer_interval_get"); 332 double *ret = va_arg(*list, double *);
265 interval = -1.0; 333 *ret = -1.0;
266 goto unlock;
267 }
268 334
269 interval = timer->in; 335 EINA_MAIN_LOOP_CHECK_RETURN;
270unlock: 336 Ecore_Timer_Private_Data *timer = _pd;
337 _ecore_lock();
338 *ret = timer->in;
271 _ecore_unlock(); 339 _ecore_unlock();
272 return interval;
273} 340}
274 341
275/** 342/**
@@ -283,16 +350,18 @@ EAPI void
283ecore_timer_delay(Ecore_Timer *timer, 350ecore_timer_delay(Ecore_Timer *timer,
284 double add) 351 double add)
285{ 352{
353 ECORE_TIMER_CHECK(timer);
354 eo_do(timer, ecore_obj_timer_delay(add));
355}
356
357static void
358_timer_delay(Eo *obj, void *_pd EINA_UNUSED, va_list *list)
359{
360 double add = va_arg(*list, double);
286 EINA_MAIN_LOOP_CHECK_RETURN; 361 EINA_MAIN_LOOP_CHECK_RETURN;
287 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER))
288 {
289 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER,
290 "ecore_timer_delay");
291 return;
292 }
293 362
294 _ecore_lock(); 363 _ecore_lock();
295 _ecore_timer_delay(timer, add); 364 _ecore_timer_delay(obj, add);
296 _ecore_unlock(); 365 _ecore_unlock();
297} 366}
298 367
@@ -309,14 +378,18 @@ ecore_timer_delay(Ecore_Timer *timer,
309EAPI void 378EAPI void
310ecore_timer_reset(Ecore_Timer *timer) 379ecore_timer_reset(Ecore_Timer *timer)
311{ 380{
381 ECORE_TIMER_CHECK(timer);
382 eo_do(timer, ecore_obj_timer_reset());
383}
384
385static void
386_timer_reset(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
387{
312 double now, add; 388 double now, add;
313 EINA_MAIN_LOOP_CHECK_RETURN; 389 EINA_MAIN_LOOP_CHECK_RETURN;
314 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER)) 390
315 { 391 Ecore_Timer_Private_Data *timer = _pd;
316 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER, 392
317 __func__);
318 return;
319 }
320 _ecore_lock(); 393 _ecore_lock();
321 now = ecore_time_get(); 394 now = ecore_time_get();
322 395
@@ -324,7 +397,7 @@ ecore_timer_reset(Ecore_Timer *timer)
324 add = timer->pending; 397 add = timer->pending;
325 else 398 else
326 add = timer->at - now; 399 add = timer->at - now;
327 _ecore_timer_delay(timer, timer->in - add); 400 _ecore_timer_delay(obj, timer->in - add);
328 _ecore_unlock(); 401 _ecore_unlock();
329} 402}
330 403
@@ -338,30 +411,33 @@ ecore_timer_reset(Ecore_Timer *timer)
338EAPI double 411EAPI double
339ecore_timer_pending_get(Ecore_Timer *timer) 412ecore_timer_pending_get(Ecore_Timer *timer)
340{ 413{
341 double now;
342 double ret = 0.0; 414 double ret = 0.0;
343 415
344 EINA_MAIN_LOOP_CHECK_RETURN_VAL(0.0); 416 ECORE_TIMER_CHECK(timer) ret;
345 _ecore_lock(); 417 eo_do(timer, ecore_obj_timer_pending_get(&ret));
418 return ret;
419}
346 420
347 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER)) 421static void
348 { 422_timer_pending_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
349 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER, 423{
350 "ecore_timer_pending_get"); 424 double now;
351 goto unlock; 425 double *ret = va_arg(*list, double *);
352 } 426 *ret = 0.0;
427
428 EINA_MAIN_LOOP_CHECK_RETURN;
429
430 _ecore_lock();
431 Ecore_Timer_Private_Data *timer = _pd;
353 432
354 now = ecore_time_get(); 433 now = ecore_time_get();
355 434
356 if (timer->frozen) 435 if (timer->frozen)
357 ret = timer->pending; 436 *ret = timer->pending;
358 else 437 else
359 ret = timer->at - now; 438 *ret = timer->at - now;
360unlock:
361 _ecore_unlock(); 439 _ecore_unlock();
362 return ret;
363} 440}
364
365/** 441/**
366 * Pauses a running timer. 442 * Pauses a running timer.
367 * 443 *
@@ -379,24 +455,26 @@ unlock:
379EAPI void 455EAPI void
380ecore_timer_freeze(Ecore_Timer *timer) 456ecore_timer_freeze(Ecore_Timer *timer)
381{ 457{
458 ECORE_TIMER_CHECK(timer);
459 eo_do(timer, eo_event_freeze());
460}
461
462static void
463_timer_freeze(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED)
464{
382 double now; 465 double now;
383 466
384 EINA_MAIN_LOOP_CHECK_RETURN; 467 EINA_MAIN_LOOP_CHECK_RETURN;
385 _ecore_lock();
386 468
387 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER)) 469 Ecore_Timer_Private_Data *timer = _pd;
388 { 470 _ecore_lock();
389 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER,
390 "ecore_timer_freeze");
391 goto unlock;
392 }
393 471
394 /* Timer already frozen */ 472 /* Timer already frozen */
395 if (timer->frozen) 473 if (timer->frozen)
396 goto unlock; 474 goto unlock;
397 475
398 timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer)); 476 timers = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer));
399 suspended = (Ecore_Timer *)eina_inlist_prepend(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer)); 477 suspended = (Ecore_Timer_Private_Data *)eina_inlist_prepend(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer));
400 478
401 now = ecore_time_get(); 479 now = ecore_time_get();
402 480
@@ -423,26 +501,28 @@ unlock:
423EAPI void 501EAPI void
424ecore_timer_thaw(Ecore_Timer *timer) 502ecore_timer_thaw(Ecore_Timer *timer)
425{ 503{
504 ECORE_TIMER_CHECK(timer);
505 eo_do(timer, eo_event_thaw());
506}
507
508static void
509_timer_thaw(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
510{
426 double now; 511 double now;
427 512
428 EINA_MAIN_LOOP_CHECK_RETURN; 513 EINA_MAIN_LOOP_CHECK_RETURN;
429 _ecore_lock(); 514 Ecore_Timer_Private_Data *timer = _pd;
430 515
431 if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER)) 516 _ecore_lock();
432 {
433 ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER,
434 "ecore_timer_thaw");
435 goto unlock;
436 }
437 517
438 /* Timer not frozen */ 518 /* Timer not frozen */
439 if (!timer->frozen) 519 if (!timer->frozen)
440 goto unlock; 520 goto unlock;
441 521
442 suspended = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer)); 522 suspended = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer));
443 now = ecore_time_get(); 523 now = ecore_time_get();
444 524
445 _ecore_timer_set(timer, timer->pending + now, timer->in, timer->func, timer->data); 525 _ecore_timer_set(obj, timer->pending + now, timer->in, timer->func, timer->data);
446unlock: 526unlock:
447 _ecore_unlock(); 527 _ecore_unlock();
448} 528}
@@ -512,52 +592,50 @@ _ecore_timer_loop_add(double in,
512 Ecore_Task_Cb func, 592 Ecore_Task_Cb func,
513 const void *data) 593 const void *data)
514{ 594{
515 double now;
516 Ecore_Timer *timer = NULL; 595 Ecore_Timer *timer = NULL;
596 timer = eo_add_custom(MY_CLASS, _ecore_parent, ecore_timer_loop_constructor(in, func, data));
597 eo_unref(timer);
517 598
518 if (!func) return timer;
519 if (in < 0.0) in = 0.0;
520 timer = ecore_timer_calloc(1);
521 if (!timer) return timer;
522 ECORE_MAGIC_SET(timer, ECORE_MAGIC_TIMER);
523 now = ecore_loop_time_get();
524
525#ifdef WANT_ECORE_TIMER_DUMP
526 timer->timer_bt_num = backtrace((void **)(timer->timer_bt),
527 ECORE_TIMER_DEBUG_BT_NUM);
528#endif
529 _ecore_timer_set(timer, now + in, in, func, (void *)data);
530 return timer; 599 return timer;
531} 600}
532 601
533EAPI void 602EAPI void
534_ecore_timer_delay(Ecore_Timer *timer, 603_ecore_timer_delay(Ecore_Timer *obj,
535 double add) 604 double add)
536{ 605{
606 Ecore_Timer_Private_Data *timer = eo_data_get(obj, MY_CLASS);
607
537 if (timer->frozen) 608 if (timer->frozen)
538 { 609 {
539 timer->pending += add; 610 timer->pending += add;
540 } 611 }
541 else 612 else
542 { 613 {
543 timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer)); 614 timers = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer));
544 _ecore_timer_set(timer, timer->at + add, timer->in, timer->func, timer->data); 615 _ecore_timer_set(obj, timer->at + add, timer->in, timer->func, timer->data);
545 } 616 }
546} 617}
547 618
548void * 619void *
549_ecore_timer_del(Ecore_Timer *timer) 620_ecore_timer_del(Ecore_Timer *obj)
550{ 621{
622 Ecore_Timer_Private_Data *timer = eo_data_get(obj, MY_CLASS);
623
551 if (timer->frozen && !timer->references) 624 if (timer->frozen && !timer->references)
552 { 625 {
553 void *data = timer->data; 626 void *data = timer->data;
554 627
555 suspended = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer)); 628 suspended = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer));
556 629
557 if (timer->delete_me) 630 if (timer->delete_me)
558 timers_delete_me--; 631 timers_delete_me--;
559 632
560 ecore_timer_mp_free(timer); 633 eo_parent_set(obj, NULL);
634
635 if (eo_destructed_is(obj))
636 eo_manual_free(obj);
637 else
638 eo_manual_free_set(obj, EINA_FALSE);
561 return data; 639 return data;
562 } 640 }
563 641
@@ -567,23 +645,45 @@ _ecore_timer_del(Ecore_Timer *timer)
567 return timer->data; 645 return timer->data;
568} 646}
569 647
648static void
649_destructor(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
650{
651 Ecore_Timer_Private_Data *pd = _pd;
652
653 if (!pd->delete_me)
654 {
655 pd->delete_me = 1;
656 timers_delete_me++;
657 }
658
659 eo_do_super(obj, eo_destructor());
660}
661
570void 662void
571_ecore_timer_shutdown(void) 663_ecore_timer_shutdown(void)
572{ 664{
573 Ecore_Timer *timer; 665 Ecore_Timer_Private_Data *timer;
574 666
575 while ((timer = timers)) 667 while ((timer = timers))
576 { 668 {
577 timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timers)); 669 timers = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timers));
578 ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); 670
579 ecore_timer_mp_free(timer); 671 eo_parent_set(timer->obj, NULL);
672 if (eo_destructed_is(timer->obj))
673 eo_manual_free(timer->obj);
674 else
675 eo_manual_free_set(timer->obj, EINA_FALSE);
580 } 676 }
581 677
582 while ((timer = suspended)) 678 while ((timer = suspended))
583 { 679 {
584 suspended = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(suspended)); 680 suspended = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(suspended));
585 ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); 681
586 ecore_timer_mp_free(timer); 682 eo_parent_set(timer->obj, NULL);
683 if (eo_destructed_is(timer->obj))
684 eo_manual_free(timer->obj);
685 else
686 eo_manual_free_set(timer->obj, EINA_FALSE);
587 } 687 }
588 688
589 timer_current = NULL; 689 timer_current = NULL;
@@ -592,15 +692,15 @@ _ecore_timer_shutdown(void)
592void 692void
593_ecore_timer_cleanup(void) 693_ecore_timer_cleanup(void)
594{ 694{
595 Ecore_Timer *l; 695 Ecore_Timer_Private_Data *l;
596 int in_use = 0, todo = timers_delete_me, done = 0; 696 int in_use = 0, todo = timers_delete_me, done = 0;
597 697
598 if (!timers_delete_me) return; 698 if (!timers_delete_me) return;
599 for (l = timers; l; ) 699 for (l = timers; l; )
600 { 700 {
601 Ecore_Timer *timer = l; 701 Ecore_Timer_Private_Data *timer = l;
602 702
603 l = (Ecore_Timer *)EINA_INLIST_GET(l)->next; 703 l = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(l)->next;
604 if (timer->delete_me) 704 if (timer->delete_me)
605 { 705 {
606 if (timer->references) 706 if (timer->references)
@@ -608,9 +708,13 @@ _ecore_timer_cleanup(void)
608 in_use++; 708 in_use++;
609 continue; 709 continue;
610 } 710 }
611 timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer)); 711 timers = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer));
612 ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); 712
613 ecore_timer_mp_free(timer); 713 eo_parent_set(timer->obj, NULL);
714 if (eo_destructed_is(timer->obj))
715 eo_manual_free(timer->obj);
716 else
717 eo_manual_free_set(timer->obj, EINA_FALSE);
614 timers_delete_me--; 718 timers_delete_me--;
615 done++; 719 done++;
616 if (timers_delete_me == 0) return; 720 if (timers_delete_me == 0) return;
@@ -618,9 +722,9 @@ _ecore_timer_cleanup(void)
618 } 722 }
619 for (l = suspended; l; ) 723 for (l = suspended; l; )
620 { 724 {
621 Ecore_Timer *timer = l; 725 Ecore_Timer_Private_Data *timer = l;
622 726
623 l = (Ecore_Timer *)EINA_INLIST_GET(l)->next; 727 l = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(l)->next;
624 if (timer->delete_me) 728 if (timer->delete_me)
625 { 729 {
626 if (timer->references) 730 if (timer->references)
@@ -628,9 +732,13 @@ _ecore_timer_cleanup(void)
628 in_use++; 732 in_use++;
629 continue; 733 continue;
630 } 734 }
631 suspended = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer)); 735 suspended = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer));
632 ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); 736
633 ecore_timer_mp_free(timer); 737 eo_parent_set(timer->obj, NULL);
738 if (eo_destructed_is(timer->obj))
739 eo_manual_free(timer->obj);
740 else
741 eo_manual_free_set(timer->obj, EINA_FALSE);
634 timers_delete_me--; 742 timers_delete_me--;
635 done++; 743 done++;
636 if (timers_delete_me == 0) return; 744 if (timers_delete_me == 0) return;
@@ -650,7 +758,7 @@ _ecore_timer_cleanup(void)
650void 758void
651_ecore_timer_enable_new(void) 759_ecore_timer_enable_new(void)
652{ 760{
653 Ecore_Timer *timer; 761 Ecore_Timer_Private_Data *timer;
654 762
655 if (!timers_added) return; 763 if (!timers_added) return;
656 timers_added = 0; 764 timers_added = 0;
@@ -660,10 +768,10 @@ _ecore_timer_enable_new(void)
660int 768int
661_ecore_timers_exists(void) 769_ecore_timers_exists(void)
662{ 770{
663 Ecore_Timer *timer = timers; 771 Ecore_Timer_Private_Data *timer = timers;
664 772
665 while ((timer) && (timer->delete_me)) 773 while ((timer) && (timer->delete_me))
666 timer = (Ecore_Timer *)EINA_INLIST_GET(timer)->next; 774 timer = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(timer)->next;
667 775
668 return !!timer; 776 return !!timer;
669} 777}
@@ -671,29 +779,37 @@ _ecore_timers_exists(void)
671static inline Ecore_Timer * 779static inline Ecore_Timer *
672_ecore_timer_first_get(void) 780_ecore_timer_first_get(void)
673{ 781{
674 Ecore_Timer *timer = timers; 782 Ecore_Timer *ret = NULL;
783 Ecore_Timer_Private_Data *timer = timers;
675 784
676 while ((timer) && ((timer->delete_me) || (timer->just_added))) 785 while ((timer) && ((timer->delete_me) || (timer->just_added)))
677 timer = (Ecore_Timer *)EINA_INLIST_GET(timer)->next; 786 timer = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(timer)->next;
678 787
679 return timer; 788 if (timer)
789 ret = timer->obj;
790 return ret;
680} 791}
681 792
682static inline Ecore_Timer * 793static inline Ecore_Timer *
683_ecore_timer_after_get(Ecore_Timer *base) 794_ecore_timer_after_get(Ecore_Timer *obj)
684{ 795{
685 Ecore_Timer *timer = (Ecore_Timer *)EINA_INLIST_GET(base)->next; 796 Ecore_Timer *ret = NULL;
686 Ecore_Timer *valid_timer = NULL; 797 Ecore_Timer_Private_Data *base = eo_data_get(obj, MY_CLASS);
798
799 Ecore_Timer_Private_Data *timer = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(base)->next;
800 Ecore_Timer_Private_Data *valid_timer = NULL;
687 double maxtime = base->at + precision; 801 double maxtime = base->at + precision;
688 802
689 while ((timer) && (timer->at < maxtime)) 803 while ((timer) && (timer->at < maxtime))
690 { 804 {
691 if (!((timer->delete_me) || (timer->just_added))) 805 if (!((timer->delete_me) || (timer->just_added)))
692 valid_timer = timer; 806 valid_timer = timer;
693 timer = (Ecore_Timer *)EINA_INLIST_GET(timer)->next; 807 timer = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(timer)->next;
694 } 808 }
695 809
696 return valid_timer; 810 if (valid_timer)
811 ret = valid_timer->obj;
812 return ret;
697} 813}
698 814
699double 815double
@@ -701,13 +817,16 @@ _ecore_timer_next_get(void)
701{ 817{
702 double now; 818 double now;
703 double in; 819 double in;
704 Ecore_Timer *first, *second; 820 Ecore_Timer *first_obj, *second_obj;
821 Ecore_Timer_Private_Data *first;
822
823 first_obj = _ecore_timer_first_get();
824 if (!first_obj) return -1;
705 825
706 first = _ecore_timer_first_get(); 826 second_obj = _ecore_timer_after_get(first_obj);
707 if (!first) return -1; 827 if (second_obj) first_obj = second_obj;
708 828
709 second = _ecore_timer_after_get(first); 829 first = eo_data_get(first_obj, MY_CLASS);
710 if (second) first = second;
711 830
712 now = ecore_loop_time_get(); 831 now = ecore_loop_time_get();
713 in = first->at - now; 832 in = first->at - now;
@@ -716,12 +835,13 @@ _ecore_timer_next_get(void)
716} 835}
717 836
718static inline void 837static inline void
719_ecore_timer_reschedule(Ecore_Timer *timer, 838_ecore_timer_reschedule(Ecore_Timer *obj,
720 double when) 839 double when)
721{ 840{
841 Ecore_Timer_Private_Data *timer = eo_data_get(obj, MY_CLASS);
722 if ((timer->delete_me) || (timer->frozen)) return; 842 if ((timer->delete_me) || (timer->frozen)) return;
723 843
724 timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer)); 844 timers = (Ecore_Timer_Private_Data *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer));
725 845
726 /* if the timer would have gone off more than 15 seconds ago, 846 /* if the timer would have gone off more than 15 seconds ago,
727 * assume that the system hung and set the timer to go off 847 * assume that the system hung and set the timer to go off
@@ -733,9 +853,9 @@ _ecore_timer_reschedule(Ecore_Timer *timer,
733 * really slow within the main loop. 853 * really slow within the main loop.
734 */ 854 */
735 if ((timer->at + timer->in) < (when - 15.0)) 855 if ((timer->at + timer->in) < (when - 15.0))
736 _ecore_timer_set(timer, when + timer->in, timer->in, timer->func, timer->data); 856 _ecore_timer_set(obj, when + timer->in, timer->in, timer->func, timer->data);
737 else 857 else
738 _ecore_timer_set(timer, timer->at + timer->in, timer->in, timer->func, timer->data); 858 _ecore_timer_set(obj, timer->at + timer->in, timer->in, timer->func, timer->data);
739} 859}
740 860
741/* assume that we hold the ecore lock when entering this function */ 861/* assume that we hold the ecore lock when entering this function */
@@ -753,7 +873,7 @@ _ecore_timer_expired_call(double when)
753 if (!timers) return 0; 873 if (!timers) return 0;
754 if (last_check > when) 874 if (last_check > when)
755 { 875 {
756 Ecore_Timer *timer; 876 Ecore_Timer_Private_Data *timer;
757 /* User set time backwards */ 877 /* User set time backwards */
758 EINA_INLIST_FOREACH(timers, timer) timer->at -= (last_check - when); 878 EINA_INLIST_FOREACH(timers, timer) timer->at -= (last_check - when);
759 } 879 }
@@ -762,19 +882,19 @@ _ecore_timer_expired_call(double when)
762 if (!timer_current) 882 if (!timer_current)
763 { 883 {
764 /* regular main loop, start from head */ 884 /* regular main loop, start from head */
765 timer_current = timers; 885 timer_current = timers;
766 } 886 }
767 else 887 else
768 { 888 {
769 /* recursive main loop, continue from where we were */ 889 /* recursive main loop, continue from where we were */
770 Ecore_Timer *timer_old = timer_current; 890 Ecore_Timer_Private_Data *timer_old = timer_current;
771 timer_current = (Ecore_Timer *)EINA_INLIST_GET(timer_current)->next; 891 timer_current = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(timer_current)->next;
772 _ecore_timer_reschedule(timer_old, when); 892 _ecore_timer_reschedule(timer_old->obj, when);
773 } 893 }
774 894
775 while (timer_current) 895 while (timer_current)
776 { 896 {
777 Ecore_Timer *timer = timer_current; 897 Ecore_Timer_Private_Data *timer = timer_current;
778 898
779 if (timer->at > when) 899 if (timer->at > when)
780 { 900 {
@@ -784,33 +904,35 @@ _ecore_timer_expired_call(double when)
784 904
785 if ((timer->just_added) || (timer->delete_me)) 905 if ((timer->just_added) || (timer->delete_me))
786 { 906 {
787 timer_current = (Ecore_Timer *)EINA_INLIST_GET(timer_current)->next; 907 timer_current = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(timer_current)->next;
788 continue; 908 continue;
789 } 909 }
790 910
791 timer->references++; 911 timer->references++;
792 if (!_ecore_call_task_cb(timer->func, timer->data)) 912 if (!_ecore_call_task_cb(timer->func, timer->data))
793 { 913 {
794 if (!timer->delete_me) _ecore_timer_del(timer); 914 if (!timer->delete_me) _ecore_timer_del(timer->obj);
795 } 915 }
796 timer->references--; 916 timer->references--;
797 917
798 if (timer_current) /* may have changed in recursive main loops */ 918 if (timer_current) /* may have changed in recursive main loops */
799 timer_current = (Ecore_Timer *)EINA_INLIST_GET(timer_current)->next; 919 timer_current = (Ecore_Timer_Private_Data *)EINA_INLIST_GET(timer_current)->next;
800 920
801 _ecore_timer_reschedule(timer, when); 921 _ecore_timer_reschedule(timer->obj, when);
802 } 922 }
803 return 0; 923 return 0;
804} 924}
805 925
806static void 926static void
807_ecore_timer_set(Ecore_Timer *timer, 927_ecore_timer_set(Ecore_Timer *obj,
808 double at, 928 double at,
809 double in, 929 double in,
810 Ecore_Task_Cb func, 930 Ecore_Task_Cb func,
811 void *data) 931 void *data)
812{ 932{
813 Ecore_Timer *t2; 933 Ecore_Timer_Private_Data *t2;
934
935 Ecore_Timer_Private_Data *timer = eo_data_get(obj, MY_CLASS);
814 936
815 timers_added = 1; 937 timers_added = 1;
816 timer->at = at; 938 timer->at = at;
@@ -826,12 +948,12 @@ _ecore_timer_set(Ecore_Timer *timer,
826 { 948 {
827 if (timer->at > t2->at) 949 if (timer->at > t2->at)
828 { 950 {
829 timers = (Ecore_Timer *)eina_inlist_append_relative(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer), EINA_INLIST_GET(t2)); 951 timers = (Ecore_Timer_Private_Data *)eina_inlist_append_relative(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer), EINA_INLIST_GET(t2));
830 return; 952 return;
831 } 953 }
832 } 954 }
833 } 955 }
834 timers = (Ecore_Timer *)eina_inlist_prepend(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer)); 956 timers = (Ecore_Timer_Private_Data *)eina_inlist_prepend(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer));
835} 957}
836 958
837#ifdef WANT_ECORE_TIMER_DUMP 959#ifdef WANT_ECORE_TIMER_DUMP
@@ -845,3 +967,50 @@ _ecore_timer_cmp(const void *d1,
845 return (int)((t1->in - t2->in) * 100); 967 return (int)((t1->in - t2->in) * 100);
846} 968}
847#endif 969#endif
970
971static void
972_class_constructor(Eo_Class *klass)
973{
974 const Eo_Op_Func_Description func_desc[] = {
975 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
976 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
977
978 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_CONSTRUCTOR), _timer_constructor),
979 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_LOOP_CONSTRUCTOR), _timer_loop_constructor),
980 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_INTERVAL_SET), _timer_interval_set),
981 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_INTERVAL_GET), _timer_interval_get),
982
983 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE), _timer_freeze),
984 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_THAW), _timer_thaw),
985
986 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_DELAY), _timer_delay),
987 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_RESET), _timer_reset),
988 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_PENDING_GET), _timer_pending_get),
989 EO_OP_FUNC_SENTINEL
990 };
991
992 eo_class_funcs_set(klass, func_desc);
993}
994
995static const Eo_Op_Description op_desc[] = {
996 EO_OP_DESCRIPTION(ECORE_TIMER_SUB_ID_CONSTRUCTOR, "Creates a timer to call the given function in the given period of time."),
997 EO_OP_DESCRIPTION(ECORE_TIMER_SUB_ID_LOOP_CONSTRUCTOR, "Creates a timer to call the given function in the given period of time."),
998 EO_OP_DESCRIPTION(ECORE_TIMER_SUB_ID_INTERVAL_SET, "Change the interval the timer ticks of."),
999 EO_OP_DESCRIPTION(ECORE_TIMER_SUB_ID_INTERVAL_GET, "Get the interval the timer ticks on."),
1000 EO_OP_DESCRIPTION(ECORE_TIMER_SUB_ID_DELAY, "Add some delay for the next occurrence of a timer."),
1001 EO_OP_DESCRIPTION(ECORE_TIMER_SUB_ID_RESET, "Reset a timer to its full interval"),
1002 EO_OP_DESCRIPTION(ECORE_TIMER_SUB_ID_PENDING_GET, "Get the pending time regarding a timer."),
1003 EO_OP_DESCRIPTION_SENTINEL
1004};
1005static const Eo_Class_Description class_desc = {
1006 EO_VERSION,
1007 MY_CLASS_NAME,
1008 EO_CLASS_TYPE_REGULAR,
1009 EO_CLASS_DESCRIPTION_OPS(&ECORE_TIMER_BASE_ID, op_desc, ECORE_TIMER_SUB_ID_LAST),
1010 NULL,
1011 sizeof(Ecore_Timer_Private_Data),
1012 _class_constructor,
1013 NULL
1014};
1015
1016EO_DEFINE_CLASS(ecore_timer_class_get, &class_desc, EO_BASE_CLASS, NULL)