summaryrefslogtreecommitdiff
path: root/legacy/eio/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2010-11-02 17:08:00 +0000
committerCedric BAIL <cedric.bail@free.fr>2010-11-02 17:08:00 +0000
commit058deb3c1f353f093aab2cbac74a9dbfb9d9297e (patch)
treec9cb1947d454b876fcd06ded9ed4a37b6a012666 /legacy/eio/src
parent17973f336ed4da265ad4b6f5a8e01d25807fc9a1 (diff)
* eio: add eio_file_stat_ls.
SVN revision: 54106
Diffstat (limited to 'legacy/eio/src')
-rw-r--r--legacy/eio/src/lib/Eio.h7
-rw-r--r--legacy/eio/src/lib/eio_file.c75
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,
149 Eio_Error_Cb error_cb, 149 Eio_Error_Cb error_cb,
150 const void *data); 150 const void *data);
151 151
152EAPI Eio_File *eio_file_stat_ls(const char *dir,
153 Eio_Filter_Direct_Cb filter_cb,
154 Eio_Main_Direct_Cb main_cb,
155 Eio_Done_Cb done_cb,
156 Eio_Error_Cb error_cb,
157 const void *data);
158
152EAPI Eio_File *eio_file_direct_stat(const char *path, 159EAPI Eio_File *eio_file_direct_stat(const char *path,
153 Eio_Stat_Cb done_cb, 160 Eio_Stat_Cb done_cb,
154 Eio_Error_Cb error_cb, 161 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)
158} 158}
159 159
160static void 160static void
161_eio_file_direct_heavy(Ecore_Thread *thread, void *data) 161_eio_file_eina_ls_heavy(Ecore_Thread *thread, Eio_File_Direct_Ls *async, Eina_Iterator *ls)
162{ 162{
163 Eio_File_Direct_Ls *async = data;
164 Eina_Iterator *ls;
165 const Eina_File_Direct_Info *info; 163 const Eina_File_Direct_Info *info;
166 164
167 ls = eina_file_direct_ls(async->ls.directory);
168 if (!ls) 165 if (!ls)
169 { 166 {
170 eio_file_thread_error(&async->ls.common, thread); 167 eio_file_thread_error(&async->ls.common, thread);
@@ -200,6 +197,28 @@ _eio_file_direct_heavy(Ecore_Thread *thread, void *data)
200} 197}
201 198
202static void 199static void
200_eio_file_direct_heavy(Ecore_Thread *thread, void *data)
201{
202 Eio_File_Direct_Ls *async = data;
203 Eina_Iterator *ls;
204
205 ls = eina_file_direct_ls(async->ls.directory);
206
207 _eio_file_eina_ls_heavy(thread, async, ls);
208}
209
210static void
211_eio_file_stat_heavy(Ecore_Thread *thread, void *data)
212{
213 Eio_File_Direct_Ls *async = data;
214 Eina_Iterator *ls;
215
216 ls = eina_file_stat_ls(async->ls.directory);
217
218 _eio_file_eina_ls_heavy(thread, async, ls);
219}
220
221static void
203_eio_file_direct_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data) 222_eio_file_direct_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data)
204{ 223{
205 Eio_File_Direct_Ls *async = data; 224 Eio_File_Direct_Ls *async = data;
@@ -702,6 +721,54 @@ eio_file_direct_ls(const char *dir,
702} 721}
703 722
704/** 723/**
724 * @brief List content of a directory without locking your app.
725 * @param dir The directory to list.
726 * @param filter_cb Callback called from another thread.
727 * @param main_cb Callback called from the main loop for each accepted file.
728 * @param done_cb Callback called from the main loop when the content of the directory has been listed.
729 * @param error_cb Callback called from the main loop when the directory could not be opened or listing content has been canceled.
730 * @param data Data passed to callback and not modified at all by eio_file_direct_ls.
731 * @return A reference to the IO operation.
732 *
733 * eio_file_stat_ls() run eina_file_stat_ls() in a separated thread using
734 * ecore_thread_feedback_run. This prevent any lock in your apps.
735 */
736EAPI Eio_File *
737eio_file_stat_ls(const char *dir,
738 Eio_Filter_Direct_Cb filter_cb,
739 Eio_Main_Direct_Cb main_cb,
740 Eio_Done_Cb done_cb,
741 Eio_Error_Cb error_cb,
742 const void *data)
743{
744 Eio_File_Direct_Ls *async;
745
746 EINA_SAFETY_ON_NULL_RETURN_VAL(dir, NULL);
747 EINA_SAFETY_ON_NULL_RETURN_VAL(main_cb, NULL);
748 EINA_SAFETY_ON_NULL_RETURN_VAL(done_cb, NULL);
749 EINA_SAFETY_ON_NULL_RETURN_VAL(error_cb, NULL);
750
751 async = malloc(sizeof(Eio_File_Direct_Ls));
752 EINA_SAFETY_ON_NULL_RETURN_VAL(async, NULL);
753
754 async->filter_cb = filter_cb;
755 async->main_cb = main_cb;
756 async->ls.directory = eina_stringshare_add(dir);
757
758 if (!eio_long_file_set(&async->ls.common,
759 done_cb,
760 error_cb,
761 data,
762 _eio_file_stat_heavy,
763 _eio_file_direct_notify,
764 _eio_file_end,
765 _eio_file_error))
766 return NULL;
767
768 return &async->ls.common;
769}
770
771/**
705 * @brief Cancel any Eio_File. 772 * @brief Cancel any Eio_File.
706 * @param ls The asynchronous IO operation to cancel. 773 * @param ls The asynchronous IO operation to cancel.
707 * @return EINA_FALSE if the destruction is delayed, EINA_TRUE if it's done. 774 * @return EINA_FALSE if the destruction is delayed, EINA_TRUE if it's done.