*Warning Breaks API so if you use eio, make the necessary changes* Make the changes k-s requested. Use Enums, Use shorter code, Change the format of the callbacks to be data first value last, etc..
SVN revision: 50771
This commit is contained in:
parent
e378c6035d
commit
bdb6e0f0ed
|
@ -54,24 +54,27 @@
|
||||||
# endif
|
# endif
|
||||||
#endif /* ! _WIN32 */
|
#endif /* ! _WIN32 */
|
||||||
|
|
||||||
#define EIO_FILE_MOD_TIME 1
|
typedef enum _Eio_File_Op_Flags
|
||||||
#define EIO_FILE_SIZE 2
|
{
|
||||||
#define EIO_FILE_EXISTS 4
|
EIO_FILE_MOD_TIME = 1,
|
||||||
#define EIO_FILE_IS_DIR 8
|
EIO_FILE_SIZE = 2,
|
||||||
#define EIO_FILE_CAN_READ 16
|
EIO_FILE_EXISTS = 4,
|
||||||
#define EIO_FILE_CAN_WRITE 32
|
EIO_FILE_IS_DIR = 8,
|
||||||
#define EIO_FILE_CAN_EXECUTE 64
|
EIO_FILE_CAN_READ = 16,
|
||||||
|
EIO_FILE_CAN_WRITE = 32,
|
||||||
|
EIO_FILE_CAN_EXECUTE = 64
|
||||||
|
} Eio_File_Op_Flags;
|
||||||
|
|
||||||
typedef struct _Eio_File Eio_File;
|
typedef struct _Eio_File Eio_File;
|
||||||
|
|
||||||
typedef Eina_Bool (*Eio_Filter_Cb)(const char *file, void *data);
|
typedef Eina_Bool (*Eio_Filter_Cb)(const void *data, const char *file);
|
||||||
typedef void (*Eio_Main_Cb)(const char *file, void *data);
|
typedef void (*Eio_Main_Cb)(const void *data, const char *file);
|
||||||
typedef void (*Eio_File_Op_Main_Cb)(void *value, short int flag, void *data);
|
typedef void (*Eio_File_Op_Main_Cb)(const void *data, Eio_File_Op_Flags flag, void *value);
|
||||||
|
|
||||||
typedef Eina_Bool (*Eio_Filter_Direct_Cb)(const Eina_File_Direct_Info *info, void *data);
|
typedef Eina_Bool (*Eio_Filter_Direct_Cb)(const void *data, const Eina_File_Direct_Info *info);
|
||||||
typedef void (*Eio_Main_Direct_Cb)(const Eina_File_Direct_Info *info, void *data);
|
typedef void (*Eio_Main_Direct_Cb)(const void *data, const Eina_File_Direct_Info *info);
|
||||||
|
|
||||||
typedef void (*Eio_Done_Cb)(void *data);
|
typedef void (*Eio_Done_Cb)(const void *data);
|
||||||
|
|
||||||
EAPI int eio_init(void);
|
EAPI int eio_init(void);
|
||||||
EAPI int eio_shutdown(void);
|
EAPI int eio_shutdown(void);
|
||||||
|
@ -93,7 +96,7 @@ EAPI Eio_File *eio_file_direct_ls(const char *dir,
|
||||||
EAPI Eina_Bool eio_file_cancel(Eio_File *ls);
|
EAPI Eina_Bool eio_file_cancel(Eio_File *ls);
|
||||||
|
|
||||||
EAPI Eio_File *eio_file_operation(const char *file,
|
EAPI Eio_File *eio_file_operation(const char *file,
|
||||||
short int eio_file_flags,
|
Eio_File_Op_Flags eio_file_flags,
|
||||||
Eio_File_Op_Main_Cb main_cb,
|
Eio_File_Op_Main_Cb main_cb,
|
||||||
Eio_Done_Cb done_cb,
|
Eio_Done_Cb done_cb,
|
||||||
Eio_Done_Cb error_cb,
|
Eio_Done_Cb error_cb,
|
||||||
|
|
|
@ -85,9 +85,9 @@ struct _Eio_File_Op
|
||||||
{
|
{
|
||||||
Eio_File common;
|
Eio_File common;
|
||||||
const char *file;
|
const char *file;
|
||||||
short int flags;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int exists;
|
Eio_File_Op_Flags flags;
|
||||||
|
Eina_Bool exists;
|
||||||
Eina_Bool can_read;
|
Eina_Bool can_read;
|
||||||
Eina_Bool can_write;
|
Eina_Bool can_write;
|
||||||
Eina_Bool can_execute;
|
Eina_Bool can_execute;
|
||||||
|
@ -99,12 +99,10 @@ static int _eio_count = 0;
|
||||||
static void
|
static void
|
||||||
_eio_file_heavy(Ecore_Thread *thread, void *data)
|
_eio_file_heavy(Ecore_Thread *thread, void *data)
|
||||||
{
|
{
|
||||||
Eio_File_Char_Ls *async;
|
Eio_File_Char_Ls *async = data;
|
||||||
Eina_Iterator *ls;
|
Eina_Iterator *ls;
|
||||||
const char *file;
|
const char *file;
|
||||||
|
|
||||||
async = data;
|
|
||||||
|
|
||||||
ls = eina_file_ls(async->ls.directory);
|
ls = eina_file_ls(async->ls.directory);
|
||||||
if (!ls)
|
if (!ls)
|
||||||
{
|
{
|
||||||
|
@ -118,7 +116,7 @@ _eio_file_heavy(Ecore_Thread *thread, void *data)
|
||||||
|
|
||||||
if (async->filter_cb)
|
if (async->filter_cb)
|
||||||
{
|
{
|
||||||
filter = async->filter_cb(file, (void*) async->ls.common.data);
|
filter = async->filter_cb(async->ls.common.data, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter) ecore_thread_notify(thread, file);
|
if (filter) ecore_thread_notify(thread, file);
|
||||||
|
@ -134,14 +132,11 @@ _eio_file_heavy(Ecore_Thread *thread, void *data)
|
||||||
static void
|
static void
|
||||||
_eio_file_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data)
|
_eio_file_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data)
|
||||||
{
|
{
|
||||||
Eio_File_Char_Ls *async;
|
Eio_File_Char_Ls *async = data;
|
||||||
const char *file;
|
const char *file = msg_data;
|
||||||
|
|
||||||
async = data;
|
|
||||||
file = msg_data;
|
|
||||||
|
|
||||||
if (async->main_cb)
|
if (async->main_cb)
|
||||||
async->main_cb(file, (void*) async->ls.common.data);
|
async->main_cb(async->ls.common.data, file);
|
||||||
|
|
||||||
eina_stringshare_del(file);
|
eina_stringshare_del(file);
|
||||||
}
|
}
|
||||||
|
@ -149,12 +144,10 @@ _eio_file_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data)
|
||||||
static void
|
static void
|
||||||
_eio_file_direct_heavy(Ecore_Thread *thread, void *data)
|
_eio_file_direct_heavy(Ecore_Thread *thread, void *data)
|
||||||
{
|
{
|
||||||
Eio_File_Direct_Ls *async;
|
Eio_File_Direct_Ls *async = data;
|
||||||
Eina_Iterator *ls;
|
Eina_Iterator *ls;
|
||||||
const Eina_File_Direct_Info *info;
|
const Eina_File_Direct_Info *info;
|
||||||
|
|
||||||
async = data;
|
|
||||||
|
|
||||||
ls = eina_file_direct_ls(async->ls.directory);
|
ls = eina_file_direct_ls(async->ls.directory);
|
||||||
if (!ls)
|
if (!ls)
|
||||||
{
|
{
|
||||||
|
@ -168,7 +161,7 @@ _eio_file_direct_heavy(Ecore_Thread *thread, void *data)
|
||||||
|
|
||||||
if (async->filter_cb)
|
if (async->filter_cb)
|
||||||
{
|
{
|
||||||
filter = async->filter_cb(info, (void*) async->ls.common.data);
|
filter = async->filter_cb(async->ls.common.data, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter)
|
if (filter)
|
||||||
|
@ -199,7 +192,7 @@ _eio_file_direct_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *d
|
||||||
info = msg_data;
|
info = msg_data;
|
||||||
|
|
||||||
if (async->main_cb)
|
if (async->main_cb)
|
||||||
async->main_cb(info, (void*) async->ls.common.data);
|
async->main_cb(async->ls.common.data, info);
|
||||||
|
|
||||||
free(info);
|
free(info);
|
||||||
}
|
}
|
||||||
|
@ -212,7 +205,7 @@ _eio_file_end(void *data)
|
||||||
async = data;
|
async = data;
|
||||||
|
|
||||||
if (async->common.done_cb)
|
if (async->common.done_cb)
|
||||||
async->common.done_cb((void*) async->common.data);
|
async->common.done_cb(async->common.data);
|
||||||
|
|
||||||
eina_stringshare_del(async->directory);
|
eina_stringshare_del(async->directory);
|
||||||
free(async);
|
free(async);
|
||||||
|
@ -226,7 +219,7 @@ _eio_file_error(void *data)
|
||||||
async = data;
|
async = data;
|
||||||
|
|
||||||
if (async->common.error_cb)
|
if (async->common.error_cb)
|
||||||
async->common.error_cb((void*) async->common.data);
|
async->common.error_cb(async->common.data);
|
||||||
|
|
||||||
eina_stringshare_del(async->directory);
|
eina_stringshare_del(async->directory);
|
||||||
free(async);
|
free(async);
|
||||||
|
@ -235,89 +228,69 @@ _eio_file_error(void *data)
|
||||||
static void
|
static void
|
||||||
_eio_file_op_cb(void *data)
|
_eio_file_op_cb(void *data)
|
||||||
{
|
{
|
||||||
Eio_File_Op *async;
|
Eio_File_Op *async = data;
|
||||||
|
|
||||||
async = data;
|
async->exists = (stat(async->file, &async->st) == 0);
|
||||||
if (stat(async->file, &async->st) >= 0)
|
if (async->exists)
|
||||||
{
|
{
|
||||||
if (async->flags & EIO_FILE_CAN_READ == EIO_FILE_CAN_READ)
|
if ((async->flags & EIO_FILE_CAN_READ) == EIO_FILE_CAN_READ)
|
||||||
{
|
{
|
||||||
if (!access(async->file, R_OK))
|
if (!access(async->file, R_OK))
|
||||||
async->can_read = EINA_TRUE;
|
async->can_read = EINA_TRUE;
|
||||||
else
|
else
|
||||||
async->can_read = EINA_FALSE;
|
async->can_read = EINA_FALSE;
|
||||||
}
|
}
|
||||||
if (async->flags & EIO_FILE_CAN_WRITE == EIO_FILE_CAN_WRITE)
|
if ((async->flags & EIO_FILE_CAN_WRITE) == EIO_FILE_CAN_WRITE)
|
||||||
{
|
{
|
||||||
if (!access(async->file, W_OK))
|
if (!access(async->file, W_OK))
|
||||||
async->can_write = EINA_TRUE;
|
async->can_write = EINA_TRUE;
|
||||||
else
|
else
|
||||||
async->can_write = EINA_FALSE;
|
async->can_write = EINA_FALSE;
|
||||||
}
|
}
|
||||||
if (async->flags & EIO_FILE_CAN_EXECUTE == EIO_FILE_CAN_EXECUTE)
|
if ((async->flags & EIO_FILE_CAN_EXECUTE) == EIO_FILE_CAN_EXECUTE)
|
||||||
{
|
{
|
||||||
if (!access(async->file, X_OK))
|
if (!access(async->file, X_OK))
|
||||||
async->can_execute = EINA_TRUE;
|
async->can_execute = EINA_TRUE;
|
||||||
else
|
else
|
||||||
async->can_execute = EINA_FALSE;
|
async->can_execute = EINA_FALSE;
|
||||||
}
|
}
|
||||||
async->exists = 1;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
async->exists = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_eio_file_op_end(void *data)
|
_eio_file_op_end(void *data)
|
||||||
{
|
{
|
||||||
Eio_File_Op *async;
|
Eio_File_Op *async = data;
|
||||||
|
|
||||||
async = data;
|
|
||||||
|
|
||||||
if (!async->exists)
|
if (!async->exists)
|
||||||
{
|
{
|
||||||
if (async->flags & EIO_FILE_EXISTS == EIO_FILE_EXISTS)
|
if ((async->flags & EIO_FILE_EXISTS) == EIO_FILE_EXISTS)
|
||||||
async->main_cb((void *)EINA_FALSE, EIO_FILE_EXISTS, data);
|
{
|
||||||
ecore_thread_cancel(async->common.thread);
|
async->main_cb(async->common.data, EIO_FILE_EXISTS, (void *)(long)async->exists);
|
||||||
|
if (async->common.done_cb)
|
||||||
|
async->common.done_cb(async->common.data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ecore_thread_cancel(async->common.thread);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (async->flags & EIO_FILE_MOD_TIME == EIO_FILE_MOD_TIME)
|
if ((async->flags & EIO_FILE_MOD_TIME) == EIO_FILE_MOD_TIME)
|
||||||
async->main_cb((void *)async->st.st_mtime, EIO_FILE_MOD_TIME, data);
|
async->main_cb(async->common.data, EIO_FILE_MOD_TIME, (void *)(long)async->st.st_mtime);
|
||||||
if (async->flags & EIO_FILE_SIZE == EIO_FILE_SIZE)
|
if ((async->flags & EIO_FILE_SIZE) == EIO_FILE_SIZE)
|
||||||
async->main_cb((void *)async->st.st_size, EIO_FILE_SIZE, data);
|
async->main_cb(async->common.data, EIO_FILE_SIZE, (void *)(long)async->st.st_size);
|
||||||
if (async->flags & EIO_FILE_EXISTS == EIO_FILE_EXISTS)
|
if ((async->flags & EIO_FILE_EXISTS) == EIO_FILE_EXISTS)
|
||||||
async->main_cb((void *)EINA_TRUE, EIO_FILE_EXISTS, data);
|
async->main_cb(async->common.data, EIO_FILE_EXISTS, (void *)(long)async->exists);
|
||||||
if (async->flags & EIO_FILE_IS_DIR == EIO_FILE_IS_DIR)
|
if ((async->flags & EIO_FILE_IS_DIR) == EIO_FILE_IS_DIR)
|
||||||
{
|
async->main_cb(async->common.data, EIO_FILE_IS_DIR, (void *)(long)S_ISDIR(async->st.st_mode));
|
||||||
if (S_ISDIR(async->st.st_mode))
|
if ((async->flags & EIO_FILE_CAN_READ) == EIO_FILE_CAN_READ)
|
||||||
async->main_cb((void *)EINA_TRUE, EIO_FILE_IS_DIR, data);
|
async->main_cb(async->common.data, EIO_FILE_CAN_READ, (void *)(long)async->can_read);
|
||||||
else
|
if ((async->flags & EIO_FILE_CAN_WRITE) == EIO_FILE_CAN_WRITE)
|
||||||
async->main_cb((void *)EINA_FALSE, EIO_FILE_IS_DIR, data);
|
async->main_cb(async->common.data, EIO_FILE_CAN_WRITE, (void *)(long)async->can_write);
|
||||||
}
|
if ((async->flags & EIO_FILE_CAN_EXECUTE) == EIO_FILE_CAN_EXECUTE)
|
||||||
if (async->flags & EIO_FILE_CAN_READ == EIO_FILE_CAN_READ)
|
async->main_cb(async->common.data, EIO_FILE_CAN_EXECUTE, (void *)(long)async->can_execute);
|
||||||
{
|
|
||||||
if (async->can_read)
|
|
||||||
async->main_cb((void *)EINA_TRUE, EIO_FILE_CAN_READ, data);
|
|
||||||
else
|
|
||||||
async->main_cb((void *)EINA_FALSE, EIO_FILE_CAN_READ, data);
|
|
||||||
}
|
|
||||||
if (async->flags & EIO_FILE_CAN_WRITE == EIO_FILE_CAN_WRITE)
|
|
||||||
{
|
|
||||||
if (async->can_write)
|
|
||||||
async->main_cb((void *)EINA_TRUE, EIO_FILE_CAN_WRITE, data);
|
|
||||||
else
|
|
||||||
async->main_cb((void *)EINA_FALSE, EIO_FILE_CAN_WRITE, data);
|
|
||||||
}
|
|
||||||
if (async->flags & EIO_FILE_CAN_EXECUTE == EIO_FILE_CAN_EXECUTE)
|
|
||||||
{
|
|
||||||
if (async->can_execute)
|
|
||||||
async->main_cb((void *)EINA_TRUE, EIO_FILE_CAN_EXECUTE, data);
|
|
||||||
else
|
|
||||||
async->main_cb((void *)EINA_FALSE, EIO_FILE_CAN_EXECUTE, data);
|
|
||||||
}
|
|
||||||
if (async->common.done_cb)
|
if (async->common.done_cb)
|
||||||
async->common.done_cb((void *) async->common.data);
|
async->common.done_cb(async->common.data);
|
||||||
|
|
||||||
free(async);
|
free(async);
|
||||||
}
|
}
|
||||||
|
@ -330,7 +303,7 @@ _eio_file_op_error(void *data)
|
||||||
async = data;
|
async = data;
|
||||||
|
|
||||||
if (async->common.error_cb)
|
if (async->common.error_cb)
|
||||||
async->common.error_cb((void *) async->common.data);
|
async->common.error_cb(async->common.data);
|
||||||
|
|
||||||
free(async);
|
free(async);
|
||||||
}
|
}
|
||||||
|
@ -462,7 +435,7 @@ eio_file_cancel(Eio_File *ls)
|
||||||
/**
|
/**
|
||||||
* @brief Perform standard File IO operations.
|
* @brief Perform standard File IO operations.
|
||||||
* @param file The file to operate on.
|
* @param file The file to operate on.
|
||||||
* @param flags Bit flags to specify which operations to do.
|
* @param flags Eio_File_Op_Flags to specify which operations to do.
|
||||||
* @param main_cb Callback called from the main loop with the results of the file operations.
|
* @param main_cb Callback called from the main loop with the results of the file operations.
|
||||||
* @param done_cb Callback called from the main loop when the operations are through.
|
* @param done_cb Callback called from the main loop when the operations are through.
|
||||||
* @param error_cb Callback called from the main loop when the file operations could not be completed.
|
* @param error_cb Callback called from the main loop when the file operations could not be completed.
|
||||||
|
@ -473,7 +446,7 @@ eio_file_cancel(Eio_File *ls)
|
||||||
*/
|
*/
|
||||||
EAPI Eio_File *
|
EAPI Eio_File *
|
||||||
eio_file_operation(const char *file,
|
eio_file_operation(const char *file,
|
||||||
short int eio_file_flags,
|
Eio_File_Op_Flags eio_file_flags,
|
||||||
Eio_File_Op_Main_Cb main_cb,
|
Eio_File_Op_Main_Cb main_cb,
|
||||||
Eio_Done_Cb done_cb,
|
Eio_Done_Cb done_cb,
|
||||||
Eio_Done_Cb error_cb,
|
Eio_Done_Cb error_cb,
|
||||||
|
|
Loading…
Reference in New Issue