]> gitweb.factorcode.org Git - factor.git/blob - basis/io/monitors/monitors-docs.factor
Remove Windows CE from core/ basis/ and build-support/
[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: file-change\r
21 { $class-description "A change notification output by " { $link next-change } ". The " { $snippet "path" } " slot holds a pathname string. The " { $snippet "changed" } " slots holds a sequence of symbols documented in " { $link "io.monitors.descriptors" } "." } ;\r
22 \r
23 HELP: next-change\r
24 { $values { "monitor" "a monitor" } { "change" file-change } }\r
25 { $contract "Waits for file system changes and outputs a change descriptor for the first changed file." }\r
26 { $errors "Throws an error if the monitor is closed from another thread." } ;\r
27 \r
28 HELP: with-monitor\r
29 { $values { "path" "a pathname string" } { "recursive?" "a boolean" } { "quot" { $quotation "( monitor -- )" } } }\r
30 { $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
31 { $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
32 \r
33 HELP: +add-file+\r
34 { $description "Indicates that a file has been added to its parent directory." } ;\r
35 \r
36 HELP: +remove-file+\r
37 { $description "Indicates that a file has been removed from its parent directory." } ;\r
38 \r
39 HELP: +modify-file+\r
40 { $description "Indicates that a file's contents have changed." } ;\r
41 \r
42 HELP: +rename-file-old+\r
43 { $description "Indicates that a file has been renamed, and this is the old name." } ;\r
44 \r
45 HELP: +rename-file-new+\r
46 { $description "Indicates that a file has been renamed, and this is the new name." } ;\r
47 \r
48 HELP: +rename-file+\r
49 { $description "Indicates that a file has been renamed." } ;\r
50 \r
51 ARTICLE: "io.monitors.descriptors" "File system change descriptors"\r
52 "The " { $link next-change } " word outputs instances of a class:"\r
53 { $subsections file-change }\r
54 "The " { $slot "changed" } " slot holds a sequence which may contain any of the following symbols:"\r
55 { $subsections\r
56     +add-file+\r
57     +remove-file+\r
58     +modify-file+\r
59     +rename-file-old+\r
60     +rename-file-new+\r
61     +rename-file+\r
62 } ;\r
63 \r
64 ARTICLE: "io.monitors.platforms" "Monitors on different platforms"\r
65 "Whether the " { $slot "path" } " slot of a " { $link file-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
66 $nl\r
67 "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
68 { $heading "Mac OS X" }\r
69 "Factor uses " { $snippet "FSEventStream" } "s to implement monitors on Mac OS X. This requires Mac OS X 10.5 or later."\r
70 $nl\r
71 { $snippet "FSEventStream" } "s always monitor directory hierarchies recursively, and the " { $snippet "recursive?" } " parameter to " { $link <monitor> } " has no effect."\r
72 $nl\r
73 "The " { $snippet "changed" } " slot of the " { $link file-change } " word tuple always contains " { $link +modify-file+ } " and the " { $snippet "path" } " slot is always the directory containing the file that changed. Unlike other platforms, fine-grained information is not available."\r
74 $nl\r
75 "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
76 { $heading "Windows" }\r
77 "Factor uses " { $snippet "ReadDirectoryChanges" } " to implement monitors on Windows."\r
78 $nl\r
79 "Both recursive and non-recursive monitors are directly supported by the operating system."\r
80 $nl\r
81 "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
82 { $heading "Linux" }\r
83 "Factor uses " { $snippet "inotify" } " to implement monitors on Linux. This requires Linux kernel version 2.6.16 or later."\r
84 $nl\r
85 "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
86 $nl\r
87 "Inside a single " { $link with-monitors } " scope, only one monitor may be created for any given directory."\r
88 $nl\r
89 "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
90 { $heading "BSD" }\r
91 "Factor uses " { $snippet "kqueue" } " to implement monitors on BSD."\r
92 $nl\r
93 "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
94 ;\r
95 \r
96 ARTICLE: "io.monitors" "File system change monitors"\r
97 "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
98 $nl\r
99 "Monitoring operations must be wrapped in a combinator:"\r
100 { $subsections with-monitors }\r
101 "Creating a file system change monitor and listening for changes:"\r
102 { $subsections\r
103     <monitor>\r
104     next-change\r
105 }\r
106 "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
107 { $subsections\r
108     (monitor)\r
109     "io.monitors.descriptors"\r
110     "io.monitors.platforms"\r
111 }\r
112 "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
113 { $subsections with-monitor }\r
114 "Monitors support the " { $link "io.timeouts" } "."\r
115 $nl\r
116 "An example which watches a directory for changes:"\r
117 { $code\r
118     "USE: io.monitors"\r
119     ""\r
120     ": watch-loop ( monitor -- )"\r
121     "    dup next-change path>> print flush watch-loop ;"\r
122     ""\r
123     ": watch-directory ( path -- )"\r
124     "    [ t [ watch-loop ] with-monitor ] with-monitors ;"\r
125 } ;\r
126 \r
127 ABOUT: "io.monitors"\r