summaryrefslogtreecommitdiff
path: root/src/examples/eio
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-09-09 16:22:20 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-09-09 16:22:55 -0700
commitfca20d55798eb981c8e93ee05b37396b0efa9ad3 (patch)
tree514b1e5f372096253b3c405f6ec4822de1562a2a /src/examples/eio
parent085adca305366415b30f80c1d67d2b736c8b1cfb (diff)
eio: finish port to new efl_io_manager API.
Diffstat (limited to 'src/examples/eio')
-rw-r--r--src/examples/eio/efl_io_manager_ls.c78
-rw-r--r--src/examples/eio/efl_io_manager_open.c70
-rw-r--r--src/examples/eio/efl_io_manager_open_multi.c124
3 files changed, 125 insertions, 147 deletions
diff --git a/src/examples/eio/efl_io_manager_ls.c b/src/examples/eio/efl_io_manager_ls.c
index 362b3c71ea..b1f5ea9a1e 100644
--- a/src/examples/eio/efl_io_manager_ls.c
+++ b/src/examples/eio/efl_io_manager_ls.c
@@ -10,69 +10,71 @@
10#include <Eio.h> 10#include <Eio.h>
11#include <Ecore.h> 11#include <Ecore.h>
12 12
13void done_cb(void *data, void *value EINA_UNUSED) 13void leave(Efl_Io_Manager *job)
14{ 14{
15 Efl_Io_Manager *job = data; 15 ecore_main_loop_quit();
16 printf("%s done listing files.\n", __FUNCTION__);
17 ecore_main_loop_quit();
18 efl_unref(job);
19} 16}
20 17
21void error_cb(void *data, Eina_Error error) 18void done_cb(void *data, const Efl_Event *ev)
22{ 19{
23 Efl_Io_Manager *job = data; 20 Efl_Future_Event_Success *success = ev->info;
24 const char *msg = eina_error_msg_get(error); 21 uint64_t *count = success->value;
25 printf("%s error: %s\n", __FUNCTION__, msg);
26 ecore_main_loop_quit();
27 22
28 efl_unref(job); 23 printf("%s done listing files %i.\n", __FUNCTION__, *count);
24
25 leave(data);
29} 26}
30 27
31void filter_cb(void *data EINA_UNUSED, const Efl_Event *event) 28void error_cb(void *data, const Efl_Event *ev)
32{ 29{
33 Eio_Filter_Name_Data *event_info = event->info; 30 Efl_Future_Event_Failure *failure = ev->info;
34 static Eina_Bool should_filter = EINA_FALSE; 31 const char *msg = eina_error_msg_get(failure->error);
35 32
36 printf("Filtering file %s\n", event_info->file); 33 printf("%s error: %s\n", __FUNCTION__, msg);
37 34
38 should_filter = !should_filter; 35 leave(data);
39 event_info->filter = should_filter;
40} 36}
41 37
42// Progress used to be the "Eio_Main_Cb" family of callbacks in the legacy API. 38// Progress used to be the "Eio_Main_Cb" family of callbacks in the legacy API.
43void progress_cb(void *data EINA_UNUSED, const char *filename) 39void progress_cb(void *data EINA_UNUSED, const Efl_Event *ev)
44{ 40{
45 EINA_SAFETY_ON_NULL_RETURN(filename); 41 Efl_Future_Event_Progress *p = ev->info;
46 printf("%s listing filename: %s\n", __FUNCTION__, filename); 42 const Eina_Array *batch = p->progress;
43 Eina_Iterator *it;
44 const char *filename;
45
46 it = eina_array_iterator_new(batch);
47 EINA_ITERATOR_FOREACH(it, filename)
48 printf("%s listing filename: %s\n", __FUNCTION__, filename);
49 eina_iterator_free(it);
47} 50}
48 51
49void list_files(void *data) 52void list_files(void *data)
50{ 53{
51 Eina_Promise *promise; 54 Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
52 const char *path = data; 55 const char *path = data;
53 56
54 Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, NULL); 57 efl_future_then(efl_io_manager_ls(job, path), &done_cb, &error_cb, &progress_cb, job);
55 efl_event_callback_add(job, EFL_IO_MANAGER_EVENT_FILTER_NAME, (Efl_Event_Cb)&filter_cb, NULL);
56 promise = efl_io_manager_file_ls(job, path);
57 eina_promise_progress_cb_add(promise, (Eina_Promise_Progress_Cb)&progress_cb, NULL, NULL);
58 eina_promise_then(promise, &done_cb, &error_cb, job);
59} 58}
60 59
61int main(int argc, char const *argv[]) 60int main(int argc, char const *argv[])
62{ 61{
63 eio_init(); 62 const char *path;
64 ecore_init(); 63 Ecore_Job *job;
64
65 eio_init();
66 ecore_init();
65 67
66 const char *path = getenv("HOME"); 68 path = getenv("HOME");
67 69
68 if (argc > 1) 70 if (argc > 1)
69 path = argv[1]; 71 path = argv[1];
70 72
71 Ecore_Job *job = ecore_job_add(&list_files, path); 73 job = ecore_job_add(&list_files, path);
72 74
73 ecore_main_loop_begin(); 75 ecore_main_loop_begin();
74 76
75 ecore_shutdown(); 77 ecore_shutdown();
76 eio_shutdown(); 78 eio_shutdown();
77 return 0; 79 return 0;
78} 80}
diff --git a/src/examples/eio/efl_io_manager_open.c b/src/examples/eio/efl_io_manager_open.c
index 4c9f4a46a2..739f76fff5 100644
--- a/src/examples/eio/efl_io_manager_open.c
+++ b/src/examples/eio/efl_io_manager_open.c
@@ -9,69 +9,59 @@
9#include <Eio.h> 9#include <Eio.h>
10#include <Ecore.h> 10#include <Ecore.h>
11 11
12void error_cb(void *data, Eina_Error error) 12void error_cb(void *data, const Efl_Event *ev)
13{ 13{
14 EINA_SAFETY_ON_NULL_RETURN(data); 14 Efl_Future_Event_Failure *failure = ev->info;
15 const char *msg = eina_error_msg_get(failure->error);
16 EINA_LOG_ERR("error: %s", msg);
15 17
16 const char *msg = eina_error_msg_get(error); 18 ecore_main_loop_quit();
17 EINA_LOG_ERR("error: %s", msg);
18
19 ecore_main_loop_quit();
20} 19}
21 20
22void done_closing_cb(void* data EINA_UNUSED, void *value EINA_UNUSED) 21void done_closing_cb(void* data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
23{ 22{
24 printf("%s closed file.\n", __FUNCTION__); 23 printf("%s closed file.\n", __FUNCTION__);
25
26 ecore_main_loop_quit();
27}
28 24
29void closing_job(Efl_Io_Manager *job, Eina_File *file) 25 ecore_main_loop_quit();
30{
31 Eina_Promise *promise = NULL;
32 printf("%s Will close the file...\n", __FUNCTION__);
33 efl_io_manager_file_close(job, file, &promise);
34 eina_promise_then(promise, &done_closing_cb, &error_cb, job);
35} 26}
36 27
37void done_open_cb(void *data, void* value) 28void done_open_cb(void *data, const Efl_Event *ev)
38{ 29{
39 EINA_SAFETY_ON_NULL_RETURN(data); 30 Efl_Future_Event_Success *success = ev->info;
40 EINA_SAFETY_ON_NULL_RETURN(value); 31 Eina_File *file = success->value;
32 Efl_Io_Manager *job = data;
41 33
42 Eina_File *file = eina_file_dup(value); 34 printf("%s opened file %s\n", __FUNCTION__, eina_file_filename_get(file));
43 35
44 Efl_Io_Manager *job = data; 36 efl_future_then(efl_io_manager_close(job, file), &done_closing_cb, &error_cb, NULL, NULL);
45
46 const char *name = eina_file_filename_get(file);
47 printf("%s opened file %s\n", __FUNCTION__, name);
48
49 closing_job(job, file);
50} 37}
51 38
52void open_file(const char *path) 39void open_file(const char *path)
53{ 40{
54 Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, NULL); 41 Efl_Io_Manager *job;
55 eina_promise_then(efl_io_manager_file_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, job);
56 42
57 efl_unref(job); 43 job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
44
45 efl_future_then(efl_io_manager_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, NULL, job);
58} 46}
59 47
60int main(int argc, char const *argv[]) 48int main(int argc, char const *argv[])
61{ 49{
62 eio_init(); 50 const char *path;
63 ecore_init(); 51
52 eio_init();
53 ecore_init();
64 54
65 const char *path = getenv("HOME"); 55 path = getenv("HOME");
66 56
67 if (argc > 1) 57 if (argc > 1)
68 path = argv[1]; 58 path = argv[1];
69 59
70 open_file(path); 60 open_file(path);
71 61
72 ecore_main_loop_begin(); 62 ecore_main_loop_begin();
73 63
74 ecore_shutdown(); 64 ecore_shutdown();
75 eio_shutdown(); 65 eio_shutdown();
76 return 0; 66 return 0;
77} 67}
diff --git a/src/examples/eio/efl_io_manager_open_multi.c b/src/examples/eio/efl_io_manager_open_multi.c
index e55f039de7..e56cffa09f 100644
--- a/src/examples/eio/efl_io_manager_open_multi.c
+++ b/src/examples/eio/efl_io_manager_open_multi.c
@@ -9,96 +9,82 @@
9#include <Eio.h> 9#include <Eio.h>
10#include <Ecore.h> 10#include <Ecore.h>
11 11
12void error_cb(void *data, Eina_Error error) 12void error_cb(void *data, const Efl_Event *ev)
13{ 13{
14 EINA_SAFETY_ON_NULL_RETURN(data); 14 Efl_Future_Event_Failure *failure = ev->info;
15 const char *msg = eina_error_msg_get(failure->error);
16 Efl_Io_Manager *job = data;
15 17
16 const char *msg = eina_error_msg_get(error); 18 EINA_LOG_ERR("error: %s", msg);
17 EINA_LOG_ERR("error: %s", msg);
18 19
19 Efl_Io_Manager *job = data; 20 ecore_main_loop_quit();
20 efl_unref(job);
21
22 ecore_main_loop_quit();
23} 21}
24 22
25void done_closing_cb(void *data, void* value EINA_UNUSED) 23void done_closing_cb(void *data, const Efl_Event *ev EINA_UNUSED)
26{ 24{
27 EINA_SAFETY_ON_NULL_RETURN(data); 25 Efl_Io_Manager *job = data;
28
29 Eina_Iterator* result = value;
30
31 printf("%s closed file.\n", __FUNCTION__);
32 26
33 Efl_Io_Manager *job = data; 27 printf("%s closed all files.\n", __FUNCTION__);
34 efl_unref(job);
35 28
36 ecore_main_loop_quit(); 29 ecore_main_loop_quit();
37} 30}
38 31
39void closing_job(Efl_Io_Manager *job, Eina_File *file1, Eina_File *file2) 32void done_open_cb(void *data, const Efl_Event *ev)
40{ 33{
41 Eina_Promise *promise; 34 Efl_Future_Event_Success *s = ev->info;
42 Eina_Promise *tasks[3] = {NULL, NULL, NULL}; 35 Efl_Io_Manager *job = data;
43 36 Eina_Accessor *ac = s->value;
44 printf("%s Closing files.\n", __FUNCTION__); 37 Eina_Iterator *it;
45 efl_io_manager_file_close(job, file1, &tasks[0]); 38 Eina_Array stack;
46 efl_io_manager_file_close(job, file2, &tasks[1]); 39 Eina_File *f;
47 promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0])); 40 unsigned int i;
48 eina_promise_then(promise, &done_closing_cb, &error_cb, job); 41
42 eina_array_step_set(&stack, sizeof (Eina_Array), 4);
43
44 EINA_ACCESSOR_FOREACH(ac, i, f)
45 {
46 printf("%s opened file %s [%i]\n", __FUNCTION__, eina_file_filename_get(f), i);
47 eina_array_push(&stack, efl_io_manager_close(job, f));
48 }
49
50 it = eina_array_iterator_new(&stack);
51 efl_future_then(efl_future_iterator_all(it), &done_closing_cb, &error_cb, NULL, job);
52
53 eina_array_flush(&stack);
49} 54}
50 55
51void done_open_cb(void *data, Eina_Iterator **iterator) 56Efl_Future *open_file(Efl_Io_Manager *job, const char *path)
52{ 57{
53 EINA_SAFETY_ON_NULL_RETURN(data); 58 return efl_io_manager_open(job, path, EINA_FALSE);
54 EINA_SAFETY_ON_NULL_RETURN(iterator);
55 EINA_SAFETY_ON_NULL_RETURN(*iterator);
56 Efl_Io_Manager *job = data;
57
58 Eina_File **file = NULL;
59 Eina_File **files = calloc(sizeof(Eina_File*),2);
60 int i = 0;
61 while (eina_iterator_next(*iterator, (void**)&file))
62 {
63 files[i] = *file;
64 const char *name = eina_file_filename_get(*file);
65 printf("%s opened file %s\n", __FUNCTION__, name);
66 i++;
67 }
68 closing_job(job, files[0], files[1]);
69 free(files);
70}
71
72void open_file(const char *path, const char *path2)
73{
74 Eina_Promise *promise;
75 Eina_Promise *tasks[3] = {NULL, NULL, NULL};
76
77 Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, NULL);
78 tasks[0] = efl_io_manager_file_open(job, path, EINA_FALSE);
79 tasks[1] = efl_io_manager_file_open(job, path2, EINA_FALSE);
80 promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0]));
81 eina_promise_then(promise, (Eina_Promise_Cb)&done_open_cb, (Eina_Promise_Error_Cb)&error_cb, job);
82} 59}
83 60
84int main(int argc, char const *argv[]) 61int main(int argc, char const *argv[])
85{ 62{
86 eio_init(); 63 Efl_Io_Manager *job;
87 ecore_init(); 64 const char *path;
65 const char *path2;
66
67 eio_init();
68 ecore_init();
69
70 job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
71
72 path = getenv("HOME");
73 path2 = "./";
88 74
89 const char *path = getenv("HOME"); 75 if (argc > 1)
90 const char *path2 = "./"; 76 path = argv[1];
77 if (argc > 2)
78 path2 = argv[2];
91 79
92 if (argc > 1) 80 efl_future_then(efl_future_all(open_file(job, path), open_file(job, path2)),
93 path = argv[1]; 81 &done_open_cb, &error_cb, NULL, job);
94 if (argc > 2)
95 path2 = argv[2];
96 82
97 open_file(path, path2); 83 ecore_main_loop_begin();
98 84
99 ecore_main_loop_begin(); 85 efl_del(job);
100 86
101 ecore_shutdown(); 87 ecore_shutdown();
102 eio_shutdown(); 88 eio_shutdown();
103 return 0; 89 return 0;
104} 90}