示例#1
0
/**
 * @brief Stop the monitoring of the given path.
 *
 * @param em The Ecore_File_Monitor to stop.
 *
 * This function stops the the monitoring of the path that has been
 * monitored by ecore_file_monitor_add(). @p em must be the value
 * returned by ecore_file_monitor_add(). If @p em is @c NULL, or none
 * of the notify methods (Inotify, Windows notification or polling) is
 * availablethis function does nothing.
 */
EAPI void
ecore_file_monitor_del(Ecore_File_Monitor *em)
{
   if (!em)
     return;

   switch (monitor_type)
     {
      case ECORE_FILE_MONITOR_TYPE_NONE:
         break;
#ifdef HAVE_INOTIFY
      case ECORE_FILE_MONITOR_TYPE_INOTIFY:
         ecore_file_monitor_inotify_del(em);
         break;
#endif
#ifdef HAVE_NOTIFY_WIN32
      case ECORE_FILE_MONITOR_TYPE_NOTIFY_WIN32:
         ecore_file_monitor_win32_del(em);
         break;
#endif
#ifdef HAVE_POLL
      case ECORE_FILE_MONITOR_TYPE_POLL:
         ecore_file_monitor_poll_del(em);
         break;
#endif
     }
}
int
ecore_file_monitor_inotify_shutdown(void)
{
   int fd;

   while(_monitors)
	ecore_file_monitor_inotify_del(_monitors);

   if (_fdh)
     {
	fd = ecore_main_fd_handler_fd_get(_fdh);
	ecore_main_fd_handler_del(_fdh);
	close(fd);
     }
   return 1;
}
Ecore_File_Monitor *
ecore_file_monitor_inotify_add(const char *path,
                               void (*func) (void *data, Ecore_File_Monitor *em,
                                             Ecore_File_Event event,
                                             const char *path),
                               void *data)
{
   Ecore_File_Monitor *em;
   int len;

   if (_inotify_fd_pid == -1) return NULL;

   if (_inotify_fd_pid != getpid())
     {
        ecore_file_monitor_inotify_shutdown();
        ecore_file_monitor_inotify_init();
     }

   em = calloc(1, sizeof(Ecore_File_Monitor_Inotify));
   if (!em) return NULL;

   em->func = func;
   em->data = data;

   em->path = strdup(path);
   len = strlen(em->path);
   if (em->path[len - 1] == '/' && strcmp(em->path, "/"))
     em->path[len - 1] = 0;

   _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));

   if (ecore_file_exists(em->path))
     {
        if (!_ecore_file_monitor_inotify_monitor(em, em->path))
          return NULL;
     }
   else
     {
        ecore_file_monitor_inotify_del(em);
        return NULL;
     }

   return em;
}