summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorGuilherme Iscaro <iscaro@profusion.mobi>2017-08-30 17:25:28 -0300
committerGuilherme Iscaro <iscaro@profusion.mobi>2017-09-04 10:24:00 -0300
commitde4825a274e81dc3035c70b38c3086b6446cba19 (patch)
treed3fee9901edb4c469de6c7c66971194f34e87764 /src/lib/ecore
parentec27ceac2769165e0454d3bf7fce3df1d8b5b8cf (diff)
efl_io_copier: Use the new Eina_Future API.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/efl_io_copier.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/lib/ecore/efl_io_copier.c b/src/lib/ecore/efl_io_copier.c
index 0f744d6eb4..dc4d1e17dd 100644
--- a/src/lib/ecore/efl_io_copier.c
+++ b/src/lib/ecore/efl_io_copier.c
@@ -14,8 +14,8 @@ typedef struct _Efl_Io_Copier_Data
14{ 14{
15 Efl_Io_Reader *source; 15 Efl_Io_Reader *source;
16 Efl_Io_Writer *destination; 16 Efl_Io_Writer *destination;
17 Efl_Future *inactivity_timer; 17 Eina_Future *inactivity_timer;
18 Efl_Future *job; 18 Eina_Future *job;
19 Eina_Binbuf *buf; 19 Eina_Binbuf *buf;
20 Eina_Slice line_delimiter; 20 Eina_Slice line_delimiter;
21 size_t buffer_limit; 21 size_t buffer_limit;
@@ -71,38 +71,34 @@ static void _efl_io_copier_read(Eo *o, Efl_Io_Copier_Data *pd);
71 } \ 71 } \
72 while (0) 72 while (0)
73 73
74static void 74static Eina_Value
75_efl_io_copier_timeout_inactivity_cb(void *data, const Efl_Event *ev EINA_UNUSED) 75_efl_io_copier_timeout_inactivity_cb(Eo *o, const Eina_Value v)
76{ 76{
77 Eo *o = data;
78 Eina_Error err = ETIMEDOUT; 77 Eina_Error err = ETIMEDOUT;
79 efl_event_callback_call(o, EFL_IO_COPIER_EVENT_ERROR, &err); 78 efl_event_callback_call(o, EFL_IO_COPIER_EVENT_ERROR, &err);
79 return v;
80} 80}
81 81
82static void 82static void
83_efl_io_copier_timeout_inactivity_reschedule(Eo *o, Efl_Io_Copier_Data *pd) 83_efl_io_copier_timeout_inactivity_reschedule(Eo *o, Efl_Io_Copier_Data *pd)
84{ 84{
85 if (pd->inactivity_timer) efl_future_cancel(pd->inactivity_timer); 85 if (pd->inactivity_timer) eina_future_cancel(pd->inactivity_timer);
86 if (pd->timeout_inactivity <= 0.0) return; 86 if (pd->timeout_inactivity <= 0.0) return;
87 87
88 efl_future_use(&pd->inactivity_timer, efl_loop_timeout(efl_loop_get(o), pd->timeout_inactivity, o)); 88 efl_future_Eina_FutureXXX_then(o, efl_loop_Eina_FutureXXX_timeout(efl_loop_get(o), pd->timeout_inactivity),
89 efl_future_then(pd->inactivity_timer, _efl_io_copier_timeout_inactivity_cb, NULL, NULL, o); 89 .success = _efl_io_copier_timeout_inactivity_cb,
90 efl_future_link(o, pd->inactivity_timer); 90 .storage = &pd->inactivity_timer);
91} 91}
92 92
93static void 93static Eina_Value
94_efl_io_copier_job(void *data, const Efl_Event *ev EINA_UNUSED) 94_efl_io_copier_job(Eo *o, const Eina_Value v)
95{ 95{
96 Eo *o = data;
97 Efl_Io_Copier_Data *pd = efl_data_scope_get(o, MY_CLASS); 96 Efl_Io_Copier_Data *pd = efl_data_scope_get(o, MY_CLASS);
98 uint64_t old_read = pd->progress.read; 97 uint64_t old_read = pd->progress.read;
99 uint64_t old_written = pd->progress.written; 98 uint64_t old_written = pd->progress.written;
100 uint64_t old_total = pd->progress.total; 99 uint64_t old_total = pd->progress.total;
101 100
102 _COPIER_DBG(o, pd); 101 _COPIER_DBG(o, pd);
103 /* FIXME: Remove this wref once efl_promise is able to handle recursive cases. */
104 efl_wref_del(pd->job, &pd->job);
105 pd->job = NULL; /* XXX TODO this should be NULL-ified by efl_promise before calling this function */
106 102
107 efl_ref(o); 103 efl_ref(o);
108 104
@@ -117,7 +113,7 @@ _efl_io_copier_job(void *data, const Efl_Event *ev EINA_UNUSED)
117 (old_total != pd->progress.total)) 113 (old_total != pd->progress.total))
118 { 114 {
119 efl_event_callback_call(o, EFL_IO_COPIER_EVENT_PROGRESS, NULL); 115 efl_event_callback_call(o, EFL_IO_COPIER_EVENT_PROGRESS, NULL);
120 if (pd->closed) return; /* cb may call close */ 116 if (pd->closed) return v; /* cb may call close */
121 _efl_io_copier_timeout_inactivity_reschedule(o, pd); 117 _efl_io_copier_timeout_inactivity_reschedule(o, pd);
122 } 118 }
123 119
@@ -129,6 +125,7 @@ _efl_io_copier_job(void *data, const Efl_Event *ev EINA_UNUSED)
129 } 125 }
130 126
131 efl_unref(o); 127 efl_unref(o);
128 return v;
132} 129}
133 130
134static void 131static void
@@ -136,9 +133,9 @@ _efl_io_copier_job_schedule(Eo *o, Efl_Io_Copier_Data *pd)
136{ 133{
137 if (pd->job) return; 134 if (pd->job) return;
138 135
139 efl_future_use(&pd->job, efl_loop_job(efl_loop_get(o), o)); 136 efl_future_Eina_FutureXXX_then(o, efl_loop_Eina_FutureXXX_job(efl_loop_get(o)),
140 efl_future_then(pd->job, _efl_io_copier_job, NULL, NULL, o); 137 .success = _efl_io_copier_job,
141 efl_future_link(o, pd->job); 138 .storage = &pd->job);
142} 139}
143 140
144/* NOTE: the returned slice may be smaller than requested since the 141/* NOTE: the returned slice may be smaller than requested since the
@@ -473,7 +470,7 @@ _efl_io_copier_destination_closed(void *data, const Efl_Event *event EINA_UNUSED
473 else 470 else
474 { 471 {
475 Eina_Error err = EBADF; 472 Eina_Error err = EBADF;
476 if (pd->inactivity_timer) efl_future_cancel(pd->inactivity_timer); 473 if (pd->inactivity_timer) eina_future_cancel(pd->inactivity_timer);
477 WRN("copier %p destination %p closed with %zd bytes pending...", 474 WRN("copier %p destination %p closed with %zd bytes pending...",
478 o, pd->destination, eina_binbuf_length_get(pd->buf)); 475 o, pd->destination, eina_binbuf_length_get(pd->buf));
479 efl_event_callback_call(o, EFL_IO_COPIER_EVENT_ERROR, &err); 476 efl_event_callback_call(o, EFL_IO_COPIER_EVENT_ERROR, &err);
@@ -631,10 +628,10 @@ _efl_io_copier_efl_io_closer_close(Eo *o, Efl_Io_Copier_Data *pd)
631 } 628 }
632 629
633 if (pd->job) 630 if (pd->job)
634 efl_future_cancel(pd->job); 631 eina_future_cancel(pd->job);
635 632
636 if (pd->inactivity_timer) 633 if (pd->inactivity_timer)
637 efl_future_cancel(pd->inactivity_timer); 634 eina_future_cancel(pd->inactivity_timer);
638 635
639 if (!pd->done) 636 if (!pd->done)
640 efl_io_copier_done_set(o, EINA_TRUE); 637 efl_io_copier_done_set(o, EINA_TRUE);
@@ -799,7 +796,7 @@ _efl_io_copier_done_set(Eo *o, Efl_Io_Copier_Data *pd, Eina_Bool value)
799 if (pd->done == value) return; 796 if (pd->done == value) return;
800 pd->done = value; 797 pd->done = value;
801 if (!value) return; 798 if (!value) return;
802 if (pd->inactivity_timer) efl_future_cancel(pd->inactivity_timer); 799 if (pd->inactivity_timer) eina_future_cancel(pd->inactivity_timer);
803 efl_event_callback_call(o, EFL_IO_COPIER_EVENT_DONE, NULL); 800 efl_event_callback_call(o, EFL_IO_COPIER_EVENT_DONE, NULL);
804} 801}
805 802
@@ -844,10 +841,10 @@ _efl_io_copier_efl_object_destructor(Eo *o, Efl_Io_Copier_Data *pd)
844 _COPIER_DBG(o, pd); 841 _COPIER_DBG(o, pd);
845 842
846 if (pd->job) 843 if (pd->job)
847 efl_future_cancel(pd->job); 844 eina_future_cancel(pd->job);
848 845
849 if (pd->inactivity_timer) 846 if (pd->inactivity_timer)
850 efl_future_cancel(pd->inactivity_timer); 847 eina_future_cancel(pd->inactivity_timer);
851 848
852 if (efl_io_closer_close_on_destructor_get(o) && 849 if (efl_io_closer_close_on_destructor_get(o) &&
853 (!efl_io_closer_closed_get(o))) 850 (!efl_io_closer_closed_get(o)))