forked from enlightenment/efl
eina: Fix examples using new Eina_Promise semantics
This commit is contained in:
parent
8fec0d5139
commit
865b69f6ff
|
@ -18,11 +18,11 @@ void done_cb(void *data, void *value EINA_UNUSED)
|
|||
eo_unref(job);
|
||||
}
|
||||
|
||||
void error_cb(void *data, Eina_Error *error)
|
||||
void error_cb(void *data, Eina_Error error)
|
||||
{
|
||||
Eio_Job *job = data;
|
||||
EINA_SAFETY_ON_NULL_RETURN(error);
|
||||
const char *msg = eina_error_msg_get(*error);
|
||||
const char *msg = eina_error_msg_get(error);
|
||||
printf("%s error: %s\n", __FUNCTION__, msg);
|
||||
ecore_main_loop_quit();
|
||||
|
||||
|
@ -54,9 +54,9 @@ void list_files(void *data)
|
|||
|
||||
Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
|
||||
eo_event_callback_add(job, EIO_JOB_EVENT_FILTER_NAME, (Eo_Event_Cb)&filter_cb, NULL);
|
||||
eio_job_file_ls(job, path, &promise);
|
||||
promise = eio_job_file_ls(job, path);
|
||||
eina_promise_progress_cb_add(promise, (Eina_Promise_Progress_Cb)&progress_cb, NULL, NULL);
|
||||
eina_promise_then(promise, (Eina_Promise_Cb)&done_cb, (Eina_Promise_Error_Cb)&error_cb, job);
|
||||
eina_promise_then(promise, &done_cb, &error_cb, job);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
|
|
|
@ -9,18 +9,17 @@
|
|||
#include <Eio.h>
|
||||
#include <Ecore.h>
|
||||
|
||||
void error_cb(void *data, Eina_Error *error)
|
||||
void error_cb(void *data, Eina_Error error, Eina_Promise* promise EINA_UNUSED)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN(error);
|
||||
EINA_SAFETY_ON_NULL_RETURN(data);
|
||||
|
||||
const char *msg = eina_error_msg_get(*error);
|
||||
const char *msg = eina_error_msg_get(error);
|
||||
EINA_LOG_ERR("error: %s", msg);
|
||||
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
void done_closing_cb(int *result EINA_UNUSED)
|
||||
void done_closing_cb(void* data EINA_UNUSED, void *value EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
|
||||
{
|
||||
printf("%s closed file.\n", __FUNCTION__);
|
||||
|
||||
|
@ -32,21 +31,22 @@ void closing_job(Eio_Job *job, Eina_File *file)
|
|||
Eina_Promise *promise = NULL;
|
||||
printf("%s Will close the file...\n", __FUNCTION__);
|
||||
eio_job_file_close(job, file, &promise);
|
||||
eina_promise_then(promise, (Eina_Promise_Cb)&done_closing_cb, (Eina_Promise_Error_Cb)&error_cb, job);
|
||||
eina_promise_then(promise, &done_closing_cb, &error_cb, job);
|
||||
}
|
||||
|
||||
void done_open_cb(void *data, Eina_File **file)
|
||||
void done_open_cb(void *data, void* value, Eina_Promise* promise)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN(data);
|
||||
EINA_SAFETY_ON_NULL_RETURN(file);
|
||||
EINA_SAFETY_ON_NULL_RETURN(*file);
|
||||
EINA_SAFETY_ON_NULL_RETURN(value);
|
||||
|
||||
Eina_File *file = eina_file_dup(value);
|
||||
|
||||
Eio_Job *job = data;
|
||||
|
||||
const char *name = eina_file_filename_get(*file);
|
||||
const char *name = eina_file_filename_get(file);
|
||||
printf("%s opened file %s\n", __FUNCTION__, name);
|
||||
|
||||
closing_job(job, *file);
|
||||
closing_job(job, file);
|
||||
}
|
||||
|
||||
void open_file(const char *path)
|
||||
|
@ -54,8 +54,7 @@ void open_file(const char *path)
|
|||
Eina_Promise *promise;
|
||||
|
||||
Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
|
||||
eio_job_file_open(job, path, EINA_FALSE, &promise);
|
||||
eina_promise_then(promise, (Eina_Promise_Cb)&done_open_cb, (Eina_Promise_Error_Cb)&error_cb, job);
|
||||
eina_promise_then(eio_job_file_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, job);
|
||||
|
||||
eo_unref(job);
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
#include <Eio.h>
|
||||
#include <Ecore.h>
|
||||
|
||||
void error_cb(void *data, Eina_Error *error)
|
||||
void error_cb(void *data, Eina_Error error)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN(error);
|
||||
EINA_SAFETY_ON_NULL_RETURN(data);
|
||||
|
||||
const char *msg = eina_error_msg_get(*error);
|
||||
const char *msg = eina_error_msg_get(error);
|
||||
EINA_LOG_ERR("error: %s", msg);
|
||||
|
||||
Eio_Job *job = data;
|
||||
|
@ -23,10 +23,12 @@ void error_cb(void *data, Eina_Error *error)
|
|||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
void done_closing_cb(void *data, Eina_Iterator **result EINA_UNUSED)
|
||||
void done_closing_cb(void *data, void* value EINA_UNUSED)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN(data);
|
||||
|
||||
Eina_Iterator* result = value;
|
||||
|
||||
printf("%s closed file.\n", __FUNCTION__);
|
||||
|
||||
Eio_Job *job = data;
|
||||
|
@ -44,7 +46,7 @@ void closing_job(Eio_Job *job, Eina_File *file1, Eina_File *file2)
|
|||
eio_job_file_close(job, file1, &tasks[0]);
|
||||
eio_job_file_close(job, file2, &tasks[1]);
|
||||
promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0]));
|
||||
eina_promise_then(promise, (Eina_Promise_Cb)&done_closing_cb, (Eina_Promise_Error_Cb)&error_cb, job);
|
||||
eina_promise_then(promise, &done_closing_cb, &error_cb, job);
|
||||
}
|
||||
|
||||
void done_open_cb(void *data, Eina_Iterator **iterator)
|
||||
|
@ -74,8 +76,8 @@ void open_file(const char *path, const char *path2)
|
|||
Eina_Promise *tasks[3] = {NULL, NULL, NULL};
|
||||
|
||||
Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
|
||||
eio_job_file_open(job, path, EINA_FALSE, &tasks[0]);
|
||||
eio_job_file_open(job, path2, EINA_FALSE, &tasks[1]);
|
||||
tasks[0] = eio_job_file_open(job, path, EINA_FALSE);
|
||||
tasks[1] = eio_job_file_open(job, path2, EINA_FALSE);
|
||||
promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0]));
|
||||
eina_promise_then(promise, (Eina_Promise_Cb)&done_open_cb, (Eina_Promise_Error_Cb)&error_cb, job);
|
||||
}
|
||||
|
|
|
@ -15,21 +15,15 @@
|
|||
|
||||
static int prop_count = 0;
|
||||
|
||||
struct eina_iterator
|
||||
{
|
||||
Eina_Iterator* success_iterator;
|
||||
Eina_Iterator* failure_iterator;
|
||||
};
|
||||
|
||||
static void
|
||||
promise_then_prop_c(Eo* obj, struct eina_iterator* it_struct)
|
||||
promise_then_prop_c(Eo* obj, void* data)
|
||||
{
|
||||
Eina_Value * property_value;
|
||||
const Eina_Array *properties_list;
|
||||
Eina_Array_Iterator a_it;
|
||||
char *property, *prop_str;
|
||||
const char *name;
|
||||
Eina_Iterator* it = it_struct->success_iterator;
|
||||
Eina_Iterator* it = data;
|
||||
|
||||
name = eldbus_model_proxy_name_get(obj);
|
||||
properties_list = efl_model_properties_get(obj);
|
||||
|
@ -59,7 +53,7 @@ error_cb(void* data EINA_UNUSED, const Eina_Error *error EINA_UNUSED)
|
|||
}
|
||||
|
||||
static void
|
||||
promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
|
||||
promise_then_a(Eo* obj EINA_UNUSED, void* data)
|
||||
{
|
||||
const Eina_Array *properties_list;
|
||||
Eina_Array_Iterator a_it;
|
||||
|
@ -68,8 +62,9 @@ promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
|
|||
char *property;
|
||||
Eo* child;
|
||||
int i = 0;
|
||||
Eina_Accessor* accessor = data;
|
||||
|
||||
EINA_ACCESSOR_FOREACH(*accessor, i, child)
|
||||
EINA_ACCESSOR_FOREACH(accessor, i, child)
|
||||
{
|
||||
properties_list = efl_model_properties_get(child);
|
||||
name = eldbus_model_proxy_name_get(child);
|
||||
|
@ -87,7 +82,7 @@ promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
|
|||
efl_model_property_get(child, property, &promises[j]);
|
||||
}
|
||||
eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
|
||||
(Eina_Promise_Cb)&promise_then_prop_c, &error_cb, child);
|
||||
&promise_then_prop_c, &error_cb, child);
|
||||
prop_count++;
|
||||
}
|
||||
else
|
||||
|
@ -100,14 +95,14 @@ promise_then_a(Eo* obj EINA_UNUSED, Eina_Accessor **accessor)
|
|||
ecore_main_loop_quit();
|
||||
}
|
||||
static void
|
||||
promise_then(Eo* obj EINA_UNUSED, struct eina_iterator* it_struct)
|
||||
promise_then(Eo* obj EINA_UNUSED, void* data)
|
||||
{
|
||||
Eina_Accessor **accessor;
|
||||
Eina_Accessor *accessor;
|
||||
unsigned int* count;
|
||||
|
||||
Eina_Iterator* iterator = it_struct->success_iterator;
|
||||
Eina_Iterator* iterator = data;
|
||||
|
||||
if (!eina_iterator_next(iterator, (void **)&accessor))
|
||||
if (!eina_iterator_next(iterator, (void**)&accessor))
|
||||
{
|
||||
printf("bye\n");
|
||||
ecore_main_loop_quit();
|
||||
|
@ -144,7 +139,7 @@ main(int argc, char **argv EINA_UNUSED)
|
|||
efl_model_children_count_get(root, &promises[1]);
|
||||
|
||||
eina_promise_then(eina_promise_all(eina_carray_iterator_new((void **)promises)),
|
||||
(Eina_Promise_Cb)&promise_then, &error_cb, root);
|
||||
&promise_then, &error_cb, root);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ _promise_then(void *data, void *value)
|
|||
char *path;
|
||||
Eo *model;
|
||||
|
||||
eina_value_get((Eina_Value *)value, &path);
|
||||
eina_value_get(value, &path);
|
||||
model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, path));
|
||||
elm_view_list_model_set(priv->fileview, model);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue