1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays combinators core-foundation.fsevents
4 destructors io.backend io.monitors kernel math sequences system
8 TUPLE: macosx-monitor < monitor handle ;
10 : enqueue-notifications ( triples monitor -- )
12 first2 V{ } clone swap {
13 [ kFSEventStreamEventFlagItemCreated bitand zero? [ +add-file+ suffix! ] unless ]
14 [ kFSEventStreamEventFlagItemRemoved bitand zero? [ +remove-file+ suffix! ] unless ]
15 [ kFSEventStreamEventFlagItemRenamed bitand zero? [ +rename-file+ suffix! ] unless ]
16 [ kFSEventStreamEventFlagItemModified bitand zero? [ +modify-file+ suffix! ] unless ]
17 } cleave [ { +modify-file+ } ] [ >array ] if-empty _ queue-change
20 M:: macosx (monitor) ( path recursive? mailbox -- monitor )
21 path normalize-path :> path
22 path mailbox macosx-monitor new-monitor
23 dup [ enqueue-notifications ] curry
24 path 1array 0 kFSEventStreamCreateFlagFileEvents <event-stream> >>handle ;
26 M: macosx-monitor dispose*
27 [ handle>> dispose ] [ call-next-method ] bi ;