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/>.
*/
# ifndef EIO_H__
# define EIO_H__
# ifdef _MSC_VER
# include <Evil.h>
# endif
2010-08-31 09:24:58 -07:00
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
2010-07-22 09:08:17 -07:00
# include <Eina.h>
# ifdef EAPI
# undef EAPI
# endif
# ifdef _WIN32
2010-07-23 04:00:44 -07:00
# ifdef EFL_EIO_BUILD
2010-07-22 09:08:17 -07:00
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif /* ! DLL_EXPORT */
# else
# define EAPI __declspec(dllimport)
2010-07-23 04:00:44 -07:00
# endif /* ! EFL_EIO_BUILD */
2010-07-22 09:08:17 -07:00
# else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define EAPI __attribute__ ((visibility("default")))
# else
# define EAPI
# endif
# else
# define EAPI
# endif
# endif /* ! _WIN32 */
2010-10-12 07:59:30 -07:00
# ifdef __cplusplus
extern " C " {
# endif
/**
2010-10-20 22:03:23 -07:00
* @ defgroup Eio_Group Eio Reference API
2010-10-12 07:59:30 -07:00
*
2010-10-28 07:50:24 -07:00
* @ brief This are the core asynchronous input / output operation
2010-10-12 07:59:30 -07:00
*
2010-10-28 07:50:24 -07:00
* All the function in this group do perform input / output operation
* in a separated thread and use the infrastructure provided by
* Ecore_Thread and Eina to work .
2010-10-12 07:59:30 -07:00
*
* @ {
*/
2010-10-20 12:17:30 -07:00
/**
* @ enum _Eio_File_Op
* Input / Output operations on files .
*/
enum _Eio_File_Op
2010-08-03 10:11:44 -07:00
{
2010-10-20 05:20:06 -07:00
EIO_FILE_COPY , /**< IO operation is about a specific file copy */
EIO_FILE_MOVE , /**< IO operation is about a specific file move */
EIO_DIR_COPY , /**< IO operation is about a specific directory copy */
2010-10-20 06:48:13 -07:00
EIO_DIR_MOVE , /**< IO operation is about a specific directory move */
2010-10-20 09:42:45 -07:00
EIO_UNLINK , /**< IO operation is about a destroying a path (source will point to base path to be destroyed and dest to path destroyed by this IO */
EIO_FILE_GETPWNAM , /**< IO operation is trying to get uid from user name */
EIO_FILE_GETGRNAM /**< IO operation is trying to get gid from user name */
2010-10-20 12:17:30 -07:00
} ;
2010-07-28 15:12:41 -07:00
2010-12-08 06:35:37 -08:00
/**
* @ typedef Eio_File_Op
* Input / Output operations on files .
*/
typedef enum _Eio_File_Op Eio_File_Op ;
2010-10-20 12:17:30 -07:00
/**
* @ typedef Eio_File
2010-10-28 07:50:24 -07:00
* Generic asynchronous IO reference .
2010-10-20 12:17:30 -07:00
*/
typedef struct _Eio_File Eio_File ;
/**
* @ typedef Eio_Progress
* Progress information on a specific operation .
*/
typedef struct _Eio_Progress Eio_Progress ;
2010-07-22 09:08:17 -07:00
2010-11-12 06:08:01 -08:00
typedef Eina_Bool ( * Eio_Filter_Cb ) ( void * data , Eio_File * handler , const char * file ) ;
typedef void ( * Eio_Main_Cb ) ( void * data , Eio_File * handler , const char * file ) ;
2010-07-22 09:08:17 -07:00
2010-11-12 06:08:01 -08:00
typedef Eina_Bool ( * Eio_Filter_Direct_Cb ) ( void * data , Eio_File * handler , const Eina_File_Direct_Info * info ) ;
typedef void ( * Eio_Main_Direct_Cb ) ( void * data , Eio_File * handler , const Eina_File_Direct_Info * info ) ;
2010-07-22 09:08:17 -07:00
2010-11-12 06:08:01 -08:00
typedef void ( * Eio_Stat_Cb ) ( void * data , Eio_File * handler , const struct stat * stat ) ;
typedef void ( * Eio_Progress_Cb ) ( void * data , Eio_File * handler , const Eio_Progress * info ) ;
2010-08-31 09:24:58 -07:00
2010-11-12 06:08:01 -08:00
typedef void ( * Eio_Done_Cb ) ( void * data , Eio_File * handler ) ;
typedef void ( * Eio_Error_Cb ) ( void * data , Eio_File * handler , int error ) ;
2010-07-22 09:08:17 -07:00
2010-08-31 09:24:58 -07:00
struct _Eio_Progress
{
2010-10-20 05:20:06 -07:00
Eio_File_Op op ; /**< IO type */
2010-10-05 07:55:47 -07:00
2011-03-09 06:53:55 -08:00
long long current ; /**< Current step in the IO operation */
long long max ; /**< Number of step to do to complete this IO */
2010-10-20 05:20:06 -07:00
float percent ; /**< Percent done of the IO operation */
* eio: add eio_file_copy (using splice when available and
fallback to mmap/write with huge tlb when not).
That what an eio_cp would look like :
#include <Ecore.h>
#include <Eio.h>
static void
_test_progress_cb(void *data, const Eio_Progress *info)
{
printf("%f (%zi / %zi octets)\n", info->percent, info->current, info->max);
}
static void
_test_done_cb(void *data)
{
printf("copy done\n");
ecore_main_loop_quit();
}
static void
_test_error_cb(int error, void *data)
{
fprintf(stderr, "error: [%s]\n", strerror(error));
ecore_main_loop_quit();
}
int
main(int argc, char **argv)
{
Eio_File *cp;
if (argc != 3)
{
fprintf(stderr, "eio_cp source_file destination_file\n");
return -1;
}
ecore_init();
eio_init();
cp = eio_file_copy(argv[1], argv[2],
_test_progress_cb,
_test_done_cb,
_test_error_cb,
NULL);
ecore_main_loop_begin();
eio_shutdown();
ecore_shutdown();
return 0;
}
SVN revision: 52787
2010-09-26 14:47:48 -07:00
2010-10-20 05:20:06 -07:00
const char * source ; /**< source of the IO operation */
const char * dest ; /**< target of the IO operation */
2010-08-31 09:24:58 -07:00
} ;
2010-07-22 09:08:17 -07:00
EAPI int eio_init ( void ) ;
EAPI int eio_shutdown ( void ) ;
2010-07-23 04:00:44 -07:00
EAPI Eio_File * eio_file_ls ( const char * dir ,
Eio_Filter_Cb filter_cb ,
Eio_Main_Cb main_cb ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-07-23 04:00:44 -07:00
const void * data ) ;
2010-07-22 09:08:17 -07:00
2010-07-23 04:00:44 -07:00
EAPI Eio_File * eio_file_direct_ls ( const char * dir ,
Eio_Filter_Direct_Cb filter_cb ,
Eio_Main_Direct_Cb main_cb ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-07-23 04:00:44 -07:00
const void * data ) ;
2010-07-22 09:08:17 -07:00
2010-11-02 10:08:00 -07:00
EAPI Eio_File * eio_file_stat_ls ( const char * dir ,
Eio_Filter_Direct_Cb filter_cb ,
Eio_Main_Direct_Cb main_cb ,
Eio_Done_Cb done_cb ,
Eio_Error_Cb error_cb ,
const void * data ) ;
2011-02-17 07:59:07 -08:00
EAPI Eio_File * eio_dir_stat_ls ( const char * dir ,
Eio_Filter_Direct_Cb filter_cb ,
Eio_Main_Direct_Cb main_cb ,
Eio_Done_Cb done_cb ,
Eio_Error_Cb error_cb ,
const void * data ) ;
2010-08-31 09:24:58 -07:00
EAPI Eio_File * eio_file_direct_stat ( const char * path ,
Eio_Stat_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-08-31 09:24:58 -07:00
const void * data ) ;
2010-10-20 09:42:45 -07:00
EAPI Eio_File * eio_file_chmod ( const char * path ,
mode_t mode ,
Eio_Done_Cb done_cb ,
Eio_Error_Cb error_cb ,
const void * data ) ;
EAPI Eio_File * eio_file_chown ( const char * path ,
const char * user ,
const char * group ,
Eio_Done_Cb done_cb ,
Eio_Error_Cb error_cb ,
const void * data ) ;
2010-08-31 09:24:58 -07:00
EAPI Eio_File * eio_file_unlink ( const char * path ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-08-31 09:24:58 -07:00
const void * data ) ;
EAPI Eio_File * eio_file_mkdir ( const char * path ,
mode_t mode ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-08-31 09:24:58 -07:00
const void * data ) ;
EAPI Eio_File * eio_file_move ( const char * source ,
const char * dest ,
Eio_Progress_Cb progress_cb ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-08-31 09:24:58 -07:00
const void * data ) ;
EAPI Eio_File * eio_file_copy ( const char * source ,
const char * dest ,
Eio_Progress_Cb progress_cb ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-08-31 09:24:58 -07:00
const void * data ) ;
EAPI Eio_File * eio_dir_move ( const char * source ,
const char * dest ,
2011-03-09 08:21:11 -08:00
Eio_Filter_Direct_Cb filter_cb ,
2010-08-31 09:24:58 -07:00
Eio_Progress_Cb progress_cb ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-08-31 09:24:58 -07:00
const void * data ) ;
EAPI Eio_File * eio_dir_copy ( const char * source ,
const char * dest ,
2011-03-09 08:21:11 -08:00
Eio_Filter_Direct_Cb filter_cb ,
2010-08-31 09:24:58 -07:00
Eio_Progress_Cb progress_cb ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-08-31 09:24:58 -07:00
const void * data ) ;
EAPI Eio_File * eio_dir_unlink ( const char * path ,
2011-03-09 08:21:11 -08:00
Eio_Filter_Direct_Cb filter_cb ,
2010-08-31 09:24:58 -07:00
Eio_Progress_Cb progress_cb ,
Eio_Done_Cb done_cb ,
2010-09-07 07:43:51 -07:00
Eio_Error_Cb error_cb ,
2010-08-31 09:24:58 -07:00
const void * data ) ;
2011-05-24 03:41:37 -07:00
EAPI void * eio_file_container_get ( Eio_File * ls ) ;
2010-07-23 04:00:44 -07:00
EAPI Eina_Bool eio_file_cancel ( Eio_File * ls ) ;
2011-06-25 15:52:01 -07:00
EAPI Eina_Bool eio_file_check ( Eio_File * ls ) ;
2010-07-22 09:08:17 -07:00
2011-06-22 10:45:22 -07:00
EAPI Eina_Bool eio_file_associate_add ( Eio_File * ls ,
const char * key ,
2011-06-23 06:29:45 -07:00
const void * data , Eina_Free_Cb free_cb ) ;
2011-06-22 10:45:22 -07:00
EAPI Eina_Bool eio_file_associate_direct_add ( Eio_File * ls ,
const char * key ,
2011-06-23 06:29:45 -07:00
const void * data , Eina_Free_Cb free_cb ) ;
2011-06-22 10:45:22 -07:00
EAPI void * eio_file_associate_find ( Eio_File * ls , const char * key ) ;
2010-10-28 07:50:24 -07:00
/**
* @ }
*/
/**
* @ defgroup Eio_Helper Eio Reference helper API
*
* @ brief This are helper provided around core Eio API .
*
* This set of functions do provide helper to work around data
* provided by Eio without the need to look at system header .
*
* @ {
*/
2010-10-29 05:58:04 -07:00
static inline double eio_file_atime ( const struct stat * stat ) ;
static inline double eio_file_mtime ( const struct stat * stat ) ;
static inline long long eio_file_size ( const struct stat * stat ) ;
static inline Eina_Bool eio_file_is_dir ( const struct stat * stat ) ;
static inline Eina_Bool eio_file_is_lnk ( const struct stat * stat ) ;
2010-10-28 07:50:24 -07:00
2011-04-25 10:04:46 -07:00
/**
* @ }
*/
/**
*
*/
/**
* @ defgroup Eio_Monitor Eio file and directory monitoring API
*
* @ brief This function help monitoring change in a directory or on a file .
*
* This function use the best available method to monitor change on a directory
* or file . It send ecore event when needed and does refcount of all monitored
* path to avoid heavy ressource consuption .
*
* @ {
*/
EAPI extern int EIO_MONITOR_FILE_CREATED ; /**< Notify creation of a new file in a watched directory */
EAPI extern int EIO_MONITOR_FILE_DELETED ; /**< Notify destruction of a watched file or in a watched directory */
EAPI extern int EIO_MONITOR_FILE_MODIFIED ; /**< Notify modification of a file in a watched directory */
2011-04-27 03:27:07 -07:00
EAPI extern int EIO_MONITOR_FILE_CLOSED ; /**< Notify closing of a file in a watched directory */
2011-04-25 10:04:46 -07:00
EAPI extern int EIO_MONITOR_DIRECTORY_CREATED ; /**< Notify creation of a new directory in a watched directory */
EAPI extern int EIO_MONITOR_DIRECTORY_DELETED ; /**< Notify destruction of a watched directory or in a watched directory */
EAPI extern int EIO_MONITOR_DIRECTORY_MODIFIED ; /**< Notify modification of a directory in a watched directory */
2011-04-27 03:27:07 -07:00
EAPI extern int EIO_MONITOR_DIRECTORY_CLOSED ; /**< Notify closing of a directory in a watched directory */
EAPI extern int EIO_MONITOR_SELF_RENAME ; /**< Notify that Eio monitored path has been renamed, an error could happen just after if the renamed path doesn't exist */
EAPI extern int EIO_MONITOR_SELF_DELETED ; /**< Notify that Eio monitored path has been removed */
2011-04-25 10:04:46 -07:00
EAPI extern int EIO_MONITOR_ERROR ; /**< Notify that during operation the pointed monitor failed and will no longer work. eio_monitor_del is required on it. */
typedef struct _Eio_Monitor Eio_Monitor ;
typedef struct _Eio_Monitor_Error Eio_Monitor_Error ;
2011-04-27 03:27:07 -07:00
typedef struct _Eio_Monitor_Event Eio_Monitor_Event ;
2011-04-25 10:04:46 -07:00
struct _Eio_Monitor_Error
{
Eio_Monitor * monitor ;
int error ;
} ;
2011-04-27 03:27:07 -07:00
struct _Eio_Monitor_Event
{
Eio_Monitor * monitor ;
const char * filename ;
} ;
2011-04-25 10:04:46 -07:00
EAPI Eio_Monitor * eio_monitor_add ( const char * path ) ;
EAPI Eio_Monitor * eio_monitor_stringshared_add ( const char * path ) ;
EAPI void eio_monitor_del ( Eio_Monitor * monitor ) ;
EAPI const char * eio_monitor_path_get ( Eio_Monitor * monitor ) ;
2010-10-12 07:59:30 -07:00
/**
* @ }
*/
2010-10-29 05:58:04 -07:00
# include "eio_inline_helper.x"
2010-10-12 07:59:30 -07:00
# ifdef __cplusplus
}
# endif
2010-07-22 09:08:17 -07:00
# endif