On Mar 13, 2008, at 8:37 PM, Olivier Chafik wrote:
That's great!
I started by a naive implementation, using one kqueue and one
thread per watched file (still available here :
http://ochafik.free.fr/Java/src/jna/NaiveKQueueFileMonitor.java)
, but this was not scalable enough so I wrote a more elaborate
version which only uses one dedicated thread and kqueue + an extra
synchronization file (used as a way to interrupt calls to kevent
prematurely, so as to add/remove watched files).
None of these implementations actually support the "recursive"
argument of FileMonitor.addWatch. I'm still unsure of what its exact
behaviour should be (and it can be implemented outside of the
FileMonitor anyway).
The recursive argument intends to generate events on any file changes
below the selected directory (obviously it doesn't make sense on a
file).
Besides, I'm having some beginner-level issues when trying to store
an int value inside a void pointer value (void* kevent.udata). Of
course, there is the Pointer.createConstant(long) that does the
storage part, but to retrieve the value, doing
Pointer.getPointer().getInt(0) only yields a JNA error saying that
the pointer is opaque... I'm sure I'm missing something obvious
here, could anyone enlighten me on this one ?
Since the data is within a structure, why not define it as a union?
e.g.
class UData extends Union {
Pointer u_ptr;
int u_int;
}
and call union.setType(int.class) on it to indicate that's the field
you want used when the union writes to native memory.
you can also do Structure.getPointer().share(field_offset) and do
setInt/setPointer on it.
I could not find any way to track a renamed file in Mac OS X / BSD.
Its file descriptor remains valid and kevent still gets modification
events, but there is no apparent way to retrieve its new path.
Possible areas of investigation might be in the getdents function.
Has anyone already experienced some success here ?
Better to try apple's cocoa-dev list or the darwin dev list for that
one.