summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-03 16:53:54 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-03 17:22:18 -0300
commit865b69f6ff3f095e5d81648c391b2e9fb8519fdf (patch)
tree8255be1d494f5f79f0b4c1086e2c39922ba67d85 /src/examples
parent8fec0d5139a3ff30037ba159bb62ff2f733d96a8 (diff)
eina: Fix examples using new Eina_Promise semantics
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/eio/eio_job_ls.c8
-rw-r--r--src/examples/eio/eio_job_open.c23
-rw-r--r--src/examples/eio/eio_job_open_multi.c14
-rw-r--r--src/examples/eldbus/dbusmodel.c27
-rw-r--r--src/examples/elementary/filemvc.c2
5 files changed, 35 insertions, 39 deletions
diff --git a/src/examples/eio/eio_job_ls.c b/src/examples/eio/eio_job_ls.c
index 354325e..2e2db1f 100644
--- a/src/examples/eio/eio_job_ls.c
+++ b/src/examples/eio/eio_job_ls.c
@@ -18,11 +18,11 @@ void done_cb(void *data, void *value EINA_UNUSED)
18 eo_unref(job); 18 eo_unref(job);
19} 19}
20 20
21void error_cb(void *data, Eina_Error *error) 21void error_cb(void *data, Eina_Error error)
22{ 22{
23 Eio_Job *job = data; 23 Eio_Job *job = data;
24 EINA_SAFETY_ON_NULL_RETURN(error); 24 EINA_SAFETY_ON_NULL_RETURN(error);
25 const char *msg = eina_error_msg_get(*error); 25 const char *msg = eina_error_msg_get(error);
26 printf("%s error: %s\n", __FUNCTION__, msg); 26 printf("%s error: %s\n", __FUNCTION__, msg);
27 ecore_main_loop_quit(); 27 ecore_main_loop_quit();
28 28
@@ -54,9 +54,9 @@ void list_files(void *data)
54 54
55 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL); 55 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
56 eo_event_callback_add(job, EIO_JOB_EVENT_FILTER_NAME, (Eo_Event_Cb)&filter_cb, NULL); 56 eo_event_callback_add(job, EIO_JOB_EVENT_FILTER_NAME, (Eo_Event_Cb)&filter_cb, NULL);
57 eio_job_file_ls(job, path, &promise); 57 promise = eio_job_file_ls(job, path);
58 eina_promise_progress_cb_add(promise, (Eina_Promise_Progress_Cb)&progress_cb, NULL, NULL); 58 eina_promise_progress_cb_add(promise, (Eina_Promise_Progress_Cb)&progress_cb, NULL, NULL);
59 eina_promise_then(promise, (Eina_Promise_Cb)&done_cb, (Eina_Promise_Error_Cb)&error_cb, job); 59 eina_promise_then(promise, &done_cb, &error_cb, job);
60} 60}
61 61
62int main(int argc, char const *argv[]) 62int main(int argc, char const *argv[])
diff --git a/src/examples/eio/eio_job_open.c b/src/examples/eio/eio_job_open.c
index fb235c2..7662bfb 100644
--- a/src/examples/eio/eio_job_open.c
+++ b/src/examples/eio/eio_job_open.c
@@ -9,18 +9,17 @@
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, Eina_Error error, Eina_Promise* promise EINA_UNUSED)
13{ 13{
14 EINA_SAFETY_ON_NULL_RETURN(error);
15 EINA_SAFETY_ON_NULL_RETURN(data); 14 EINA_SAFETY_ON_NULL_RETURN(data);
16 15
17 const char *msg = eina_error_msg_get(*error); 16 const char *msg = eina_error_msg_get(error);
18 EINA_LOG_ERR("error: %s", msg); 17 EINA_LOG_ERR("error: %s", msg);
19 18
20 ecore_main_loop_quit(); 19 ecore_main_loop_quit();
21} 20}
22 21
23void done_closing_cb(int *result EINA_UNUSED) 22void done_closing_cb(void* data EINA_UNUSED, void *value EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
24{ 23{
25 printf("%s closed file.\n", __FUNCTION__); 24 printf("%s closed file.\n", __FUNCTION__);
26 25
@@ -32,21 +31,22 @@ void closing_job(Eio_Job *job, Eina_File *file)
32 Eina_Promise *promise = NULL; 31 Eina_Promise *promise = NULL;
33 printf("%s Will close the file...\n", __FUNCTION__); 32 printf("%s Will close the file...\n", __FUNCTION__);
34 eio_job_file_close(job, file, &promise); 33 eio_job_file_close(job, file, &promise);
35 eina_promise_then(promise, (Eina_Promise_Cb)&done_closing_cb, (Eina_Promise_Error_Cb)&error_cb, job); 34 eina_promise_then(promise, &done_closing_cb, &error_cb, job);
36} 35}
37 36
38void done_open_cb(void *data, Eina_File **file) 37void done_open_cb(void *data, void* value, Eina_Promise* promise)
39{ 38{
40 EINA_SAFETY_ON_NULL_RETURN(data); 39 EINA_SAFETY_ON_NULL_RETURN(data);
41 EINA_SAFETY_ON_NULL_RETURN(file); 40 EINA_SAFETY_ON_NULL_RETURN(value);
42 EINA_SAFETY_ON_NULL_RETURN(*file); 41
42 Eina_File *file = eina_file_dup(value);
43 43
44 Eio_Job *job = data; 44 Eio_Job *job = data;
45 45
46 const char *name = eina_file_filename_get(*file); 46 const char *name = eina_file_filename_get(file);
47 printf("%s opened file %s\n", __FUNCTION__, name); 47 printf("%s opened file %s\n", __FUNCTION__, name);
48 48
49 closing_job(job, *file); 49 closing_job(job, file);
50} 50}
51 51
52void open_file(const char *path) 52void open_file(const char *path)
@@ -54,8 +54,7 @@ void open_file(const char *path)
54 Eina_Promise *promise; 54 Eina_Promise *promise;
55 55
56 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL); 56 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
57 eio_job_file_open(job, path, EINA_FALSE, &promise); 57 eina_promise_then(eio_job_file_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, job);
58 eina_promise_then(promise, (Eina_Promise_Cb)&done_open_cb, (Eina_Promise_Error_Cb)&error_cb, job);
59 58
60 eo_unref(job); 59 eo_unref(job);
61} 60}
diff --git a/src/examples/eio/eio_job_open_multi.c b/src/examples/eio/eio_job_open_multi.c
index 8082d4b..d1f8fa9 100644
--- a/src/examples/eio/eio_job_open_multi.c
+++ b/src/examples/eio/eio_job_open_multi.c
@@ -9,12 +9,12 @@
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, Eina_Error error)
13{ 13{
14 EINA_SAFETY_ON_NULL_RETURN(error); 14 EINA_SAFETY_ON_NULL_RETURN(error);
15 EINA_SAFETY_ON_NULL_RETURN(data); 15 EINA_SAFETY_ON_NULL_RETURN(data);
16 16
17 const char *msg = eina_error_msg_get(*error); 17 const char *msg = eina_error_msg_get(error);
18 EINA_LOG_ERR("error: %s", msg); 18 EINA_LOG_ERR("error: %s", msg);
19 19
20 Eio_Job *job = data; 20 Eio_Job *job = data;
@@ -23,10 +23,12 @@ void error_cb(void *data, Eina_Error *error)
23 ecore_main_loop_quit(); 23 ecore_main_loop_quit();
24} 24}
25 25
26void done_closing_cb(void *data, Eina_Iterator **result EINA_UNUSED) 26void done_closing_cb(void *data, void* value EINA_UNUSED)
27{ 27{
28 EINA_SAFETY_ON_NULL_RETURN(data); 28 EINA_SAFETY_ON_NULL_RETURN(data);
29 29
30 Eina_Iterator* result = value;
31
30 printf("%s closed file.\n", __FUNCTION__); 32 printf("%s closed file.\n", __FUNCTION__);
31 33
32 Eio_Job *job = data; 34 Eio_Job *job = data;
@@ -44,7 +46,7 @@ void closing_job(Eio_Job *job, Eina_File *file1, Eina_File *file2)
44 eio_job_file_close(job, file1, &tasks[0]); 46 eio_job_file_close(job, file1, &tasks[0]);
45 eio_job_file_close(job, file2, &tasks[1]); 47 eio_job_file_close(job, file2, &tasks[1]);
46 promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0])); 48 promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0]));
47 eina_promise_then(promise, (Eina_Promise_Cb)&done_closing_cb, (Eina_Promise_Error_Cb)&error_cb, job); 49 eina_promise_then(promise, &done_closing_cb, &error_cb, job);
48} 50}
49 51
50void done_open_cb(void *data, Eina_Iterator **iterator) 52void done_open_cb(void *data, Eina_Iterator **iterator)
@@ -74,8 +76,8 @@ void open_file(const char *path, const char *path2)
74 Eina_Promise *tasks[3] = {NULL, NULL, NULL}; 76 Eina_Promise *tasks[3] = {NULL, NULL, NULL};
75 77
76 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL); 78 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
77 eio_job_file_open(job, path, EINA_FALSE, &tasks[0]); 79 tasks[0] = eio_job_file_open(job, path, EINA_FALSE);
78 eio_job_file_open(job, path2, EINA_FALSE, &tasks[1]); 80 tasks[1] = eio_job_file_open(job, path2, EINA_FALSE);
79 promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0])); 81 promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0]));
80 eina_promise_then(promise, (Eina_Promise_Cb)&done_open_cb, (Eina_Promise_Error_Cb)&error_cb, job); 82 eina_promise_then(promise, (Eina_Promise_Cb)&done_open_cb, (Eina_Promise_Error_Cb)&error_cb, job);
81} 83}
diff --git a/src/examples/eldbus/dbusmodel.c b/src/examples/eldbus/dbusmodel.c
index a7c8ee7..4cc7178 100644
--- a/src/examples/eldbus/dbusmodel.c
+++ b/src/examples/eldbus/dbusmodel.c
@@ -15,21 +15,15 @@
15 15
16static int prop_count = 0; 16static int prop_count = 0;
17 17
18struct eina_iterator
19{
20 Eina_Iterator* success_iterator;
21 Eina_Iterator* failure_iterator;
22};
23
24static void 18static void
25promise_then_prop_c(Eo* obj, struct eina_iterator* it_struct) 19promise_then_prop_c(Eo* obj, void* data)
26{ 20{
27 Eina_Value * property_value; 21 Eina_Value * property_value;
28 const Eina_Array *properties_list; 22 const Eina_Array *properties_list;
29 Eina_Array_Iterator a_it; 23 Eina_Array_Iterator a_it;
30 char *property, *prop_str; 24 char *property, *prop_str;
31 const char *name; 25 const char *name;
32 Eina_Iterator* it = it_struct->success_iterator; 26 Eina_Iterator* it = data;
33 27
34 name = eldbus_model_proxy_name_get(obj); 28 name = eldbus_model_proxy_name_get(obj);
35 properties_list = efl_model_properties_get(obj); 29 properties_list = efl_model_properties_get(obj);
@@ -59,7 +53,7 @@ error_cb(void* data EINA_UNUSED, const Eina_Error *error EINA_UNUSED)
59} 53}
60 54
61static void 55static void
62promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor) 56promise_then_a(Eo* obj EINA_UNUSED, void* data)
63{ 57{
64 const Eina_Array *properties_list; 58 const Eina_Array *properties_list;
65 Eina_Array_Iterator a_it; 59 Eina_Array_Iterator a_it;
@@ -68,8 +62,9 @@ promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
68 char *property; 62 char *property;
69 Eo* child; 63 Eo* child;
70 int i = 0; 64 int i = 0;
65 Eina_Accessor* accessor = data;
71 66
72 EINA_ACCESSOR_FOREACH(*accessor, i, child) 67 EINA_ACCESSOR_FOREACH(accessor, i, child)
73 { 68 {
74 properties_list = efl_model_properties_get(child); 69 properties_list = efl_model_properties_get(child);
75 name = eldbus_model_proxy_name_get(child); 70 name = eldbus_model_proxy_name_get(child);
@@ -87,7 +82,7 @@ promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
87 efl_model_property_get(child, property, &promises[j]); 82 efl_model_property_get(child, property, &promises[j]);
88 } 83 }
89 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)), 84 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
90 (Eina_Promise_Cb)&promise_then_prop_c, &error_cb, child); 85 &promise_then_prop_c, &error_cb, child);
91 prop_count++; 86 prop_count++;
92 } 87 }
93 else 88 else
@@ -100,14 +95,14 @@ promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
100 ecore_main_loop_quit(); 95 ecore_main_loop_quit();
101} 96}
102static void 97static void
103promise_then(Eo* obj EINA_UNUSED, struct eina_iterator* it_struct) 98promise_then(Eo* obj EINA_UNUSED, void* data)
104{ 99{
105 Eina_Accessor **accessor; 100 Eina_Accessor *accessor;
106 unsigned int* count; 101 unsigned int* count;
107 102
108 Eina_Iterator* iterator = it_struct->success_iterator; 103 Eina_Iterator* iterator = data;
109 104
110 if (!eina_iterator_next(iterator, (void **)&accessor)) 105 if (!eina_iterator_next(iterator, (void**)&accessor))
111 { 106 {
112 printf("bye\n"); 107 printf("bye\n");
113 ecore_main_loop_quit(); 108 ecore_main_loop_quit();
@@ -144,7 +139,7 @@ main(int argc, char **argv EINA_UNUSED)
144 efl_model_children_count_get(root, &promises[1]); 139 efl_model_children_count_get(root, &promises[1]);
145 140
146 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)), 141 eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
147 (Eina_Promise_Cb)&promise_then, &error_cb, root); 142 &promise_then, &error_cb, root);
148 143
149 ecore_main_loop_begin(); 144 ecore_main_loop_begin();
150 145
diff --git a/src/examples/elementary/filemvc.c b/src/examples/elementary/filemvc.c
index f33b200..1f05feb 100644
--- a/src/examples/elementary/filemvc.c
+++ b/src/examples/elementary/filemvc.c
@@ -65,7 +65,7 @@ _promise_then(void *data, void *value)
65 char *path; 65 char *path;
66 Eo *model; 66 Eo *model;
67 67
68 eina_value_get((Eina_Value *)value, &path); 68 eina_value_get(value, &path);
69 model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, path)); 69 model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, path));
70 elm_view_list_model_set(priv->fileview, model); 70 elm_view_list_model_set(priv->fileview, model);
71} 71}