[EXTRAS] Inotifytools testing
authorAlan Knowles <alan@akbkhome.com>
Sun, 4 Apr 2010 10:04:16 +0000 (18:04 +0800)
committerAlan Knowles <alan@akbkhome.com>
Sun, 4 Apr 2010 10:04:16 +0000 (18:04 +0800)
Inotify tools test code.

extras/inotifytools/example.js [new file with mode: 0644]
extras/inotifytools/inotifytools.h [new file with mode: 0644]
extras/inotifytools/inotifytools.sh [new file with mode: 0644]

diff --git a/extras/inotifytools/example.js b/extras/inotifytools/example.js
new file mode 100644 (file)
index 0000000..fce5471
--- /dev/null
@@ -0,0 +1,100 @@
+#!/usr/bin/seed
+
+//<script type="text/javascript">
+// silly test to see how libc works :)
+// borked - inotify sends a struct via a buffer -- need to use inotify tools!
+inotifytools = imports.gi.inotifytools;
+GLib = imports.gi.GLib;
+
+
+
+if (!inotifytools.initialize()) {
+    Seed.print("Failed to init");
+    Seed.quit();
+}
+Seed.print("watch Error?" + GLib.strerror(inotifytools.error()));
+var events = inotifytools.IN_ACCESS | 
+       inotifytools.IN_MODIFY | 
+        inotifytools.IN_ATTRIB | 
+        inotifytools.IN_CLOSE_WRITE | 
+        inotifytools.IN_CLOSE_NOWRITE | 
+       inotifytools.IN_OPEN | 
+       inotifytools.IN_MOVED_FROM | 
+       inotifytools.IN_MOVED_TO | 
+       inotifytools.IN_DELETE | 
+       inotifytools.IN_CREATE | 
+       inotifytools.IN_DELETE_SELF | 
+       inotifytools.IN_MOVE_SELF;
+print("EVENTS:"+ events);
+var dir = String(Seed.argv[2]) 
+Seed.print("MONITOR: " + dir +"?");
+var r = inotifytools.watch_recursively(  dir , events);
+
+Seed.print("GOT " +r );
+if (!r) {
+       Seed.print("watch Error?" + GLib.strerror(inotifytools.error()));
+    Seed.quit();
+}
+
+
+var num_watches = inotifytools.get_num_watches();
+Seed.print("Watch " + num_watches );
+var moved_from = '';
+while (true) {
+    
+    var event = inotifytools.next_event( 0 );
+    if ( !event ) {
+        if ( !inotifytools.error() ) {
+            Seed.print("Timeout?");
+            Seed.quit();
+        }
+        else if ( inotifytools.error() != 4 ) {
+                               Seed.print("Error?" + inotifytools.error());
+                               Seed.quit();
+        } else {
+            continue;
+                       
+               }
+    }
+    if ( moved_from.length && !(event.mask & inotifytools.IN_MOVED_TO) ) {
+        if ( !inotifytools.remove_watch_by_filename( moved_from ) ) {
+            Seed.print( "Error removing watch on " + moved_from );
+        }
+        moved_from = '';
+    }
+     
+    if ((event.mask & inotifytools.IN_CREATE) ||
+        (!moved_from.length && (event.mask & inotifytools.IN_MOVED_TO))) {
+        // New file - if it is a directory, watch it
+        
+
+        var new_file =  inotifytools.filename_from_wd( event.wd ) + event.name ;
+
+        if (  GLib.file_test(new_file, GLib.FileTest.IS_DIR) &&
+            !inotifytools.watch_recursively( new_file, events ) ) {
+            Seed.print( "Couldn't watch new directory " + new_file);
+        }
+        
+    } // IN_CREATE
+    else if (event.mask & inotifytools.IN_MOVED_FROM) {
+        moved_from =  inotifytools.filename_from_wd( event.wd ) + event.name ;
+        // if not watched...
+        if ( inotifytools.wd_from_filename(moved_from) == -1 ) {
+            moved_from = '';
+        }
+    } // IN_MOVED_FROM
+    else if (event.mask & inotifytools.IN_MOVED_TO) {
+        if ( moved_from.length ) {
+            var new_name = inotifytools_filename_from_wd( event. wd ) + 
+                       event.name;
+            inotifytools.replace_filename( moved_from, new_name );
+            
+            moved_from = '';
+        } // moved_from
+    }
+       Seed.print("CHANGE" + inotifytools.event_to_str(event.mask) + "\n" + 
+        inotifytools.filename_from_wd( event.wd ) + event.name + "\n");
+    
+}
\ No newline at end of file
diff --git a/extras/inotifytools/inotifytools.h b/extras/inotifytools/inotifytools.h
new file mode 100644 (file)
index 0000000..10e460f
--- /dev/null
@@ -0,0 +1,13 @@
+/* FIXES TO INOTIFY */
+
+/**
+ * inotifytools_watch_recursively:
+ * @path: (transfer full): path mask
+ * @events: event mask
+ * Return value: (type int): status
+ */
+
+/**
+ * inotifytools_event_to_str:
+ * Return value: (transfer none) (type utf8): 
+ */
\ No newline at end of file
diff --git a/extras/inotifytools/inotifytools.sh b/extras/inotifytools/inotifytools.sh
new file mode 100644 (file)
index 0000000..63ef9f3
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+# This program is free software; you can redistribute it and/or modify
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#  
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#  
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with main.c;if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+
+# generate inotify tools gir. 
+# probably should be in make file...
+
+# apt-get install inotify-tools libinotifytools0 libinotifytools0-dev
+d=`dirname $0`
+
+
+g-ir-scanner  \
+     -I/usr/include \
+     $d/inotifytools.h \
+      /usr/include/inotifytools/*.h \
+      --strip-prefix=inotifytools  \
+      --namespace=inotifytools \
+      --library=inotifytools \
+      --nsversion=3.0 --output=/usr/share/gir-1.0/inotifytools-3.0.gir
\ No newline at end of file