Inotify.dcl 5.54 KB
Newer Older
Camil Staps's avatar
Camil Staps committed
1 2
definition module Inotify

Camil Staps's avatar
Camil Staps committed
3 4 5 6
/**
 * Links with Linux's inotify
 */

Camil Staps's avatar
Camil Staps committed
7 8 9
from Data.Either import ::Either
from Data.Maybe import ::Maybe

Camil Staps's avatar
Camil Staps committed
10 11 12 13 14
/**
 * An inotify file descriptor
 *
 * @var A state that is used for callbacks
 */
Camil Staps's avatar
Camil Staps committed
15
:: *Inotify st
Camil Staps's avatar
Camil Staps committed
16

17
//* An inotify watch descriptor
Camil Staps's avatar
Camil Staps committed
18 19
:: INWatch

20
//* An inotify event mask
Camil Staps's avatar
Camil Staps committed
21 22
:: INMask :== Int

23
//* An inotify event
Camil Staps's avatar
Camil Staps committed
24
:: INEvent :== Int
25

Camil Staps's avatar
Camil Staps committed
26 27 28 29 30
/**
 * An inotify callback: event, maybe filename, state, world -> state, world
 *
 * @var A state that is passed on.
 */
31
:: INCallback st :== INEvent (Maybe String) st *World -> *(st, *World)
Camil Staps's avatar
Camil Staps committed
32

33
//* Bitwise OR for event masks
Camil Staps's avatar
Camil Staps committed
34 35
(|-) infixl 6 :: (INMask INMask -> INMask)

Camil Staps's avatar
Camil Staps committed
36 37 38 39 40 41
/**
 * Initialise an inotify file descriptor with some state.
 *
 * @param The initial state
 * @result A file descriptor or Nothing if the C initialisation failed
 */
Camil Staps's avatar
Camil Staps committed
42
inotify_init :: st -> Maybe *(Inotify st)
43

Camil Staps's avatar
Camil Staps committed
44 45 46 47 48 49
/**
 * Close an inotify file descriptor and get back the state
 *
 * @param The file descriptor
 * @result The final state
 */
Camil Staps's avatar
Camil Staps committed
50
inotify_close :: *(Inotify st) -> st
Camil Staps's avatar
Camil Staps committed
51

52 53 54
/**
 * Add a watch on some file
 *
Camil Staps's avatar
Camil Staps committed
55 56 57 58 59
 * @param The callback for events
 * @param A mask of events to watch for
 * @param The filename
 * @param The inotify file descriptor
 * @result Either an error code or a watch descriptor, and the inotify file descriptor
60 61
 */
inotify_add_watch :: (INCallback st) !INMask !String !*(Inotify st)
Camil Staps's avatar
Camil Staps committed
62
	-> *(!Either Int INWatch, !*Inotify st)
63 64 65 66

/**
 * Remove a watch
 *
Camil Staps's avatar
Camil Staps committed
67 68 69
 * @param The watch to remove
 * @param The inotify file descriptor
 * @result A boolean indicating success and the inotify file descriptor
70 71 72 73 74 75
 */
inotify_rm_watch :: !INWatch !*(Inotify st) -> *(!Bool, !*Inotify st)

/**
 * Poll an inotify file descriptor; i.e. wait for new events
 *
Camil Staps's avatar
Camil Staps committed
76 77 78
 * @param Timeout in milliseconds (Nothing for no timeout)
 * @param The inotify file descriptor
 * @result The number of events, and the inotify file descriptor
79 80
 */
inotify_poll :: !(Maybe Int) !*(Inotify st) -> *(!Int, !*Inotify st)
Camil Staps's avatar
Camil Staps committed
81

82 83 84 85
/**
 * Check for new events and call callbacks
 */
inotify_check :: !*(Inotify st) !*World -> *(!*Inotify st, !*World)
Camil Staps's avatar
Camil Staps committed
86

87 88
/**
 * Check if an event matches a mask
Camil Staps's avatar
Camil Staps committed
89 90 91 92
 *
 * @param The mask
 * @param The event
 * @result True iff the event matches the mask
93 94 95 96 97 98
 */
inotify_is_event :: INMask INEvent -> Bool

/**
 * Combination of inotify_poll and inotify_check that will return only if no
 * events were given when a timeout occurred.
Camil Staps's avatar
Camil Staps committed
99 100 101 102 103 104 105
 *
 * @param Timeout in milliseconds (Nothing for no timeout)
 * @param The inotify file descriptor
 * @param The World
 * @result The inotify file descriptor and the World. However, the function
 *   only returns if no events were given when the timeout occurred. Otherwise,
 *   it will loop.
106
 */
Camil Staps's avatar
Camil Staps committed
107
inotify_loop_with_timeout :: !(Maybe Int) !*(Inotify st) !*World
Camil Staps's avatar
Camil Staps committed
108
	-> *(!*Inotify st, !*World)
109 110 111

/**
 * inotify_loop_with_timeout with Nothing as timeout (will never return)
Camil Staps's avatar
Camil Staps committed
112 113 114 115
 *
 * @param The inotify file descriptor
 * @param The World
 * @result The parameters back, however, this function will never return.
116 117 118 119
 */
inotify_loop_forever :: !*(Inotify st) !*World -> *(!*Inotify st, !*World)

/*** Begin inotify.h ***/
120

121
//* Inotify event mask: file was accessed
Camil Staps's avatar
Camil Staps committed
122
IN_ACCESS        :== 0x00000001
123
//* Inotify event mask: file was modified
Camil Staps's avatar
Camil Staps committed
124
IN_MODIFY        :== 0x00000002
125
//* Inotify event mask: metadata changed
Camil Staps's avatar
Camil Staps committed
126
IN_ATTRIB        :== 0x00000004
127
//* Inotify event mask: file opened for writing was closed
Camil Staps's avatar
Camil Staps committed
128
IN_CLOSE_WRITE   :== 0x00000008
129
//* Inotify event mask: file not opened for writing was closed
Camil Staps's avatar
Camil Staps committed
130
IN_CLOSE_NOWRITE :== 0x00000010
131
//* Inotify event mask: file was opened
Camil Staps's avatar
Camil Staps committed
132
IN_OPEN          :== 0x00000020
133
//* Inotify event mask: file was moved from watched directory
Camil Staps's avatar
Camil Staps committed
134
IN_MOVED_FROM    :== 0x00000040
135
//* Inotify event mask: file was moved to watched directory
Camil Staps's avatar
Camil Staps committed
136
IN_MOVED_TO      :== 0x00000080
137
//* Inotify event mask: file was created in watched directory
Camil Staps's avatar
Camil Staps committed
138
IN_CREATE        :== 0x00000100
139
//* Inotify event mask: file in watched directory was deleted
Camil Staps's avatar
Camil Staps committed
140
IN_DELETE        :== 0x00000200
141
//* Inotify event mask: watched file was deleted
Camil Staps's avatar
Camil Staps committed
142
IN_DELETE_SELF   :== 0x00000400
143
//* Inotify event mask: watched file was moved
Camil Staps's avatar
Camil Staps committed
144
IN_MOVE_SELF     :== 0x00000800
145
//* Inotify event mask: backing fs of watched file was unmounted
Camil Staps's avatar
Camil Staps committed
146
IN_UNMOUNT       :== 0x00002000
147
//* Inotify event mask: the inotify event queue overflowed
Camil Staps's avatar
Camil Staps committed
148 149 150 151 152 153 154 155
IN_Q_OVERFLOW    :== 0x00004000
/**
 * Inotify event mask: the watch has been removed, either through
 * inotify_rm_watch or because it was deleted, the fs was unmounted, etc.
 */
IN_IGNORED       :== 0x00008000
/**
 * Inotify event mask: watched file was closed
156
 * @type Int
Camil Staps's avatar
Camil Staps committed
157 158 159 160
 */
IN_CLOSE         :== (IN_CLOSE_WRITE |- IN_CLOSE_NOWRITE)
/**
 * Inotify event mask: a file was moved from or to a watched directory
161
 * @type Int
Camil Staps's avatar
Camil Staps committed
162 163
 */
IN_MOVE          :== (IN_MOVED_FROM |- IN_MOVED_TO)
164
//* Inotify event mask: only watch the path if it is a directory
Camil Staps's avatar
Camil Staps committed
165
IN_ONLYDIR       :== 0x01000000
166
//* Inotify event mask: don't follow symlinks
Camil Staps's avatar
Camil Staps committed
167
IN_DONT_FOLLOW   :== 0x02000000
168
//* Inotify event mask: stop watching files when they get unlinked
Camil Staps's avatar
Camil Staps committed
169 170 171 172 173 174
IN_EXCL_UNLINK   :== 0x04000000
/**
 * Inotify event mask: when adding a watch on a path for which a watch already
 * exists, OR the new event mask with the old one instead of replacing it.
 */
IN_MASK_ADD      :== 0x20000000
175
//* Inotify event mask: the event occurred against a directory
Camil Staps's avatar
Camil Staps committed
176
IN_ISDIR         :== 0x40000000
177
//* Inotify event mask: monitor a watch only for one event, then remove it
Camil Staps's avatar
Camil Staps committed
178 179 180
IN_ONESHOT       :== 0x80000000
/**
 * Inotify event mask: OR of all events
181
 * @type Int
Camil Staps's avatar
Camil Staps committed
182
 */
Camil Staps's avatar
Camil Staps committed
183 184 185 186
IN_ALL_EVENTS    :==
	(IN_ACCESS |- IN_MODIFY |- IN_ATTRIB |- IN_CLOSE_WRITE |- IN_CLOSE_NOWRITE
	|- IN_OPEN |- IN_MOVED_FROM |- IN_MOVED_TO |- IN_DELETE |- IN_CREATE |-
	IN_DELETE_SELF |- IN_MOVE_SELF)
187 188

/*** End inotify.h ***/