2 messages in net.java.dev.jna.usersRe: [jna-users] KQueueFileMonitor exa...
FromSent OnAttachments
Olivier ChafikMar 13, 2008 5:36 pm 
Timothy WallMar 14, 2008 6:55 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] KQueueFileMonitor example contribution (for Mac OS X & other BSD-derivatives)Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Mar 14, 2008 6:55:33 am
List:net.java.dev.jna.users

On Mar 13, 2008, at 8:37 PM, Olivier Chafik wrote:

Hi All,

I would like to contribute a FileMonitor implementation for Mac OS X and BSD systems, as part of JNA's example classes. It compiles against the latest SVN version of JNA :

http://ochafik.free.fr/Java/src/jna/FileMonitor.java http://ochafik.free.fr/Java/src/jna/unix/bsd/CLibrary.java

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.