Top Description Inners Fields
com.sun.jna

public Interface Library

Known Direct Subinterfaces
com.sun.jna.examples.CLibrary, com.sun.jna.examples.unix.X11, com.sun.jna.examples.unix.X11.Xext, com.sun.jna.examples.unix.X11.Xrender, com.sun.jna.win32.StdCallLibrary
Imports
java.lang.reflect.InvocationHandler, .Method, .Proxy, java.util.Arrays, .Collection, .HashMap, .Map, .WeakHashMap

Derive from this interface for all native library definitions. Define an instance of your library like this:
MyNativeLibrary INSTANCE = (MyNativeLibrary)
    Native.loadLibrary("mylib", MyNativeLibrary.class);

By convention, method names are identical to the native names, although you can map java names to different native names by providing a FunctionMapper as a value for key OPTION_FUNCTION_MAPPER in the options map passed to the Native#loadLibrary(String, Class, Map) call.

Although the names for structures and structure fields may be chosen arbitrarily, they should correspond as closely as possible to the native definitions. The same is true for parameter names.

This interface supports multiple, concurrent invocations of any library methods on the Java side. Check your library documentation for its multi-threading requirements on the native side. If a library is not safe for simultaneous multi-threaded access, consider using Native#synchronizedLibrary to prevent simultaneous multi-threaded access to the native code.

Optional fields
Interface options will be automatically propagated to structures defined within the library provided a call to Native#loadLibrary(String, Class, Map) is made prior to instantiating any of those structures. One common way of ensuring this is to declare an INSTANCE field in the interface which holds the loadLibrary result.

OPTIONS (an instance of Map), TYPE_MAPPER (an instance of TypeMapper) and STRUCTURE_ALIGNMENT (one of the alignment types defined in Structure) may also be defined. If no instance of the interface has been instantiated, these fields will be used to determine customization settings for structures and methods defined within the interface.

Authors
Todd Fast, [email protected], Timothy Wall, [email protected]

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public static final String
OPTION_FUNCTION_MAPPER

Option key for a FunctionMapper for the library.

public static final String
OPTION_INVOCATION_MAPPER

Option key for an InvocationMapper for the library.

public static final String
OPTION_STRUCTURE_ALIGNMENT

Option key for structure alignment type (Integer), which should be one of the predefined alignment types in Structure.

public static final String
OPTION_TYPE_MAPPER

Option key for a TypeMapper for the library.

Field Detail

OPTION_FUNCTION_MAPPERback to summary
public static final String OPTION_FUNCTION_MAPPER

Option key for a FunctionMapper for the library.

OPTION_INVOCATION_MAPPERback to summary
public static final String OPTION_INVOCATION_MAPPER

Option key for an InvocationMapper for the library.

OPTION_STRUCTURE_ALIGNMENTback to summary
public static final String OPTION_STRUCTURE_ALIGNMENT

Option key for structure alignment type (Integer), which should be one of the predefined alignment types in Structure.

OPTION_TYPE_MAPPERback to summary
public static final String OPTION_TYPE_MAPPER

Option key for a TypeMapper for the library.

com.sun.jna back to summary

public Class Library.Handler

extends Object
implements InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private int
private FunctionMapper
private final Map<K, V>
private final Class<T>
private InvocationMapper
private final NativeLibrary
pack-priv static final Method
pack-priv static final Method
pack-priv static final Method
private final Map<K, V>

Constructor Summary

AccessConstructor and Description
public
Handler(String libname, Class<T> interfaceClass, Map<K, V> options)

Method Summary

Modifier and TypeMethod and Description
public Class<T>
public String
public NativeLibrary
public Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
inArgs
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callingConventionback to summary
private int callingConvention
functionMapperback to summary
private FunctionMapper functionMapper
functionsback to summary
private final Map<K, V> functions
interfaceClassback to summary
private final Class<T> interfaceClass
invocationMapperback to summary
private InvocationMapper invocationMapper
nativeLibraryback to summary
private final NativeLibrary nativeLibrary
OBJECT_EQUALSback to summary
pack-priv static final Method OBJECT_EQUALS
OBJECT_HASHCODEback to summary
pack-priv static final Method OBJECT_HASHCODE
OBJECT_TOSTRINGback to summary
pack-priv static final Method OBJECT_TOSTRING
optionsback to summary
private final Map<K, V> options

Constructor Detail

Handlerback to summary
public Handler(String libname, Class<T> interfaceClass, Map<K, V> options)

Method Detail

getInterfaceClassback to summary
public Class<T> getInterfaceClass()
getLibraryNameback to summary
public String getLibraryName()
getNativeLibraryback to summary
public NativeLibrary getNativeLibrary()
invokeback to summary
public Object invoke(Object proxy, Method method, Object[] inArgs) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

inArgs:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.
com.sun.jna back to summary

private Class Library.Handler.FunctionInfo

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Function
pack-priv InvocationHandler
pack-priv boolean
pack-priv Map<K, V>

Constructor Summary

AccessConstructor and Description
private

Field Detail

functionback to summary
pack-priv Function function
handlerback to summary
pack-priv InvocationHandler handler
isVarArgsback to summary
pack-priv boolean isVarArgs
optionsback to summary
pack-priv Map<K, V> options

Constructor Detail

FunctionInfoback to summary
private FunctionInfo()
com.sun.jna back to summary

private Class Library.Handler.FunctionNameMap

extends Object
implements FunctionMapper
Class Inheritance
All Implemented Interfaces
com.sun.jna.FunctionMapper

Field Summary

Modifier and TypeField and Description
private final Map<K, V>

Constructor Summary

AccessConstructor and Description
public
FunctionNameMap(Map<K, V> map)

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
private final Map<K, V> map

Constructor Detail

FunctionNameMapback to summary
public FunctionNameMap(Map<K, V> map)

Method Detail

getFunctionNameback to summary
public String getFunctionName(NativeLibrary library, Method method)

Implements com.sun.jna.FunctionMapper.getFunctionName.