# HG changeset patch # User Bill Welliver # Date 1324670526 18000 # Node ID e9ce404138ad74bd3c9d01236b81ef4e88e5c1e2 # Parent b391e02c134c500e18cfaabd7b026b097d056343 some documentation, pretty up the example diff -r b391e02c134c500e18cfaabd7b026b097d056343 -r e9ce404138ad74bd3c9d01236b81ef4e88e5c1e2 README --- a/README Thu Dec 22 22:58:52 2011 -0500 +++ b/README Fri Dec 23 15:02:06 2011 -0500 @@ -0,0 +1,15 @@ +Public.System.FSEvents is a Pike module that provides an interface to FSEvents. +FSEvents is an API in Mac OS X which allows an application to register for +notifications of changes to a given directory tree without forcing the +application to continously poll the directory tree. + +This module is designed for use in asynchronous or backend mode, that is, +rather than polling for changes, a function you specify will be called when +events of interest occur. This module assumes the presence and use of +a CFRunLoop based Backend object, otherwise this module will not receive +events from the OS. The CFRunLoop Backend is a new feature that is available +in development versions of Pike 7.9.6 and greater running on Mac OS X 10.5 and +higher. + +See the examples directory for a sample script that prints out events for +a given directory, as they occur. diff -r b391e02c134c500e18cfaabd7b026b097d056343 -r e9ce404138ad74bd3c9d01236b81ef4e88e5c1e2 TODO --- a/TODO Thu Dec 22 22:58:52 2011 -0500 +++ b/TODO Fri Dec 23 15:02:06 2011 -0500 @@ -1,5 +1,6 @@ Implement the rest of the API -Handle cleanup better -Write some higher level pike code to make it easier to work with -Integrate the Backend runner better with the rest of Pike -Look for Leaks +Write some higher level pike code to make it easier to work with (mostly done, see tunesd) +Look for Leaks (in progress) +Handle cleanup better (mostly complete) +Integrate the Backend runner better with the rest of Pike (added to Pike 7.9) + diff -r b391e02c134c500e18cfaabd7b026b097d056343 -r e9ce404138ad74bd3c9d01236b81ef4e88e5c1e2 examples/demo.pike --- a/examples/demo.pike Thu Dec 22 22:58:52 2011 -0500 +++ b/examples/demo.pike Fri Dec 23 15:02:06 2011 -0500 @@ -5,16 +5,23 @@ void cb(string path, int flags, int event_id) { - werror("%s => %s, %d\n", path, FSEvents.describe_event_flag(flags), event_id); + werror("%s => %s, id=%d\n", path, FSEvents.describe_event_flag(flags), event_id); } -int main() +int main(int argc, array(string argv) { + string dir = "/tmp"; + if(sizeof(argv)) + dir = argv[1]; - m = FSEvents.EventStream(({}), 3.0, FSEvents.kFSEventStreamEventIdSinceNow, FSEvents.kFSEventStreamCreateFlagNone); -// m = FSEvents.EventStream(({"/Users/hww3/Music/iTunes/iTunes Media/Music"}), 3.0, FSEvents.kFSEventStreamEventIdSinceNow, FSEvents.kFSEventStreamCreateFlagNone); - m->add_path("/Users/hww3/Music/iTunes/iTunes Media/Music"); - m->callback_func = (cb); - m->start(); - return -1; + werror("watching %O for changes...\n", dir); + + m = FSEvents.EventStream(({}), 3.0, FSEvents.kFSEventStreamEventIdSinceNow, + FSEvents.kFSEventStreamCreateFlagNone); + + m->add_path(dir); + m->callback_func = (cb); + m->start(); + + return -1; }