]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/core-foundation/fsevents/fsevents.factor
Updating code to use with-out-parameters
[factor.git] / basis / core-foundation / fsevents / fsevents.factor
index 1956cd9c20d4d6761d978fa8afa4ff765652a3f0..fd17843bf3dceb3c2eff158edb50b4394d1c30bd 100644 (file)
@@ -3,12 +3,15 @@
 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
 
@@ -26,15 +29,14 @@ TYPEDEF: int FSEventStreamEventFlags
 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
 
@@ -104,8 +106,8 @@ FUNCTION: void FSEventStreamShow ( FSEventStreamRef streamRef ) ;
 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
@@ -117,8 +119,7 @@ FUNCTION: CFStringRef FSEventStreamCopyDescription ( FSEventStreamRef streamRef
     flags
     FSEventStreamCreate ;
 
-: kCFRunLoopCommonModes ( -- string )
-    &: kCFRunLoopCommonModes *void* ;
+C-GLOBAL: void* kCFRunLoopCommonModes
 
 : schedule-event-stream ( event-stream -- )
     CFRunLoopGetMain
@@ -153,7 +154,7 @@ SYMBOL: event-stream-callbacks
 [
     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>
@@ -170,26 +171,17 @@ SYMBOL: event-stream-callbacks
     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*
     {