Its sole parameter is the event stream to start. This function tells the event stream to begin sending events. The final step in setting up an event stream is to call FSEventStreamStart. */įSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode) * Create the stream before calling this.
Any future calls to CFRunLoopGetCurrent will return the same run loop.įor example, the following snippet shows how to schedule a stream, called stream, on the current thread’s run loop (not yet running): After creating a thread using your API of choice, call CFRunLoopGetCurrent to allocate an initial run loop for that thread. If you don’t already have a run loop, you will need to devote a thread to this task. For more information about run loops, read Run Loops. To do this, call FSEventStreamScheduleWithRunLoop, passing in the newly-created stream, a reference to your run loop, and a run loop mode. Once you have created an event stream, you must schedule it on your application’s run loop. KFSEventStreamCreateFlagNone /* Flags explained in reference */ KFSEventStreamEventIdSinceNow, /* Or a previous event ID */ * Create the stream, passing in a callback */ Void *callbackInfo = NULL // could put stream-specific data here.ĬFAbsoluteTime latency = 3.0 /* Latency in seconds */ * Define variables and create a CFArray object containingĬFString objects containing paths to watch.ĬFStringRef mypath = CFSTR("/path/to/scan") ĬFArrayRef pathsToWatch = CFArra圜reate(NULL, (const void **)&mypath, 1, NULL) By contrast, per-host streams are most convenient if you are monitoring for changes in a directory or tree of directories during normal execution, such as watching a queue directory.
In general, if you are writing software that requires persistence, you should use per-disk streams to avoid any confusion due to ID conflicts. It does not have any relationship with other events on other disks, and thus you must create a separate event stream for each physical device that you wish to monitor. Any new events will automatically start after the highest-numbered historical ID for any attached drive.Ī per-disk event stream, by contrast, consists of events whose IDs are increasing with respect to previous events on that disk. These IDs are guaranteed to be unique with one exception: if additional disks are added from another computer that was also running OS X v10.5 or later, historical IDs may conflict between these volumes. You can create these streams by calling the functions FSEventStreamCreate and FSEventStreamCreateRelativeToDevice, respectively.Ī per-host event stream consists of events whose IDs are increasing with respect to other events on that host. Before you can create a stream, you must decide which type of stream to create: a per-host event stream or a per-disk event stream. The file system events API supports two types of event streams: per-disk event streams and a per-host event streams. When you compile, you must include the Core Services Framework by adding it to your target in Xcode or by adding the flag -framework CoreServices to your linker flags on the command line or in a Makefile. Adding Include Directivesīefore you use the file system event stream API, you must include the Core Services framework as follows: These steps are explained in more detail in the sections that follow. The application releases its reference to the stream by calling FSEventStreamRelease. The application invalidates the stream by calling FSEventStreamInvalidate. The application unschedules the event from its run loop by calling FSEventStreamUnscheduleFromRunLoop. If the application needs to restart the stream, go to step 3. The application tells the daemon to stop sending events by calling FSEventStreamStop.
The API posts events by calling the callback function specified in step 1. The application services events as they arrive. The application tells the file system events daemon to start sending events by calling FSEventStreamStart. The application schedules the stream on the run loop by calling FSEventStreamScheduleWithRunLoop. The application creates a stream by calling FSEventStreamCreate or FSEventStreamCreateRelativeToDevice. The life cycle of a file system events stream is as follows: You can create a new event stream, perform operations on the stream, and so on using functions that begin with FSEventStream. You can obtain general information about volumes and events by using functions that begin with FSEvents. The File System Events API consists of several distinct groups of functions. Next Previous Using the File System Events API