]> gitweb.factorcode.org Git - factor.git/blob - basis/io/monitors/monitors-docs.factor
ce59e23b459e53855f12cb67d5a0eee55e28781e
[factor.git] / basis / io / monitors / monitors-docs.factor
1 IN: io.monitors\r
2 USING: help.markup help.syntax continuations destructors\r
3 concurrency.mailboxes quotations ;\r
4 \r
5 HELP: with-monitors\r
6 { $values { "quot" quotation } }\r
7 { $description "Calls a quotation in a new dynamic scope where file system monitor operations can be performed." }\r
8 { $errors "Throws an error if the platform does not support file system change monitors." } ;\r
9 \r
10 HELP: <monitor>\r
11 { $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "monitor" "a new monitor" } }\r
12 { $contract "Opens a file system change monitor which listens for changes on " { $snippet "path" } ". The boolean indicates whether changes in subdirectories should be reported." }\r
13 { $errors "Throws an error if the pathname does not exist, if a monitor could not be created or if the platform does not support monitors." } ;\r
14 \r
15 HELP: (monitor)\r
16 { $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "mailbox" mailbox } { "monitor" "a new monitor" } }\r
17 { $contract "Opens a file system change monitor which listens for changes on " { $snippet "path" } " and posts notifications to " { $snippet "mailbox" } " as triples with shape " { $snippet "{ path changed monitor } " } ". The boolean indicates whether changes in subdirectories should be reported." }\r
18 { $errors "Throws an error if the pathname does not exist, if a monitor could not be created or if the platform does not support monitors." } ;\r
19 \r
20 HELP: next-change\r
21 { $values { "monitor" "a monitor" } { "path" "a pathname string" } { "changed" "a change descriptor" } }\r
22 { $contract "Waits for file system changes and outputs the pathname of the first changed file. The change descriptor is a sequence of symbols documented in " { $link "io.monitors.descriptors" } "." }\r
23 { $errors "Throws an error if the monitor is closed from another thread." } ;\r
24 \r
25 HELP: with-monitor\r
26 { $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "quot" "a quotation with stack effect " { $snippet "( monitor -- )" } } }\r
27 { $description "Opens a file system change monitor and passes it to the quotation. Closes the monitor after the quotation returns or throws an error." }\r
28 { $errors "Throws an error if the pathname does not exist, if a monitor could not be created or if the platform does not support monitors." } ;\r
29 \r
30 HELP: +add-file+\r
31 { $description "Indicates that a file has been added to its parent directory." } ;\r
32 \r
33 HELP: +remove-file+\r
34 { $description "Indicates that a file has been removed from its parent directory." } ;\r
35 \r
36 HELP: +modify-file+\r
37 { $description "Indicates that a file's contents have changed." } ;\r
38 \r
39 HELP: +rename-file-old+\r
40 { $description "Indicates that a file has been renamed, and this is the old name." } ;\r
41 \r
42 HELP: +rename-file-new+\r
43 { $description "Indicates that a file has been renamed, and this is the new name." } ;\r
44 \r
45 HELP: +rename-file+\r
46 { $description "Indicates that a file has been renamed." } ;\r
47 \r
48 ARTICLE: "io.monitors.descriptors" "File system change descriptors"\r
49 "Change descriptors output by " { $link next-change } ":"\r
50 { $subsection +add-file+ }\r
51 { $subsection +remove-file+ }\r
52 { $subsection +modify-file+ }\r
53 { $subsection +rename-file-old+ }\r
54 { $subsection +rename-file-new+ }\r
55 { $subsection +rename-file+ } ;\r
56 \r
57 ARTICLE: "io.monitors.platforms" "Monitors on different platforms"\r
58 "Whether the " { $snippet "path" } " output value of " { $link next-change } " contains an absolute path or a path relative to the path given to " { $link <monitor> } " is unspecified, and may even vary on the same platform. User code should not assume either case."\r
59 $nl\r
60 "If the immediate path being monitored was changed, then " { $snippet "path" } " will equal " { $snippet "\"\"" } "; however this condition is not reported on all platforms. See below."\r
61 { $heading "Mac OS X" }\r
62 "Factor uses " { $snippet "FSEventStream" } "s to implement monitors on Mac OS X. This requires Mac OS X 10.5 or later."\r
63 $nl\r
64 { $snippet "FSEventStream" } "s always monitor directory hierarchies recursively, and the " { $snippet "recursive?" } " parameter to " { $link <monitor> } " has no effect."\r
65 $nl\r
66 "The " { $snippet "changed" } " output value of the " { $link next-change } " word always outputs " { $link +modify-file+ } " and the " { $snippet "path" } " output value is always the directory containing the file that changed. Unlike other platforms, fine-grained information is not available."\r
67 $nl\r
68 "Only directories may be monitored, not individual files. Changes to the directory itself (permissions, modification time, and so on) are not reported; only changes to children are reported."\r
69 { $heading "Windows" }\r
70 "Factor uses " { $snippet "ReadDirectoryChanges" } " to implement monitors on Windows."\r
71 $nl\r
72 "Both recursive and non-recursive monitors are directly supported by the operating system."\r
73 $nl\r
74 "Only directories may be monitored, not individual files. Changes to the directory itself (permissions, modification time, and so on) are not reported; only changes to children are reported."\r
75 { $heading "Linux" }\r
76 "Factor uses " { $snippet "inotify" } " to implement monitors on Linux. This requires Linux kernel version 2.6.16 or later."\r
77 $nl\r
78 "Factor simulates recursive monitors by creating a hierarchy of monitors for every subdirectory, since " { $snippet "inotify" } " can only monitor a single directory. This is transparent to user code."\r
79 $nl\r
80 "Inside a single " { $link with-monitors } " scope, only one monitor may be created for any given directory."\r
81 $nl\r
82 "Both directories and files may be monitored. Unlike Mac OS X and Windows, changes to the immediate directory being monitored (permissions, modification time, and so on) are reported."\r
83 { $heading "BSD" }\r
84 "Factor uses " { $snippet "kqueue" } " to implement monitors on BSD."\r
85 $nl\r
86 "The " { $snippet "kqueue" } " system is limited to monitoring individual files and directories. Monitoring a directory only notifies of files being added and removed to the directory itself, not of changes to file contents."\r
87 { $heading "Windows CE" }\r
88 "Windows CE does not support monitors." ;\r
89 \r
90 ARTICLE: "io.monitors" "File system change monitors"\r
91 "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."\r
92 $nl\r
93 "Monitoring operations must be wrapped in a combinator:"\r
94 { $subsection with-monitors }\r
95 "Creating a file system change monitor and listening for changes:"\r
96 { $subsection <monitor> }\r
97 { $subsection next-change }\r
98 "An alternative programming style is where instead of having a thread listen for changes on a monitor, change notifications are posted to a mailbox:"\r
99 { $subsection (monitor) }\r
100 { $subsection "io.monitors.descriptors" }\r
101 { $subsection "io.monitors.platforms" } \r
102 "Monitors are closed by calling " { $link dispose } " or " { $link with-disposal } ". An easy way to pair construction with disposal is to use a combinator:"\r
103 { $subsection with-monitor }\r
104 "Monitors support the " { $link "io.timeouts" } "."\r
105 $nl\r
106 "An example which watches a directory for changes:"\r
107 { $code\r
108     "USE: io.monitors"\r
109     ": watch-loop ( monitor -- )"\r
110     "    dup next-change . . nl nl flush watch-loop ;"\r
111     ""\r
112     ": watch-directory ( path -- )"\r
113     "    [ t [ watch-loop ] with-monitor ] with-monitors"\r
114 } ;\r
115 \r
116 ABOUT: "io.monitors"\r