eio_file_ls() tutorial

To use eio_file_ls(), you just need to define four callbacks:

  • The filter callback, which allows a file to be seen (or not) by the main loop handler. This callback runs in a separate thread.
  • The main callback, which receive in the main loop all the file that are allowed by the filter. If you are updating a user interface it makes sense to delay the insertion a little, so you get a chance to update the canvas for a bunch of files instead of one by one.
  • The end callback, which is called in the main loop when the content of the directory has been correctly scanned and all the file notified to the main loop.
  • The error callback, which is called if an error occurred or if the listing was cancelled during its run. You can then retrieve the error type as an errno error.

Here is a simple example:

#include <Ecore.h>
#include <Eio.h>
static Eina_Bool
_test_filter_cb(void *data, Eio_File *handler, const char *file)
{
fprintf(stderr, "ACCEPTING: %s\n", file);
return EINA_TRUE;
}
static void
_test_main_cb(void *data, Eio_File *handler, const char *file)
{
fprintf(stderr, "PROCESS: %s\n", file);
}
static void
_test_done_cb(void *data, Eio_File *handler)
{
printf("ls done\n");
}
static void
_test_error_cb(void *data, Eio_File *handler, int error)
{
fprintf(stderr, "error: [%s]\n", strerror(error));
}
int
main(int argc, char **argv)
{
Eio_File *cp;
if (argc != 2)
{
fprintf(stderr, "eio_ls directory\n");
return -1;
}
cp = eio_file_ls(argv[1],
_test_filter_cb,
_test_main_cb,
_test_done_cb,
_test_error_cb,
NULL);
return 0;
}
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:371
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:230
void ecore_main_loop_quit(void)
Quits the main loop once all the events currently on the queue have been processed.
Definition: ecore_main.c:1321
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
EIO_API int eio_init(void)
Initialize eio and all its required submodule.
Definition: eio_main.c:276
EIO_API int eio_shutdown(void)
Shutdown eio and all its submodule if possible.
Definition: eio_main.c:340
EIO_API Eio_File * eio_file_ls(const char *dir, Eio_Filter_Cb filter_cb, Eio_Main_Cb main_cb, Eio_Done_Cb done_cb, Eio_Error_Cb error_cb, const void *data)
List contents of a directory without locking your app.
Definition: eio_file.c:577
struct _Eio_File Eio_File
Generic asynchronous I/O reference.
Definition: Eio.h:73