Tizen Native API  3.0

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);
    if( type == EIO_MONITOR_FILE_MODIFIED )
       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;
    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);
 }

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
 *