summaryrefslogtreecommitdiff
path: root/src/examples/eio
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-10-09 17:44:33 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-10-09 17:44:33 -0700
commit044acdf1d29fe492002a9caeaefef1b6fb38fe0c (patch)
treead5bc33ef712732d0ae7f0222380408855705564 /src/examples/eio
parenta8e7cf74b14c23fbcd4a2e5d14c7b586635964b3 (diff)
eio: update example for openning and closing file asynchronously using a chain.
Diffstat (limited to 'src/examples/eio')
-rw-r--r--src/examples/eio/efl_io_manager_open.c59
1 files 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 a3c4cacccb..dfc96e4dfe 100644
--- a/src/examples/eio/efl_io_manager_open.c
+++ b/src/examples/eio/efl_io_manager_open.c
@@ -9,31 +9,56 @@
9#include <Eio.h> 9#include <Eio.h>
10#include <Ecore.h> 10#include <Ecore.h>
11 11
12void error_cb(void *data EINA_UNUSED, const Efl_Event *ev) 12static Eina_Value
13_closing_cb(void* data EINA_UNUSED,
14 const Eina_Value file,
15 const Eina_Future *dead EINA_UNUSED)
13{ 16{
14 Efl_Future_Event_Failure *failure = ev->info; 17 if (file.type == EINA_VALUE_TYPE_ERROR)
15 const char *msg = eina_error_msg_get(failure->error); 18 {
16 EINA_LOG_ERR("error: %s", msg); 19 Eina_Error err;
20
21 eina_value_get(&file, &err);
22 fprintf(stderr, "Something has gone wrong: %s\n", eina_error_msg_get(err));
23 }
24 else
25 {
26 printf("%s closed file.\n", __FUNCTION__);
27 }
17 28
18 ecore_main_loop_quit(); 29 ecore_main_loop_quit();
19}
20
21void done_closing_cb(void* data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
22{
23 printf("%s closed file.\n", __FUNCTION__);
24 30
25 ecore_main_loop_quit(); 31 return file;
26} 32}
27 33
28void done_open_cb(void *data, const Efl_Event *ev) 34static Eina_Value
35_open_cb(void *data,
36 const Eina_Value file,
37 const Eina_Future *dead EINA_UNUSED)
29{ 38{
30 Efl_Future_Event_Success *success = ev->info;
31 Eina_File *file = success->value;
32 Efl_Io_Manager *job = data; 39 Efl_Io_Manager *job = data;
33 40
34 printf("%s opened file %s\n", __FUNCTION__, eina_file_filename_get(file)); 41 if (file.type == EINA_VALUE_TYPE_ERROR)
42 {
43 Eina_Error err;
44
45 eina_value_get(&file, &err);
46 fprintf(stderr, "Something has gone wrong: %s\n", eina_error_msg_get(err));
47 ecore_main_loop_quit();
48
49 return file;
50 }
51 if (file.type == EINA_VALUE_TYPE_FILE)
52 {
53 Eina_File *f;
54
55 eina_value_get(&file, &f);
56
57 printf("%s opened file %s\n", __FUNCTION__, eina_file_filename_get(f));
35 58
36 efl_future_then(efl_io_manager_close(job, file), &done_closing_cb, &error_cb, NULL, NULL); 59 return eina_future_as_value(efl_io_manager_close(job, f));
60 }
61 return file;
37} 62}
38 63
39void open_file(const char *path) 64void open_file(const char *path)
@@ -42,7 +67,9 @@ void open_file(const char *path)
42 67
43 job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get()); 68 job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
44 69
45 efl_future_then(efl_io_manager_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, NULL, job); 70 eina_future_chain(efl_io_manager_open(job, path, EINA_FALSE),
71 { .cb = _open_cb, .data = job },
72 { .cb = _closing_cb, .data = NULL });
46} 73}
47 74
48int main(int argc, char const *argv[]) 75int main(int argc, char const *argv[])