summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-12-19 16:35:24 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-12-20 12:42:34 -0800
commit9b5155c9f135f9ef450a817979f5884352b2d4c0 (patch)
tree69775932d4aebc2a7977e074f352bcfdae516c3f /src/lib
parentce56f32270c2f75adab022b701d3bdcbbbc3fb44 (diff)
downloadefl-9b5155c9f135f9ef450a817979f5884352b2d4c0.tar.gz
ecore: make efl_loop_promise_new a function of Efl.Loop_Consumer.
I am not sure this is the right way to do it as binding would have to likely to bind it manually. Reviewed-by: Lauro Neto <Lauro Moura <lauromoura@expertisesolutions.com.br>> Differential Revision: https://phab.enlightenment.org/D7492
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ecore/Ecore_Eo.h13
-rw-r--r--src/lib/ecore/efl_loop.c7
-rw-r--r--src/lib/ecore/efl_loop_consumer.c47
-rw-r--r--src/lib/ecore/efl_loop_consumer.eo17
-rw-r--r--src/lib/ecore/efl_thread.c4
-rw-r--r--src/lib/ecore_con/efl_net_control_access_point-connman.c4
-rw-r--r--src/lib/ecore_con/efl_net_control_technology-connman.c6
-rw-r--r--src/lib/ecore_con/efl_net_ip_address.c2
-rw-r--r--src/lib/eio/efl_io_manager.c18
-rw-r--r--src/lib/eio/eio_model.c4
-rw-r--r--src/lib/eldbus/eldbus_model_connection.c2
-rw-r--r--src/lib/eldbus/eldbus_model_object.c2
-rw-r--r--src/lib/eldbus/eldbus_model_private.h1
-rw-r--r--src/lib/eldbus/eldbus_model_proxy.c3
-rw-r--r--src/lib/elementary/efl_selection_manager.c4
-rw-r--r--src/lib/eo/eina_types.eot2
16 files changed, 92 insertions, 44 deletions
diff --git a/src/lib/ecore/Ecore_Eo.h b/src/lib/ecore/Ecore_Eo.h
index 33e864f267..a070cd1b60 100644
--- a/src/lib/ecore/Ecore_Eo.h
+++ b/src/lib/ecore/Ecore_Eo.h
@@ -62,19 +62,6 @@ EAPI int efl_loop_exit_code_process(Eina_Value *value);
*/
EAPI Eina_Future_Scheduler *efl_loop_future_scheduler_get(const Eo *obj);
-/**
- * @brief Create a promise attached to the current loop
- *
- * @param[in] An object which will provide a loop, either by being a loop or a loop consumer
- * @param cancel_cb A callback used to inform that the promise was canceled. Use
- * this callback to @c free @p data. @p cancel_cb must not be @c NULL !
- * @param data Data to @p cancel_cb.
- * @return A promise or @c NULL on error.
- *
- * @see eina_promise_new()
- */
-EAPI Eina_Promise *efl_loop_promise_new(const Eo *obj, Eina_Promise_Cancel_Cb cancel_cb, const void *data);
-
#include "efl_loop_fd.eo.h"
#include "efl_loop_handler.eo.h"
diff --git a/src/lib/ecore/efl_loop.c b/src/lib/ecore/efl_loop.c
index 1ef212f731..ab6d198316 100644
--- a/src/lib/ecore/efl_loop.c
+++ b/src/lib/ecore/efl_loop.c
@@ -902,11 +902,4 @@ efl_loop_future_scheduler_get(const Eo *obj)
#define EFL_LOOP_EXTRA_OPS \
EFL_OBJECT_OP_FUNC(efl_loop_message_process, _efl_loop_message_process)
-EAPI Eina_Promise *
-efl_loop_promise_new(const Eo *obj, Eina_Promise_Cancel_Cb cancel_cb, const void *data)
-{
- return eina_promise_new(efl_loop_future_scheduler_get(obj),
- cancel_cb, data);
-}
-
#include "efl_loop.eo.c"
diff --git a/src/lib/ecore/efl_loop_consumer.c b/src/lib/ecore/efl_loop_consumer.c
index 29e94ed52d..f88c3e4473 100644
--- a/src/lib/ecore/efl_loop_consumer.c
+++ b/src/lib/ecore/efl_loop_consumer.c
@@ -50,4 +50,51 @@ _efl_loop_consumer_future_rejected(Eo *obj, Efl_Loop_Consumer_Data *pd EINA_UNUS
return eina_future_rejected(efl_loop_future_scheduler_get(obj), error);
}
+typedef struct _Efl_Loop_Consumer_Promise Efl_Loop_Consumer_Promise;
+struct _Efl_Loop_Consumer_Promise
+{
+ EflLoopConsumerPromiseCancel func;
+ Eina_Free_Cb free;
+ void *data;
+ Eo *obj;
+};
+
+static void
+_cancel_free(void *data)
+{
+ Efl_Loop_Consumer_Promise *lcp = data;
+
+ if (lcp->free) lcp->free(lcp->data);
+ efl_unref(lcp->obj);
+ free(lcp);
+}
+
+static void
+_cancel_triggered(void *data, const Eina_Promise *p)
+{
+ Efl_Loop_Consumer_Promise *lcp = data;
+
+ if (lcp->func) lcp->func(lcp->data, lcp->obj, p);
+}
+
+static Eina_Promise *
+_efl_loop_consumer_promise_new(Eo *obj, Efl_Loop_Consumer_Data *pd,
+ void *cancel_data, EflLoopConsumerPromiseCancel cancel, Eina_Free_Cb cancel_free_cb)
+{
+ Efl_Loop_Consumer_Promise *lcp;
+ Eina_Promise *p;
+
+ lcp = calloc(1, sizeof (Efl_Loop_Consumer_Promise));
+ if (!lcp) return NULL;
+
+ lcp->func = cancel;
+ lcp->data = cancel_data;
+ lcp->free = cancel_free_cb;
+ lcp->obj = efl_ref(obj);
+
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _cancel_triggered, lcp);
+ eina_promise_data_free_cb_set(p, _cancel_free);
+ return p;
+}
+
#include "efl_loop_consumer.eo.c"
diff --git a/src/lib/ecore/efl_loop_consumer.eo b/src/lib/ecore/efl_loop_consumer.eo
index 4d7484e13c..ed9d351faa 100644
--- a/src/lib/ecore/efl_loop_consumer.eo
+++ b/src/lib/ecore/efl_loop_consumer.eo
@@ -1,3 +1,11 @@
+function EflLoopConsumerPromiseCancel {
+ [[EflLoopConsumerPromiseCancel function callback called when a promise is cancelled.]]
+ params {
+ @in consumer: Efl.Loop_Consumer; [[The consumer that was used to create the promise.]]
+ @in dead_promise: const(ptr(Eina.Promise)); [[The promise that was just cancelled.]]
+ }
+};
+
class Efl.Loop_Consumer (Efl.Object)
{
[[An Efl.Loop_Consumer is a class which requires one of the parents to provide
@@ -26,6 +34,15 @@ class Efl.Loop_Consumer (Efl.Object)
}
return: future<Eina.Error>;
}
+ promise_new {
+ [[Create a new promise with the scheduler coming from the loop provided by this object.
+
+ Note: You should not use eina_promise_data_set as this function rely on controlling the promise data.]]
+ params {
+ cancel: EflLoopConsumerPromiseCancel; [[Callback called when the promise is being cancelled.]]
+ }
+ return: ptr(Eina.Promise) @owned; [[The new promise.]]
+ }
}
implements {
Efl.Object.parent { set; }
diff --git a/src/lib/ecore/efl_thread.c b/src/lib/ecore/efl_thread.c
index f72aa07231..c44e59b73a 100644
--- a/src/lib/ecore/efl_thread.c
+++ b/src/lib/ecore/efl_thread.c
@@ -412,7 +412,7 @@ _cb_thread_parent_ctrl_out(void *data, const Efl_Event *event EINA_UNUSED)
//////////////////////////////////////////////////////////////////////////
static void
-_run_cancel_cb(void *data, const Eina_Promise *dead_promise EINA_UNUSED)
+_run_cancel_cb(void *data, Efl_Loop_Consumer *consumer EINA_UNUSED, const Eina_Promise *dead_promise EINA_UNUSED)
{
Eo *obj = data;
Efl_Thread_Data *pd = efl_data_scope_get(obj, MY_CLASS);
@@ -777,7 +777,7 @@ _efl_thread_efl_task_run(Eo *obj, Efl_Thread_Data *pd)
}
pd->thdat = thdat;
pd->run = EINA_TRUE;
- pd->promise = efl_loop_promise_new(obj, _run_cancel_cb, obj);
+ pd->promise = efl_loop_promise_new(obj, obj, _run_cancel_cb, NULL);
return efl_future_then(obj, eina_future_new(pd->promise));
}
diff --git a/src/lib/ecore_con/efl_net_control_access_point-connman.c b/src/lib/ecore_con/efl_net_control_access_point-connman.c
index a54cce2a50..32394ab989 100644
--- a/src/lib/ecore_con/efl_net_control_access_point-connman.c
+++ b/src/lib/ecore_con/efl_net_control_access_point-connman.c
@@ -751,7 +751,7 @@ _efl_net_control_access_point_connect_cb(void *data, const Eldbus_Message *msg,
}
static void
-_efl_net_control_access_point_connect_promise_del(void *data, const Eina_Promise *dead_ptr)
+_efl_net_control_access_point_connect_promise_del(void *data, Efl_Loop_Consumer *consumer EINA_UNUSED, const Eina_Promise *dead_ptr)
{
Eldbus_Pending *p = data;
Efl_Net_Control_Access_Point_Data *pd;
@@ -773,7 +773,7 @@ _efl_net_control_access_point_connect(Eo *o, Efl_Net_Control_Access_Point_Data *
Eina_Promise *promise;
Eina_Future *f = NULL;
- promise = efl_loop_promise_new(o, _efl_net_control_access_point_connect_promise_del, o);
+ promise = efl_loop_promise_new(o, o, _efl_net_control_access_point_connect_promise_del, NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(promise, NULL);
f = eina_future_new(promise);
diff --git a/src/lib/ecore_con/efl_net_control_technology-connman.c b/src/lib/ecore_con/efl_net_control_technology-connman.c
index 92660de83f..a006923e61 100644
--- a/src/lib/ecore_con/efl_net_control_technology-connman.c
+++ b/src/lib/ecore_con/efl_net_control_technology-connman.c
@@ -371,9 +371,9 @@ _efl_net_control_technology_scan_cb(void *data, const Eldbus_Message *msg, Eldbu
}
static void
-_efl_net_control_technology_scan_promise_del(void *data, const Eina_Promise *dead_ptr)
+_efl_net_control_technology_scan_promise_del(void *data, Efl_Loop_Consumer *consumer, const Eina_Promise *dead_ptr)
{
- Eldbus_Pending *p = data;
+ Eldbus_Pending *p = consumer;
Efl_Net_Control_Technology_Data *pd;
Eo *o;
@@ -399,7 +399,7 @@ _efl_net_control_technology_scan(Eo *o, Efl_Net_Control_Technology_Data *pd)
Eina_Promise *promise;
Eina_Future *f = NULL;
- promise = efl_loop_promise_new(o, _efl_net_control_technology_scan_promise_del, NULL);
+ promise = efl_loop_promise_new(o, NULL, _efl_net_control_technology_scan_promise_del, NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(promise, NULL);
f = eina_future_new(promise);
diff --git a/src/lib/ecore_con/efl_net_ip_address.c b/src/lib/ecore_con/efl_net_ip_address.c
index b6d9317dee..46fe75bd08 100644
--- a/src/lib/ecore_con/efl_net_ip_address.c
+++ b/src/lib/ecore_con/efl_net_ip_address.c
@@ -573,7 +573,7 @@ _efl_net_ip_address_resolve(Eo *cls EINA_UNUSED, void *pd EINA_UNUSED, const cha
ctx->thread = efl_net_ip_resolve_async_new(host, port, &hints, _efl_net_ip_address_resolve_done, ctx);
EINA_SAFETY_ON_NULL_GOTO(ctx->thread, error_thread);
- ctx->promise = efl_loop_promise_new(efl_main_loop_get(), _efl_net_ip_address_resolve_del, ctx);
+ ctx->promise = eina_promise_new(efl_loop_future_scheduler_get(efl_main_loop_get()), _efl_net_ip_address_resolve_del, ctx);
EINA_SAFETY_ON_NULL_GOTO(ctx->promise, error_promise);
free(str);
diff --git a/src/lib/eio/efl_io_manager.c b/src/lib/eio/efl_io_manager.c
index 6ac1746621..9dcdfeeedf 100644
--- a/src/lib/eio/efl_io_manager.c
+++ b/src/lib/eio/efl_io_manager.c
@@ -119,7 +119,7 @@ _efl_io_manager_direct_ls(const Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
@@ -162,7 +162,7 @@ _efl_io_manager_stat_ls(const Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
@@ -204,7 +204,7 @@ _efl_io_manager_ls(const Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
@@ -256,7 +256,7 @@ _efl_io_manager_stat(const Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
@@ -285,7 +285,7 @@ _efl_io_manager_xattr_ls(const Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
@@ -336,7 +336,7 @@ _efl_io_manager_xattr_set(Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
@@ -366,7 +366,7 @@ _efl_io_manager_xattr_get(const Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
@@ -405,7 +405,7 @@ _efl_io_manager_open(const Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
@@ -431,7 +431,7 @@ _efl_io_manager_close(const Eo *obj,
Eina_Future *future;
Eio_File *h;
- p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
if (!p) return NULL;
future = eina_future_new(p);
diff --git a/src/lib/eio/eio_model.c b/src/lib/eio/eio_model.c
index 309af24a01..c6e03e663b 100644
--- a/src/lib/eio/eio_model.c
+++ b/src/lib/eio/eio_model.c
@@ -417,7 +417,7 @@ _build_delay(Efl_Loop *loop)
{
Eina_Promise *p;
- p = efl_loop_promise_new(loop, _cancel_request, NULL);
+ p = eina_promise_new(efl_loop_future_scheduler_get(loop), _cancel_request, NULL);
if (!delayed_queue)
{
@@ -682,7 +682,7 @@ _eio_model_efl_model_property_set(Eo *obj,
if (finalized)
{
- Eina_Promise *p = efl_loop_promise_new(obj, _efl_io_manager_future_cancel, NULL);
+ Eina_Promise *p = eina_promise_new(efl_loop_future_scheduler_get(obj), _efl_io_manager_future_cancel, NULL);
f = eina_future_new(p);
pd->request.move = eio_file_move(pd->path, path,
diff --git a/src/lib/eldbus/eldbus_model_connection.c b/src/lib/eldbus/eldbus_model_connection.c
index 175afcd924..a8f2d52478 100644
--- a/src/lib/eldbus/eldbus_model_connection.c
+++ b/src/lib/eldbus/eldbus_model_connection.c
@@ -70,7 +70,7 @@ _eldbus_model_connection_efl_model_children_slice_get(Eo *obj,
return efl_loop_future_resolved(obj, v);
}
- p = efl_loop_promise_new(obj, _eldbus_eina_promise_cancel, NULL);
+ p = efl_loop_promise_new(obj, NULL, _eldbus_eina_promise_cancel, NULL);
slice = calloc(1, sizeof (Eldbus_Children_Slice_Promise));
slice->p = p;
diff --git a/src/lib/eldbus/eldbus_model_object.c b/src/lib/eldbus/eldbus_model_object.c
index 3759fc3f8f..b975514cbd 100644
--- a/src/lib/eldbus/eldbus_model_object.c
+++ b/src/lib/eldbus/eldbus_model_object.c
@@ -127,7 +127,7 @@ _eldbus_model_object_efl_model_children_slice_get(Eo *obj EINA_UNUSED,
return efl_loop_future_resolved(obj, v);
}
- p = efl_loop_promise_new(obj, _eldbus_eina_promise_cancel, NULL);
+ p = efl_loop_promise_new(obj, NULL, _eldbus_eina_promise_cancel, NULL);
slice = calloc(1, sizeof(struct _Eldbus_Children_Slice_Promise));
slice->p = p;
diff --git a/src/lib/eldbus/eldbus_model_private.h b/src/lib/eldbus/eldbus_model_private.h
index 3f6685921b..e58a25d30d 100644
--- a/src/lib/eldbus/eldbus_model_private.h
+++ b/src/lib/eldbus/eldbus_model_private.h
@@ -41,6 +41,7 @@ extern int eldbus_model_log_dom;
static inline void
_eldbus_eina_promise_cancel(void *data EINA_UNUSED,
+ Efl_Loop_Consumer *consumer EINA_UNUSED,
const Eina_Promise *dead_ptr EINA_UNUSED)
{
}
diff --git a/src/lib/eldbus/eldbus_model_proxy.c b/src/lib/eldbus/eldbus_model_proxy.c
index 4da54ad7f4..ca5cfc3bf2 100644
--- a/src/lib/eldbus/eldbus_model_proxy.c
+++ b/src/lib/eldbus/eldbus_model_proxy.c
@@ -230,6 +230,7 @@ eldbus_model_proxy_property_check(Eldbus_Model_Proxy_Data *pd,
static void
_eldbus_model_proxy_cancel_cb(void *data,
+ Efl_Loop_Consumer *consumer EINA_UNUSED,
const Eina_Promise *dead_promise EINA_UNUSED)
{
Eldbus_Model_Proxy_Property_Set_Data *sd = data;
@@ -293,7 +294,7 @@ _eldbus_model_proxy_efl_model_property_set(Eo *obj EINA_UNUSED,
if (!data) goto on_error;
data->pd = pd;
- data->promise = efl_loop_promise_new(obj, _eldbus_model_proxy_cancel_cb, data);
+ data->promise = efl_loop_promise_new(obj, data, _eldbus_model_proxy_cancel_cb, NULL);
data->property = eina_stringshare_add(property);
if (!(data->value = eina_value_dup(value))) goto on_error;
diff --git a/src/lib/elementary/efl_selection_manager.c b/src/lib/elementary/efl_selection_manager.c
index 42d66a9918..d0c4463a18 100644
--- a/src/lib/elementary/efl_selection_manager.c
+++ b/src/lib/elementary/efl_selection_manager.c
@@ -224,7 +224,7 @@ _sel_manager_seat_selection_init(Efl_Selection_Manager_Data *pd, unsigned int se
}
static void
-_sel_manager_promise_cancel(void *data, const Eina_Promise *dead_future EINA_UNUSED)
+_sel_manager_promise_cancel(void *data, Efl_Loop_Consumer *consumer, const Eina_Promise *dead_future EINA_UNUSED)
{
Sel_Manager_Selection_Lost *sel_lost = data;
sel_lost->seat_sel->sel_lost_list = eina_list_remove(
@@ -247,7 +247,7 @@ _update_sel_lost_list(Efl_Object *obj, Efl_Selection_Type type,
sel_lost->seat_sel = seat_sel;
seat_sel->sel_lost_list = eina_list_append(seat_sel->sel_lost_list, sel_lost);
- p = efl_loop_promise_new(obj, _sel_manager_promise_cancel, NULL);
+ p = efl_loop_promise_new(obj, NULL, _sel_manager_promise_cancel, NULL);
eina_promise_data_set(p, sel_lost);
if (!p) return NULL;
sel_lost->promise = p;
diff --git a/src/lib/eo/eina_types.eot b/src/lib/eo/eina_types.eot
index d08382c1cd..d0b3dcbcb9 100644
--- a/src/lib/eo/eina_types.eot
+++ b/src/lib/eo/eina_types.eot
@@ -99,6 +99,8 @@ struct @extern Eina.Stat {
ctimensec: ulong; [[The nano version of the timestmap when the file was created]]
}
+struct @extern Eina.Promise; [[Eina promise type]]
+
/* FIXME: This definitely shouldn't be here. */
type Efl.Event_Cb: __undefined_type; [[Efl event callback type]]