* @author Stephen "okra" Houston <unixtitan@@gmail.com>
* @author Gustavo Sverzut Barbieri <barbieri@@gmail.com>
* @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
* @version @PACKAGE_VERSION@
* @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
+ */
+
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);
+
+/**
+ * @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);
+
+/**
+ * @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);
+
+/**
+ * @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);
/**
monitor->error = error;
monitor->exist = NULL;
- if (EINA_REFCOUNT_GET(monitor) > 1)
+ if (EINA_REFCOUNT_GET(monitor) >= 1)
_eio_monitor_error(monitor, error);
EINA_REFCOUNT_UNREF(monitor)
monitor->rename = EINA_FALSE;
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,
_eio_monitor_stat_cb,
return ;
}
+ EINA_REFCOUNT_REF(monitor); /* as we spawn a thread for this monitor, we need to refcount specifically for it */
+
/* restart */
monitor->rename = EINA_TRUE;
monitor->exist = eio_file_direct_stat(monitor->path,