fsevent_sys/
fsevent.rs

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