2008-05-25 22:16:34 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2005-02-22 04:41:14 -08:00
|
|
|
#include "ecore_file_private.h"
|
|
|
|
|
2005-03-29 22:35:12 -08:00
|
|
|
typedef enum {
|
|
|
|
ECORE_FILE_MONITOR_TYPE_NONE,
|
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
ECORE_FILE_MONITOR_TYPE_INOTIFY,
|
|
|
|
#endif
|
2009-11-11 09:45:55 -08:00
|
|
|
#ifdef HAVE_NOTIFY_WIN32
|
|
|
|
ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32,
|
|
|
|
#endif
|
2005-03-29 22:35:12 -08:00
|
|
|
#ifdef HAVE_POLL
|
|
|
|
ECORE_FILE_MONITOR_TYPE_POLL
|
|
|
|
#endif
|
|
|
|
} Ecore_File_Monitor_Type;
|
|
|
|
|
|
|
|
static Ecore_File_Monitor_Type monitor_type = ECORE_FILE_MONITOR_TYPE_NONE;
|
|
|
|
|
|
|
|
int
|
|
|
|
ecore_file_monitor_init(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
monitor_type = ECORE_FILE_MONITOR_TYPE_INOTIFY;
|
|
|
|
if (ecore_file_monitor_inotify_init())
|
2009-10-09 22:28:43 -07:00
|
|
|
return 1;
|
2005-03-29 22:35:12 -08:00
|
|
|
#endif
|
2009-11-11 09:45:55 -08:00
|
|
|
#ifdef HAVE_NOTIFY_WIN32
|
|
|
|
monitor_type = ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32;
|
|
|
|
if (ecore_file_monitor_win32_init())
|
|
|
|
return 1;
|
|
|
|
#endif
|
2005-03-29 22:35:12 -08:00
|
|
|
#ifdef HAVE_POLL
|
|
|
|
monitor_type = ECORE_FILE_MONITOR_TYPE_POLL;
|
|
|
|
if (ecore_file_monitor_poll_init())
|
2009-10-09 22:28:43 -07:00
|
|
|
return 1;
|
2005-03-29 22:35:12 -08:00
|
|
|
#endif
|
|
|
|
monitor_type = ECORE_FILE_MONITOR_TYPE_NONE;
|
2009-10-09 22:28:43 -07:00
|
|
|
return 0;
|
2005-03-29 22:35:12 -08:00
|
|
|
}
|
|
|
|
|
2009-10-09 22:28:43 -07:00
|
|
|
void
|
2005-03-29 22:35:12 -08:00
|
|
|
ecore_file_monitor_shutdown(void)
|
|
|
|
{
|
|
|
|
switch (monitor_type)
|
|
|
|
{
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_NONE:
|
2005-09-07 01:50:25 -07:00
|
|
|
break;
|
2005-03-29 22:35:12 -08:00
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_INOTIFY:
|
2005-09-07 01:50:25 -07:00
|
|
|
ecore_file_monitor_inotify_shutdown();
|
|
|
|
break;
|
2005-03-29 22:35:12 -08:00
|
|
|
#endif
|
2009-11-11 09:45:55 -08:00
|
|
|
#ifdef HAVE_NOTIFY_WIN32
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32:
|
|
|
|
ecore_file_monitor_win32_shutdown();
|
|
|
|
break;
|
|
|
|
#endif
|
2005-03-29 22:35:12 -08:00
|
|
|
#ifdef HAVE_POLL
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_POLL:
|
2005-09-07 01:50:25 -07:00
|
|
|
ecore_file_monitor_poll_shutdown();
|
|
|
|
break;
|
2005-03-29 22:35:12 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-06 13:00:28 -07:00
|
|
|
/**
|
2007-11-05 10:57:11 -08:00
|
|
|
* Monitor a path using inotify or polling
|
2007-08-06 13:00:28 -07:00
|
|
|
* @param path The path to monitor
|
|
|
|
* @param func The function to call on changes
|
|
|
|
* @param data The data passed to func
|
|
|
|
* @return An Ecore_File_Monitor pointer or NULL on failure
|
|
|
|
*/
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI Ecore_File_Monitor *
|
2005-03-29 22:35:12 -08:00
|
|
|
ecore_file_monitor_add(const char *path,
|
2009-11-11 09:45:55 -08:00
|
|
|
void (*func) (void *data,
|
|
|
|
Ecore_File_Monitor *em,
|
|
|
|
Ecore_File_Event event,
|
|
|
|
const char *path),
|
|
|
|
void *data)
|
2005-03-29 22:35:12 -08:00
|
|
|
{
|
|
|
|
switch (monitor_type)
|
|
|
|
{
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_NONE:
|
|
|
|
return NULL;
|
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_INOTIFY:
|
|
|
|
return ecore_file_monitor_inotify_add(path, func, data);
|
|
|
|
#endif
|
2009-11-11 09:45:55 -08:00
|
|
|
#ifdef HAVE_NOTIFY_WIN32
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32:
|
|
|
|
return ecore_file_monitor_win32_add(path, func, data);
|
|
|
|
#endif
|
2005-03-29 22:35:12 -08:00
|
|
|
#ifdef HAVE_POLL
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_POLL:
|
|
|
|
return ecore_file_monitor_poll_add(path, func, data);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-06 13:00:28 -07:00
|
|
|
/**
|
|
|
|
* Stop monitoring a path
|
|
|
|
* @param em The Ecore_File_Monitor to stop
|
|
|
|
*/
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI void
|
2005-03-29 22:35:12 -08:00
|
|
|
ecore_file_monitor_del(Ecore_File_Monitor *em)
|
|
|
|
{
|
|
|
|
switch (monitor_type)
|
|
|
|
{
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_NONE:
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_INOTIFY:
|
|
|
|
ecore_file_monitor_inotify_del(em);
|
|
|
|
break;
|
|
|
|
#endif
|
2009-11-11 09:45:55 -08:00
|
|
|
#ifdef HAVE_NOTIFY_WIN32
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32:
|
|
|
|
ecore_file_monitor_win32_del(em);
|
|
|
|
break;
|
|
|
|
#endif
|
2005-03-29 22:35:12 -08:00
|
|
|
#ifdef HAVE_POLL
|
|
|
|
case ECORE_FILE_MONITOR_TYPE_POLL:
|
|
|
|
ecore_file_monitor_poll_del(em);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-06 13:00:28 -07:00
|
|
|
/**
|
|
|
|
* Get the monitored path
|
|
|
|
* @param em The Ecore_File_Monitor to query
|
|
|
|
* @return The path that is monitored by @p em
|
|
|
|
*/
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI const char *
|
2005-03-29 22:35:12 -08:00
|
|
|
ecore_file_monitor_path_get(Ecore_File_Monitor *em)
|
2005-02-22 04:41:14 -08:00
|
|
|
{
|
2005-03-29 22:35:12 -08:00
|
|
|
return em->path;
|
2005-02-22 04:41:14 -08:00
|
|
|
}
|