forked from enlightenment/efl
parent
061c5ec0ba
commit
71b13c4b72
|
@ -22,6 +22,14 @@
|
|||
#include "eio_private.h"
|
||||
#include "Eio.h"
|
||||
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
static void
|
||||
_eio_eet_open_job(void *data, Ecore_Thread *thread)
|
||||
{
|
||||
|
@ -286,6 +294,19 @@ _eio_eet_read_cipher_end(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
_eio_eet_read_free(er);
|
||||
}
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Global *
|
||||
*============================================================================*/
|
||||
|
||||
|
||||
/*============================================================================*
|
||||
* API *
|
||||
*============================================================================*/
|
||||
|
||||
EAPI Eio_File *
|
||||
eio_eet_open(const char *filename,
|
||||
Eet_File_Mode mode,
|
||||
|
|
|
@ -25,11 +25,25 @@
|
|||
#else
|
||||
# include <asm/unistd.h>
|
||||
# include <linux/inotify.h>
|
||||
static inline int inotify_init(void);
|
||||
static inline int inotify_add_watch(int fd, const char *name, __u32 mask);
|
||||
static inline int inotify_rm_watch(int fd, __u32 wd);
|
||||
#endif
|
||||
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
typedef struct _Eio_Inotify_Table Eio_Inotify_Table;
|
||||
|
||||
struct _Eio_Inotify_Table
|
||||
{
|
||||
int mask;
|
||||
int *ev_file_code;
|
||||
int *ev_dir_code;
|
||||
};
|
||||
|
||||
struct _Eio_Monitor_Backend
|
||||
{
|
||||
Eio_Monitor *parent;
|
||||
|
@ -40,30 +54,6 @@ struct _Eio_Monitor_Backend
|
|||
static Ecore_Fd_Handler *_inotify_fdh = NULL;
|
||||
static Eina_Hash *_inotify_monitors = NULL;
|
||||
|
||||
static void
|
||||
_eio_inotify_del(void *data)
|
||||
{
|
||||
Eio_Monitor_Backend *emb = data;
|
||||
int fd;
|
||||
|
||||
if (emb->hwnd)
|
||||
{
|
||||
fd = ecore_main_fd_handler_fd_get(_inotify_fdh);
|
||||
inotify_rm_watch(fd, emb->hwnd);
|
||||
emb->hwnd = 0;
|
||||
}
|
||||
|
||||
free(emb);
|
||||
}
|
||||
|
||||
typedef struct _Eio_Inotify_Table Eio_Inotify_Table;
|
||||
struct _Eio_Inotify_Table
|
||||
{
|
||||
int mask;
|
||||
int *ev_file_code;
|
||||
int *ev_dir_code;
|
||||
};
|
||||
|
||||
#define EIO_INOTIFY_LINE(Ino, Ef, Ed) \
|
||||
{ Ino, &EIO_MONITOR_##Ef, &EIO_MONITOR_##Ed }
|
||||
|
||||
|
@ -80,6 +70,42 @@ static const Eio_Inotify_Table match[] = {
|
|||
EIO_INOTIFY_LINE(IN_UNMOUNT, SELF_DELETED, SELF_DELETED)
|
||||
};
|
||||
|
||||
#ifndef HAVE_SYS_INOTIFY
|
||||
static inline int
|
||||
inotify_init(void)
|
||||
{
|
||||
return syscall(__NR_inotify_init);
|
||||
}
|
||||
|
||||
static inline int
|
||||
inotify_add_watch(int fd, const char *name, __u32 mask)
|
||||
{
|
||||
return syscall(__NR_inotify_add_watch, fd, name, mask);
|
||||
}
|
||||
|
||||
static inline int
|
||||
inotify_rm_watch(int fd, __u32 wd)
|
||||
{
|
||||
return syscall(__NR_inotify_rm_watch, fd, wd);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
_eio_inotify_del(void *data)
|
||||
{
|
||||
Eio_Monitor_Backend *emb = data;
|
||||
int fd;
|
||||
|
||||
if (emb->hwnd)
|
||||
{
|
||||
fd = ecore_main_fd_handler_fd_get(_inotify_fdh);
|
||||
inotify_rm_watch(fd, emb->hwnd);
|
||||
emb->hwnd = 0;
|
||||
}
|
||||
|
||||
free(emb);
|
||||
}
|
||||
|
||||
static void
|
||||
_eio_inotify_events(Eio_Monitor_Backend *backend, const char *file, int mask)
|
||||
{
|
||||
|
@ -138,6 +164,23 @@ _eio_inotify_handler(void *data __UNUSED__, Ecore_Fd_Handler *fdh)
|
|||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
|
||||
/*============================================================================*
|
||||
* Global *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
void eio_monitor_backend_init(void)
|
||||
{
|
||||
int fd;
|
||||
|
@ -212,22 +255,7 @@ void eio_monitor_backend_del(Eio_Monitor *monitor)
|
|||
monitor->backend = NULL;
|
||||
}
|
||||
|
||||
#ifndef HAVE_SYS_INOTIFY
|
||||
static inline int
|
||||
inotify_init(void)
|
||||
{
|
||||
return syscall(__NR_inotify_init);
|
||||
}
|
||||
|
||||
static inline int
|
||||
inotify_add_watch(int fd, const char *name, __u32 mask)
|
||||
{
|
||||
return syscall(__NR_inotify_add_watch, fd, name, mask);
|
||||
}
|
||||
|
||||
static inline int
|
||||
inotify_rm_watch(int fd, __u32 wd)
|
||||
{
|
||||
return syscall(__NR_inotify_rm_watch, fd, wd);
|
||||
}
|
||||
#endif
|
||||
/*============================================================================*
|
||||
* API *
|
||||
*============================================================================*/
|
||||
|
|
|
@ -20,17 +20,13 @@
|
|||
#include "eio_private.h"
|
||||
#include "Eio.h"
|
||||
|
||||
EAPI int EIO_MONITOR_ERROR;
|
||||
EAPI int EIO_MONITOR_FILE_CREATED;
|
||||
EAPI int EIO_MONITOR_FILE_DELETED;
|
||||
EAPI int EIO_MONITOR_FILE_MODIFIED;
|
||||
EAPI int EIO_MONITOR_FILE_CLOSED;
|
||||
EAPI int EIO_MONITOR_DIRECTORY_CREATED;
|
||||
EAPI int EIO_MONITOR_DIRECTORY_DELETED;
|
||||
EAPI int EIO_MONITOR_DIRECTORY_MODIFIED;
|
||||
EAPI int EIO_MONITOR_DIRECTORY_CLOSED;
|
||||
EAPI int EIO_MONITOR_SELF_RENAME;
|
||||
EAPI int EIO_MONITOR_SELF_DELETED;
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
static Eina_Hash *_eio_monitors = NULL;
|
||||
static pid_t _monitor_pid = -1;
|
||||
|
@ -121,6 +117,18 @@ _eio_monitor_error_cb(void *data, Eio_File *handler __UNUSED__, int error)
|
|||
return ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Global *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
void
|
||||
eio_monitor_init(void)
|
||||
{
|
||||
|
@ -158,6 +166,86 @@ eio_monitor_shutdown(void)
|
|||
_monitor_pid = -1;
|
||||
}
|
||||
|
||||
void
|
||||
_eio_monitor_send(Eio_Monitor *monitor, const char *filename, int event_code)
|
||||
{
|
||||
Eio_Monitor_Event *ev;
|
||||
|
||||
ev = calloc(1, sizeof (Eio_Monitor_Event));
|
||||
if (!ev) return ;
|
||||
|
||||
ev->monitor = monitor;
|
||||
EINA_REFCOUNT_REF(ev->monitor);
|
||||
ev->filename = eina_stringshare_add(filename);
|
||||
|
||||
ecore_event_add(event_code, ev, _eio_monitor_event_cleanup_cb, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
_eio_monitor_rename(Eio_Monitor *monitor, const char *newpath)
|
||||
{
|
||||
const char *tmp;
|
||||
|
||||
/* destroy old state */
|
||||
if (monitor->exist) eio_file_cancel(monitor->exist);
|
||||
|
||||
if (monitor->backend)
|
||||
{
|
||||
if (!monitor->fallback)
|
||||
eio_monitor_backend_del(monitor);
|
||||
else
|
||||
eio_monitor_fallback_del(monitor);
|
||||
}
|
||||
|
||||
/* rename */
|
||||
tmp = monitor->path;
|
||||
monitor->path = eina_stringshare_add(newpath);
|
||||
eina_hash_move(_eio_monitors, tmp, monitor->path);
|
||||
eina_stringshare_del(tmp);
|
||||
|
||||
/* That means death (cmp pointer and not content) */
|
||||
if (tmp == monitor->path)
|
||||
{
|
||||
_eio_monitor_error(monitor, -1);
|
||||
return ;
|
||||
}
|
||||
|
||||
EINA_REFCOUNT_REF(monitor); /* as we spawn a thread for this monitor, we need to refcount specifically for it */
|
||||
|
||||
/* restart */
|
||||
monitor->rename = EINA_TRUE;
|
||||
monitor->exist = eio_file_direct_stat(monitor->path,
|
||||
_eio_monitor_stat_cb,
|
||||
_eio_monitor_error_cb,
|
||||
monitor);
|
||||
|
||||
/* FIXME: probably should handle this more gracefully */
|
||||
if (!monitor->exist) abort();
|
||||
/* and notify the app */
|
||||
_eio_monitor_send(monitor, newpath, EIO_MONITOR_SELF_RENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
|
||||
/*============================================================================*
|
||||
* API *
|
||||
*============================================================================*/
|
||||
|
||||
EAPI int EIO_MONITOR_ERROR;
|
||||
EAPI int EIO_MONITOR_FILE_CREATED;
|
||||
EAPI int EIO_MONITOR_FILE_DELETED;
|
||||
EAPI int EIO_MONITOR_FILE_MODIFIED;
|
||||
EAPI int EIO_MONITOR_FILE_CLOSED;
|
||||
EAPI int EIO_MONITOR_DIRECTORY_CREATED;
|
||||
EAPI int EIO_MONITOR_DIRECTORY_DELETED;
|
||||
EAPI int EIO_MONITOR_DIRECTORY_MODIFIED;
|
||||
EAPI int EIO_MONITOR_DIRECTORY_CLOSED;
|
||||
EAPI int EIO_MONITOR_SELF_RENAME;
|
||||
EAPI int EIO_MONITOR_SELF_DELETED;
|
||||
|
||||
EAPI Eio_Monitor *
|
||||
eio_monitor_add(const char *path)
|
||||
{
|
||||
|
@ -230,62 +318,3 @@ eio_monitor_path_get(Eio_Monitor *monitor)
|
|||
EINA_SAFETY_ON_NULL_RETURN_VAL(monitor, NULL);
|
||||
return monitor->path;
|
||||
}
|
||||
|
||||
void
|
||||
_eio_monitor_send(Eio_Monitor *monitor, const char *filename, int event_code)
|
||||
{
|
||||
Eio_Monitor_Event *ev;
|
||||
|
||||
ev = calloc(1, sizeof (Eio_Monitor_Event));
|
||||
if (!ev) return ;
|
||||
|
||||
ev->monitor = monitor;
|
||||
EINA_REFCOUNT_REF(ev->monitor);
|
||||
ev->filename = eina_stringshare_add(filename);
|
||||
|
||||
ecore_event_add(event_code, ev, _eio_monitor_event_cleanup_cb, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
_eio_monitor_rename(Eio_Monitor *monitor, const char *newpath)
|
||||
{
|
||||
const char *tmp;
|
||||
|
||||
/* destroy old state */
|
||||
if (monitor->exist) eio_file_cancel(monitor->exist);
|
||||
|
||||
if (monitor->backend)
|
||||
{
|
||||
if (!monitor->fallback)
|
||||
eio_monitor_backend_del(monitor);
|
||||
else
|
||||
eio_monitor_fallback_del(monitor);
|
||||
}
|
||||
|
||||
/* rename */
|
||||
tmp = monitor->path;
|
||||
monitor->path = eina_stringshare_add(newpath);
|
||||
eina_hash_move(_eio_monitors, tmp, monitor->path);
|
||||
eina_stringshare_del(tmp);
|
||||
|
||||
/* That means death (cmp pointer and not content) */
|
||||
if (tmp == monitor->path)
|
||||
{
|
||||
_eio_monitor_error(monitor, -1);
|
||||
return ;
|
||||
}
|
||||
|
||||
EINA_REFCOUNT_REF(monitor); /* as we spawn a thread for this monitor, we need to refcount specifically for it */
|
||||
|
||||
/* restart */
|
||||
monitor->rename = EINA_TRUE;
|
||||
monitor->exist = eio_file_direct_stat(monitor->path,
|
||||
_eio_monitor_stat_cb,
|
||||
_eio_monitor_error_cb,
|
||||
monitor);
|
||||
|
||||
/* FIXME: probably should handle this more gracefully */
|
||||
if (!monitor->exist) abort();
|
||||
/* and notify the app */
|
||||
_eio_monitor_send(monitor, newpath, EIO_MONITOR_SELF_RENAME);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,16 @@
|
|||
#include "eio_private.h"
|
||||
#include "Eio.h"
|
||||
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
typedef struct _Eio_Monitor_Stat Eio_Monitor_Stat;
|
||||
|
||||
struct _Eio_Monitor_Stat
|
||||
{
|
||||
Eina_Stat buffer;
|
||||
|
@ -47,26 +56,6 @@ struct _Eio_Monitor_Backend
|
|||
|
||||
static Eina_Bool _eio_monitor_fallback_timer_cb(void *data);
|
||||
|
||||
#if !defined HAVE_INOTIFY && !defined HAVE_NOTIFY_WIN32
|
||||
void eio_monitor_backend_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void eio_monitor_backend_shutdown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void eio_monitor_backend_add(Eio_Monitor *monitor)
|
||||
{
|
||||
eio_monitor_fallback_add(monitor);
|
||||
}
|
||||
|
||||
void eio_monitor_backend_del(Eio_Monitor *monitor)
|
||||
{
|
||||
eio_monitor_fallback_del(monitor);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
_eio_monitor_fallback_heavy_cb(void *data, Ecore_Thread *thread)
|
||||
{
|
||||
|
@ -269,6 +258,38 @@ _eio_monitor_fallback_timer_cb(void *data)
|
|||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Global *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
#if !defined HAVE_INOTIFY && !defined HAVE_NOTIFY_WIN32
|
||||
void eio_monitor_backend_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void eio_monitor_backend_shutdown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void eio_monitor_backend_add(Eio_Monitor *monitor)
|
||||
{
|
||||
eio_monitor_fallback_add(monitor);
|
||||
}
|
||||
|
||||
void eio_monitor_backend_del(Eio_Monitor *monitor)
|
||||
{
|
||||
eio_monitor_fallback_del(monitor);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
eio_monitor_fallback_init(void)
|
||||
{
|
||||
|
@ -321,3 +342,12 @@ eio_monitor_fallback_del(Eio_Monitor *monitor)
|
|||
}
|
||||
free(backend);
|
||||
}
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
|
||||
/*============================================================================*
|
||||
* API *
|
||||
*============================================================================*/
|
||||
|
|
|
@ -20,10 +20,30 @@
|
|||
#include "eio_private.h"
|
||||
#include "Eio.h"
|
||||
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
struct _Eio_Monitor_Backend
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Global *
|
||||
*============================================================================*/
|
||||
|
||||
/**
|
||||
* @cond LOCAL
|
||||
*/
|
||||
|
||||
void eio_monitor_backend_init(void)
|
||||
{
|
||||
abort();
|
||||
|
@ -40,3 +60,13 @@ void eio_monitor_backend_add(Eio_Monitor *monitor)
|
|||
void eio_monitor_backend_del(Eio_Monitor *monitor)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
|
||||
/*============================================================================*
|
||||
* API *
|
||||
*============================================================================*/
|
||||
|
|
Loading…
Reference in New Issue