• The filter callback, which allow or not a file to be seen by the main loop handler. This callback run in a separated thread. It also take care of getting a stat buffer needed by the main callback to display the file size.
  • 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 make sense to delay the insertion a little, so you get a chance to update the canvas for a bunch of file 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 it's run. You can then retrieve the error type as an errno error.

Here is a simple example that implement a stupidly simple recursive ls that display file size:

#include <Eina.h>
#include <Ecore.h>
#include <Eio.h>
static Eina_Bool
_test_filter_cb(void *data, Eio_File *handler, Eina_File_Direct_Info *info)
{
Eina_Stat *buffer;
Eina_Bool isdir;
isdir = info->type == EINA_FILE_DIR;
buffer = malloc(sizeof (Eina_Stat));
if (eina_file_statat(eio_file_container_get(handler), info, buffer))
{
free(buffer);
return EINA_FALSE;
}
if (!isdir && info->type == EINA_FILE_DIR)
{
struct stat st;
if (lstat(info->path, &st) == 0)
{
if (S_ISLNK(st.st_mode))
}
}
eio_file_associate_direct_add(handler, "stat", buffer, free);
fprintf(stdout, "ACCEPTING: %s\n", info->path);
return EINA_TRUE;
}
static void
_test_main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info)
{
struct stat *buffer;
buffer = eio_file_associate_find(handler, "stat");
fprintf(stdout, "PROCESS: %s of size %li\n", info->path, buffer->st_size);
}
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(stdout, "error: [%s]\n", strerror(error));
}
int
main(int argc, char **argv)
{
Eio_File *cp;
if (argc != 2)
{
fprintf(stdout, "eio_ls directory\n");
return -1;
}
cp = eio_dir_direct_ls(argv[1],
_test_filter_cb,
_test_main_cb,
_test_done_cb,
_test_error_cb,
NULL);
return 0;
}
_Eina_File_Direct_Info::path
char path[EINA_PATH_MAX]
The path.
Definition: eina_file.h:198
eio_file_associate_direct_add
Eina_Bool eio_file_associate_direct_add(Eio_File *ls, const char *key, const void *data, Eina_Free_Cb free_cb)
Associate data with the current filtered file.
Definition: eio_file.c:782
eio_dir_direct_ls
Eio_File * eio_dir_direct_ls(const char *dir, Eio_Filter_Dir_Cb filter_cb, Eio_Main_Direct_Cb main_cb, Eio_Done_Cb done_cb, Eio_Error_Cb error_cb, const void *data)
List the content of a directory and all its sub-content asynchronously.
Definition: eio_dir.c:1086
ecore_main_loop_quit
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:1300
Eina.h
Eina Utility library.
EINA_FALSE
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
_Eina_File_Direct_Info
The structure to store information of a path.
Definition: eina_file.h:193
eio_shutdown
int eio_shutdown(void)
Shutdown eio and all its submodule if possible.
Definition: eio_main.c:340
_Eina_Stat
The structure to store some file statistics.
Definition: eina_file.h:207
EINA_FILE_LNK
@ EINA_FILE_LNK
Symbolic link type (unused on Windows)
Definition: eina_file.h:126
eio_file_container_get
void * eio_file_container_get(Eio_File *ls)
Return the container during EIO operation.
Definition: eio_file.c:759
eio_init
int eio_init(void)
Initialize eio and all its required submodule.
Definition: eio_main.c:276
_Eina_File_Direct_Info::type
Eina_File_Type type
File type.
Definition: eina_file.h:197
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1290
eio_file_associate_find
void * eio_file_associate_find(Eio_File *ls, const char *key)
Get the data associated during the filter callback inside the main loop.
Definition: eio_file.c:798
EINA_FILE_DIR
@ EINA_FILE_DIR
Directory type.
Definition: eina_file.h:123
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
eina_file_statat
int eina_file_statat(void *container, Eina_File_Direct_Info *info, Eina_Stat *st)
Uses information provided by Eina_Iterator of eina_file_stat_ls() or eina_file_direct_ls() to call st...
Definition: eina_file.c:1181
Eina_Bool
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
ecore_shutdown
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:373
Eio_File
struct _Eio_File Eio_File
Generic asynchronous I/O reference.
Definition: Eio.h:72
ecore_init
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:229