summaryrefslogtreecommitdiff
path: root/src/examples/eio
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-10-09 18:27:56 -0700
committerCedric Bail <cedric@osg.samsung.com>2017-10-09 18:27:56 -0700
commit35a3b3ca4cdac81ce028338a8659a49c7c87a474 (patch)
tree9301f77b9d77a22f9728dcdf937b751c120c2b1c /src/examples/eio
parent044acdf1d29fe492002a9caeaefef1b6fb38fe0c (diff)
eio: fix multiple open/close chain example.
Diffstat (limited to 'src/examples/eio')
-rw-r--r--src/examples/eio/efl_io_manager_open_multi.c68
1 files changed, 43 insertions, 25 deletions
diff --git a/src/examples/eio/efl_io_manager_open_multi.c b/src/examples/eio/efl_io_manager_open_multi.c
index cedb91613d..9937b9b8e6 100644
--- a/src/examples/eio/efl_io_manager_open_multi.c
+++ b/src/examples/eio/efl_io_manager_open_multi.c
@@ -21,48 +21,62 @@ void error_cb(void *data, const Efl_Event *ev)
21 ecore_main_loop_quit(); 21 ecore_main_loop_quit();
22} 22}
23 23
24void done_closing_cb(void *data, const Efl_Event *ev EINA_UNUSED) 24static Eina_Value
25_close_cb(void *data EINA_UNUSED, const Eina_Value array, const Eina_Future *dead EINA_UNUSED)
25{ 26{
26 Efl_Io_Manager *job = data;
27 (void) job;
28
29 printf("%s closed all files.\n", __FUNCTION__); 27 printf("%s closed all files.\n", __FUNCTION__);
30 28
31 ecore_main_loop_quit(); 29 ecore_main_loop_quit();
30
31 return array;
32} 32}
33 33
34void done_open_cb(void *data, const Efl_Event *ev) 34static Eina_Value
35_open_cb(void *data, const Eina_Value array, const Eina_Future *dead EINA_UNUSED)
35{ 36{
36 Efl_Future_Event_Success *s = ev->info;
37 Efl_Io_Manager *job = data; 37 Efl_Io_Manager *job = data;
38 Eina_Accessor *ac = s->value; 38 unsigned int i, len;
39 Eina_Iterator *it; 39 Eina_Value v = EINA_VALUE_EMPTY;
40 Eina_Array stack; 40 Eina_Future *futures[eina_value_array_count(&array) + 1];
41 Eina_File *f;
42 unsigned int i;
43 41
44 eina_array_step_set(&stack, sizeof (Eina_Array), 4); 42 EINA_VALUE_ARRAY_FOREACH(&array, len, i, &v)
45
46 EINA_ACCESSOR_FOREACH(ac, i, f)
47 { 43 {
48 printf("%s opened file %s [%i]\n", __FUNCTION__, eina_file_filename_get(f), i); 44 if (v.type == EINA_VALUE_TYPE_ERROR)
49 eina_array_push(&stack, efl_io_manager_close(job, f)); 45 {
46 Eina_Error err;
47
48 eina_value_get(&v, &err);
49 fprintf(stderr, "Something has gone wrong: %s at index: %i\n", eina_error_msg_get(err), i);
50 goto on_error;
51 }
52 else if (v.type == EINA_VALUE_TYPE_FILE)
53 {
54 Eina_File *f;
55
56 eina_value_get(&v, &f);
57
58 futures[i] = efl_io_manager_close(job, f);
59 }
60 else
61 {
62 goto on_error;
63 }
50 } 64 }
51 65
52 it = eina_array_iterator_new(&stack); 66 futures[i] = EINA_FUTURE_SENTINEL;
53 efl_future_then(efl_future_iterator_all(it), &done_closing_cb, &error_cb, NULL, job);
54 67
55 eina_array_flush(&stack); 68 return eina_future_as_value(eina_future_all_array(futures));
56}
57 69
58Efl_Future *open_file(Efl_Io_Manager *job, const char *path) 70 on_error:
59{ 71 for (; i > 0; i--)
60 return efl_io_manager_open(job, path, EINA_FALSE); 72 eina_future_cancel(futures[i - 1]);
73 return v;
61} 74}
62 75
63int main(int argc, char const *argv[]) 76int main(int argc, char const *argv[])
64{ 77{
65 Efl_Io_Manager *job; 78 Efl_Io_Manager *job;
79 Eina_Future *futures[3] = { NULL, NULL, EINA_FUTURE_SENTINEL };
66 const char *path; 80 const char *path;
67 const char *path2; 81 const char *path2;
68 82
@@ -79,8 +93,12 @@ int main(int argc, char const *argv[])
79 if (argc > 2) 93 if (argc > 2)
80 path2 = argv[2]; 94 path2 = argv[2];
81 95
82 efl_future_then(efl_future_all(open_file(job, path), open_file(job, path2)), 96 futures[0] = efl_io_manager_open(job, path, EINA_FALSE);
83 &done_open_cb, &error_cb, NULL, job); 97 futures[1] = efl_io_manager_open(job, path2, EINA_FALSE);
98
99 eina_future_chain(eina_future_all_array(futures),
100 { .cb = _open_cb, .data = job },
101 { .cb = _close_cb, .data = NULL });
84 102
85 ecore_main_loop_begin(); 103 ecore_main_loop_begin();
86 104