barbieri pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=bb5f91273c68e350fbe4aeeb282942c1bd017178
commit bb5f91273c68e350fbe4aeeb282942c1bd017178 Author: Gustavo Sverzut Barbieri <[email protected]> Date: Wed Dec 7 16:55:42 2016 -0200 efl_io_buffered_stream: property and event 'progress' useful to get feedback on when data was actually sent/received, and how much. --- src/lib/ecore/efl_io_buffered_stream.c | 27 +++++++++++++++++++++++++++ src/lib/ecore/efl_io_buffered_stream.eo | 10 ++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/lib/ecore/efl_io_buffered_stream.c b/src/lib/ecore/efl_io_buffered_stream.c index f75c033..69ea69c 100644 --- a/src/lib/ecore/efl_io_buffered_stream.c +++ b/src/lib/ecore/efl_io_buffered_stream.c @@ -35,6 +35,13 @@ _efl_io_buffered_stream_error(void *data, const Efl_Event *event) } static void +_efl_io_buffered_stream_copier_progress(void *data, const Efl_Event *event EINA_UNUSED) +{ + Eo *o = data; + efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_PROGRESS, NULL); +} + +static void _efl_io_buffered_stream_incoming_can_read_changed(void *data, const Efl_Event *event) { Eo *o = data; @@ -69,6 +76,7 @@ _efl_io_buffered_stream_receiver_done(void *data, const Efl_Event *event EINA_UN } EFL_CALLBACKS_ARRAY_DEFINE(_efl_io_buffered_stream_receiver_cbs, + { EFL_IO_COPIER_EVENT_PROGRESS, _efl_io_buffered_stream_copier_progress }, { EFL_IO_COPIER_EVENT_DONE, _efl_io_buffered_stream_receiver_done }, { EFL_IO_COPIER_EVENT_LINE, _efl_io_buffered_stream_receiver_line }, { EFL_IO_COPIER_EVENT_ERROR, _efl_io_buffered_stream_error }); @@ -90,12 +98,16 @@ _efl_io_buffered_stream_sender_done(void *data, const Efl_Event *event EINA_UNUS { Eo *o = data; Efl_Io_Buffered_Stream_Data *pd = efl_data_scope_get(o, MY_CLASS); + efl_ref(o); + efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_PROGRESS, NULL); efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_WRITE_FINISHED, NULL); if (efl_io_copier_done_get(pd->receiver)) efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_FINISHED, NULL); + efl_unref(o); } EFL_CALLBACKS_ARRAY_DEFINE(_efl_io_buffered_stream_sender_cbs, + { EFL_IO_COPIER_EVENT_PROGRESS, _efl_io_buffered_stream_copier_progress }, { EFL_IO_COPIER_EVENT_DONE, _efl_io_buffered_stream_sender_done }, { EFL_IO_COPIER_EVENT_ERROR, _efl_io_buffered_stream_error }); @@ -262,10 +274,13 @@ _efl_io_buffered_stream_efl_io_reader_eos_set(Eo *o, Efl_Io_Buffered_Stream_Data pd->eos = is_eos; if (!is_eos) return; + efl_ref(o); + efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_PROGRESS, NULL); efl_event_callback_call(o, EFL_IO_READER_EVENT_EOS, NULL); efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_READ_FINISHED, NULL); if (efl_io_copier_done_get(pd->sender)) efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_FINISHED, NULL); + efl_unref(o); } EOLIAN static Eina_Error @@ -482,6 +497,18 @@ _efl_io_buffered_stream_pending_read_get(Eo *o EINA_UNUSED, Efl_Io_Buffered_Stre return efl_io_queue_usage_get(pd->incoming); } +EOLIAN static void +_efl_io_buffered_stream_progress_get(Eo *o EINA_UNUSED, Efl_Io_Buffered_Stream_Data *pd, size_t *pr, size_t *pw) +{ + size_t r = 0, w = 0; + + if (pd->sender) efl_io_copier_progress_get(pd->sender, NULL, &w, NULL); + if (pd->receiver) efl_io_copier_progress_get(pd->receiver, &r, NULL, NULL); + + if (pr) *pr = r; + if (pw) *pw = w; +} + EOLIAN static Eina_Bool _efl_io_buffered_stream_slice_get(Eo *o EINA_UNUSED, Efl_Io_Buffered_Stream_Data *pd, Eina_Slice *slice) { diff --git a/src/lib/ecore/efl_io_buffered_stream.eo b/src/lib/ecore/efl_io_buffered_stream.eo index 28049c4..e8a7b52 100644 --- a/src/lib/ecore/efl_io_buffered_stream.eo +++ b/src/lib/ecore/efl_io_buffered_stream.eo @@ -146,6 +146,15 @@ class Efl.Io.Buffered_Stream (Efl.Loop_User, Efl.Io.Reader, Efl.Io.Writer, Efl.I } } + @property progress { + [[How many bytes were written and read.]] + get { } + values { + read_bytes: size; [[Bytes that were read until now]] + written_bytes: size; [[Bytes that were written until now]] + } + } + slice_get { // TODO: property and return of Eina.Slice (not pointer) [[Get a temporary access to input queue's internal read memory. @@ -231,6 +240,7 @@ class Efl.Io.Buffered_Stream (Efl.Loop_User, Efl.Io.Reader, Efl.Io.Writer, Efl.I read,finished; [[Same as @Efl.Io.Reader "eos", for consistency.]] finished; [[Both read and write are finished.]] error: Eina.Error; [[An error happened and the I/O stopped]] + progress; [[Property @.progress changed]] slice,changed; [[The read-slice returned by @.slice_get may have changed.]] line: ptr(const(Eina.Slice)); [[If @.line_delimiter is set, will be emitted with current line. The memory is only valid during event callback dispatched and should not be modified. Note that the line slice may not be inside @.slice_get, don't assume that!]] } --
