Rename io.monitor to io.monitors; add log-viewer demo

db4
Slava Pestov 2008-02-05 18:00:24 -06:00
parent 9804d9462d
commit f8df69d9a1
13 changed files with 32 additions and 16 deletions

View File

@ -137,7 +137,7 @@ ARTICLE: "collections" "Collections"
{ $subsection "graphs" } { $subsection "graphs" }
{ $subsection "buffers" } ; { $subsection "buffers" } ;
USING: io.sockets io.launcher io.mmap io.monitor ; USING: io.sockets io.launcher io.mmap io.monitors ;
ARTICLE: "io" "Input and output" ARTICLE: "io" "Input and output"
{ $subsection "streams" } { $subsection "streams" }
@ -155,7 +155,7 @@ ARTICLE: "io" "Input and output"
"Advanced features:" "Advanced features:"
{ $subsection "io.launcher" } { $subsection "io.launcher" }
{ $subsection "io.mmap" } { $subsection "io.mmap" }
{ $subsection "io.monitor" } ; { $subsection "io.monitors" } ;
ARTICLE: "tools" "Developer tools" ARTICLE: "tools" "Developer tools"
{ $subsection "tools.annotations" } { $subsection "tools.annotations" }

View File

@ -1,4 +1,4 @@
IN: io.monitor IN: io.monitors
USING: help.markup help.syntax continuations ; USING: help.markup help.syntax continuations ;
HELP: <monitor> HELP: <monitor>
@ -9,7 +9,7 @@ $nl
HELP: next-change HELP: next-change
{ $values { "monitor" "a monitor" } { "path" "a pathname string" } { "changes" "a change descriptor" } } { $values { "monitor" "a monitor" } { "path" "a pathname string" } { "changes" "a change descriptor" } }
{ $description "Waits for file system changes and outputs the pathname of the first changed file. The change descriptor is aq sequence of symbols documented in " { $link "io.monitor.descriptors" } "." } ; { $description "Waits for file system changes and outputs the pathname of the first changed file. The change descriptor is aq sequence of symbols documented in " { $link "io.monitors.descriptors" } "." } ;
HELP: with-monitor HELP: with-monitor
{ $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "quot" "a quotation with stack effect " { $snippet "( monitor -- )" } } } { $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "quot" "a quotation with stack effect " { $snippet "( monitor -- )" } } }
@ -27,7 +27,7 @@ HELP: +modify-file+
HELP: +rename-file+ HELP: +rename-file+
{ $description "Indicates that file has been renamed." } ; { $description "Indicates that file has been renamed." } ;
ARTICLE: "io.monitor.descriptors" "File system change descriptors" ARTICLE: "io.monitors.descriptors" "File system change descriptors"
"Change descriptors output by " { $link next-change } ":" "Change descriptors output by " { $link next-change } ":"
{ $subsection +add-file+ } { $subsection +add-file+ }
{ $subsection +remove-file+ } { $subsection +remove-file+ }
@ -35,24 +35,24 @@ ARTICLE: "io.monitor.descriptors" "File system change descriptors"
{ $subsection +rename-file+ } { $subsection +rename-file+ }
{ $subsection +add-file+ } ; { $subsection +add-file+ } ;
ARTICLE: "io.monitor" "File system change monitors" ARTICLE: "io.monitors" "File system change monitors"
"File system change monitors listen for changes to file names, attributes and contents under a specified directory. They can optionally be recursive, in which case subdirectories are also monitored." "File system change monitors listen for changes to file names, attributes and contents under a specified directory. They can optionally be recursive, in which case subdirectories are also monitored."
$nl $nl
"Creating a file system change monitor and listening for changes:" "Creating a file system change monitor and listening for changes:"
{ $subsection <monitor> } { $subsection <monitor> }
{ $subsection next-change } { $subsection next-change }
{ $subsection "io.monitor.descriptors" } { $subsection "io.monitors.descriptors" }
"Monitors are closed by calling " { $link dispose } " or " { $link with-disposal } "." "Monitors are closed by calling " { $link dispose } " or " { $link with-disposal } "."
$nl $nl
"A utility combinator which opens a monitor and cleans it up after:" "A utility combinator which opens a monitor and cleans it up after:"
{ $subsection with-monitor } { $subsection with-monitor }
"An example which watches the Factor directory for changes:" "An example which watches the Factor directory for changes:"
{ $code { $code
"USE: io.monitor" "USE: io.monitors"
": watch-loop ( monitor -- )" ": watch-loop ( monitor -- )"
" dup next-change . . nl nl flush watch-loop ;" " dup next-change . . nl nl flush watch-loop ;"
"" ""
"\"\" resource-path f [ watch-loop ] with-monitor" "\"\" resource-path f [ watch-loop ] with-monitor"
} ; } ;
ABOUT: "io.monitor" ABOUT: "io.monitors"

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: io.backend kernel continuations namespaces sequences USING: io.backend kernel continuations namespaces sequences
assocs hashtables sorting arrays ; assocs hashtables sorting arrays ;
IN: io.monitor IN: io.monitors
<PRIVATE <PRIVATE

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel io.backend io.monitor io.monitor.private io.files USING: kernel io.backend io.monitors io.monitors.private io.files
io.buffers io.nonblocking io.unix.backend io.unix.select io.buffers io.nonblocking io.unix.backend io.unix.select
io.unix.launcher unix.linux.inotify assocs namespaces threads io.unix.launcher unix.linux.inotify assocs namespaces threads
continuations init math alien.c-types alien ; continuations init math alien.c-types alien ;

View File

@ -3,9 +3,9 @@
USING: alien.c-types destructors io.windows USING: alien.c-types destructors io.windows
io.windows.nt.backend kernel math windows windows.kernel32 io.windows.nt.backend kernel math windows windows.kernel32
windows.types libc assocs alien namespaces continuations windows.types libc assocs alien namespaces continuations
io.monitor io.monitor.private io.nonblocking io.buffers io.files io.monitors io.monitors.private io.nonblocking io.buffers io.files
io sequences hashtables sorting arrays combinators ; io sequences hashtables sorting arrays combinators ;
IN: io.windows.nt.monitor IN: io.windows.nt.monitors
: open-directory ( path -- handle ) : open-directory ( path -- handle )
FILE_LIST_DIRECTORY FILE_LIST_DIRECTORY
@ -70,8 +70,7 @@ M: windows-nt-io <monitor> ( path recursive? -- monitor )
FILE_NOTIFY_INFORMATION-FileName FILE_NOTIFY_INFORMATION-FileName
FILE_NOTIFY_INFORMATION-FileNameLength FILE_NOTIFY_INFORMATION-FileNameLength
FILE_NOTIFY_INFORMATION-Action FILE_NOTIFY_INFORMATION-Action
} get-slots parse-action 1array swap } get-slots parse-action 1array -rot memory>u16-string ;
memory>u16-string ;
: (changed-files) ( buffer -- ) : (changed-files) ( buffer -- )
dup parse-file-notify changed-file dup parse-file-notify changed-file

View File

@ -5,7 +5,7 @@ USE: io.windows
USE: io.windows.nt.backend USE: io.windows.nt.backend
USE: io.windows.nt.files USE: io.windows.nt.files
USE: io.windows.nt.launcher USE: io.windows.nt.launcher
USE: io.windows.nt.monitor USE: io.windows.nt.monitors
USE: io.windows.nt.sockets USE: io.windows.nt.sockets
USE: io.windows.mmap USE: io.windows.mmap
USE: io.backend USE: io.backend

1
extra/log-viewer/authors.txt Executable file
View File

@ -0,0 +1 @@
Slava Pestov

View File

@ -0,0 +1,14 @@
USING: kernel io io.files io.monitors ;
IN: log-viewer
: read-lines ( stream -- )
dup stream-readln dup
[ print read-lines ] [ 2drop flush ] if ;
: tail-file-loop ( stream monitor -- )
dup next-change 2drop over read-lines tail-file-loop ;
: tail-file ( file -- )
dup <file-reader> dup read-lines
swap parent-directory f <monitor>
tail-file-loop ;

1
extra/log-viewer/summary.txt Executable file
View File

@ -0,0 +1 @@
Simple log file watcher demo using io.monitors

1
extra/log-viewer/tags.txt Executable file
View File

@ -0,0 +1 @@
demos