I've cobbled together a class that wraps FSEventStreamCreate so that I can monitor a settings.json file and update my application upon its change - à la Sublime Text 2. I refactored the code I found on the subject in Matt Aimonetti's book.
So far, it seems to be doing what I expect, but it would ease my mind a bit if someone who know something of the subject could tell me if I'm setting myself up for problems, as I don't really understand what's happening in the background.
def initialize(paths, callback, object)
callback = Proc.new do |stream, client_callback_info, number_of_events, paths_pointer, event_flags, event_ids|
paths_pointer.cast!("*") # cast as a string pointer
client_callback_info:client_callback_info,
number_of_events:number_of_events,
paths_pointer:paths_pointer,
object.send(@callback, stuff)
@stream = FSEventStreamCreate(KCFAllocatorDefault, callback, nil, @paths, KFSEventStreamEventIdSinceNow, 0.0, 0)
FSEventStreamScheduleWithRunLoop(@stream, CFRunLoopGetCurrent(), KCFRunLoopDefaultMode)
FSEventStreamStart(@stream)
FSEventStreamStop(@stream)
puts hash[:paths_pointer][0]
callback_object = Klass.new
f = FolderWatch.new("/Users/fatboy/Desktop", :callback, callback_object)