FSEvents Objective-C Wrapper

I thought it was about time I posted some source code here, so tonight I'm releasing SCEvents. As the title suggests SCEvents is an Objective-C wrapper around the FSEvents C API that is included Mac OS X 10.5. Basically, the FSEvents API allows you to register specific directories that your application is interested in with regard to file system activity that occurs within them. In keeping with the principles of Cocoa, your application will then be notified of these events, rather than your application continually polling and actively watching for changes. The idea is that the functionality that the system provides and is made accessible through the FSEvents API should do all the work instead of your application, because in nearly all cases the system can do it far more efficiently. Spotlight and Time Machine are built upon the technology provided by the FSEvents API. For a more detailed description and overview of how it is implemented and operates see the section on it in Ars Technica's Mac OS X 10.5 review.

So where does SCEvents come in? Well as mentioned its an Objective-C wrapper around the C interface and allows you to utilise the full power of FSEvents in only a few lines of code. The design of SCEvents is relatively simple and is largely inspired by Uli Kusterer's excellent UKKQueue wrapper around the kqueue file change notification mechanism, which by the way I would definitely recommend checking out if you are interested in finding out when specific files change rather than directories. SCEvents is similar in the sense that clients that register to be notified of events implement the only method of the SCEventListenerProtocol which in turn passes along an instance of SCEvent representing the event that just occurred.

The source includes an example foundation application that simply registers the user's home directory for events then prints them to the console whenever they occur. It can be downloaded from my new source code page, but the most update-to-date version can always be found in my Subversion source repository at dev.stuconnolly.com. SCEvents is by no means perfect so I'm looking for feedback on ways it can be improved, so please check it out and let me know what you think.

Posted May 8th, 2008