auto i=x::inotify::create(); x::ref<x::obj> w=i->create(".", x::inotify_create | x::inotify_delete, [] (uint32_t mask, uint32_t cookie, const char *name) { // Do something }); i->read();
The
inotify(7)
API is a mechanism for applications to monitor the contents
of a directory or a file, and be notified when it changes.
The x::inotify
handle is a file descriptor handle. A single
x::inotify
handle may be used to monitor
multiple files or directories.
x::inotify
handle's
create
() method begins monitoring a new directory
or a file. Its first parameter specifies the directory or the file
to monitor.
The second parameter is a set of one or more flags:
x::inotify_access
,
x::inotify_attrib
,
x::inotify_close
,
x::inotify_close_nowrite
,
x::inotify_close_write
,
x::inotify_create
,
x::inotify_delete
,
x::inotify_delete_self
,
x::inotify_dont_follow
,
x::inotify_excl_unlink
,
x::inotify_modify
,
x::inotify_move
,
x::inotify_move_self
,
x::inotify_moved_from
,
x::inotify_moved_to
, and
x::inotify_open
;
this selects which events to report.
The third parameter is a lambda that gets invoked when the
selected event occured. The first parameter is one of the events that
have occured; additionally
x::inotify_ignored
,
x::inotify_isdir
,
or
x::inotify_unmount
could be reported too.
The second parameter is an event cookie (this is used mostly to
link together the
x::inotify_moved_from
and
x::inotify_moved_to
events.
The third parameter is the file or the directory pathname whose event
is reported.
create
() return a
mcguffin handle for the events being
monitored.
x::inotify
's read
()
reads one or more events from the underlying file descriptors, and
invokes the appropriate lambdas. There is no explicit call to
stop monitoring, when the last reference to the
mcguffin handle goes out of scope, and it gets destroyed, the monitoring
stops automatically.
The x::inotify
handle is a blocking file
descriptor by default.
Use nonblock
() to put the inotify handle
into non-blocking mode.