2008-01-26 02:40:09 -05:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-02-02 17:23:04 -05:00
|
|
|
USING: io.backend kernel continuations namespaces sequences
|
2008-04-11 08:15:26 -04:00
|
|
|
assocs hashtables sorting arrays threads boxes io.timeouts
|
|
|
|
accessors concurrency.mailboxes ;
|
2008-02-05 19:00:24 -05:00
|
|
|
IN: io.monitors
|
2008-01-26 02:40:09 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
HOOK: init-monitors io-backend ( -- )
|
2008-02-02 17:23:04 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
HOOK: dispose-monitors io-backend ( -- )
|
2008-02-02 17:23:04 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
: with-monitors ( quot -- )
|
|
|
|
[
|
|
|
|
init-monitors
|
|
|
|
[ dispose-monitors ] [ ] cleanup
|
|
|
|
] with-scope ; inline
|
2008-02-12 03:19:18 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
TUPLE: monitor < identity-tuple path queue timeout ;
|
2008-02-12 03:19:18 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
M: monitor hashcode* path>> hashcode* ;
|
2008-02-12 03:19:18 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
M: monitor timeout timeout>> ;
|
2008-02-12 03:19:18 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
M: monitor set-timeout (>>timeout) ;
|
2008-02-28 02:20:44 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
: construct-monitor ( path mailbox class -- monitor )
|
|
|
|
construct-empty
|
|
|
|
swap >>queue
|
|
|
|
swap >>path ; inline
|
2008-02-12 03:19:18 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
: queue-change ( path changes monitor -- )
|
2008-04-11 09:35:21 -04:00
|
|
|
3dup and and
|
|
|
|
[ [ 3array ] keep queue>> mailbox-put ] [ 3drop ] if ;
|
2008-02-12 03:19:18 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
HOOK: (monitor) io-backend ( path recursive? mailbox -- monitor )
|
2008-02-02 17:23:04 -05:00
|
|
|
|
2008-04-11 08:15:26 -04:00
|
|
|
: <monitor> ( path recursive? -- monitor )
|
|
|
|
<mailbox> (monitor) ;
|
2008-01-26 02:40:09 -05:00
|
|
|
|
2008-02-02 17:23:04 -05:00
|
|
|
: next-change ( monitor -- path changed )
|
2008-04-11 08:15:26 -04:00
|
|
|
[ queue>> ] [ timeout ] bi mailbox-get-timeout first2 ;
|
2008-01-26 22:38:30 -05:00
|
|
|
|
2008-02-01 18:13:57 -05:00
|
|
|
SYMBOL: +add-file+
|
|
|
|
SYMBOL: +remove-file+
|
|
|
|
SYMBOL: +modify-file+
|
2008-04-11 08:15:26 -04:00
|
|
|
SYMBOL: +rename-file-old+
|
|
|
|
SYMBOL: +rename-file-new+
|
2008-04-11 10:54:50 -04:00
|
|
|
SYMBOL: +rename-file+
|
2008-01-26 22:38:30 -05:00
|
|
|
|
|
|
|
: with-monitor ( path recursive? quot -- )
|
2008-01-31 01:52:06 -05:00
|
|
|
>r <monitor> r> with-disposal ; inline
|