* 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_List2 *_monitors = NULL;
|
||||
static Ecore_File_Monitor *_monitors = NULL;
|
||||
|
||||
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);
|
||||
|
@ -81,16 +81,9 @@ int
|
|||
ecore_file_monitor_inotify_shutdown(void)
|
||||
{
|
||||
int fd;
|
||||
Ecore_List2 *l;
|
||||
|
||||
for (l = _monitors; l;)
|
||||
{
|
||||
Ecore_File_Monitor *em;
|
||||
|
||||
em = ECORE_FILE_MONITOR(l);
|
||||
l = l->next;
|
||||
ecore_file_monitor_inotify_del(em);
|
||||
}
|
||||
while(_monitors)
|
||||
ecore_file_monitor_inotify_del(_monitors);
|
||||
|
||||
if (_fdh)
|
||||
{
|
||||
|
@ -122,7 +115,7 @@ ecore_file_monitor_inotify_add(const char *path,
|
|||
if (em->path[len - 1] == '/' && strcmp(em->path, "/"))
|
||||
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))
|
||||
{
|
||||
|
@ -143,7 +136,7 @@ ecore_file_monitor_inotify_del(Ecore_File_Monitor *em)
|
|||
{
|
||||
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);
|
||||
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 *
|
||||
_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;
|
||||
|
||||
em = ECORE_FILE_MONITOR(l);
|
||||
|
||||
if (ECORE_FILE_MONITOR_INOTIFY(em)->wd == wd)
|
||||
return em;
|
||||
if (ECORE_FILE_MONITOR_INOTIFY(l)->wd == wd)
|
||||
return l;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
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))
|
||||
|
||||
|
@ -33,21 +32,13 @@ struct _Ecore_File_Monitor_Poll
|
|||
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_STEP 0.5
|
||||
#define ECORE_FILE_INTERVAL_MAX 5.0
|
||||
|
||||
static double _interval = ECORE_FILE_INTERVAL_MIN;
|
||||
static Ecore_Timer *_timer = NULL;
|
||||
static Ecore_List2 *_monitors = NULL;
|
||||
static Ecore_File_Monitor *_monitors = NULL;
|
||||
static int _lock = 0;
|
||||
|
||||
static int _ecore_file_monitor_poll_handler(void *data);
|
||||
|
@ -63,16 +54,8 @@ ecore_file_monitor_poll_init(void)
|
|||
int
|
||||
ecore_file_monitor_poll_shutdown(void)
|
||||
{
|
||||
Ecore_List2 *l;
|
||||
|
||||
for (l = _monitors; l;)
|
||||
{
|
||||
Ecore_File_Monitor *em;
|
||||
|
||||
em = ECORE_FILE_MONITOR(l);
|
||||
l = l->next;
|
||||
ecore_file_monitor_poll_del(em);
|
||||
}
|
||||
while(_monitors)
|
||||
ecore_file_monitor_poll_del(_monitors);
|
||||
|
||||
if (_timer)
|
||||
{
|
||||
|
@ -97,7 +80,7 @@ ecore_file_monitor_poll_add(const char *path,
|
|||
|
||||
em = calloc(1, sizeof(Ecore_File_Monitor_Poll));
|
||||
if (!em) return NULL;
|
||||
|
||||
|
||||
if (!_timer)
|
||||
_timer = ecore_timer_add(_interval, _ecore_file_monitor_poll_handler, NULL);
|
||||
else
|
||||
|
@ -134,10 +117,10 @@ ecore_file_monitor_poll_add(const char *path,
|
|||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", em->path, file);
|
||||
f->name = file;
|
||||
f->name = file;
|
||||
f->mtime = ecore_file_mod_time(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;
|
||||
}
|
||||
|
||||
_monitors = _ecore_list2_append(_monitors, em);
|
||||
_monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
|
||||
|
||||
return em;
|
||||
}
|
||||
|
@ -155,7 +138,7 @@ ecore_file_monitor_poll_add(const char *path,
|
|||
void
|
||||
ecore_file_monitor_poll_del(Ecore_File_Monitor *em)
|
||||
{
|
||||
Ecore_List2 *l;
|
||||
Ecore_File *l;
|
||||
|
||||
if (_lock)
|
||||
{
|
||||
|
@ -169,20 +152,19 @@ ecore_file_monitor_poll_del(Ecore_File_Monitor *em)
|
|||
{
|
||||
for (l = em->files; l;)
|
||||
{
|
||||
Ecore_File *file;
|
||||
|
||||
file = (Ecore_File *)l;
|
||||
l = l->next;
|
||||
Ecore_File *file = l;
|
||||
|
||||
l = (Ecore_File *) EINA_INLIST_GET(l)->next;
|
||||
free(file->name);
|
||||
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);
|
||||
|
||||
|
||||
if (_timer)
|
||||
{
|
||||
if (!_monitors)
|
||||
|
@ -198,18 +180,13 @@ ecore_file_monitor_poll_del(Ecore_File_Monitor *em)
|
|||
static int
|
||||
_ecore_file_monitor_poll_handler(void *data __UNUSED__)
|
||||
{
|
||||
Ecore_List2 *l;
|
||||
Ecore_File_Monitor *l;
|
||||
|
||||
_interval += ECORE_FILE_INTERVAL_STEP;
|
||||
|
||||
_lock = 1;
|
||||
for (l = _monitors; l; l = l->next)
|
||||
{
|
||||
Ecore_File_Monitor *em;
|
||||
|
||||
em = ECORE_FILE_MONITOR(l);
|
||||
_ecore_file_monitor_poll_check(em);
|
||||
}
|
||||
EINA_INLIST_FOREACH(_monitors, l)
|
||||
_ecore_file_monitor_poll_check(l);
|
||||
_lock = 0;
|
||||
|
||||
if (_interval > ECORE_FILE_INTERVAL_MAX)
|
||||
|
@ -218,10 +195,9 @@ _ecore_file_monitor_poll_handler(void *data __UNUSED__)
|
|||
|
||||
for (l = _monitors; l;)
|
||||
{
|
||||
Ecore_File_Monitor *em;
|
||||
Ecore_File_Monitor *em = l;
|
||||
|
||||
em = ECORE_FILE_MONITOR(l);
|
||||
l = l->next;
|
||||
l = ECORE_FILE_MONITOR(EINA_INLIST_GET(l)->next);
|
||||
if (ECORE_FILE_MONITOR_POLL(em)->deleted)
|
||||
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);
|
||||
if (mtime < ECORE_FILE_MONITOR_POLL(em)->mtime)
|
||||
{
|
||||
Ecore_List2 *l;
|
||||
Ecore_File *l;
|
||||
Ecore_File_Event event;
|
||||
|
||||
|
||||
/* Notify all files deleted */
|
||||
for (l = em->files; l;)
|
||||
{
|
||||
Ecore_File *f;
|
||||
Ecore_File *f = l;
|
||||
char buf[PATH_MAX];
|
||||
|
||||
f = (Ecore_File *)l;
|
||||
l = l->next;
|
||||
|
||||
l = (Ecore_File *) EINA_INLIST_GET(l)->next;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", em->path, f->name);
|
||||
if (f->is_dir)
|
||||
|
@ -265,18 +240,17 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
|||
}
|
||||
else
|
||||
{
|
||||
Ecore_List2 *l;
|
||||
Ecore_File *l;
|
||||
|
||||
/* Check for changed files */
|
||||
for (l = em->files; l;)
|
||||
{
|
||||
Ecore_File *f;
|
||||
Ecore_File *f = l;
|
||||
char buf[PATH_MAX];
|
||||
int mtime;
|
||||
Ecore_File_Event event;
|
||||
|
||||
f = (Ecore_File *)l;
|
||||
l = l->next;
|
||||
l = (Ecore_File *) EINA_INLIST_GET(l)->next;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", em->path, f->name);
|
||||
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;
|
||||
|
||||
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);
|
||||
_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 = ecore_file_ls(em->path);
|
||||
if (files)
|
||||
{
|
||||
{
|
||||
/* Are we a directory? We should check first, rather than rely on null here*/
|
||||
EINA_LIST_FOREACH(files, l, file)
|
||||
{
|
||||
Ecore_File *f;
|
||||
char buf[PATH_MAX];
|
||||
Ecore_File_Event event;
|
||||
|
||||
|
||||
if (_ecore_file_monitor_poll_checking(em, file))
|
||||
continue;
|
||||
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", em->path, file);
|
||||
f = calloc(1, sizeof(Ecore_File));
|
||||
if (!f)
|
||||
continue;
|
||||
|
||||
|
||||
f->name = strdup(file);
|
||||
f->mtime = 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
|
||||
event = ECORE_FILE_EVENT_CREATED_FILE;
|
||||
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)
|
||||
{
|
||||
|
@ -346,7 +320,7 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
|||
files = eina_list_remove_list(files, files);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!ecore_file_is_dir(em->path))
|
||||
em->func(em->data, em, ECORE_FILE_EVENT_MODIFIED, em->path);
|
||||
_interval = ECORE_FILE_INTERVAL_MIN;
|
||||
|
@ -358,14 +332,11 @@ _ecore_file_monitor_poll_check(Ecore_File_Monitor *em)
|
|||
static int
|
||||
_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;
|
||||
|
||||
f = (Ecore_File *)l;
|
||||
if (!strcmp(f->name, name))
|
||||
if (!strcmp(l->name, name))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -21,9 +21,18 @@ int ecore_file_monitor_shutdown(void);
|
|||
|
||||
#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
|
||||
{
|
||||
Ecore_List2 __list_data;
|
||||
EINA_INLIST;
|
||||
void (*func) (void *data,
|
||||
Ecore_File_Monitor *ecore_file_monitor,
|
||||
Ecore_File_Event event,
|
||||
|
@ -31,7 +40,7 @@ struct _Ecore_File_Monitor
|
|||
|
||||
char *path;
|
||||
void *data;
|
||||
Ecore_List2 *files;
|
||||
Ecore_File *files;
|
||||
};
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
|
|
Loading…
Reference in New Issue