eio_notify is borken so i try to fxi it.

Review my patch please (seriously, i havent changed much lines, but im
not sure that this is the good way to do it)

Thanks
Index: src/lib/Eio.h
===================================================================
--- src/lib/Eio.h	(révision 67487)
+++ src/lib/Eio.h	(copie de travail)
@@ -815,9 +815,41 @@ struct _Eio_Monitor_Event
    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);
 
 /**
Index: src/lib/eio_monitor.c
===================================================================
--- src/lib/eio_monitor.c	(révision 67487)
+++ src/lib/eio_monitor.c	(copie de travail)
@@ -82,8 +82,10 @@ _eio_monitor_stat_cb(void *data, __UNUSED__ Eio_Fi
 
    monitor->exist = NULL;
 
-   if (EINA_REFCOUNT_GET(monitor) > 1)
+   if (EINA_REFCOUNT_GET(monitor) >= 1) {
      eio_monitor_backend_add(monitor);
+     return;
+   }
 
    EINA_REFCOUNT_UNREF(monitor)
      _eio_monitor_free(monitor);
Index: src/lib/eio_inotify.c
===================================================================
--- src/lib/eio_inotify.c	(révision 67487)
+++ src/lib/eio_inotify.c	(copie de travail)
@@ -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);
    if (!backend->hwnd)
      return eio_monitor_fallback_add(monitor);
+
+   eina_hash_direct_add(_inotify_monitors, &backend->hwnd, backend);
 }
 
 void eio_monitor_backend_del(Eio_Monitor *monitor)
Index: doc/eio.dox.in
===================================================================
--- doc/eio.dox.in	(révision 67487)
+++ doc/eio.dox.in	(copie de travail)
@@ -26,7 +26,8 @@
  * @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@
@@ -284,3 +285,60 @@
  * @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
+ */
+

<<attachment: guillaume_friloux.vcf>>

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to