On Wed, Sep 6, 2017 at 5:18 AM, Jean-Philippe André <j...@videolan.org> wrote:
> 2017-09-06 16:33 GMT+09:00 Cedric Bail <ced...@ddlm.me>:
>
>> > -------- Original Message --------
>> > Subject: [E-devel] Proposal: automatic Event->Promise/Future
>> > Local Time: September 5, 2017 6:20 AM
>> > UTC Time: September 5, 2017 1:20 PM
>> > From: barbi...@gmail.com
>> > To: edevel <enlightenment-devel@lists.sourceforge.net>
>> >
>> > In many cases we use events as a single shot event, then we
>> > efl_event_callback_add(), wait for the callback, then
>> > efl_event_callback_del()...
>> >
>> > With the introduction of Promise/Future pair it would be nice to have
>> > that automated, for example Efl.Io.Copier produces an event "done".
>> > Most of the times when you"re using Efl.Io.Copier you only want to
>> > know when it was finished or when it produced an error (event:
>> > "error").
>> >
>> > Then it would improve usability to do something like:
>> >
>> > Eina_Future *f = efl_future_event(copier,
>> > EFL_IO_COPIER_EVENT_DONE, /* success event */
>> > EFL_IO_COPIER_EVENT_ERROR); /* error event */
>> > eina_future_chain(f, do_something, do_something_else, on_error);
>> >
>> > and all would be handled for you: add/del callbacks, resolve the
>> > promise and all.
>>
>> Just a potential idea here, why not reverse the problem. Instead of
>> implementing this future on top of this events, why not have a future and
>> have this events automatically create a future when someone register a
>> callback on it. This avoid completely the problem of dealing with the void*
>> and seems really simple to me.
>>
>> > This is doable, EXCEPT events are "void *" and may go away when the
>> > event callback returns. However eina_promise_resolve() will postpone
>> > the future chain to another mainloop iteration -- thus needs a COPY.
>> > How to copy "void *"?
>>
>> Filling the Eina_Value_Type from the eolian type seems quite complex to
>> me. It would require to give a function to do the copy and destruction of
>> the structure in eolian most likely. Also I am not sure it would work in
>> all case, some object that we put in the structure are really build to only
>> be alive for the duration of the callback (I am thinking about input event
>> here).
>
>
> Yeah I was also thinking the same. Input events should be duplicated with a
> specific function call because they are internally reused a lot.

This is doable by EINA_VALUE_TYPE_STRUCT + Eina_Value_Struct_Desc with
custom Eina_Value_Struct_Operations, see:

https://git.enlightenment.org/core/efl.git/tree/src/lib/eina/eina_value.h#n2884

But you also have another option here, that is to simply use copies as
usual/malloc and free, then operations are not required and will be
done automatically on eina_value_setup(&my_copy_value) and
eina_value_flush(&my_copy_value).

when you call eina_value_type_copy(type, src, dst) it won't modify
src, just read its stuff. Then this is doable:

   const Eina_Value_Struct src_st = {
      .desc = EINA_VALUE_STRUCT_DESC_EFL_INPUT, // ops
(malloc/free/..) and members array
      .memory = input, // what your event provides
   };
   const Eina_Value src = {
      .type = EINA_VALUE_TYPE_STRUCT,
      .value.ptr = &src_st, // struct is actually  "struct
description", not the final structure itself
                          // which is at "Eina_Value_Struct->memory"
   };
   Eina_Value dst;

   eina_value_copy(&src, &dst);
   eina_promise_resolve(p, dst); // takes owneship of "dst"

   ...

   eina_value_flush(&dst); // done by eina_future when it becomes unused


If EINA_VALUE_STRUCT_DESC_EFL_INPUT does provide "ops", then it may
use mempool or something like that. Otherwise it will use regular
"malloc() + free()". ONLY to "dst", "src" is left untouched there (see
"const" to highlight that).

Each described member in EINA_VALUE_STRUCT_DESC_EFL_INPUT will be
walked and the provided Eina_Value_Type->copy is used... like for
string it will strdup(), for stringshare it will
eina_stringshare_ref(), for Eo it will efl_ref()... for basic types
it's "memcpy()". If you put a custom type there, your custom "copy"
will be called.


-- 
Gustavo Sverzut Barbieri
--------------------------------------
Mobile: +55 (16) 99354-9890

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to