12 messages in net.java.dev.jna.usersRe: [jna-users] Requiring Library sup...
FromSent OnAttachments
Charles Oliver NutterSep 4, 2007 8:36 am 
Timothy WallSep 4, 2007 9:01 am 
Charles Oliver NutterSep 4, 2007 9:50 am 
Timothy WallSep 4, 2007 10:29 am 
Charles Oliver NutterSep 4, 2007 12:59 pm 
Wayne MeissnerSep 4, 2007 7:13 pm 
Philip JenveySep 4, 2007 9:38 pm 
Wayne MeissnerSep 4, 2007 10:01 pm 
Charles Oliver NutterSep 4, 2007 10:40 pm 
Wayne MeissnerSep 4, 2007 11:41 pm 
Charles Oliver NutterSep 5, 2007 12:04 am 
Timothy WallSep 5, 2007 5:45 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] Requiring Library superinterface?Actions...
From:Wayne Meissner (wmei@gmail.com)
Date:Sep 4, 2007 7:13:46 pm
List:net.java.dev.jna.users

Charles Oliver Nutter wrote:

Why is it that native library definition interfaces must derive from com.sun.jna.Library?

In JRuby, we'd like to have the option of compiling/running without JNA, and that generally means being able to avoid all static references to JNA classes. I can use reflection to load up com.sun.jna.Native and loadLibrary that way, but I eventually have to have a real interface to use. Because that interface must derive from Library, I'm sunk if JNA isn't present.

Would it be possible to eliminate this requirement? The eventual library returned could still implement Library, but requiring me to extend it seems a bit of a problem.

One work around would be to implement your own equivalents of Library and Library.Handler using a Proxy.

At a really basic level, all your Proxy.invoke() needs to do is call:

NativeLibrary.getInstance(libraryName).getFunction(method.getName()).invoke(method.getReturnType(), args, Collections.EMPTY_MAP);

Like Timothy said, you do lose access to TypeMappers and custom alignments on structures, but for most posix things, these are probably superfluous anyway.