definition module Inotify /** * Links with Linux's inotify */ from Data.Either import ::Either from Data.Maybe import ::Maybe /** * An inotify file descriptor * * @var A state that is used for callbacks */ :: *Inotify st //* An inotify watch descriptor :: INWatch //* An inotify event mask :: INMask :== Int //* An inotify event :: INEvent :== Int /** * An inotify callback: event, maybe filename, state, world -> state, world * * @var A state that is passed on. */ :: INCallback st :== INEvent (Maybe String) st *World -> *(st, *World) //* Bitwise OR for event masks (|-) infixl 6 :: (INMask INMask -> INMask) /** * Initialise an inotify file descriptor with some state. * * @param The initial state * @result A file descriptor or Nothing if the C initialisation failed */ inotify_init :: st -> Maybe *(Inotify st) /** * Close an inotify file descriptor and get back the state * * @param The file descriptor * @result The final state */ inotify_close :: *(Inotify st) -> st /** * Add a watch on some file * * @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 */ inotify_add_watch :: (INCallback st) !INMask !String !*(Inotify st) -> *(!Either Int INWatch, !*Inotify st) /** * Remove a watch * * @param The watch to remove * @param The inotify file descriptor * @result A boolean indicating success and the inotify file descriptor */ inotify_rm_watch :: !INWatch !*(Inotify st) -> *(!Bool, !*Inotify st) /** * Poll an inotify file descriptor; i.e. wait for new events * * @param Timeout in milliseconds (Nothing for no timeout) * @param The inotify file descriptor * @result The number of events, and the inotify file descriptor */ inotify_poll :: !(Maybe Int) !*(Inotify st) -> *(!Int, !*Inotify st) /** * Check for new events and call callbacks */ inotify_check :: !*(Inotify st) !*World -> *(!*Inotify st, !*World) /** * Check if an event matches a mask * * @param The mask * @param The event * @result True iff the event matches the mask */ 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. * * @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. */ inotify_loop_with_timeout :: !(Maybe Int) !*(Inotify st) !*World -> *(!*Inotify st, !*World) /** * inotify_loop_with_timeout with Nothing as timeout (will never return) * * @param The inotify file descriptor * @param The World * @result The parameters back, however, this function will never return. */ inotify_loop_forever :: !*(Inotify st) !*World -> *(!*Inotify st, !*World) /*** Begin inotify.h ***/ //* Inotify event mask: file was accessed IN_ACCESS :== 0x00000001 //* Inotify event mask: file was modified IN_MODIFY :== 0x00000002 //* Inotify event mask: metadata changed IN_ATTRIB :== 0x00000004 //* Inotify event mask: file opened for writing was closed IN_CLOSE_WRITE :== 0x00000008 //* Inotify event mask: file not opened for writing was closed IN_CLOSE_NOWRITE :== 0x00000010 //* Inotify event mask: file was opened IN_OPEN :== 0x00000020 //* Inotify event mask: file was moved from watched directory IN_MOVED_FROM :== 0x00000040 //* Inotify event mask: file was moved to watched directory IN_MOVED_TO :== 0x00000080 //* Inotify event mask: file was created in watched directory IN_CREATE :== 0x00000100 //* Inotify event mask: file in watched directory was deleted IN_DELETE :== 0x00000200 //* Inotify event mask: watched file was deleted IN_DELETE_SELF :== 0x00000400 //* Inotify event mask: watched file was moved IN_MOVE_SELF :== 0x00000800 //* Inotify event mask: backing fs of watched file was unmounted IN_UNMOUNT :== 0x00002000 //* Inotify event mask: the inotify event queue overflowed 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 * @type Int */ IN_CLOSE :== (IN_CLOSE_WRITE |- IN_CLOSE_NOWRITE) /** * Inotify event mask: a file was moved from or to a watched directory * @type Int */ IN_MOVE :== (IN_MOVED_FROM |- IN_MOVED_TO) //* Inotify event mask: only watch the path if it is a directory IN_ONLYDIR :== 0x01000000 //* Inotify event mask: don't follow symlinks IN_DONT_FOLLOW :== 0x02000000 //* Inotify event mask: stop watching files when they get unlinked 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 //* Inotify event mask: the event occurred against a directory IN_ISDIR :== 0x40000000 //* Inotify event mask: monitor a watch only for one event, then remove it IN_ONESHOT :== 0x80000000 /** * Inotify event mask: OR of all events * @type Int */ 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) /*** End inotify.h ***/