fsevent_sys/
fsevent.rs

1#![allow(non_upper_case_globals, non_camel_case_types)]
2
3use crate::core_foundation::{
4    Boolean, CFAbsoluteTime, CFAllocatorCopyDescriptionCallBack, CFAllocatorRef,
5    CFAllocatorReleaseCallBack, CFAllocatorRetainCallBack, CFArrayRef, CFIndex, CFRunLoopRef,
6    CFStringRef, CFTimeInterval,
7};
8use libc::dev_t;
9use std::os::raw::{c_uint, c_void};
10
11pub type FSEventStreamRef = *mut c_void;
12pub type ConstFSEventStreamRef = *const c_void;
13
14pub type FSEventStreamCallback = extern "C" fn(
15    FSEventStreamRef,               // ConstFSEventStreamRef streamRef
16    *mut c_void,                    // void *clientCallBackInfo
17    usize,                          // size_t numEvents
18    *mut c_void,                    // void *eventPaths
19    *const FSEventStreamEventFlags, // const FSEventStreamEventFlags eventFlags[]
20    *const FSEventStreamEventId,    // const FSEventStreamEventId eventIds[]
21);
22
23pub type FSEventStreamEventId = u64;
24
25pub type FSEventStreamCreateFlags = c_uint;
26
27pub type FSEventStreamEventFlags = c_uint;
28
29pub const kFSEventStreamEventIdSinceNow: FSEventStreamEventId = 0xFFFFFFFFFFFFFFFF;
30
31pub const kFSEventStreamCreateFlagNone: FSEventStreamCreateFlags = 0x00000000;
32pub const kFSEventStreamCreateFlagUseCFTypes: FSEventStreamCreateFlags = 0x00000001;
33pub const kFSEventStreamCreateFlagNoDefer: FSEventStreamCreateFlags = 0x00000002;
34pub const kFSEventStreamCreateFlagWatchRoot: FSEventStreamCreateFlags = 0x00000004;
35pub const kFSEventStreamCreateFlagIgnoreSelf: FSEventStreamCreateFlags = 0x00000008;
36pub const kFSEventStreamCreateFlagFileEvents: FSEventStreamCreateFlags = 0x00000010;
37pub const kFSEventStreamCreateFlagMarkSelf: FSEventStreamCreateFlags = 0x00000020;
38pub const kFSEventStreamCreateFlagUseExtendedData: FSEventStreamCreateFlags = 0x00000040;
39pub const kFSEventStreamCreateFlagFullHistory: FSEventStreamCreateFlags = 0x00000080;
40
41pub const kFSEventStreamEventFlagNone: FSEventStreamEventFlags = 0x00000000;
42pub const kFSEventStreamEventFlagMustScanSubDirs: FSEventStreamEventFlags = 0x00000001;
43pub const kFSEventStreamEventFlagUserDropped: FSEventStreamEventFlags = 0x00000002;
44pub const kFSEventStreamEventFlagKernelDropped: FSEventStreamEventFlags = 0x00000004;
45pub const kFSEventStreamEventFlagEventIdsWrapped: FSEventStreamEventFlags = 0x00000008;
46pub const kFSEventStreamEventFlagHistoryDone: FSEventStreamEventFlags = 0x00000010;
47pub const kFSEventStreamEventFlagRootChanged: FSEventStreamEventFlags = 0x00000020;
48pub const kFSEventStreamEventFlagMount: FSEventStreamEventFlags = 0x00000040;
49pub const kFSEventStreamEventFlagUnmount: FSEventStreamEventFlags = 0x00000080;
50pub const kFSEventStreamEventFlagItemCreated: FSEventStreamEventFlags = 0x00000100;
51pub const kFSEventStreamEventFlagItemRemoved: FSEventStreamEventFlags = 0x00000200;
52pub const kFSEventStreamEventFlagItemInodeMetaMod: FSEventStreamEventFlags = 0x00000400;
53pub const kFSEventStreamEventFlagItemRenamed: FSEventStreamEventFlags = 0x00000800;
54pub const kFSEventStreamEventFlagItemModified: FSEventStreamEventFlags = 0x00001000;
55pub const kFSEventStreamEventFlagItemFinderInfoMod: FSEventStreamEventFlags = 0x00002000;
56pub const kFSEventStreamEventFlagItemChangeOwner: FSEventStreamEventFlags = 0x00004000;
57pub const kFSEventStreamEventFlagItemXattrMod: FSEventStreamEventFlags = 0x00008000;
58pub const kFSEventStreamEventFlagItemIsFile: FSEventStreamEventFlags = 0x00010000;
59pub const kFSEventStreamEventFlagItemIsDir: FSEventStreamEventFlags = 0x00020000;
60pub const kFSEventStreamEventFlagItemIsSymlink: FSEventStreamEventFlags = 0x00040000;
61pub const kFSEventStreamEventFlagOwnEvent: FSEventStreamEventFlags = 0x00080000;
62pub const kFSEventStreamEventFlagItemIsHardlink: FSEventStreamEventFlags = 0x00100000;
63pub const kFSEventStreamEventFlagItemIsLastHardlink: FSEventStreamEventFlags = 0x00200000;
64pub const kFSEventStreamEventFlagItemCloned: FSEventStreamEventFlags = 0x00400000;
65
66#[repr(C)]
67pub struct FSEventStreamContext {
68    pub version: CFIndex,
69    pub info: *mut c_void,
70    pub retain: Option<CFAllocatorRetainCallBack>,
71    pub release: Option<CFAllocatorReleaseCallBack>,
72    pub copy_description: Option<CFAllocatorCopyDescriptionCallBack>,
73}
74
75// https://developer.apple.com/documentation/coreservices/file_system_events
76#[link(name = "CoreServices", kind = "framework")]
77extern "C" {
78    pub fn FSEventStreamCopyDescription(stream_ref: ConstFSEventStreamRef) -> CFStringRef;
79    pub fn FSEventStreamCopyPathsBeingWatched(streamRef: ConstFSEventStreamRef) -> CFArrayRef;
80    pub fn FSEventStreamCreate(
81        allocator: CFAllocatorRef,
82        callback: FSEventStreamCallback,
83        context: *const FSEventStreamContext,
84        pathsToWatch: CFArrayRef,
85        sinceWhen: FSEventStreamEventId,
86        latency: CFTimeInterval,
87        flags: FSEventStreamCreateFlags,
88    ) -> FSEventStreamRef;
89    pub fn FSEventStreamCreateRelativeToDevice(
90        allocator: CFAllocatorRef,
91        callback: FSEventStreamCallback,
92        context: *const FSEventStreamContext,
93        deviceToWatch: dev_t,
94        pathsToWatchRelativeToDevice: CFArrayRef,
95        sinceWhen: FSEventStreamEventId,
96        latency: CFTimeInterval,
97        flags: FSEventStreamCreateFlags,
98    ) -> FSEventStreamRef;
99    pub fn FSEventStreamFlushAsync(stream_ref: FSEventStreamRef) -> FSEventStreamEventId;
100    pub fn FSEventStreamFlushSync(streamRef: FSEventStreamRef);
101    pub fn FSEventStreamGetDeviceBeingWatched(stream_ref: ConstFSEventStreamRef) -> dev_t;
102    pub fn FSEventStreamGetLatestEventId(stream_ref: ConstFSEventStreamRef)
103        -> FSEventStreamEventId;
104    pub fn FSEventStreamInvalidate(stream_ref: FSEventStreamRef);
105    pub fn FSEventStreamRelease(stream_ref: FSEventStreamRef);
106    pub fn FSEventStreamRetain(stream_ref: FSEventStreamRef);
107    pub fn FSEventStreamScheduleWithRunLoop(
108        stream_ref: FSEventStreamRef,
109        run_loop: CFRunLoopRef,
110        run_loop_mode: CFStringRef,
111    );
112    // pub fn FSEventStreamSetDispatchQueue(streamRef: FSEventStreamRef, q: DispatchQueue);
113    pub fn FSEventStreamSetExclusionPaths(
114        stream_ref: FSEventStreamRef,
115        paths_to_exclude: CFArrayRef,
116    ) -> Boolean;
117    pub fn FSEventStreamShow(stream_ref: FSEventStreamRef);
118    pub fn FSEventStreamStart(stream_ref: FSEventStreamRef) -> Boolean;
119    pub fn FSEventStreamStop(stream_ref: FSEventStreamRef);
120    pub fn FSEventStreamUnscheduleFromRunLoop(
121        stream_ref: FSEventStreamRef,
122        run_loop: CFRunLoopRef,
123        run_loop_mode: CFStringRef,
124    );
125    // pub fn FSEventsCopyUUIDForDevice(dev: dev_t) -> CFUUID;
126    pub fn FSEventsGetCurrentEventId() -> FSEventStreamEventId;
127    pub fn FSEventsGetLastEventIdForDeviceBeforeTime(
128        dev: dev_t,
129        time: CFAbsoluteTime,
130    ) -> FSEventStreamEventId;
131    pub fn FSEventsPurgeEventsForDeviceUpToEventId(
132        dev: dev_t,
133        eventId: FSEventStreamEventId,
134    ) -> Boolean;
135}