ADC Home > Reference Library > Reference > Darwin > File Management > FSEvents Reference
|
FSEvents.h |
Includes: | <mach/mach.h> <sys/types.h> <CoreFoundation/CFRunLoop.h> <CoreFoundation/CFUUID.h> <AvailabilityMacros.h> |
This header describes the FSEvents API. This API provides a mechanism to notify
clients about directories they ought to re-scan in order to keep their internal
data structures up-to-date with respect to the true state of the file system.
(For example, when files or directories are created, modified, or removed.)
It sends these notifications "in bulk", possibly notifying the client of changes
to several directories in a single callback.
By using the API, clients can notice such changes quickly, without needing
to resort to recursive polling/scanning of the file system.
Much like kqueues, the FSEvents API allows an application to find near-immediately
when the contents of a particular directory has changed. However, unlike kqueues,
the FSEvents API allows the application to monitor the whole file system hierarchy
rooted at a specified directory (and still get precise per-directory notifications) --
to do this with the kqueues API would require the client to monitor each directory
individually.
Clients can register interest in a chunk of the filesystem hierarchy and will
receive callbacks from their runloop whenever an event occurs that modifies the
filesystem therein. The callback will indicate the exact directory in which the event
occurred, so the client only has to scan that directory for updated info, not all its
children. Clients can supply a "latency" parameter that tells how long to wait after an
event occurs before forwarding it; this reduces the volume of events and reduces the chance
that the client will see an "intermediate" state, like those that arise when doing a
"safe save" of a file, creating a package, or downloading a file via Safari.
The lifecycle of an FSEventStream consists of these stages:
FSEventsCopyUUIDForDevice |
CFUUIDRef FSEventsCopyUUIDForDevice( dev_t dev);
dev
The UUID associated with the stream of events on this machine. Ownership follows the Copy Rule.
Gets the UUID associated with a device. This uniquely identifies
a given stream of FSEvents. If this UUID is different than one that
you stored from a previous run then the event stream is different
because it wrapped around back to zero or was purged (and thus any
stored event IDs you may have are not valid).
FSEventsGetCurrentEventId |
FSEventStreamEventId FSEventsGetCurrentEventId( void);
The event ID of the most recent event generated by the system.
Fetches the most current event ID on the system. The ID
returned is for the most recently generated event and is
therefore obsolete as soon as it is returned.
FSEventsGetLastEventIdForDeviceBeforeTime |
FSEventStreamEventId FSEventsGetLastEventIdForDeviceBeforeTime( dev_t dev, CFAbsoluteTime time);
dev
time
The last event ID for the given device that was returned before the given time.
Gets the last event ID for the given device that was returned
before the given time. This is conservative in the sense that if
you then use the returned event ID as the sinceWhen parameter of
FSEventStreamCreateRelativeToDevice() that you will not miss any
events that happened since that time. On the other hand, you might
receive some (harmless) extra events.
Beware: there are things that can cause this to fail to be accurate.
For example, someone might change the system's clock (either backwards
or forwards). Or an external drive might be used on different systems
without perfectly synchronized clocks.
FSEventsPurgeEventsForDeviceUpToEventId |
Boolean FSEventsPurgeEventsForDeviceUpToEventId( dev_t dev, FSEventStreamEventId eventId);
dev
eventId
True if it succeeds, otherwise False if it fails.
Purges old events from the persistent per-volume database maintained by the service.
Can only be called by the root user.
FSEventStreamCopyDescription |
CFStringRef FSEventStreamCopyDescription( ConstFSEventStreamRef streamRef);
A CFStringRef containing the description of the supplied stream. Ownership follows the Copy rule.
Returns a CFStringRef containing the description of the supplied stream.
For debugging only.
FSEventStreamCopyPathsBeingWatched |
CFArrayRef FSEventStreamCopyPathsBeingWatched( ConstFSEventStreamRef streamRef);
streamRef
A CFArray of CFStringRefs corresponding to those supplied when the stream was created. Ownership follows the Copy rule.
Fetches the paths supplied when the stream was created via
one of the FSEventStreamCreate...() functions.
FSEventStreamCreate |
FSEventStreamRef FSEventStreamCreate( CFAllocatorRef allocator, FSEventStreamCallback callback, FSEventStreamContext *context, CFArrayRef pathsToWatch, FSEventStreamEventId sinceWhen, CFTimeInterval latency, FSEventStreamCreateFlags flags);
allocator
callback
context
pathsToWatch
sinceWhen
latency
flags
A valid FSEventStreamRef.
Creates a new FS event stream object with the given parameters.
In order to start receiving callbacks you must also call
FSEventStreamScheduleWithRunLoop() and FSEventStreamStart().
FSEventStreamCreateRelativeToDevice |
FSEventStreamRef FSEventStreamCreateRelativeToDevice( CFAllocatorRef allocator, FSEventStreamCallback callback, FSEventStreamContext *context, dev_t deviceToWatch, CFArrayRef pathsToWatchRelativeToDevice, FSEventStreamEventId sinceWhen, CFTimeInterval latency, FSEventStreamCreateFlags flags);
allocator
callback
context
deviceToWatch
pathsToWatchRelativeToDevice
sinceWhen
latency
flags
A valid FSEventStreamRef.
Creates a new FS event stream object for a particular device
with the given parameters.
In order to start receiving callbacks you must also call
FSEventStreamScheduleWithRunLoop() and FSEventStreamStart().
FSEventStreamFlushAsync |
void FSEventStreamFlushAsync( FSEventStreamRef streamRef);
streamRef
Asks the FS Events service to flush out any events that have occurred but
have not yet been delivered, due to the latency parameter that was supplied
when the stream was created. This flushing occurs asynchronously -- do not
expect the events to have already been delivered by the time this call returns.
FSEventStreamFlushAsync() can only be called after the stream has been
started, via FSEventStreamStart().
FSEventStreamFlushSync |
void FSEventStreamFlushSync( FSEventStreamRef streamRef);
streamRef
Asks the FS Events service to flush out any events that have occurred but
have not yet been delivered, due to the latency parameter that was supplied
when the stream was created. This flushing occurs synchronously -- by the
time this call returns, your callback will have been invoked for every
event that had already occurred at the time you made this call.
FSEventStreamFlushSync() can only be called after the stream has been
started, via FSEventStreamStart().
FSEventStreamGetDeviceBeingWatched |
dev_t FSEventStreamGetDeviceBeingWatched( ConstFSEventStreamRef streamRef);
streamRef
The dev_t for a device-relative stream, otherwise 0.
Fetches the dev_t supplied when the stream was created via
FSEventStreamCreateRelativeToDevice(), otherwise 0.
FSEventStreamGetLatestEventId |
FSEventStreamEventId FSEventStreamGetLatestEventId( ConstFSEventStreamRef streamRef);
streamRef
The sinceWhen attribute of the stream.
Fetches the sinceWhen property of the stream. Upon receiving an event
(and just before invoking the client's callback) this attribute is updated
to the highest-numbered event ID mentioned in the event.
FSEventStreamInvalidate |
void FSEventStreamInvalidate( FSEventStreamRef streamRef);
streamRef
Invalidates the stream, like CFRunLoopSourceInvalidate() does for
a CFRunLoopSourceRef. It will be unscheduled from any runloops upon which
it had been scheduled.
FSEventStreamInvalidate() can only be called after the stream has been
scheduled on at least one runloop, via FSEventStreamSchedueWithRunLoop().
FSEventStreamRelease |
void FSEventStreamRelease( FSEventStreamRef streamRef);
streamRef
Decrements the stream's refcount. The refcount is initially one and is
incremented via FSEventStreamRetain(). If the refcount reaches zero then
the stream is deallocated.
FSEventStreamRetain |
void FSEventStreamRetain( FSEventStreamRef streamRef);
streamRef
Increments the stream's refcount. The refcount is initially one and is
decremented via FSEventStreamRelease().
FSEventStreamScheduleWithRunLoop |
void FSEventStreamScheduleWithRunLoop( FSEventStreamRef streamRef, CFRunLoopRef runLoop, CFStringRef runLoopMode);
streamRef
runLoop
runLoopMode
This function schedules the stream on the specified run loop,
like CFRunLoopAddSource() does for a CFRunLoopSourceRef. The caller is
responsible for ensuring that the stream is scheduled on at least one run
loop and that at least one of the run loops on which the stream is
scheduled is being run.
To start receiving events on the stream, call FSEventStreamStart().
To remove the stream from the run loops upon which it has been scheduled,
call FSEventStreamUnscheduleFromRunLoop() or FSEventStreamInvalidate().
FSEventStreamShow |
void FSEventStreamShow( ConstFSEventStreamRef streamRef);
streamRef
Prints a description of the supplied stream to stderr.
For debugging only.
FSEventStreamStart |
Boolean FSEventStreamStart( FSEventStreamRef streamRef);
streamRef
True if it succeeds, otherwise False if it fails. It ought to always succeed, but in the event it does not then your code should fall back to performing recursive scans of the directories of interest as appropriate.
Attempts to register with the FS Events service to receive events per
the parameters in the stream.
FSEventStreamStart() can only be called once the stream has been scheduled
on at least one runloop, via FSEventStreamScheduleWithRunLoop().
Once started, the stream can be stopped via FSEventStreamStop().
FSEventStreamStop |
void FSEventStreamStop( FSEventStreamRef streamRef);
streamRef
Unregisters with the FS Events service. The client callback will
not be called for this stream while it is stopped.
FSEventStreamStop() can only be called if the stream has been started,
via FSEventStreamStart().
Once stopped, the stream can be restarted via FSEventStreamStart(),
at which point it will resume receiving events from where it left off ("sinceWhen").
FSEventStreamUnscheduleFromRunLoop |
void FSEventStreamUnscheduleFromRunLoop( FSEventStreamRef streamRef, CFRunLoopRef runLoop, CFStringRef runLoopMode);
streamRef
runLoop
runLoopMode
This function removes the stream from the specified run loop,
like CFRunLoopRemoveSource() does for a CFRunLoopSourceRef.
ConstFSEventStreamRef |
typedef const struct __FSEventStream *ConstFSEventStreamRef;
This is the type of a reference to a constant FSEventStream.
FSEventStreamCallback |
typedef void ( *FSEventStreamCallback)( ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]);
This is the type of the callback function supplied by the client when creating
a new stream. This callback is invoked by the service from the client's
runloop(s) when events occur, per the parameters specified when the stream was created.
FSEventStreamContext |
typedef struct FSEventStreamContext { CFIndex version; void *info; CFAllocatorRetainCallBack retain; CFAllocatorReleaseCallBack release; CFAllocatorCopyDescriptionCallBack copyDescription; } FSEventStreamContext;
version
- Currently the only valid value is zero.
info
- An arbitrary client-defined value (for instance, a pointer) to be associated with the stream and passed to the callback when it is invoked. If a non-NULL value is supplied for the retain callback the framework will use it to retain this value. If a non-NULL value is supplied for the release callback then when the stream is deallocated it will be used to release this value. This can be NULL.
retain
- The callback used retain the info pointer. This can be NULL.
release
- The callback used release a retain on the info pointer. This can be NULL.
copyDescription
- The callback used to create a descriptive string representation of the info pointer (or the data pointed to by the info pointer) for debugging purposes. This can be NULL.
Structure containing client-supplied data (and callbacks to manage it) that should be associated with a newly-created stream.
FSEventStreamCreateFlags |
typedef UInt32 FSEventStreamCreateFlags;
Flags that can be passed to the FSEventStreamCreate...() functions.
FSEventStreamEventFlags |
typedef UInt32 FSEventStreamEventFlags;
Flags that can be passed to FSEventStreamCallback().
FSEventStreamEventId |
typedef uint64_t FSEventStreamEventId;
Event IDs that can be passed to the FSEventStreamCreate...() functions and FSEventStreamCallback(). They are monotonically increasing per system, even across reboots and drives coming and going. They bear no relation to any particular clock or timebase.
FSEventStreamRef |
typedef struct __FSEventStream *FSEventStreamRef;
This is the type of a reference to an FSEventStream.
|