};
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);
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)
{
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))
{
{
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)
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;
}
*/
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))
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);
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)
{
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
}
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));
}
}
}
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;
}
void
ecore_file_monitor_poll_del(Ecore_File_Monitor *em)
{
- Ecore_List2 *l;
+ Ecore_File *l;
if (_lock)
{
{
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)
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)
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);
}
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)
}
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);
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;
/* 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);
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)
{
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;
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;