2008-04-11 23:36:24 -04:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-05-15 00:23:12 -04:00
|
|
|
USING: io.backend kernel continuations destructors namespaces
|
|
|
|
sequences assocs hashtables sorting arrays threads boxes
|
2008-07-02 22:52:28 -04:00
|
|
|
io.timeouts accessors concurrency.mailboxes
|
|
|
|
system vocabs.loader combinators ;
|
2008-04-11 23:36:24 -04:00
|
|
|
IN: io.monitors
|
|
|
|
|
|
|
|
HOOK: init-monitors io-backend ( -- )
|
|
|
|
|
|
|
|
M: object init-monitors ;
|
|
|
|
|
|
|
|
HOOK: dispose-monitors io-backend ( -- )
|
|
|
|
|
|
|
|
M: object dispose-monitors ;
|
|
|
|
|
|
|
|
: with-monitors ( quot -- )
|
|
|
|
[
|
|
|
|
init-monitors
|
|
|
|
[ dispose-monitors ] [ ] cleanup
|
|
|
|
] with-scope ; inline
|
|
|
|
|
|
|
|
TUPLE: monitor < identity-tuple path queue timeout ;
|
|
|
|
|
|
|
|
M: monitor hashcode* path>> hashcode* ;
|
|
|
|
|
|
|
|
M: monitor timeout timeout>> ;
|
|
|
|
|
|
|
|
M: monitor set-timeout (>>timeout) ;
|
|
|
|
|
2008-04-14 06:07:31 -04:00
|
|
|
: new-monitor ( path mailbox class -- monitor )
|
2008-04-13 16:06:27 -04:00
|
|
|
new
|
2008-04-11 23:36:24 -04:00
|
|
|
swap >>queue
|
|
|
|
swap >>path ; inline
|
|
|
|
|
|
|
|
: queue-change ( path changes monitor -- )
|
|
|
|
3dup and and
|
|
|
|
[ [ 3array ] keep queue>> mailbox-put ] [ 3drop ] if ;
|
|
|
|
|
|
|
|
HOOK: (monitor) io-backend ( path recursive? mailbox -- monitor )
|
|
|
|
|
|
|
|
: <monitor> ( path recursive? -- monitor )
|
|
|
|
<mailbox> (monitor) ;
|
|
|
|
|
|
|
|
: next-change ( monitor -- path changed )
|
|
|
|
[ queue>> ] [ timeout ] bi mailbox-get-timeout first2 ;
|
|
|
|
|
|
|
|
SYMBOL: +add-file+
|
|
|
|
SYMBOL: +remove-file+
|
|
|
|
SYMBOL: +modify-file+
|
|
|
|
SYMBOL: +rename-file-old+
|
|
|
|
SYMBOL: +rename-file-new+
|
|
|
|
SYMBOL: +rename-file+
|
|
|
|
|
|
|
|
: with-monitor ( path recursive? quot -- )
|
2008-12-02 04:10:13 -05:00
|
|
|
[ <monitor> ] dip with-disposal ; inline
|
2008-07-02 22:52:28 -04:00
|
|
|
|
|
|
|
{
|
2008-12-14 21:03:00 -05:00
|
|
|
{ [ os macosx? ] [ "io.monitors.macosx" require ] }
|
|
|
|
{ [ os linux? ] [ "io.monitors.linux" require ] }
|
|
|
|
{ [ os winnt? ] [ "io.monitors.windows.nt" require ] }
|
2008-07-02 22:52:28 -04:00
|
|
|
[ ]
|
|
|
|
} cond
|