2010-07-22 09:08:17 -07:00
|
|
|
/* EIO - EFL data type library
|
|
|
|
* Copyright (C) 2010 Enlightenment Developers:
|
|
|
|
* Cedric Bail <cedric.bail@free.fr>
|
|
|
|
* Vincent "caro" Torri <vtorri at univ-evry dot fr>
|
2010-07-28 15:12:41 -07:00
|
|
|
* Stephen "okra" Houston <UnixTitan@gmail.com>
|
2010-07-22 09:08:17 -07:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Ecore.h>
|
|
|
|
|
2010-07-28 15:12:41 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <libgen.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_FEATURES_H
|
|
|
|
# include <features.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
2010-07-22 09:08:17 -07:00
|
|
|
#include "Eio.h"
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
typedef struct _Eio_File_Ls Eio_File_Ls;
|
|
|
|
typedef struct _Eio_File_Direct_Ls Eio_File_Direct_Ls;
|
|
|
|
typedef struct _Eio_File_Char_Ls Eio_File_Char_Ls;
|
2010-07-28 15:12:41 -07:00
|
|
|
typedef struct _Eio_File_Op Eio_File_Op;
|
2010-07-23 04:00:44 -07:00
|
|
|
|
|
|
|
struct _Eio_File
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
|
|
|
Ecore_Thread *thread;
|
|
|
|
const void *data;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_Done_Cb done_cb;
|
|
|
|
Eio_Done_Cb error_cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Eio_File_Ls
|
|
|
|
{
|
|
|
|
Eio_File common;
|
|
|
|
const char *directory;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Eio_File_Direct_Ls
|
|
|
|
{
|
|
|
|
Eio_File_Ls ls;
|
|
|
|
|
|
|
|
Eio_Filter_Direct_Cb filter_cb;
|
|
|
|
Eio_Main_Direct_Cb main_cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Eio_File_Char_Ls
|
|
|
|
{
|
|
|
|
Eio_File_Ls ls;
|
|
|
|
|
|
|
|
Eio_Filter_Cb filter_cb;
|
|
|
|
Eio_Main_Cb main_cb;
|
2010-07-22 09:08:17 -07:00
|
|
|
};
|
|
|
|
|
2010-07-28 15:12:41 -07:00
|
|
|
struct _Eio_File_Op
|
|
|
|
{
|
|
|
|
Eio_File common;
|
|
|
|
const char *file;
|
|
|
|
short int flags;
|
|
|
|
struct stat st;
|
|
|
|
int exists;
|
|
|
|
Eina_Bool can_read;
|
|
|
|
Eina_Bool can_write;
|
|
|
|
Eina_Bool can_execute;
|
|
|
|
Eio_File_Op_Main_Cb main_cb;
|
|
|
|
};
|
|
|
|
|
2010-07-22 09:08:17 -07:00
|
|
|
static int _eio_count = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eio_file_heavy(Ecore_Thread *thread, void *data)
|
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_File_Char_Ls *async;
|
|
|
|
Eina_Iterator *ls;
|
2010-07-22 09:08:17 -07:00
|
|
|
const char *file;
|
|
|
|
|
|
|
|
async = data;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
ls = eina_file_ls(async->ls.directory);
|
|
|
|
if (!ls)
|
|
|
|
{
|
|
|
|
ecore_thread_cancel(thread);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
EINA_ITERATOR_FOREACH(ls, file)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
|
|
|
Eina_Bool filter = EINA_TRUE;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
if (async->filter_cb)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
filter = async->filter_cb(file, (void*) async->ls.common.data);
|
2010-07-22 09:08:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (filter) ecore_thread_notify(thread, file);
|
|
|
|
else eina_stringshare_del(file);
|
2010-07-23 04:00:44 -07:00
|
|
|
|
|
|
|
if (ecore_thread_check(thread))
|
|
|
|
break;
|
2010-07-22 09:08:17 -07:00
|
|
|
}
|
2010-07-23 04:00:44 -07:00
|
|
|
|
|
|
|
eina_iterator_free(ls);
|
2010-07-22 09:08:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-23 04:00:44 -07:00
|
|
|
_eio_file_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_File_Char_Ls *async;
|
2010-07-22 09:08:17 -07:00
|
|
|
const char *file;
|
|
|
|
|
|
|
|
async = data;
|
|
|
|
file = msg_data;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
if (async->main_cb)
|
|
|
|
async->main_cb(file, (void*) async->ls.common.data);
|
2010-07-22 09:08:17 -07:00
|
|
|
|
|
|
|
eina_stringshare_del(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eio_file_direct_heavy(Ecore_Thread *thread, void *data)
|
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_File_Direct_Ls *async;
|
|
|
|
Eina_Iterator *ls;
|
2010-07-22 09:08:17 -07:00
|
|
|
const Eina_File_Direct_Info *info;
|
|
|
|
|
|
|
|
async = data;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
ls = eina_file_direct_ls(async->ls.directory);
|
|
|
|
if (!ls)
|
|
|
|
{
|
|
|
|
ecore_thread_cancel(thread);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
EINA_ITERATOR_FOREACH(ls, info)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
|
|
|
Eina_Bool filter = EINA_TRUE;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
if (async->filter_cb)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
filter = async->filter_cb(info, (void*) async->ls.common.data);
|
2010-07-22 09:08:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
{
|
|
|
|
Eina_File_Direct_Info *send;
|
|
|
|
|
|
|
|
send = malloc(sizeof (Eina_File_Direct_Info));
|
|
|
|
if (!send) continue;
|
|
|
|
|
|
|
|
memcpy(send, info, sizeof (Eina_File_Direct_Info));
|
|
|
|
ecore_thread_notify(thread, send);
|
|
|
|
}
|
2010-07-23 04:00:44 -07:00
|
|
|
|
|
|
|
if (ecore_thread_check(thread))
|
|
|
|
break;
|
2010-07-22 09:08:17 -07:00
|
|
|
}
|
2010-07-23 04:00:44 -07:00
|
|
|
|
|
|
|
eina_iterator_free(ls);
|
2010-07-22 09:08:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-07-23 04:00:44 -07:00
|
|
|
_eio_file_direct_notify(Ecore_Thread *thread __UNUSED__, void *msg_data, void *data)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_File_Direct_Ls *async;
|
2010-07-22 09:08:17 -07:00
|
|
|
Eina_File_Direct_Info *info;
|
|
|
|
|
|
|
|
async = data;
|
|
|
|
info = msg_data;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
if (async->main_cb)
|
|
|
|
async->main_cb(info, (void*) async->ls.common.data);
|
2010-07-22 09:08:17 -07:00
|
|
|
|
|
|
|
free(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eio_file_end(void *data)
|
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_File_Ls *async;
|
|
|
|
|
|
|
|
async = data;
|
|
|
|
|
|
|
|
if (async->common.done_cb)
|
|
|
|
async->common.done_cb((void*) async->common.data);
|
|
|
|
|
|
|
|
eina_stringshare_del(async->directory);
|
|
|
|
free(async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eio_file_error(void *data)
|
|
|
|
{
|
|
|
|
Eio_File_Ls *async;
|
2010-07-22 09:08:17 -07:00
|
|
|
|
|
|
|
async = data;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
if (async->common.error_cb)
|
|
|
|
async->common.error_cb((void*) async->common.data);
|
2010-07-22 09:08:17 -07:00
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
eina_stringshare_del(async->directory);
|
2010-07-22 09:08:17 -07:00
|
|
|
free(async);
|
|
|
|
}
|
|
|
|
|
2010-07-28 15:12:41 -07:00
|
|
|
static void
|
|
|
|
_eio_file_op_cb(void *data)
|
|
|
|
{
|
|
|
|
Eio_File_Op *async;
|
|
|
|
|
|
|
|
async = data;
|
|
|
|
if (stat(async->file, &async->st) >= 0)
|
|
|
|
{
|
|
|
|
if (async->flags & EIO_FILE_CAN_READ == EIO_FILE_CAN_READ)
|
|
|
|
{
|
|
|
|
if (!access(async->file, R_OK))
|
|
|
|
async->can_read = EINA_TRUE;
|
|
|
|
else
|
|
|
|
async->can_read = EINA_FALSE;
|
|
|
|
}
|
|
|
|
if (async->flags & EIO_FILE_CAN_WRITE == EIO_FILE_CAN_WRITE)
|
|
|
|
{
|
|
|
|
if (!access(async->file, W_OK))
|
|
|
|
async->can_write = EINA_TRUE;
|
|
|
|
else
|
|
|
|
async->can_write = EINA_FALSE;
|
|
|
|
}
|
|
|
|
if (async->flags & EIO_FILE_CAN_EXECUTE == EIO_FILE_CAN_EXECUTE)
|
|
|
|
{
|
|
|
|
if (!access(async->file, X_OK))
|
|
|
|
async->can_execute = EINA_TRUE;
|
|
|
|
else
|
|
|
|
async->can_execute = EINA_FALSE;
|
|
|
|
}
|
|
|
|
async->exists = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
async->exists = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eio_file_op_end(void *data)
|
|
|
|
{
|
|
|
|
Eio_File_Op *async;
|
|
|
|
|
|
|
|
async = data;
|
|
|
|
|
|
|
|
if (!async->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);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (async->flags & EIO_FILE_MOD_TIME == EIO_FILE_MOD_TIME)
|
|
|
|
async->main_cb((void *)async->st.st_mtime, EIO_FILE_MOD_TIME, data);
|
|
|
|
if (async->flags & EIO_FILE_SIZE == EIO_FILE_SIZE)
|
|
|
|
async->main_cb((void *)async->st.st_size, EIO_FILE_SIZE, data);
|
|
|
|
if (async->flags & EIO_FILE_EXISTS == EIO_FILE_EXISTS)
|
|
|
|
async->main_cb((void *)EINA_TRUE, EIO_FILE_EXISTS, data);
|
|
|
|
if (async->flags & EIO_FILE_IS_DIR == EIO_FILE_IS_DIR)
|
|
|
|
{
|
|
|
|
if (S_ISDIR(async->st.st_mode))
|
|
|
|
async->main_cb((void *)EINA_TRUE, EIO_FILE_IS_DIR, data);
|
|
|
|
else
|
|
|
|
async->main_cb((void *)EINA_FALSE, EIO_FILE_IS_DIR, data);
|
|
|
|
}
|
|
|
|
if (async->flags & EIO_FILE_CAN_READ == EIO_FILE_CAN_READ)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
async->common.done_cb((void *) async->common.data);
|
|
|
|
|
|
|
|
free(async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eio_file_op_error(void *data)
|
|
|
|
{
|
|
|
|
Eio_File_Op *async;
|
|
|
|
|
|
|
|
async = data;
|
|
|
|
|
|
|
|
if (async->common.error_cb)
|
|
|
|
async->common.error_cb((void *) async->common.data);
|
|
|
|
|
|
|
|
free(async);
|
|
|
|
}
|
|
|
|
|
2010-07-22 09:08:17 -07:00
|
|
|
EAPI int
|
|
|
|
eio_init(void)
|
|
|
|
{
|
|
|
|
_eio_count++;
|
|
|
|
|
|
|
|
if (_eio_count > 1) return _eio_count;
|
|
|
|
|
|
|
|
eina_init();
|
|
|
|
ecore_init();
|
|
|
|
|
|
|
|
return _eio_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
eio_shutdown(void)
|
|
|
|
{
|
|
|
|
_eio_count--;
|
|
|
|
|
|
|
|
if (_eio_count > 0) return _eio_count;
|
|
|
|
|
|
|
|
ecore_shutdown();
|
|
|
|
eina_shutdown();
|
|
|
|
return _eio_count;
|
|
|
|
}
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
* @return A reference to the IO operation.
|
|
|
|
*
|
|
|
|
* eio_file_ls run eina_file_ls in a separated thread using ecore_long_run. This prevent
|
|
|
|
* any lock in your apps.
|
|
|
|
*/
|
|
|
|
EAPI Eio_File *
|
2010-07-22 09:08:17 -07:00
|
|
|
eio_file_ls(const char *dir,
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_Filter_Cb filter_cb,
|
|
|
|
Eio_Main_Cb main_cb,
|
|
|
|
Eio_Done_Cb done_cb,
|
|
|
|
Eio_Done_Cb error_cb,
|
|
|
|
const void *data)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_File_Char_Ls *async = NULL;
|
2010-07-22 09:08:17 -07:00
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
async = malloc(sizeof (Eio_File_Char_Ls));
|
2010-07-22 09:08:17 -07:00
|
|
|
if (!async) goto on_error;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
async->filter_cb = filter_cb;
|
|
|
|
async->main_cb = main_cb;
|
|
|
|
async->ls.directory = eina_stringshare_add(dir);
|
|
|
|
async->ls.common.done_cb = done_cb;
|
|
|
|
async->ls.common.error_cb = error_cb;
|
|
|
|
async->ls.common.data = data;
|
|
|
|
async->ls.common.thread = ecore_long_run(_eio_file_heavy,
|
|
|
|
_eio_file_notify,
|
|
|
|
_eio_file_end,
|
|
|
|
_eio_file_error,
|
|
|
|
async,
|
|
|
|
EINA_FALSE);
|
|
|
|
if (!async->ls.common.thread) goto on_error;
|
|
|
|
|
|
|
|
return &async->ls.common;
|
2010-07-22 09:08:17 -07:00
|
|
|
|
|
|
|
on_error:
|
|
|
|
free(async);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
* @return A reference to the IO operation.
|
|
|
|
*
|
|
|
|
* eio_file_direct_ls run eina_file_direct_ls in a separated thread using
|
|
|
|
* ecore_long_run. This prevent any lock in your apps.
|
|
|
|
*/
|
|
|
|
EAPI Eio_File *
|
2010-07-22 09:08:17 -07:00
|
|
|
eio_file_direct_ls(const char *dir,
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_Filter_Direct_Cb filter_cb,
|
|
|
|
Eio_Main_Direct_Cb main_cb,
|
|
|
|
Eio_Done_Cb done_cb,
|
|
|
|
Eio_Done_Cb error_cb,
|
|
|
|
const void *data)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
Eio_File_Direct_Ls *async = NULL;
|
2010-07-22 09:08:17 -07:00
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
async = malloc(sizeof (Eio_File_Direct_Ls));
|
2010-07-22 09:08:17 -07:00
|
|
|
if (!async) goto on_error;
|
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
async->filter_cb = filter_cb;
|
|
|
|
async->main_cb = main_cb;
|
|
|
|
async->ls.directory = eina_stringshare_add(dir);
|
|
|
|
async->ls.common.done_cb = done_cb;
|
|
|
|
async->ls.common.error_cb = error_cb;
|
|
|
|
async->ls.common.data = data;
|
|
|
|
async->ls.common.thread = ecore_long_run(_eio_file_direct_heavy,
|
|
|
|
_eio_file_direct_notify,
|
|
|
|
_eio_file_end,
|
|
|
|
_eio_file_error,
|
|
|
|
async,
|
|
|
|
EINA_FALSE);
|
|
|
|
if (!async->ls.common.thread) goto on_error;
|
2010-07-22 09:08:17 -07:00
|
|
|
|
2010-07-23 04:00:44 -07:00
|
|
|
return &async->ls.common;
|
2010-07-22 09:08:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
on_error:
|
|
|
|
free(async);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2010-07-23 04:00:44 -07:00
|
|
|
eio_file_cancel(Eio_File *ls)
|
2010-07-22 09:08:17 -07:00
|
|
|
{
|
2010-07-23 04:00:44 -07:00
|
|
|
return ecore_thread_cancel(ls->thread);
|
2010-07-22 09:08:17 -07:00
|
|
|
}
|
|
|
|
|
2010-07-28 15:12:41 -07:00
|
|
|
/**
|
|
|
|
* @brief Perform standard File IO operations.
|
|
|
|
* @param file The file to operate on.
|
|
|
|
* @param flags Bit flags to specify which operations to do.
|
|
|
|
* @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 error_cb Callback called from the main loop when the file operations could not be completed.
|
|
|
|
* @return A reference to the IO operation.
|
|
|
|
*
|
|
|
|
* eio_file_operation runs selected operations in a separated thread using
|
|
|
|
* ecore_thread_run. This prevents any locking in your apps.
|
|
|
|
*/
|
|
|
|
EAPI Eio_File *
|
|
|
|
eio_file_operation(const char *file,
|
|
|
|
short int eio_file_flags,
|
|
|
|
Eio_File_Op_Main_Cb main_cb,
|
|
|
|
Eio_Done_Cb done_cb,
|
|
|
|
Eio_Done_Cb error_cb,
|
|
|
|
const void *data)
|
|
|
|
{
|
|
|
|
Eio_File_Op *async = NULL;
|
|
|
|
|
|
|
|
async = malloc(sizeof (Eio_File_Op));
|
|
|
|
if (!async) goto on_error;
|
|
|
|
|
|
|
|
async->main_cb = main_cb;
|
|
|
|
async->file = file;
|
|
|
|
async->flags = eio_file_flags;
|
|
|
|
async->common.done_cb = done_cb;
|
|
|
|
async->common.error_cb = error_cb;
|
|
|
|
async->common.data = data;
|
|
|
|
|
|
|
|
async->common.thread = ecore_thread_run(_eio_file_op_cb,
|
|
|
|
_eio_file_op_end,
|
|
|
|
_eio_file_op_error,
|
|
|
|
async);
|
|
|
|
if (!async->common.thread) goto on_error;
|
|
|
|
|
|
|
|
return &async->common;
|
|
|
|
|
|
|
|
on_error:
|
|
|
|
free(async);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-07-22 09:08:17 -07:00
|
|
|
|