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 :

#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);
printf("is being modified");
else if( type == EIO_MONITOR_FILE_CLOSED )
printf("is no longer being modified");
else printf("got unexpected changes");
printf("\n");
}
int main(int argc, char **argv) {
Eio_Monitor *monitor = NULL,
*monitor2 = NULL;
const char *filename = eina_stringshare_add("/tmp/eio_notify_testfile");
monitor = eio_monitor_add(filename);
}
Eina Utility library.
Eina_Bool(* Ecore_Event_Handler_Cb)(void *data, int type, void *event)
A callback used by the main loop to handle events of a specified type.
Definition: Ecore_Common.h:603
Ecore_Event_Handler * ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void *data)
Adds an event handler.
Definition: ecore_events.c:13
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
EINA_API Eina_Stringshare * eina_stringshare_add(const char *str)
Retrieves an instance of a string for use in a program.
Definition: eina_stringshare.c:606
EINA_API void eina_stringshare_del(Eina_Stringshare *str)
Notes that the given string has lost an instance.
Definition: eina_stringshare.c:533
EIO_API int eio_init(void)
Initialize eio and all its required submodule.
Definition: eio_main.c:276
EIO_API int eio_shutdown(void)
Shutdown eio and all its submodule if possible.
Definition: eio_main.c:340
EIO_API int EIO_MONITOR_FILE_MODIFIED
A file was modified in a watched directory.
Definition: eio_monitor.c:308
EIO_API int EIO_MONITOR_FILE_CLOSED
A file was closed in a watched directory.
Definition: eio_monitor.c:309
EIO_API Eio_Monitor * eio_monitor_add(const char *path)
Adds a file/directory to monitor (inotify mechanism)
Definition: eio_monitor.c:318

Build the example doing :

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 :
* touch /tmp/eio_notify_testfile
* and launch tutorial_monitor_add, and in another terminal, write into /tmp/eio_notify_testfile, doing for example :
* echo "test" >> /tmp/eio_notify_testfile
*