From 044acdf1d29fe492002a9caeaefef1b6fb38fe0c Mon Sep 17 00:00:00 2001 From: Cedric Bail Date: Mon, 9 Oct 2017 17:44:33 -0700 Subject: [PATCH] eio: update example for openning and closing file asynchronously using a chain. --- src/examples/eio/efl_io_manager_open.c | 59 +++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/examples/eio/efl_io_manager_open.c b/src/examples/eio/efl_io_manager_open.c index a3c4cac..dfc96e4 100644 --- a/src/examples/eio/efl_io_manager_open.c +++ b/src/examples/eio/efl_io_manager_open.c @@ -9,31 +9,56 @@ #include #include -void error_cb(void *data EINA_UNUSED, const Efl_Event *ev) +static Eina_Value +_closing_cb(void* data EINA_UNUSED, + const Eina_Value file, + const Eina_Future *dead EINA_UNUSED) { - Efl_Future_Event_Failure *failure = ev->info; - const char *msg = eina_error_msg_get(failure->error); - EINA_LOG_ERR("error: %s", msg); + 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)); + } + else + { + printf("%s closed file.\n", __FUNCTION__); + } ecore_main_loop_quit(); -} - -void done_closing_cb(void* data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) -{ - printf("%s closed file.\n", __FUNCTION__); - ecore_main_loop_quit(); + return file; } -void done_open_cb(void *data, const Efl_Event *ev) +static Eina_Value +_open_cb(void *data, + const Eina_Value file, + const Eina_Future *dead EINA_UNUSED) { - Efl_Future_Event_Success *success = ev->info; - Eina_File *file = success->value; Efl_Io_Manager *job = data; - printf("%s opened file %s\n", __FUNCTION__, eina_file_filename_get(file)); + 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)); + ecore_main_loop_quit(); + + return file; + } + if (file.type == EINA_VALUE_TYPE_FILE) + { + Eina_File *f; + + eina_value_get(&file, &f); + + printf("%s opened file %s\n", __FUNCTION__, eina_file_filename_get(f)); - efl_future_then(efl_io_manager_close(job, file), &done_closing_cb, &error_cb, NULL, NULL); + return eina_future_as_value(efl_io_manager_close(job, f)); + } + return file; } void open_file(const char *path) @@ -42,7 +67,9 @@ void open_file(const char *path) job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get()); - efl_future_then(efl_io_manager_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, NULL, job); + eina_future_chain(efl_io_manager_open(job, path, EINA_FALSE), + { .cb = _open_cb, .data = job }, + { .cb = _closing_cb, .data = NULL }); } int main(int argc, char const *argv[]) -- 2.7.4