]> gitweb.factorcode.org Git - factor.git/blob - basis/io/monitors/macosx/macosx.factor
e22b3dbd9998cb72ef9deb0ae1a1da3b763399b2
[factor.git] / basis / io / monitors / macosx / macosx.factor
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
5 ;
6 IN: io.monitors.macosx
7
8 TUPLE: macosx-monitor < monitor handle ;
9
10 : enqueue-notifications ( triples monitor -- )
11     '[
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
18     ] each ;
19
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 ;
25
26 M: macosx-monitor dispose*
27     [ handle>> dispose ] [ call-next-method ] bi ;
28
29 macosx set-io-backend