eio: finish port to new efl_io_manager API.
authorCedric BAIL <cedric@osg.samsung.com>
Fri, 9 Sep 2016 23:22:20 +0000 (16:22 -0700)
committerCedric BAIL <cedric@osg.samsung.com>
Fri, 9 Sep 2016 23:22:55 +0000 (16:22 -0700)
src/examples/eio/efl_io_manager_ls.c
src/examples/eio/efl_io_manager_open.c
src/examples/eio/efl_io_manager_open_multi.c

index 362b3c7..b1f5ea9 100644 (file)
 #include <Eio.h>
 #include <Ecore.h>
 
-void done_cb(void *data, void *value EINA_UNUSED)
+void leave(Efl_Io_Manager *job)
 {
-    Efl_Io_Manager *job = data;
-    printf("%s done listing files.\n", __FUNCTION__);
-    ecore_main_loop_quit();
-    efl_unref(job);
+   ecore_main_loop_quit();
 }
 
-void error_cb(void *data, Eina_Error error)
+void done_cb(void *data, const Efl_Event *ev)
 {
-    Efl_Io_Manager *job = data;
-    const char *msg = eina_error_msg_get(error);
-    printf("%s error: %s\n", __FUNCTION__, msg);
-    ecore_main_loop_quit();
+   Efl_Future_Event_Success *success = ev->info;
+   uint64_t *count = success->value;
 
-    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;
-    static Eina_Bool should_filter = EINA_FALSE;
+   Efl_Future_Event_Failure *failure = ev->info;
+   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;
-    event_info->filter = should_filter;
+   leave(data);
 }
 
 // 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);
-    printf("%s listing filename: %s\n", __FUNCTION__, filename);
+   Efl_Future_Event_Progress *p = ev->info;
+   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)
 {
-    Eina_Promise *promise;
-    const char *path = data;
-
-    Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, NULL);
-    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);
+   Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
+   const char *path = data;
+
+   efl_future_then(efl_io_manager_ls(job, path), &done_cb, &error_cb, &progress_cb, job);
 }
 
 int main(int argc, char const *argv[])
 {
-    eio_init();
-    ecore_init();
+   const char *path;
+   Ecore_Job *job;
+
+   eio_init();
+   ecore_init();
 
-    const char *path = getenv("HOME");
+   path = getenv("HOME");
 
-    if (argc > 1)
-        path = argv[1];
+   if (argc > 1)
+     path = argv[1];
 
-    Ecore_Job *job = ecore_job_add(&list_files, path);
+   job = ecore_job_add(&list_files, path);
 
-    ecore_main_loop_begin();
+   ecore_main_loop_begin();
 
-    ecore_shutdown();
-    eio_shutdown();
-    return 0;
+   ecore_shutdown();
+   eio_shutdown();
+   return 0;
 }
index 4c9f4a4..739f76f 100644 (file)
@@ -9,69 +9,59 @@
 #include <Eio.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);
-    EINA_LOG_ERR("error: %s", msg);
-
-    ecore_main_loop_quit();
+   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__);
-
-    ecore_main_loop_quit();
-}
+   printf("%s closed file.\n", __FUNCTION__);
 
-void closing_job(Efl_Io_Manager *job, Eina_File *file)
-{
-    Eina_Promise *promise = NULL;
-    printf("%s Will close the file...\n", __FUNCTION__);
-    efl_io_manager_file_close(job, file, &promise);
-    eina_promise_then(promise, &done_closing_cb, &error_cb, job);
+   ecore_main_loop_quit();
 }
 
-void done_open_cb(void *data, void* value)
+void done_open_cb(void *data, const Efl_Event *ev)
 {
-    EINA_SAFETY_ON_NULL_RETURN(data);
-    EINA_SAFETY_ON_NULL_RETURN(value);
+   Efl_Future_Event_Success *success = ev->info;
+   Eina_File *file = success->value;
+   Efl_Io_Manager *job = data;
 
-    Eina_File *file = eina_file_dup(value);
+   printf("%s opened file %s\n", __FUNCTION__, eina_file_filename_get(file));
 
-    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);
+   efl_future_then(efl_io_manager_close(job, file), &done_closing_cb, &error_cb, NULL, NULL);
 }
 
 void open_file(const char *path)
 {
-    Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, NULL);
-    eina_promise_then(efl_io_manager_file_open(job, path, EINA_FALSE), &done_open_cb, &error_cb, job);
+   Efl_Io_Manager *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[])
 {
-    eio_init();
-    ecore_init();
+   const char *path;
+
+   eio_init();
+   ecore_init();
 
-    const char *path = getenv("HOME");
+   path = getenv("HOME");
 
-    if (argc > 1)
-        path = argv[1];
+   if (argc > 1)
+     path = argv[1];
 
-    open_file(path);
+   open_file(path);
 
-    ecore_main_loop_begin();
+   ecore_main_loop_begin();
 
-    ecore_shutdown();
-    eio_shutdown();
-    return 0;
+   ecore_shutdown();
+   eio_shutdown();
+   return 0;
 }
index e55f039..e56cffa 100644 (file)
@@ -9,96 +9,82 @@
 #include <Eio.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;
-    efl_unref(job);
-
-    ecore_main_loop_quit();
+   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);
-
-    Eina_Iterator* result = value;
-
-    printf("%s closed file.\n", __FUNCTION__);
+   Efl_Io_Manager *job = data;
 
-    Efl_Io_Manager *job = data;
-    efl_unref(job);
+   printf("%s closed all files.\n", __FUNCTION__);
 
-    ecore_main_loop_quit();
+   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;
-    Eina_Promise *tasks[3] = {NULL, NULL, NULL};
-
-    printf("%s Closing files.\n", __FUNCTION__);
-    efl_io_manager_file_close(job, file1, &tasks[0]);
-    efl_io_manager_file_close(job, file2, &tasks[1]);
-    promise = eina_promise_all(eina_carray_iterator_new((void**)&tasks[0]));
-    eina_promise_then(promise, &done_closing_cb, &error_cb, job);
+   Efl_Future_Event_Success *s = ev->info;
+   Efl_Io_Manager *job = data;
+   Eina_Accessor *ac = s->value;
+   Eina_Iterator *it;
+   Eina_Array stack;
+   Eina_File *f;
+   unsigned int i;
+
+   eina_array_step_set(&stack, sizeof (Eina_Array), 4);
+
+   EINA_ACCESSOR_FOREACH(ac, i, f)
+     {
+        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);
-    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);
+   return efl_io_manager_open(job, path, EINA_FALSE);
 }
 
 int main(int argc, char const *argv[])
 {
-    eio_init();
-    ecore_init();
+   Efl_Io_Manager *job;
+   const char *path;
+   const char *path2;
+
+   eio_init();
+   ecore_init();
+
+   job = efl_add(EFL_IO_MANAGER_CLASS, ecore_main_loop_get());
+
+   path = getenv("HOME");
+   path2 = "./";
 
-    const char *path = getenv("HOME");
-    const char *path2 = "./";
+   if (argc > 1)
+     path = argv[1];
+   if (argc > 2)
+     path2 = argv[2];
 
-    if (argc > 1)
-        path = argv[1];
-    if (argc > 2)
-        path2 = argv[2];
+   efl_future_then(efl_future_all(open_file(job, path), open_file(job, path2)),
+                   &done_open_cb, &error_cb, NULL, job);
 
-    open_file(path, path2);
+   ecore_main_loop_begin();
 
-    ecore_main_loop_begin();
+   efl_del(job);
 
-    ecore_shutdown();
-    eio_shutdown();
-    return 0;
+   ecore_shutdown();
+   eio_shutdown();
+   return 0;
 }