summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-09-13 15:52:40 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-09-13 15:53:00 -0700
commitb9ef9af74a4cc401c02468f20a68659b9b2a1235 (patch)
tree09740386a9da902389c689d0b96524bf09dd3d73
parentba34b998eb6920fe0dbccd1037e8344c028754ec (diff)
downloadefl-b9ef9af74a4cc401c02468f20a68659b9b2a1235.tar.gz
eio: migrate efl.io.manager.open to use Eina_Future.
-rw-r--r--src/lib/eio/efl_io_manager.c36
-rw-r--r--src/lib/eio/efl_io_manager.eo2
-rw-r--r--src/tests/eio/eio_test_manager.c32
-rw-r--r--src/tests/eio/eio_test_manager_xattr.c2
4 files changed, 42 insertions, 30 deletions
diff --git a/src/lib/eio/efl_io_manager.c b/src/lib/eio/efl_io_manager.c
index 75fa2289b0..0b7fb3def9 100644
--- a/src/lib/eio/efl_io_manager.c
+++ b/src/lib/eio/efl_io_manager.c
@@ -519,43 +519,43 @@ _efl_io_manager_xattr_get(Eo *obj,
}
static void
-_file_open_cb(void *data, Eio_File *handler, Eina_File *file)
+_future_file_open_cb(void *data, Eio_File *handler EINA_UNUSED, Eina_File *file)
{
- Efl_Promise *p = data;
-
- efl_event_callback_array_del(p, promise_handling(), handler);
-
- efl_promise_value_set(p, eina_file_dup(file), EINA_FREE_CB(eina_file_close));
+ Eina_Promise *p = data;
+ Eina_Value v = EINA_VALUE_EMPTY;
- efl_del(p);
+ eina_value_setup(&v, EINA_VALUE_TYPE_FILE);
+ eina_value_set(&v, file);
+ eina_promise_resolve(p, v);
+ eina_value_flush(&v);
}
-static Efl_Future *
+static Eina_Future *
_efl_io_manager_open(Eo *obj,
Efl_Io_Manager_Data *pd EINA_UNUSED,
const char *path,
Eina_Bool shared)
{
- Efl_Promise *p;
+ Eina_Promise *p;
+ Eina_Future *future;
Eio_File *h;
- Eo *loop = efl_loop_get(obj);
- p = efl_add(EFL_PROMISE_CLASS, loop);
+ 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);
h = eio_file_open(path, shared,
- _file_open_cb,
- _file_error_cb,
+ _future_file_open_cb,
+ _future_file_error_cb,
p);
-
if (!h) goto end;
+ eina_promise_data_set(p, h);
- efl_event_callback_array_add(p, promise_handling(), h);
- return efl_promise_future_get(p);
+ return efl_future_Eina_FutureXXX_then(obj, future);
end:
- efl_del(p);
- return NULL;
+ return future;
}
static Eina_Future *
diff --git a/src/lib/eio/efl_io_manager.eo b/src/lib/eio/efl_io_manager.eo
index a4e8aaddc5..b1b5d85806 100644
--- a/src/lib/eio/efl_io_manager.eo
+++ b/src/lib/eio/efl_io_manager.eo
@@ -83,7 +83,7 @@ class Efl.Io.Manager (Efl.Loop_User)
@in path: string; [[Path to file]]
@in shared: bool; [[$true if the file can be accessed by others, $false otherwise]]
}
- return: future<Eina.File>; [[Eina file handle]]
+ return: own(ptr(Eina.Future)); [[Eina file handle]]
}
close {
[[Closes an open Eina.File.]]
diff --git a/src/tests/eio/eio_test_manager.c b/src/tests/eio/eio_test_manager.c
index ebfcc9edf7..e97310276c 100644
--- a/src/tests/eio/eio_test_manager.c
+++ b/src/tests/eio/eio_test_manager.c
@@ -51,16 +51,28 @@ _error_cb(void *data EINA_UNUSED, const Efl_Event *ev)
ecore_main_loop_quit();
}
-static void
-_open_done_cb(void *data, const Efl_Event *ev)
+static Eina_Value
+_open_done_cb(void *data,
+ const Eina_Value file,
+ const Eina_Future *dead EINA_UNUSED)
{
- Efl_Future_Event_Success *success = ev->info;
- Eina_Bool *opened = (Eina_Bool *)data;
- Eina_File* file = eina_file_dup(success->value);
- eina_file_close(file);
-
- *opened = EINA_TRUE;
+ if (file.type == EINA_VALUE_TYPE_ERROR)
+ {
+ Eina_Error err;
+
+ eina_value_get(&file, &err);
+ fprintf(stderr, "Something has gone wrong: %s\n", eina_error_msg_get(err));
+ abort();
+ }
+ if (file.type == EINA_VALUE_TYPE_FILE)
+ {
+ Eina_Bool *opened = (Eina_Bool *)data;
+
+ *opened = EINA_TRUE;
+ }
ecore_main_loop_quit();
+
+ return file;
}
static void
@@ -221,7 +233,7 @@ START_TEST(efl_io_manager_test_open)
Eina_Tmpstr *nested_dirname;
Eina_Tmpstr *nested_filename;
Efl_Io_Manager *job;
- Efl_Future *f;
+ Eina_Future *f;
Eina_Bool opened_file = EINA_FALSE;
int ret;
@@ -241,7 +253,7 @@ START_TEST(efl_io_manager_test_open)
job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
f = efl_io_manager_open(job, nested_filename, EINA_FALSE);
- efl_future_then(f, &_open_done_cb, &_error_cb, NULL, &opened_file);
+ eina_future_then(f, _open_done_cb, &opened_file);
ecore_main_loop_begin();
fail_if(!opened_file);
diff --git a/src/tests/eio/eio_test_manager_xattr.c b/src/tests/eio/eio_test_manager_xattr.c
index 3d41316f20..bb2ddece02 100644
--- a/src/tests/eio/eio_test_manager_xattr.c
+++ b/src/tests/eio/eio_test_manager_xattr.c
@@ -118,7 +118,7 @@ _error_cb(void *data EINA_UNUSED, const Efl_Event *ev)
}
static Eina_Value
-_future_all_cb(const void *data,
+_future_all_cb(void *data,
const Eina_Value array,
const Eina_Future *dead EINA_UNUSED)
{