forked from enlightenment/efl
* ecore: Remove Ecore_List2 from ecore_file.
SVN revision: 41072
This commit is contained in:
parent
429fc4b4f8
commit
79291ef06b
|
@ -47,7 +47,7 @@ struct _Ecore_File_Monitor_Inotify
|
||||||
};
|
};
|
||||||
|
|
||||||
static Ecore_Fd_Handler *_fdh = NULL;
|
static Ecore_Fd_Handler *_fdh = NULL;
|
||||||
static Ecore_List2 *_monitors = NULL;
|
static Ecore_File_Monitor *_monitors = NULL;
|
||||||
|
|
||||||
static int _ecore_file_monitor_inotify_handler(void *data, Ecore_Fd_Handler *fdh);
|
static int _ecore_file_monitor_inotify_handler(void *data, Ecore_Fd_Handler *fdh);
|
||||||
static Ecore_File_Monitor *_ecore_file_monitor_inotify_monitor_find(int wd);
|
static Ecore_File_Monitor *_ecore_file_monitor_inotify_monitor_find(int wd);
|
||||||
|
@ -81,16 +81,9 @@ int
|
||||||
ecore_file_monitor_inotify_shutdown(void)
|
ecore_file_monitor_inotify_shutdown(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
Ecore_List2 *l;
|
|
||||||
|
|
||||||
for (l = _monitors; l;)
|
while(_monitors)
|
||||||
{
|
ecore_file_monitor_inotify_del(_monitors);
|
||||||
Ecore_File_Monitor *em;
|
|
||||||
|
|
||||||
em = ECORE_FILE_MONITOR(l);
|
|
||||||
l = l->next;
|
|
||||||
ecore_file_monitor_inotify_del(em);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_fdh)
|
if (_fdh)
|
||||||
{
|
{
|
||||||
|
@ -122,7 +115,7 @@ ecore_file_monitor_inotify_add(const char *path,
|
||||||
if (em->path[len - 1] == '/' && strcmp(em->path, "/"))
|
if (em->path[len - 1] == '/' && strcmp(em->path, "/"))
|
||||||
em->path[len - 1] = 0;
|
em->path[len - 1] = 0;
|
||||||
|
|
||||||
_monitors = _ecore_list2_append(_monitors, em);
|
_monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
|
||||||
|
|
||||||
if (ecore_file_exists(em->path))
|
if (ecore_file_exists(em->path))
|
||||||
{
|
{
|
||||||
|
@ -143,7 +136,7 @@ ecore_file_monitor_inotify_del(Ecore_File_Monitor *em)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
_monitors = _ecore_list2_remove(_monitors, em);
|
_monitors = ECORE_FILE_MONITOR(eina_inlist_remove(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
|
||||||
|
|
||||||
fd = ecore_main_fd_handler_fd_get(_fdh);
|
fd = ecore_main_fd_handler_fd_get(_fdh);
|
||||||
if (ECORE_FILE_MONITOR_INOTIFY(em)->wd)
|
if (ECORE_FILE_MONITOR_INOTIFY(em)->wd)
|
||||||
|
@ -181,16 +174,12 @@ _ecore_file_monitor_inotify_handler(void *data __UNUSED__, Ecore_Fd_Handler *fdh
|
||||||
static Ecore_File_Monitor *
|
static Ecore_File_Monitor *
|
||||||
_ecore_file_monitor_inotify_monitor_find(int wd)
|
_ecore_file_monitor_inotify_monitor_find(int wd)
|
||||||
{
|
{
|
||||||
Ecore_List2 *l;
|
Ecore_File_Monitor *l;
|
||||||
|
|
||||||
for (l = _monitors; l; l = l->next)
|
EINA_INLIST_FOREACH(_monitors, l)
|
||||||
{
|
{
|
||||||
Ecore_File_Monitor *em;
|
if (ECORE_FILE_MONITOR_INOTIFY(l)->wd == wd)
|
||||||
|
return l;
|
||||||
em = ECORE_FILE_MONITOR(l);
|
|
||||||
|
|
||||||
if (ECORE_FILE_MONITOR_INOTIFY(em)->wd == wd)
|
|
||||||
return em;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct _Ecore_File_Monitor_Poll Ecore_File_Monitor_Poll;
|
typedef struct _Ecore_File_Monitor_Poll Ecore_File_Monitor_Poll;
|
||||||
typedef struct _Ecore_File Ecore_File;
|
|
||||||
|
|
||||||
#define ECORE_FILE_MONITOR_POLL(x) ((Ecore_File_Monitor_Poll *)(x))
|
#define ECORE_FILE_MONITOR_POLL(x) ((Ecore_File_Monitor_Poll *)(x))
|
||||||
|
|
||||||
|
@ -33,21 +32,13 @@ struct _Ecore_File_Monitor_Poll
|
||||||
unsigned char deleted;
|
unsigned char deleted;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _Ecore_File
|
|
||||||
{
|
|
||||||
Ecore_List2 __list_data;
|
|
||||||
char *name;
|
|
||||||
int mtime;
|
|
||||||
unsigned char is_dir;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define ECORE_FILE_INTERVAL_MIN 1.0
|
#define ECORE_FILE_INTERVAL_MIN 1.0
|
||||||
#define ECORE_FILE_INTERVAL_STEP 0.5
|
#define ECORE_FILE_INTERVAL_STEP 0.5
|
||||||
#define ECORE_FILE_INTERVAL_MAX 5.0
|
#define ECORE_FILE_INTERVAL_MAX 5.0
|
||||||
|
|
||||||
static double _interval = ECORE_FILE_INTERVAL_MIN;
|
static double _interval = ECORE_FILE_INTERVAL_MIN;
|
||||||
static Ecore_Timer *_timer = NULL;
|
static Ecore_Timer *_timer = NULL;
|
||||||
static Ecore_List2 *_monitors = NULL;
|
static Ecore_File_Monitor *_monitors = NULL;
|
||||||
static int _lock = 0;
|
static int _lock = 0;
|
||||||
|
|
||||||
static int _ecore_file_monitor_poll_handler(void *data);
|
static int _ecore_file_monitor_poll_handler(void *data);
|
||||||
|
@ -63,16 +54,8 @@ ecore_file_monitor_poll_init(void)
|
||||||
int
|
int
|
||||||
ecore_file_monitor_poll_shutdown(void)
|
ecore_file_monitor_poll_shutdown(void)
|
||||||
{
|
{
|
||||||
Ecore_List2 *l;
|
while(_monitors)
|
||||||
|
ecore_file_monitor_poll_del(_monitors);
|
||||||
for (l = _monitors; l;)
|
|
||||||
{
|
|
||||||
Ecore_File_Monitor *em;
|
|
||||||
|
|
||||||
em = ECORE_FILE_MONITOR(l);
|
|
||||||
l = l->next;
|
|
||||||
ecore_file_monitor_poll_del(em);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_timer)
|
if (_timer)
|
||||||
{
|
{
|
||||||
|
@ -97,7 +80,7 @@ ecore_file_monitor_poll_add(const char *path,
|
||||||
|
|
||||||
em = calloc(1, sizeof(Ecore_File_Monitor_Poll));
|
em = calloc(1, sizeof(Ecore_File_Monitor_Poll));
|
||||||
if (!em) return NULL;
|
if (!em) return NULL;
|
||||||
|
|
||||||
if (!_timer)
|
if (!_timer)
|
||||||
_timer = ecore_timer_add(_interval, _ecore_file_monitor_poll_handler, NULL);
|
_timer = ecore_timer_add(_interval, _ecore_file_monitor_poll_handler, NULL);
|
||||||
else
|
else
|
||||||
|
@ -134,10 +117,10 @@ ecore_file_monitor_poll_add(const char *path,
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", em->path, file);
|
snprintf(buf, sizeof(buf), "%s/%s", em->path, file);
|
||||||
f->name = file;
|
f->name = file;
|
||||||
f->mtime = ecore_file_mod_time(buf);
|
f->mtime = ecore_file_mod_time(buf);
|
||||||
f->is_dir = ecore_file_is_dir(buf);
|
f->is_dir = ecore_file_is_dir(buf);
|
||||||
em->files = _ecore_list2_append(em->files, f);
|
em->files = (Ecore_File *) eina_inlist_append(EINA_INLIST_GET(em->files), EINA_INLIST_GET(f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +130,7 @@ ecore_file_monitor_poll_add(const char *path,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_monitors = _ecore_list2_append(_monitors, em);
|
_monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
|
||||||
|
|
||||||
return em;
|
return em;
|
||||||
}
|
}
|
||||||
|
@ -155,7 +138,7 @@ ecore_file_monitor_poll_add(const char *path,
|
||||||
void
|
void
|
||||||
ecore_file_monitor_poll_del(Ecore_File_Monitor *em)
|
ecore_file_monitor_poll_del(Ecore_File_Monitor *em)
|
||||||
{
|
{
|
||||||
Ecore_List2 *l;
|
Ecore_File *l;
|
||||||
|
|
||||||
if (_lock)
|
if (_lock)
|
||||||
{
|
{
|
||||||
|
@ -169,20 +152,19 @@ ecore_file_monitor_poll_del(Ecore_File_Monitor *em)
|
||||||
{
|
{
|
||||||
for (l = em->files; l;)
|
for (l = em->files; l;)
|
||||||
{
|
{
|
||||||
Ecore_File *file;
|
Ecore_File *file = l;
|
||||||
|
|
||||||
file = (Ecore_File *)l;
|
l = (Ecore_File *) EINA_INLIST_GET(l)->next;
|
||||||
l = l->next;
|
|
||||||
free(file->name);
|
free(file->name);
|
||||||
free(file);
|
free(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_monitors = _ecore_list2_remove(_monitors, em);
|
_monitors = ECORE_FILE_MONITOR(eina_inlist_remove(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
|
||||||
|
|
||||||
free(em->path);
|
free(em->path);
|
||||||
free(em);
|
free(em);
|
||||||
|
|
||||||
if (_timer)
|
if (_timer)
|
||||||
{
|
{
|
||||||
if (!_monitors)
|
if (!_monitors)
|
||||||
|
@ -198,18 +180,13 @@ ecore_file_monitor_poll_del(Ecore_File_Monitor *em)
|
||||||
static int
|
static int
|
||||||
_ecore_file_monitor_poll_handler(void *data __UNUSED__)
|
_ecore_file_monitor_poll_handler(void *data __UNUSED__)
|
||||||
{
|
{
|
||||||
Ecore_List2 *l;
|
Ecore_File_Monitor *l;
|
||||||
|
|
||||||
_interval += ECORE_FILE_INTERVAL_STEP;
|
_interval += ECORE_FILE_INTERVAL_STEP;
|
||||||
|
|
||||||
_lock = 1;
|
_lock = 1;
|
||||||
for (l = _monitors; l; l = l->next)
|
EINA_INLIST_FOREACH(_monitors, l)
|
||||||
{
|
_ecore_file_monitor_poll_check(l);
|
||||||
Ecore_File_Monitor *em;
|
|
||||||
|
|
||||||
em = ECORE_FILE_MONITOR(l);
|
|
||||||
_ecore_file_monitor_poll_check(em);
|
|
||||||
}
|
|
||||||
_lock = 0;
|
_lock = 0;
|
||||||
|
|
||||||
if (_interval > ECORE_FILE_INTERVAL_MAX)
|
if (_interval > ECORE_FILE_INTERVAL_MAX)
|
||||||
|
@ -218,10 +195,9 @@ _ecore_file_monitor_poll_handler(void *data __UNUSED__)
|
||||||
|
|
||||||
for (l = _monitors; l;)
|
for (l = _monitors; l;)
|
||||||
{
|
{
|
||||||
Ecore_File_Monitor *em;
|
Ecore_File_Monitor *em = l;
|
||||||
|
|
||||||
em = ECORE_FILE_MONITOR(l);
|
l = ECORE_FILE_MONITOR(EINA_INLIST_GET(l)->next);
|
||||||
l = l->next;
|
|
||||||
if (ECORE_FILE_MONITOR_POLL(em)->deleted)
|
if (ECORE_FILE_MONITOR_POLL(em)->deleted)
|
||||||
ecore_file_monitor_del(em);
|
ecore_file_monitor_del(em);
|
||||||
}
|
}
|
||||||
|
@ -238,17 +214,16 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
||||||
is_dir = ecore_file_is_dir(em->path);
|
is_dir = ecore_file_is_dir(em->path);
|
||||||
if (mtime < ECORE_FILE_MONITOR_POLL(em)->mtime)
|
if (mtime < ECORE_FILE_MONITOR_POLL(em)->mtime)
|
||||||
{
|
{
|
||||||
Ecore_List2 *l;
|
Ecore_File *l;
|
||||||
Ecore_File_Event event;
|
Ecore_File_Event event;
|
||||||
|
|
||||||
/* Notify all files deleted */
|
/* Notify all files deleted */
|
||||||
for (l = em->files; l;)
|
for (l = em->files; l;)
|
||||||
{
|
{
|
||||||
Ecore_File *f;
|
Ecore_File *f = l;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
|
|
||||||
f = (Ecore_File *)l;
|
l = (Ecore_File *) EINA_INLIST_GET(l)->next;
|
||||||
l = l->next;
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", em->path, f->name);
|
snprintf(buf, sizeof(buf), "%s/%s", em->path, f->name);
|
||||||
if (f->is_dir)
|
if (f->is_dir)
|
||||||
|
@ -265,18 +240,17 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Ecore_List2 *l;
|
Ecore_File *l;
|
||||||
|
|
||||||
/* Check for changed files */
|
/* Check for changed files */
|
||||||
for (l = em->files; l;)
|
for (l = em->files; l;)
|
||||||
{
|
{
|
||||||
Ecore_File *f;
|
Ecore_File *f = l;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
int mtime;
|
int mtime;
|
||||||
Ecore_File_Event event;
|
Ecore_File_Event event;
|
||||||
|
|
||||||
f = (Ecore_File *)l;
|
l = (Ecore_File *) EINA_INLIST_GET(l)->next;
|
||||||
l = l->next;
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", em->path, f->name);
|
snprintf(buf, sizeof(buf), "%s/%s", em->path, f->name);
|
||||||
mtime = ecore_file_mod_time(buf);
|
mtime = ecore_file_mod_time(buf);
|
||||||
|
@ -288,7 +262,7 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
||||||
event = ECORE_FILE_EVENT_DELETED_FILE;
|
event = ECORE_FILE_EVENT_DELETED_FILE;
|
||||||
|
|
||||||
em->func(em->data, em, event, buf);
|
em->func(em->data, em, event, buf);
|
||||||
em->files = _ecore_list2_remove(em->files, f);
|
em->files = (Ecore_File *) eina_inlist_remove(EINA_INLIST_GET(em->files), EINA_INLIST_GET(f));
|
||||||
free(f->name);
|
free(f->name);
|
||||||
free(f);
|
free(f);
|
||||||
_interval = ECORE_FILE_INTERVAL_MIN;
|
_interval = ECORE_FILE_INTERVAL_MIN;
|
||||||
|
@ -313,22 +287,22 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
||||||
/* Files have been added or removed */
|
/* Files have been added or removed */
|
||||||
files = ecore_file_ls(em->path);
|
files = ecore_file_ls(em->path);
|
||||||
if (files)
|
if (files)
|
||||||
{
|
{
|
||||||
/* Are we a directory? We should check first, rather than rely on null here*/
|
/* Are we a directory? We should check first, rather than rely on null here*/
|
||||||
EINA_LIST_FOREACH(files, l, file)
|
EINA_LIST_FOREACH(files, l, file)
|
||||||
{
|
{
|
||||||
Ecore_File *f;
|
Ecore_File *f;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
Ecore_File_Event event;
|
Ecore_File_Event event;
|
||||||
|
|
||||||
if (_ecore_file_monitor_poll_checking(em, file))
|
if (_ecore_file_monitor_poll_checking(em, file))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", em->path, file);
|
snprintf(buf, sizeof(buf), "%s/%s", em->path, file);
|
||||||
f = calloc(1, sizeof(Ecore_File));
|
f = calloc(1, sizeof(Ecore_File));
|
||||||
if (!f)
|
if (!f)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
f->name = strdup(file);
|
f->name = strdup(file);
|
||||||
f->mtime = ecore_file_mod_time(buf);
|
f->mtime = ecore_file_mod_time(buf);
|
||||||
f->is_dir = ecore_file_mod_time(buf);
|
f->is_dir = ecore_file_mod_time(buf);
|
||||||
|
@ -337,7 +311,7 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
||||||
else
|
else
|
||||||
event = ECORE_FILE_EVENT_CREATED_FILE;
|
event = ECORE_FILE_EVENT_CREATED_FILE;
|
||||||
em->func(em->data, em, event, buf);
|
em->func(em->data, em, event, buf);
|
||||||
em->files = _ecore_list2_append(em->files, f);
|
em->files = (Ecore_File *) eina_inlist_append(EINA_INLIST_GET(em->files), EINA_INLIST_GET(f));
|
||||||
}
|
}
|
||||||
while (files)
|
while (files)
|
||||||
{
|
{
|
||||||
|
@ -346,7 +320,7 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
||||||
files = eina_list_remove_list(files, files);
|
files = eina_list_remove_list(files, files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ecore_file_is_dir(em->path))
|
if (!ecore_file_is_dir(em->path))
|
||||||
em->func(em->data, em, ECORE_FILE_EVENT_MODIFIED, em->path);
|
em->func(em->data, em, ECORE_FILE_EVENT_MODIFIED, em->path);
|
||||||
_interval = ECORE_FILE_INTERVAL_MIN;
|
_interval = ECORE_FILE_INTERVAL_MIN;
|
||||||
|
@ -358,14 +332,11 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
||||||
static int
|
static int
|
||||||
_ecore_file_monitor_poll_checking(Ecore_File_Monitor *em, char *name)
|
_ecore_file_monitor_poll_checking(Ecore_File_Monitor *em, char *name)
|
||||||
{
|
{
|
||||||
Ecore_List2 *l;
|
Ecore_File *l;
|
||||||
|
|
||||||
for (l = em->files; l; l = l->next)
|
EINA_INLIST_FOREACH(em->files, l)
|
||||||
{
|
{
|
||||||
Ecore_File *f;
|
if (!strcmp(l->name, name))
|
||||||
|
|
||||||
f = (Ecore_File *)l;
|
|
||||||
if (!strcmp(f->name, name))
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -21,9 +21,18 @@ int ecore_file_monitor_shutdown(void);
|
||||||
|
|
||||||
#define ECORE_FILE_MONITOR(x) ((Ecore_File_Monitor *)(x))
|
#define ECORE_FILE_MONITOR(x) ((Ecore_File_Monitor *)(x))
|
||||||
|
|
||||||
|
typedef struct _Ecore_File Ecore_File;
|
||||||
|
struct _Ecore_File
|
||||||
|
{
|
||||||
|
EINA_INLIST;
|
||||||
|
char *name;
|
||||||
|
int mtime;
|
||||||
|
unsigned char is_dir;
|
||||||
|
};
|
||||||
|
|
||||||
struct _Ecore_File_Monitor
|
struct _Ecore_File_Monitor
|
||||||
{
|
{
|
||||||
Ecore_List2 __list_data;
|
EINA_INLIST;
|
||||||
void (*func) (void *data,
|
void (*func) (void *data,
|
||||||
Ecore_File_Monitor *ecore_file_monitor,
|
Ecore_File_Monitor *ecore_file_monitor,
|
||||||
Ecore_File_Event event,
|
Ecore_File_Event event,
|
||||||
|
@ -31,7 +40,7 @@ struct _Ecore_File_Monitor
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
void *data;
|
void *data;
|
||||||
Ecore_List2 *files;
|
Ecore_File *files;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_INOTIFY
|
#ifdef HAVE_INOTIFY
|
||||||
|
|
Loading…
Reference in New Issue