eio: finish port to new efl_io_manager API.

This commit is contained in:
Cedric BAIL 2016-09-09 16:22:20 -07:00
parent 085adca305
commit fca20d5579
3 changed files with 123 additions and 145 deletions

View File

@ -10,69 +10,71 @@
#include <Eio.h> #include <Eio.h>
#include <Ecore.h> #include <Ecore.h>
void done_cb(void *data, void *value EINA_UNUSED) void leave(Efl_Io_Manager *job)
{ {
Efl_Io_Manager *job = data; ecore_main_loop_quit();
printf("%s done listing files.\n", __FUNCTION__);
ecore_main_loop_quit();
efl_unref(job);
} }
void error_cb(void *data, Eina_Error error) void done_cb(void *data, const Efl_Event *ev)
{ {
Efl_Io_Manager *job = data; Efl_Future_Event_Success *success = ev->info;
const char *msg = eina_error_msg_get(error); uint64_t *count = success->value;
printf("%s error: %s\n", __FUNCTION__, msg);
ecore_main_loop_quit();
efl_unref(job); printf("%s done listing files %i.\n", __FUNCTION__, *count);
leave(data);
} }
void filter_cb(void *data EINA_UNUSED, const Efl_Event *event) void error_cb(void *data, const Efl_Event *ev)
{ {
Eio_Filter_Name_Data *event_info = event->info; Efl_Future_Event_Failure *failure = ev->info;
static Eina_Bool should_filter = EINA_FALSE; const char *msg = eina_error_msg_get(failure->error);
printf("Filtering file %s\n", event_info->file); printf("%s error: %s\n", __FUNCTION__, msg);
should_filter = !should_filter; leave(data);
event_info->filter = should_filter;
} }
// Progress used to be the "Eio_Main_Cb" family of callbacks in the legacy API. // Progress used to be the "Eio_Main_Cb" family of callbacks in the legacy API.
void progress_cb(void *data EINA_UNUSED, const char *filename) void progress_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{ {
EINA_SAFETY_ON_NULL_RETURN(filename); Efl_Future_Event_Progress *p = ev->info;
printf("%s listing filename: %s\n", __FUNCTION__, filename); const Eina_Array *batch = p->progress;
Eina_Iterator *it;
const char *filename;
it = eina_array_iterator_new(batch);
EINA_ITERATOR_FOREACH(it, filename)
printf("%s listing filename: %s\n", __FUNCTION__, filename);
eina_iterator_free(it);
} }
void list_files(void *data) void list_files(void *data)
{ {
Eina_Promise *promise; Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
const char *path = data; const char *path = data;
Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, NULL); efl_future_then(efl_io_manager_ls(job, path), &done_cb, &error_cb, &progress_cb, job);
efl_event_callback_add(job, EFL_IO_MANAGER_EVENT_FILTER_NAME, (Efl_Event_Cb)&filter_cb, NULL);
promise = efl_io_manager_file_ls(job, path);
eina_promise_progress_cb_add(promise, (Eina_Promise_Progress_Cb)&progress_cb, NULL, NULL);
eina_promise_then(promise, &done_cb, &error_cb, job);
} }
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
eio_init(); const char *path;
ecore_init(); Ecore_Job *job;
const char *path = getenv("HOME"); eio_init();
ecore_init();
if (argc > 1) path = getenv("HOME");
path = argv[1];
Ecore_Job *job = ecore_job_add(&list_files, path); if (argc > 1)
path = argv[1];
ecore_main_loop_begin(); job = ecore_job_add(&list_files, path);
ecore_shutdown(); ecore_main_loop_begin();
eio_shutdown();
return 0; ecore_shutdown();
eio_shutdown();
return 0;
} }

View File

@ -9,69 +9,59 @@
#include <Eio.h> #include <Eio.h>
#include <Ecore.h> #include <Ecore.h>
void error_cb(void *data, Eina_Error error) void error_cb(void *data, const Efl_Event *ev)
{ {
EINA_SAFETY_ON_NULL_RETURN(data); Efl_Future_Event_Failure *failure = ev->info;
const char *msg = eina_error_msg_get(failure->error);
EINA_LOG_ERR("error: %s", msg);
const char *msg = eina_error_msg_get(error); ecore_main_loop_quit();
EINA_LOG_ERR("error: %s", msg);
ecore_main_loop_quit();
} }
void done_closing_cb(void* data EINA_UNUSED, void *value EINA_UNUSED) void done_closing_cb(void* data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{ {
printf("%s closed file.\n", __FUNCTION__); printf("%s closed file.\n", __FUNCTION__);
ecore_main_loop_quit(); ecore_main_loop_quit();
} }
void closing_job(Efl_Io_Manager *job, Eina_File *file) void done_open_cb(void *data, const Efl_Event *ev)
{ {
Eina_Promise *promise = NULL; Efl_Future_Event_Success *success = ev->info;
printf("%s Will close the file...\n", __FUNCTION__); Eina_File *file = success->value;
efl_io_manager_file_close(job, file, &promise); Efl_Io_Manager *job = data;
eina_promise_then(promise, &done_closing_cb, &error_cb, job);
}
void done_open_cb(void *data, void* value) printf("%s opened file %s\n", __FUNCTION__, eina_file_filename_get(file));
{
EINA_SAFETY_ON_NULL_RETURN(data);
EINA_SAFETY_ON_NULL_RETURN(value);
Eina_File *file = eina_file_dup(value); efl_future_then(efl_io_manager_close(job, file), &done_closing_cb, &error_cb, NULL, NULL);
Efl_Io_Manager *job = data;
const char *name = eina_file_filename_get(file);
printf("%s opened file %s\n", __FUNCTION__, name);
closing_job(job, file);
} }
void open_file(const char *path) void open_file(const char *path)
{ {
Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, NULL); Efl_Io_Manager *job;
eina_promise_then(efl_io_manager_file_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, job);
efl_unref(job); job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
efl_future_then(efl_io_manager_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, NULL, job);
} }
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
eio_init(); const char *path;
ecore_init();
const char *path = getenv("HOME"); eio_init();
ecore_init();
if (argc > 1) path = getenv("HOME");
path = argv[1];
open_file(path); if (argc > 1)
path = argv[1];
ecore_main_loop_begin(); open_file(path);
ecore_shutdown(); ecore_main_loop_begin();
eio_shutdown();
return 0; ecore_shutdown();
eio_shutdown();
return 0;
} }

View File

@ -9,96 +9,82 @@
#include <Eio.h> #include <Eio.h>
#include <Ecore.h> #include <Ecore.h>
void error_cb(void *data, Eina_Error error) void error_cb(void *data, const Efl_Event *ev)
{ {
EINA_SAFETY_ON_NULL_RETURN(data); Efl_Future_Event_Failure *failure = ev->info;
const char *msg = eina_error_msg_get(failure->error);
Efl_Io_Manager *job = data;
const char *msg = eina_error_msg_get(error); EINA_LOG_ERR("error: %s", msg);
EINA_LOG_ERR("error: %s", msg);
Efl_Io_Manager *job = data; ecore_main_loop_quit();
efl_unref(job);
ecore_main_loop_quit();
} }
void done_closing_cb(void *data, void* value EINA_UNUSED) void done_closing_cb(void *data, const Efl_Event *ev EINA_UNUSED)
{ {
EINA_SAFETY_ON_NULL_RETURN(data); Efl_Io_Manager *job = data;
Eina_Iterator* result = value; printf("%s closed all files.\n", __FUNCTION__);
printf("%s closed file.\n", __FUNCTION__); ecore_main_loop_quit();
Efl_Io_Manager *job = data;
efl_unref(job);
ecore_main_loop_quit();
} }
void closing_job(Efl_Io_Manager *job, Eina_File *file1, Eina_File *file2) void done_open_cb(void *data, const Efl_Event *ev)
{ {
Eina_Promise *promise; Efl_Future_Event_Success *s = ev->info;
Eina_Promise *tasks[3] = {NULL, NULL, NULL}; Efl_Io_Manager *job = data;
Eina_Accessor *ac = s->value;
Eina_Iterator *it;
Eina_Array stack;
Eina_File *f;
unsigned int i;
printf("%s Closing files.\n", __FUNCTION__); eina_array_step_set(&stack, sizeof (Eina_Array), 4);
efl_io_manager_file_close(job, file1, &tasks[0]);
efl_io_manager_file_close(job, file2, &tasks[1]); EINA_ACCESSOR_FOREACH(ac, i, f)
promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0])); {
eina_promise_then(promise, &done_closing_cb, &error_cb, job); printf("%s opened file %s [%i]\n", __FUNCTION__, eina_file_filename_get(f), i);
eina_array_push(&stack, efl_io_manager_close(job, f));
}
it = eina_array_iterator_new(&stack);
efl_future_then(efl_future_iterator_all(it), &done_closing_cb, &error_cb, NULL, job);
eina_array_flush(&stack);
} }
void done_open_cb(void *data, Eina_Iterator **iterator) Efl_Future *open_file(Efl_Io_Manager *job, const char *path)
{ {
EINA_SAFETY_ON_NULL_RETURN(data); return efl_io_manager_open(job, path, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN(iterator);
EINA_SAFETY_ON_NULL_RETURN(*iterator);
Efl_Io_Manager *job = data;
Eina_File **file = NULL;
Eina_File **files = calloc(sizeof(Eina_File*),2);
int i = 0;
while (eina_iterator_next(*iterator, (void**)&file))
{
files[i] = *file;
const char *name = eina_file_filename_get(*file);
printf("%s opened file %s\n", __FUNCTION__, name);
i++;
}
closing_job(job, files[0], files[1]);
free(files);
}
void open_file(const char *path, const char *path2)
{
Eina_Promise *promise;
Eina_Promise *tasks[3] = {NULL, NULL, NULL};
Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, NULL);
tasks[0] = efl_io_manager_file_open(job, path, EINA_FALSE);
tasks[1] = efl_io_manager_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);
} }
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
eio_init(); Efl_Io_Manager *job;
ecore_init(); const char *path;
const char *path2;
const char *path = getenv("HOME"); eio_init();
const char *path2 = "./"; ecore_init();
if (argc > 1) job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
path = argv[1];
if (argc > 2)
path2 = argv[2];
open_file(path, path2); path = getenv("HOME");
path2 = "./";
ecore_main_loop_begin(); if (argc > 1)
path = argv[1];
if (argc > 2)
path2 = argv[2];
ecore_shutdown(); efl_future_then(efl_future_all(open_file(job, path), open_file(job, path2)),
eio_shutdown(); &done_open_cb, &error_cb, NULL, job);
return 0;
ecore_main_loop_begin();
efl_del(job);
ecore_shutdown();
eio_shutdown();
return 0;
} }