Author: gonzalo
Date: 2006-07-25 17:19:08 -0400 (Tue, 25 Jul 2006)
New Revision: 62971

Modified:
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/filewatcher.c
   trunk/mono/mono/metadata/filewatcher.h
   trunk/mono/mono/metadata/icall.c
Log:
2006-07-25 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * filewatcher.[ch]: support for inotify file system watcher.
        * icall.c: add new internal calls for the inotify file system watcher.



Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2006-07-25 21:15:50 UTC (rev 62970)
+++ trunk/mono/mono/metadata/ChangeLog  2006-07-25 21:19:08 UTC (rev 62971)
@@ -1,3 +1,8 @@
+2006-07-25 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * filewatcher.[ch]: support for inotify file system watcher.
+       * icall.c: add new internal calls for the inotify file system watcher.
+
 2006-07-24 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
        * threadpool.c: Windows also misbehaves on async. connects. Fixes bug

Modified: trunk/mono/mono/metadata/filewatcher.c
===================================================================
--- trunk/mono/mono/metadata/filewatcher.c      2006-07-25 21:15:50 UTC (rev 
62970)
+++ trunk/mono/mono/metadata/filewatcher.c      2006-07-25 21:19:08 UTC (rev 
62971)
@@ -4,7 +4,7 @@
  * Authors:
  *     Gonzalo Paniagua Javier ([EMAIL PROTECTED])
  *
- * (C) 2004 Novell, Inc. (http://www.novell.com)
+ * (C) 2004,2005,2006 Novell, Inc. (http://www.novell.com)
  */
 
 #ifdef HAVE_CONFIG_H
@@ -92,6 +92,7 @@
 {
        return FALSE;
 }
+
 #else
 
 static int (*FAMNextEvent) (gpointer, gpointer);
@@ -105,9 +106,16 @@
        GModule *fam_module;
        gchar *filename;
        int lib_used = 4; /* gamin */
+       int inotify_instance;
 
        MONO_ARCH_SAVE_REGS;
 
+       inotify_instance = 
ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ();
+       if (inotify_instance != -1) {
+               close (inotify_instance);
+               return 5; /* inotify */
+       }
+
        filename = g_module_build_path (NULL, "libgamin-1.so.0");
        fam_module = g_module_open (filename, G_MODULE_BIND_LAZY);
        g_free (filename);
@@ -185,6 +193,56 @@
 
        return FALSE;
 }
+#endif
 
+#if !defined(__linux__) || !defined(__NR_inotify_init)
+int ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ()
+{
+       return -1;
+}
+
+int ves_icall_System_IO_InotifyWatcher_AddDirectoryWatch (int fd, MonoString 
*directory, gint32 mask)
+{
+       return -1;
+}
+
+int ves_icall_System_IO_InotifyWatcher_RemoveDirectoryWatch (int fd, int 
watch_descriptor)
+{
+       return -1;
+}
+#else
+#include <errno.h>
+
+int
+ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ()
+{
+       return syscall (__NR_inotify_init);
+}
+
+int
+ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *name, gint32 
mask)
+{
+       char *str;
+       int retval;
+       int error;
+
+       if (name == NULL)
+               return -1;
+
+       str = mono_string_to_utf8 (name);
+       retval = syscall (__NR_inotify_add_watch, fd, str, mask);
+       if (retval < 0)
+               error = errno;
+       g_free (str);
+       if (retval < 0)
+               errno = error;
+       return retval;
+}
+
+int
+ves_icall_System_IO_InotifyWatcher_RemoveWatch (int fd, gint32 
watch_descriptor)
+{
+       return syscall (__NR_inotify_rm_watch, fd, watch_descriptor);
+}
 #endif
 

Modified: trunk/mono/mono/metadata/filewatcher.h
===================================================================
--- trunk/mono/mono/metadata/filewatcher.h      2006-07-25 21:15:50 UTC (rev 
62970)
+++ trunk/mono/mono/metadata/filewatcher.h      2006-07-25 21:19:08 UTC (rev 
62971)
@@ -13,6 +13,14 @@
 #include <mono/metadata/object.h>
 #include <mono/io-layer/io-layer.h>
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
+
 G_BEGIN_DECLS
 
 gboolean ves_icall_System_IO_FSW_SupportsFSW (void);
@@ -34,6 +42,10 @@
                                                        gint *code,
                                                        gint *reqnum);
 
+int ves_icall_System_IO_InotifyWatcher_GetInotifyInstance (void);
+int ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString 
*directory, gint32 mask);
+int ves_icall_System_IO_InotifyWatcher_RemoveWatch (int fd, gint32 
watch_descriptor);
+
 G_END_DECLS
 
 #endif

Modified: trunk/mono/mono/metadata/icall.c
===================================================================
--- trunk/mono/mono/metadata/icall.c    2006-07-25 21:15:50 UTC (rev 62970)
+++ trunk/mono/mono/metadata/icall.c    2006-07-25 21:19:08 UTC (rev 62971)
@@ -6645,6 +6645,12 @@
        {"InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent}
 };
 
+static const IcallEntry inotifywatcher_icalls [] = {
+       {"AddWatch", ves_icall_System_IO_InotifyWatcher_AddWatch},
+       {"GetInotifyInstance", 
ves_icall_System_IO_InotifyWatcher_GetInotifyInstance},
+       {"RemoveWatch", ves_icall_System_IO_InotifyWatcher_RemoveWatch}
+};
+
 static const IcallEntry filewatcher_icalls [] = {
        {"InternalCloseDirectory", ves_icall_System_IO_FSW_CloseDirectory},
        {"InternalOpenDirectory", ves_icall_System_IO_FSW_OpenDirectory},
@@ -7356,6 +7362,7 @@
        {"System.Globalization.RegionInfo", regioninfo_icalls, G_N_ELEMENTS 
(regioninfo_icalls)},
        {"System.IO.FAMWatcher", famwatcher_icalls, G_N_ELEMENTS 
(famwatcher_icalls)},
        {"System.IO.FileSystemWatcher", filewatcher_icalls, G_N_ELEMENTS 
(filewatcher_icalls)},
+       {"System.IO.InotifyWatcher", inotifywatcher_icalls, G_N_ELEMENTS 
(inotifywatcher_icalls)},
        {"System.IO.MonoIO", monoio_icalls, G_N_ELEMENTS (monoio_icalls)},
        {"System.IO.Path", path_icalls, G_N_ELEMENTS (path_icalls)},
        {"System.Math", math_icalls, G_N_ELEMENTS (math_icalls)},

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to