USING: alien alien.c-types alien.strings alien.syntax kernel
math sequences namespaces make assocs init accessors
continuations combinators io.encodings.utf8 destructors locals
-arrays specialized-arrays.direct.alien
-specialized-arrays.direct.int specialized-arrays.direct.longlong
-core-foundation core-foundation.run-loop core-foundation.strings
-core-foundation.time ;
+arrays specialized-arrays classes.struct core-foundation
+core-foundation.arrays core-foundation.run-loop
+core-foundation.strings core-foundation.time unix.types ;
IN: core-foundation.fsevents
+SPECIALIZED-ARRAY: void*
+SPECIALIZED-ARRAY: int
+SPECIALIZED-ARRAY: longlong
+
CONSTANT: kFSEventStreamCreateFlagUseCFTypes 2
CONSTANT: kFSEventStreamCreateFlagWatchRoot 4
TYPEDEF: longlong FSEventStreamEventId
TYPEDEF: void* FSEventStreamRef
-C-STRUCT: FSEventStreamContext
- { "CFIndex" "version" }
- { "void*" "info" }
- { "void*" "retain" }
- { "void*" "release" }
- { "void*" "copyDescription" } ;
+STRUCT: FSEventStreamContext
+ { version CFIndex }
+ { info void* }
+ { retain void* }
+ { release void* }
+ { copyDescription void* } ;
-! callback(FSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]);
-TYPEDEF: void* FSEventStreamCallback
+CALLBACK: void FSEventStreamCallback ( FSEventStreamRef streamRef, void* clientCallBackInfo, size_t numEvents, void* eventPaths, FSEventStreamEventFlags* eventFlags, FSEventStreamEventId* eventIds ) ;
CONSTANT: FSEventStreamEventIdSinceNow HEX: FFFFFFFFFFFFFFFF
FUNCTION: CFStringRef FSEventStreamCopyDescription ( FSEventStreamRef streamRef ) ;
: make-FSEventStreamContext ( info -- alien )
- "FSEventStreamContext" <c-object>
- [ set-FSEventStreamContext-info ] keep ;
+ FSEventStreamContext <struct>
+ swap >>info ;
:: <FSEventStream> ( callback info paths latency flags -- event-stream )
f ! allocator
flags
FSEventStreamCreate ;
-: kCFRunLoopCommonModes ( -- string )
- &: kCFRunLoopCommonModes *void* ;
+C-GLOBAL: void* kCFRunLoopCommonModes
: schedule-event-stream ( event-stream -- )
CFRunLoopGetMain
[
event-stream-callbacks
[ [ drop expired? not ] assoc-filter H{ } assoc-like ] change-global
-] "core-foundation" add-init-hook
+] "core-foundation" add-startup-hook
: add-event-source-callback ( quot -- id )
event-stream-counter <alien>
info event-stream-callbacks get at [ drop ] or call( changes -- ) ;
: master-event-source-callback ( -- alien )
- "void"
- {
- "FSEventStreamRef"
- "void*" ! info
- "size_t" ! numEvents
- "void*" ! eventPaths
- "FSEventStreamEventFlags*"
- "FSEventStreamEventId*"
- }
- "cdecl" [ (master-event-source-callback) ] alien-callback ;
+ [ (master-event-source-callback) ] FSEventStreamCallback ;
-TUPLE: event-stream info handle disposed ;
+TUPLE: event-stream < disposable info handle ;
: <event-stream> ( quot paths latency flags -- event-stream )
[
- add-event-source-callback dup
- [ master-event-source-callback ] dip
+ add-event-source-callback
+ [ master-event-source-callback ] keep
] 3dip <FSEventStream>
dup enable-event-stream
- f event-stream boa ;
+ event-stream new-disposable swap >>handle swap >>info ;
M: event-stream dispose*
{