Merge branch 'master' of git://factorcode.org/git/factor
commit
578741e3ae
|
@ -1,11 +1,11 @@
|
||||||
! Copyright (C) 2008 Doug Coleman, Slava Pestov.
|
! Copyright (C) 2008 Doug Coleman, Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.c-types destructors io.windows
|
USING: alien alien.c-types libc destructors locals
|
||||||
io.windows.nt.backend kernel math windows windows.kernel32
|
kernel math assocs namespaces continuations sequences hashtables
|
||||||
windows.types libc assocs alien namespaces continuations
|
sorting arrays combinators math.bitfields strings system
|
||||||
io.monitors io.monitors.private io.nonblocking io.buffers
|
io.windows io.windows.nt.backend io.monitors io.nonblocking
|
||||||
io.files io.timeouts io sequences hashtables sorting arrays
|
io.buffers io.files io.timeouts io
|
||||||
combinators math.bitfields strings system ;
|
windows windows.kernel32 windows.types ;
|
||||||
IN: io.windows.nt.monitors
|
IN: io.windows.nt.monitors
|
||||||
|
|
||||||
: open-directory ( path -- handle )
|
: open-directory ( path -- handle )
|
||||||
|
@ -21,69 +21,72 @@ IN: io.windows.nt.monitors
|
||||||
dup add-completion
|
dup add-completion
|
||||||
f <win32-file> ;
|
f <win32-file> ;
|
||||||
|
|
||||||
TUPLE: win32-monitor path recursive? ;
|
TUPLE: win32-monitor < monitor port path recursive ;
|
||||||
|
|
||||||
: <win32-monitor> ( path recursive? port -- monitor )
|
: begin-reading-changes ( port -- overlapped )
|
||||||
(monitor) {
|
|
||||||
set-win32-monitor-path
|
|
||||||
set-win32-monitor-recursive?
|
|
||||||
set-delegate
|
|
||||||
} win32-monitor construct ;
|
|
||||||
|
|
||||||
M: winnt <monitor> ( path recursive? -- monitor )
|
|
||||||
[
|
|
||||||
over open-directory win32-monitor <buffered-port>
|
|
||||||
<win32-monitor>
|
|
||||||
] with-destructors ;
|
|
||||||
|
|
||||||
: begin-reading-changes ( monitor -- overlapped )
|
|
||||||
{
|
{
|
||||||
[ handle>> handle>> ]
|
[ handle>> handle>> ]
|
||||||
[ buffer>> buffer-ptr ]
|
[ buffer>> buffer-ptr ]
|
||||||
[ buffer>> buffer-size ]
|
[ buffer>> buffer-size ]
|
||||||
[ win32-monitor-recursive? 1 0 ? ]
|
[ recursive>> 1 0 ? ]
|
||||||
} cleave
|
} cleave
|
||||||
FILE_NOTIFY_CHANGE_ALL
|
FILE_NOTIFY_CHANGE_ALL
|
||||||
0 <uint>
|
0 <uint>
|
||||||
(make-overlapped)
|
(make-overlapped)
|
||||||
[ f ReadDirectoryChangesW win32-error=0/f ] keep ;
|
[ f ReadDirectoryChangesW win32-error=0/f ] keep ;
|
||||||
|
|
||||||
: read-changes ( monitor -- bytes )
|
: read-changes ( port -- bytes )
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
dup begin-reading-changes
|
dup begin-reading-changes
|
||||||
swap [ save-callback ] 2keep
|
swap [ save-callback ] 2keep
|
||||||
dup check-monitor ! we may have closed it...
|
check-closed ! we may have closed it...
|
||||||
get-overlapped-result
|
get-overlapped-result
|
||||||
] with-timeout
|
] with-timeout
|
||||||
] with-destructors ;
|
] with-destructors ;
|
||||||
|
|
||||||
: parse-action ( action -- changed )
|
: parse-action ( action -- changed )
|
||||||
{
|
{
|
||||||
{ \ FILE_ACTION_ADDED [ +add-file+ ] }
|
{ FILE_ACTION_ADDED [ +add-file+ ] }
|
||||||
{ \ FILE_ACTION_REMOVED [ +remove-file+ ] }
|
{ FILE_ACTION_REMOVED [ +remove-file+ ] }
|
||||||
{ \ FILE_ACTION_MODIFIED [ +modify-file+ ] }
|
{ FILE_ACTION_MODIFIED [ +modify-file+ ] }
|
||||||
{ \ FILE_ACTION_RENAMED_OLD_NAME [ +rename-file+ ] }
|
{ FILE_ACTION_RENAMED_OLD_NAME [ +rename-file+ ] }
|
||||||
{ \ FILE_ACTION_RENAMED_NEW_NAME [ +rename-file+ ] }
|
{ FILE_ACTION_RENAMED_NEW_NAME [ +rename-file+ ] }
|
||||||
[ drop +modify-file+ ]
|
[ drop +modify-file+ ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
: memory>u16-string ( alien len -- string )
|
: memory>u16-string ( alien len -- string )
|
||||||
[ memory>byte-array ] keep 2/ c-ushort-array> >string ;
|
[ memory>byte-array ] [ 2/ ] bi c-ushort-array> >string ;
|
||||||
|
|
||||||
: parse-file-notify ( buffer -- changed path )
|
: parse-notify-record ( buffer -- changed path )
|
||||||
{
|
[ FILE_NOTIFY_INFORMATION-Action parse-action ]
|
||||||
FILE_NOTIFY_INFORMATION-FileName
|
[ FILE_NOTIFY_INFORMATION-FileName ]
|
||||||
FILE_NOTIFY_INFORMATION-FileNameLength
|
[ FILE_NOTIFY_INFORMATION-FileNameLength ]
|
||||||
FILE_NOTIFY_INFORMATION-Action
|
tri memory>u16-string ;
|
||||||
} get-slots parse-action 1array -rot memory>u16-string ;
|
|
||||||
|
|
||||||
: (changed-files) ( buffer -- )
|
: file-notify-records ( buffer -- seq )
|
||||||
dup parse-file-notify changed-file
|
[ dup FILE_NOTIFY_INFORMATION-NextEntryOffset 0 > ]
|
||||||
dup FILE_NOTIFY_INFORMATION-NextEntryOffset dup zero?
|
[ [ [ FILE_NOTIFY_INFORMATION-NextEntryOffset ] keep <displaced-alien> ] keep ]
|
||||||
[ 2drop ] [ swap <displaced-alien> (changed-files) ] if ;
|
[ ] unfold nip ;
|
||||||
|
|
||||||
M: win32-monitor fill-queue ( monitor -- )
|
: parse-notify-records ( monitor buffer -- )
|
||||||
dup buffer>> buffer-ptr over read-changes
|
file-notify-records
|
||||||
[ zero? [ drop ] [ (changed-files) ] if ] H{ } make-assoc
|
[ parse-notify-record rot queue-change ] with each ;
|
||||||
swap set-monitor-queue ;
|
|
||||||
|
: fill-queue ( monitor -- )
|
||||||
|
dup port>> [ buffer>> buffer-ptr ] [ read-changes zero? ] bi
|
||||||
|
[ 2dup parse-notify-records ] unless 2drop ;
|
||||||
|
|
||||||
|
: fill-queue-thread ( monitor -- )
|
||||||
|
dup fill-queue fill-queue ;
|
||||||
|
|
||||||
|
M:: winnt (monitor) ( path recursive? mailbox -- monitor )
|
||||||
|
[
|
||||||
|
path mailbox win32-monitor construct-monitor
|
||||||
|
path open-directory <buffered-port> >>port
|
||||||
|
recursive? >>recursive
|
||||||
|
dup port>> [ fill-queue-thread ] curry spawn drop
|
||||||
|
] with-destructors ;
|
||||||
|
|
||||||
|
M: win32-monitor dispose
|
||||||
|
port>> dispose ;
|
||||||
|
|
|
@ -5,7 +5,7 @@ io.buffers io.files io.nonblocking io.sockets io.binary
|
||||||
io.sockets.impl windows.errors strings io.streams.duplex
|
io.sockets.impl windows.errors strings io.streams.duplex
|
||||||
kernel math namespaces sequences windows windows.kernel32
|
kernel math namespaces sequences windows windows.kernel32
|
||||||
windows.shell32 windows.types windows.winsock splitting
|
windows.shell32 windows.types windows.winsock splitting
|
||||||
continuations math.bitfields system ;
|
continuations math.bitfields system accessors ;
|
||||||
IN: io.windows
|
IN: io.windows
|
||||||
|
|
||||||
M: windows destruct-handle CloseHandle drop ;
|
M: windows destruct-handle CloseHandle drop ;
|
||||||
|
|
Loading…
Reference in New Issue