From 058deb3c1f353f093aab2cbac74a9dbfb9d9297e Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Tue, 2 Nov 2010 17:08:00 +0000 Subject: [PATCH] * eio: add eio_file_stat_ls. SVN revision: 54106 --- legacy/eio/src/lib/Eio.h | 7 ++++ legacy/eio/src/lib/eio_file.c | 75 +++++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/legacy/eio/src/lib/Eio.h b/legacy/eio/src/lib/Eio.h index bb89f43ab6..495d7a4d0e 100644 --- a/legacy/eio/src/lib/Eio.h +++ b/legacy/eio/src/lib/Eio.h @@ -149,6 +149,13 @@ EAPI Eio_File *eio_file_direct_ls(const char *dir, Eio_Error_Cb error_cb, const void *data); +EAPI Eio_File *eio_file_stat_ls(const char *dir, + Eio_Filter_Direct_Cb filter_cb, + Eio_Main_Direct_Cb main_cb, + Eio_Done_Cb done_cb, + Eio_Error_Cb error_cb, + const void *data); + EAPI Eio_File *eio_file_direct_stat(const char *path, Eio_Stat_Cb done_cb, Eio_Error_Cb error_cb, diff --git a/legacy/eio/src/lib/eio_file.c b/legacy/eio/src/lib/eio_file.c index dfcc021c08..d00d536ed0 100644 --- a/legacy/eio/src/lib/eio_file.c +++ b/legacy/eio/src/lib/eio_file.c @@ -158,13 +158,10 @@ _eio_file_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data) } static void -_eio_file_direct_heavy(Ecore_Thread *thread, void *data) +_eio_file_eina_ls_heavy(Ecore_Thread *thread, Eio_File_Direct_Ls *async, Eina_Iterator *ls) { - Eio_File_Direct_Ls *async = data; - Eina_Iterator *ls; const Eina_File_Direct_Info *info; - ls = eina_file_direct_ls(async->ls.directory); if (!ls) { eio_file_thread_error(&async->ls.common, thread); @@ -199,6 +196,28 @@ _eio_file_direct_heavy(Ecore_Thread *thread, void *data) eina_iterator_free(ls); } +static void +_eio_file_direct_heavy(Ecore_Thread *thread, void *data) +{ + Eio_File_Direct_Ls *async = data; + Eina_Iterator *ls; + + ls = eina_file_direct_ls(async->ls.directory); + + _eio_file_eina_ls_heavy(thread, async, ls); +} + +static void +_eio_file_stat_heavy(Ecore_Thread *thread, void *data) +{ + Eio_File_Direct_Ls *async = data; + Eina_Iterator *ls; + + ls = eina_file_stat_ls(async->ls.directory); + + _eio_file_eina_ls_heavy(thread, async, ls); +} + static void _eio_file_direct_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data) { @@ -701,6 +720,54 @@ eio_file_direct_ls(const char *dir, return &async->ls.common; } +/** + * @brief List content of a directory without locking your app. + * @param dir The directory to list. + * @param filter_cb Callback called from another thread. + * @param main_cb Callback called from the main loop for each accepted file. + * @param done_cb Callback called from the main loop when the content of the directory has been listed. + * @param error_cb Callback called from the main loop when the directory could not be opened or listing content has been canceled. + * @param data Data passed to callback and not modified at all by eio_file_direct_ls. + * @return A reference to the IO operation. + * + * eio_file_stat_ls() run eina_file_stat_ls() in a separated thread using + * ecore_thread_feedback_run. This prevent any lock in your apps. + */ +EAPI Eio_File * +eio_file_stat_ls(const char *dir, + Eio_Filter_Direct_Cb filter_cb, + Eio_Main_Direct_Cb main_cb, + Eio_Done_Cb done_cb, + Eio_Error_Cb error_cb, + const void *data) +{ + Eio_File_Direct_Ls *async; + + EINA_SAFETY_ON_NULL_RETURN_VAL(dir, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(main_cb, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL); + + async = malloc(sizeof(Eio_File_Direct_Ls)); + EINA_SAFETY_ON_NULL_RETURN_VAL(async, NULL); + + async->filter_cb = filter_cb; + async->main_cb = main_cb; + async->ls.directory = eina_stringshare_add(dir); + + if (!eio_long_file_set(&async->ls.common, + done_cb, + error_cb, + data, + _eio_file_stat_heavy, + _eio_file_direct_notify, + _eio_file_end, + _eio_file_error)) + return NULL; + + return &async->ls.common; +} + /** * @brief Cancel any Eio_File. * @param ls The asynchronous IO operation to cancel.