summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2016-05-20 02:25:48 -0700
committerCedric Bail <cedric@osg.samsung.com>2016-05-20 02:25:48 -0700
commit4f43c2745053814f26a75b7c5530279fabc9a132 (patch)
treecbe064b75d286f986dd5f0dad0cc78d49f69d267
parent73444173066a224f40705fcfc62bca1d960d38f2 (diff)
ecore: promise for timeout and job are clearly never optional, so return them.
-rw-r--r--src/lib/ecore/ecore_main.c41
-rw-r--r--src/lib/ecore/efl_loop.eo5
-rw-r--r--src/tests/ecore/ecore_test_job.c2
-rw-r--r--src/tests/ecore/ecore_test_timer.c2
4 files changed, 36 insertions, 14 deletions
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index 0db106384c..a32daa8447 100644
--- a/src/lib/ecore/ecore_main.c
+++ b/src/lib/ecore/ecore_main.c
@@ -2872,20 +2872,31 @@ _efl_internal_promise_new(Eina_Promise_Owner* promise, const void *data)
2872 return p; 2872 return p;
2873} 2873}
2874 2874
2875static void 2875static Eina_Promise *
2876_efl_loop_job(Eo *obj EINA_UNUSED, Efl_Loop_Data *pd EINA_UNUSED, Eina_Promise_Owner *promise, const void *data) 2876_efl_loop_job(Eo *obj EINA_UNUSED, Efl_Loop_Data *pd EINA_UNUSED, const void *data)
2877{ 2877{
2878 Efl_Internal_Promise *j; 2878 Efl_Internal_Promise *j;
2879 Eina_Promise_Owner *promise;
2880
2881 promise = eina_promise_default_add(sizeof (void*));
2882 fprintf(stderr, "da promise: %p\n", promise);
2883 if (!promise) return NULL;
2879 2884
2880 j = _efl_internal_promise_new(promise, data); 2885 j = _efl_internal_promise_new(promise, data);
2881 if (!j) return ; 2886 fprintf(stderr, "da internal job: %p\n", j);
2887 if (!j) goto on_error;
2882 2888
2883 j->job_is = EINA_TRUE; 2889 j->job_is = EINA_TRUE;
2884 j->u.job = ecore_job_add(_efl_loop_job_cb, j); 2890 j->u.job = ecore_job_add(_efl_loop_job_cb, j);
2891 if (!j->u.job) goto on_error;
2885 2892
2886 if (j->u.job) return ; 2893 return eina_promise_owner_promise_get(promise);
2887 2894
2888 _efl_loop_internal_cancel(j); 2895 on_error:
2896 eina_promise_unref(eina_promise_owner_promise_get(promise));
2897 free(j);
2898
2899 return NULL;
2889} 2900}
2890 2901
2891/* This event will be triggered when the main loop is destroyed and destroy its timers along */ 2902/* This event will be triggered when the main loop is destroyed and destroy its timers along */
@@ -2901,22 +2912,32 @@ EO_CALLBACKS_ARRAY_DEFINE(timeout,
2901 { EFL_TIMER_EVENT_TICK, _efl_loop_timeout_cb }, 2912 { EFL_TIMER_EVENT_TICK, _efl_loop_timeout_cb },
2902 { EO_EVENT_DEL, _efl_loop_timeout_force_cancel_cb }); 2913 { EO_EVENT_DEL, _efl_loop_timeout_force_cancel_cb });
2903 2914
2904static void 2915static Eina_Promise *
2905_efl_loop_timeout(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED, Eina_Promise_Owner *promise, double time, const void *data) 2916_efl_loop_timeout(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED, double time, const void *data)
2906{ 2917{
2907 Efl_Internal_Promise *t; 2918 Efl_Internal_Promise *t;
2919 Eina_Promise_Owner *promise;
2920
2921 promise = eina_promise_default_add(sizeof (void*));
2922 if (!promise) return NULL;
2908 2923
2909 t = _efl_internal_promise_new(promise, data); 2924 t = _efl_internal_promise_new(promise, data);
2910 if (!t) return ; 2925 if (!t) goto on_error;
2911 2926
2912 t->job_is = EINA_FALSE; 2927 t->job_is = EINA_FALSE;
2913 t->u.timer = eo_add(EFL_TIMER_CLASS, obj, 2928 t->u.timer = eo_add(EFL_TIMER_CLASS, obj,
2914 efl_timer_interval_set(eo_self, time), 2929 efl_timer_interval_set(eo_self, time),
2915 eo_event_callback_array_add(eo_self, timeout(), t)); 2930 eo_event_callback_array_add(eo_self, timeout(), t));
2916 2931
2917 if (t->u.timer) return ; 2932 if (!t->u.timer) goto on_error;
2918 2933
2919 _efl_loop_internal_cancel(t); 2934 return eina_promise_owner_promise_get(promise);
2935
2936 on_error:
2937 eina_promise_unref(eina_promise_owner_promise_get(promise));
2938 free(t);
2939
2940 return NULL;
2920} 2941}
2921 2942
2922#include "efl_loop.eo.c" 2943#include "efl_loop.eo.c"
diff --git a/src/lib/ecore/efl_loop.eo b/src/lib/ecore/efl_loop.eo
index 25ce3fec88..73af5cebfa 100644
--- a/src/lib/ecore/efl_loop.eo
+++ b/src/lib/ecore/efl_loop.eo
@@ -33,17 +33,18 @@ class Efl.Loop (Eo.Base)
33 job { 33 job {
34 [[Will execute that promise in the near future.]] 34 [[Will execute that promise in the near future.]]
35 params { 35 params {
36 @inout promise: promise<void*>*; [[The promise that will be triggered.]]
37 @in data: const(void)* @optional; [[The data to be given when the promise is done.]] 36 @in data: const(void)* @optional; [[The data to be given when the promise is done.]]
38 } 37 }
38 return: promise<void*>*; [[The promise that will be triggered.]]
39 } 39 }
40 timeout { 40 timeout {
41 [[Will trigger this promise when the specified timeout occur.]] 41 [[Will trigger this promise when the specified timeout occur.]]
42 params { 42 params {
43 @inout promise: promise<void*>*; [[The promise that will be triggered.]]
44 @in time: double; [[The time from now in second that the main loop will wait before triggering it.]] 43 @in time: double; [[The time from now in second that the main loop will wait before triggering it.]]
45 @in data: const(void)* @optional; [[The data to be given when the promise is done.]] 44 @in data: const(void)* @optional; [[The data to be given when the promise is done.]]
46 } 45 }
46 return: promise<void*>*; [[The promise that will be triggered.]]
47
47 } 48 }
48 } 49 }
49 events { 50 events {
diff --git a/src/tests/ecore/ecore_test_job.c b/src/tests/ecore/ecore_test_job.c
index 4f94be0e1c..05158c9460 100644
--- a/src/tests/ecore/ecore_test_job.c
+++ b/src/tests/ecore/ecore_test_job.c
@@ -22,7 +22,7 @@ START_TEST(ecore_test_job_promise)
22 22
23 ecore_init(); 23 ecore_init();
24 24
25 efl_loop_job(ecore_main_loop_get(), &job, &bob); 25 job = efl_loop_job(ecore_main_loop_get(), &bob);
26 eina_promise_then(job, &_ecore_promise_quit, NULL, &bob); 26 eina_promise_then(job, &_ecore_promise_quit, NULL, &bob);
27 27
28 ecore_main_loop_begin(); 28 ecore_main_loop_begin();
diff --git a/src/tests/ecore/ecore_test_timer.c b/src/tests/ecore/ecore_test_timer.c
index cdb0d2567e..35e900ecda 100644
--- a/src/tests/ecore/ecore_test_timer.c
+++ b/src/tests/ecore/ecore_test_timer.c
@@ -197,7 +197,7 @@ START_TEST(ecore_test_timeout)
197 ecore_init(); 197 ecore_init();
198 198
199 start = ecore_time_get(); 199 start = ecore_time_get();
200 efl_loop_timeout(ecore_main_loop_get(), &timeout, 0.2, &start); 200 timeout = efl_loop_timeout(ecore_main_loop_get(), 0.2, &start);
201 eina_promise_then(timeout, &_ecore_promise_quit, NULL, &bob); 201 eina_promise_then(timeout, &_ecore_promise_quit, NULL, &bob);
202 202
203 ecore_main_loop_begin(); 203 ecore_main_loop_begin();