forked from enlightenment/efl
eio: fix eio monitor by Guillaume Friloux.
SVN revision: 67501
This commit is contained in:
parent
457de1db0b
commit
7e8b2681c9
|
@ -26,7 +26,8 @@
|
||||||
* @author Stephen "okra" Houston <unixtitan@@gmail.com>
|
* @author Stephen "okra" Houston <unixtitan@@gmail.com>
|
||||||
* @author Gustavo Sverzut Barbieri <barbieri@@gmail.com>
|
* @author Gustavo Sverzut Barbieri <barbieri@@gmail.com>
|
||||||
* @author Vincent "caro" Torri <vtorri at univ-evry dot fr>
|
* @author Vincent "caro" Torri <vtorri at univ-evry dot fr>
|
||||||
* @date 2010-2011
|
* @author Guillaume "kuri" Friloux <guillaume.friloux@@asp64.com>
|
||||||
|
* @date 2010-2012
|
||||||
*
|
*
|
||||||
* @section eio_intro_sec Introduction
|
* @section eio_intro_sec Introduction
|
||||||
* @version @PACKAGE_VERSION@
|
* @version @PACKAGE_VERSION@
|
||||||
|
@ -284,3 +285,60 @@
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page tutorial_monitor_add eio_monitor_add() tutorial
|
||||||
|
*
|
||||||
|
* To use eio_monitor_add(), you have to define callbacks
|
||||||
|
* for events declared by eio.
|
||||||
|
* Available events are :
|
||||||
|
* - EIO_MONITOR_FILE_CREATED
|
||||||
|
* - EIO_MONITOR_FILE_DELETED
|
||||||
|
* - EIO_MONITOR_FILE_MODIFIED
|
||||||
|
* - EIO_MONITOR_FILE_CLOSED
|
||||||
|
* - EIO_MONITOR_DIRECTORY_CREATED
|
||||||
|
* - EIO_MONITOR_DIRECTORY_DELETED
|
||||||
|
* - EIO_MONITOR_DIRECTORY_CLOSED
|
||||||
|
* - EIO_MONITOR_SELF_RENAME
|
||||||
|
* - EIO_MONITOR_SELF_DELETED
|
||||||
|
*
|
||||||
|
* As nothing is worth an example, here it is :
|
||||||
|
* @code
|
||||||
|
* #include <Eina.h>
|
||||||
|
* #include <Ecore.h>
|
||||||
|
* #include <Eio.h>
|
||||||
|
*
|
||||||
|
* void file_modified(void *data, int type, void *event)
|
||||||
|
* {
|
||||||
|
* const char *filename = (const char *)data;
|
||||||
|
* printf("file %s ", filename);
|
||||||
|
* if( type == EIO_MONITOR_FILE_MODIFIED )
|
||||||
|
* printf("is being modified");
|
||||||
|
* else if( type == EIO_MONITOR_FILE_CLOSED )
|
||||||
|
* printf("is not more being modified");
|
||||||
|
* else printf("got unexpected changes");
|
||||||
|
* printf("\n");
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* int main(int argc, char **argv) {
|
||||||
|
* Eio_Monitor *monitor = NULL,
|
||||||
|
* *monitor2 = NULL;
|
||||||
|
* eio_init();
|
||||||
|
* const char *filename = eina_stringshare_add("/tmp/eio_notify_testfile");
|
||||||
|
*
|
||||||
|
* monitor = eio_monitor_add(filename);
|
||||||
|
* ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)file_modified, filename);
|
||||||
|
* ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, (Ecore_Event_Handler_Cb)file_modified, filename);
|
||||||
|
*
|
||||||
|
* ecore_main_loop_begin();
|
||||||
|
* eio_shutdown();
|
||||||
|
* eina_stringshare_del(filename);
|
||||||
|
* }
|
||||||
|
* @endcode
|
||||||
|
* Build the example doing :
|
||||||
|
* @verbatim gcc -o tutorial_monitor_add tutorial_monitor_add.c `pkg-config --libs --cflags eio ecore ecore-file eina`
|
||||||
|
* then create the file /tmp/eio_notify_testfile :
|
||||||
|
* @verbatim touch /tmp/eio_notify_testfile
|
||||||
|
* and launch tutorial_monitor_add, and in another terminal, write into /tmp/eio_notify_testfile, doing for example :
|
||||||
|
* @verbatim echo "test" >> /tmp/eio_notify_testfile
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
|
@ -815,9 +815,41 @@ struct _Eio_Monitor_Event
|
||||||
const char *filename;
|
const char *filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a file/directory to monitor (inotify mechanism)
|
||||||
|
* @param path file/directory to monitor
|
||||||
|
* @return NULL in case of a failure.
|
||||||
|
*
|
||||||
|
* This function will add the given path to its internal
|
||||||
|
* list of files to monitor. Its using inotify mechanism
|
||||||
|
* introduced in kernel 2.6.13 to get non active monitoring.
|
||||||
|
*/
|
||||||
EAPI Eio_Monitor *eio_monitor_add(const char *path);
|
EAPI Eio_Monitor *eio_monitor_add(const char *path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path file/directory to monitor
|
||||||
|
* @return NULL in case of a failure.
|
||||||
|
* Does the same thing than eio_monitor_add() but
|
||||||
|
* expects an eina_stringshared buffer.
|
||||||
|
* @warning dont give anything else than a stringshared buffer!
|
||||||
|
* if you dont know what you do, use eio_monitor_add().
|
||||||
|
*/
|
||||||
EAPI Eio_Monitor *eio_monitor_stringshared_add(const char *path);
|
EAPI Eio_Monitor *eio_monitor_stringshared_add(const char *path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deletes a path from the “watched” list
|
||||||
|
* @param monitor Eio_Monitor you want to stop watching.
|
||||||
|
* it can only be an Eio_Monitor given to you when calling
|
||||||
|
* eio_monitor_add() or eio_monitor_stringshared_add()
|
||||||
|
*/
|
||||||
EAPI void eio_monitor_del(Eio_Monitor *monitor);
|
EAPI void eio_monitor_del(Eio_Monitor *monitor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief returns the path being watched by the given
|
||||||
|
* Eio_Monitor.
|
||||||
|
* @param monitor Eio_Monitor that you want to get path
|
||||||
|
* @return returns a stringshared buffer, do not free it!
|
||||||
|
*/
|
||||||
EAPI const char *eio_monitor_path_get(Eio_Monitor *monitor);
|
EAPI const char *eio_monitor_path_get(Eio_Monitor *monitor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -196,6 +196,8 @@ void eio_monitor_backend_add(Eio_Monitor *monitor)
|
||||||
backend->hwnd = inotify_add_watch(ecore_main_fd_handler_fd_get(_inotify_fdh), monitor->path, mask);
|
backend->hwnd = inotify_add_watch(ecore_main_fd_handler_fd_get(_inotify_fdh), monitor->path, mask);
|
||||||
if (!backend->hwnd)
|
if (!backend->hwnd)
|
||||||
return eio_monitor_fallback_add(monitor);
|
return eio_monitor_fallback_add(monitor);
|
||||||
|
|
||||||
|
eina_hash_direct_add(_inotify_monitors, &backend->hwnd, backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void eio_monitor_backend_del(Eio_Monitor *monitor)
|
void eio_monitor_backend_del(Eio_Monitor *monitor)
|
||||||
|
|
|
@ -112,7 +112,7 @@ _eio_monitor_error_cb(void *data, Eio_File *handler __UNUSED__, int error)
|
||||||
monitor->error = error;
|
monitor->error = error;
|
||||||
monitor->exist = NULL;
|
monitor->exist = NULL;
|
||||||
|
|
||||||
if (EINA_REFCOUNT_GET(monitor) > 1)
|
if (EINA_REFCOUNT_GET(monitor) >= 1)
|
||||||
_eio_monitor_error(monitor, error);
|
_eio_monitor_error(monitor, error);
|
||||||
|
|
||||||
EINA_REFCOUNT_UNREF(monitor)
|
EINA_REFCOUNT_UNREF(monitor)
|
||||||
|
@ -195,6 +195,7 @@ eio_monitor_stringshared_add(const char *path)
|
||||||
monitor->rename = EINA_FALSE;
|
monitor->rename = EINA_FALSE;
|
||||||
|
|
||||||
EINA_REFCOUNT_INIT(monitor);
|
EINA_REFCOUNT_INIT(monitor);
|
||||||
|
EINA_REFCOUNT_REF(monitor); /* as we spawn a thread for this monitor, we need to refcount specifically for it */
|
||||||
|
|
||||||
monitor->exist = eio_file_direct_stat(monitor->path,
|
monitor->exist = eio_file_direct_stat(monitor->path,
|
||||||
_eio_monitor_stat_cb,
|
_eio_monitor_stat_cb,
|
||||||
|
@ -263,6 +264,8 @@ _eio_monitor_rename(Eio_Monitor *monitor, const char *newpath)
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EINA_REFCOUNT_REF(monitor); /* as we spawn a thread for this monitor, we need to refcount specifically for it */
|
||||||
|
|
||||||
/* restart */
|
/* restart */
|
||||||
monitor->rename = EINA_TRUE;
|
monitor->rename = EINA_TRUE;
|
||||||
monitor->exist = eio_file_direct_stat(monitor->path,
|
monitor->exist = eio_file_direct_stat(monitor->path,
|
||||||
|
|
Loading…
Reference in New Issue