MyNativeLibrary INSTANCE = (MyNativeLibrary)
Native.load("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#load(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#load(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
load result.
OPTIONS (an instance of Map),
TYPE_MAPPER (an instance of TypeMapper),
STRUCTURE_ALIGNMENT (one of the alignment types defined in
Structure), and STRING_ENCODING (a String) 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.
| Modifier and Type | Class and Description |
|---|---|
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | OPTION_ALLOW_OBJECTS
Option key for a boolean flag to allow any Java class instance as a parameter. |
| public static final String | OPTION_CALLING_CONVENTION
Calling convention for the entire library. |
| public static final String | OPTION_CLASSLOADER
Class loader to use when searching for native libraries on the resource path (classpath). |
| public static final String | OPTION_FUNCTION_MAPPER
Option key for a |
| public static final String | OPTION_INVOCATION_MAPPER
Option key for an |
| public static final String | OPTION_OPEN_FLAGS
Flags to use when opening the native library (see |
| public static final String | OPTION_STRING_ENCODING
Option key for per-library String encoding. |
| public static final String | OPTION_STRUCTURE_ALIGNMENT
Option key for structure alignment type ( |
| public static final String | OPTION_SYMBOL_PROVIDER
Supports a custom symbol provider for the NativeLibrary (see |
| public static final String | OPTION_TYPE_MAPPER
Option key for a |
| OPTION_ALLOW_OBJECTS | back to summary |
|---|---|
| public static final String OPTION_ALLOW_OBJECTS Option key for a boolean flag to allow any Java class instance as a parameter. If no type mapper is found, the object is passed as a pointer Note This is for use with raw JNI interactions via the JNIEnv data structure. | |
| OPTION_CALLING_CONVENTION | back to summary |
|---|---|
| public static final String OPTION_CALLING_CONVENTION Calling convention for the entire library. | |
| OPTION_CLASSLOADER | back to summary |
|---|---|
| public static final String OPTION_CLASSLOADER Class loader to use when searching for native libraries on the resource path (classpath). If not provided the current thread's context class loader is used. If extracted from the resource path (i.e. bundled in a jar file), the loaded library's lifespan will mirror that of the class loader, which means you can use the same library in isolated contexts without conflict. | |
| OPTION_FUNCTION_MAPPER | back to summary |
|---|---|
| public static final String OPTION_FUNCTION_MAPPER Option key for a | |
| OPTION_INVOCATION_MAPPER | back to summary |
|---|---|
| public static final String OPTION_INVOCATION_MAPPER Option key for an | |
| OPTION_OPEN_FLAGS | back to summary |
|---|---|
| public static final String OPTION_OPEN_FLAGS Flags to use when opening the native library (see | |
| OPTION_STRING_ENCODING | back to summary |
|---|---|
| public static final String OPTION_STRING_ENCODING Option key for per-library String encoding. This affects conversions
between Java unicode and native ( Native#getDefaultStringEncoding().
| |
| OPTION_STRUCTURE_ALIGNMENT | back to summary |
|---|---|
| public static final String OPTION_STRUCTURE_ALIGNMENT Option key for structure alignment type ( | |
| OPTION_SYMBOL_PROVIDER | back to summary |
|---|---|
| public static final String OPTION_SYMBOL_PROVIDER Supports a custom symbol provider for the NativeLibrary (see | |
| OPTION_TYPE_MAPPER | back to summary |
|---|---|
| public static final String OPTION_TYPE_MAPPER Option key for a | |
| Modifier and Type | Class and Description |
|---|---|
| private static class | Library.Handler.FunctionInfo
FunctionInfo has to be immutable to to make the object visible to other threads fully initialized. |
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| private final Class | |
| private final InvocationMapper | |
| private final NativeLibrary | |
| pack-priv static final Method | |
| pack-priv static final Method | |
| pack-priv static final Method | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Class | |
| public String | |
| public NativeLibrary | |
| public Object | invoke(Object
the proxy instance that the method was invoked on proxy, Method the method, Object[] 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.an array of objects containing the values of the
arguments passed in the method invocation on the proxy instance,
or inArgs)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.Implements java. |
| functions | back to summary |
|---|---|
| private final Map<Method, Library. | |
| interfaceClass | back to summary |
|---|---|
| private final Class<?> interfaceClass | |
| invocationMapper | back to summary |
|---|---|
| private final InvocationMapper invocationMapper | |
| nativeLibrary | back to summary |
|---|---|
| private final NativeLibrary nativeLibrary | |
| OBJECT_EQUALS | back to summary |
|---|---|
| pack-priv static final Method OBJECT_EQUALS | |
| OBJECT_HASHCODE | back to summary |
|---|---|
| pack-priv static final Method OBJECT_HASHCODE | |
| OBJECT_TOSTRING | back to summary |
|---|---|
| pack-priv static final Method OBJECT_TOSTRING | |
| options | back to summary |
|---|---|
| private final Map<String, Object> options | |
| Handler | back to summary |
|---|---|
| public Handler(String libname, Class<?> interfaceClass, Map<String, ?> options) | |
| getInterfaceClass | back to summary |
|---|---|
| public Class | |
| getLibraryName | back to summary |
|---|---|
| public String getLibraryName() | |
| getNativeLibrary | back to summary |
|---|---|
| public NativeLibrary getNativeLibrary() | |
| invoke | back to summary |
|---|---|
| public Object invoke(Object proxy, Method method, Object[] inArgs) throws Throwable Implements java. Doc from java. 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.
| |
Handler#invoke(Object, Method, Object[])
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Function | |
| pack-priv final InvocationHandler | |
| pack-priv final boolean | |
| pack-priv final Object | |
| pack-priv final Map | |
| pack-priv final Class |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | FunctionInfo(InvocationHandler handler, Function function, Class<?>[] parameterTypes, boolean isVarArgs, Map<String, ?> options)
|
| function | back to summary |
|---|---|
| pack-priv final Function function | |
| handler | back to summary |
|---|---|
| pack-priv final InvocationHandler handler | |
| isVarArgs | back to summary |
|---|---|
| pack-priv final boolean isVarArgs | |
| methodHandle | back to summary |
|---|---|
| pack-priv final Object methodHandle | |
| options | back to summary |
|---|---|
| pack-priv final Map<String, ?> options | |
| parameterTypes | back to summary |
|---|---|
| pack-priv final Class<?>[] parameterTypes | |
| FunctionInfo | back to summary |
|---|---|
| pack-priv FunctionInfo(Object mh) | |
| FunctionInfo | back to summary |
|---|---|
| pack-priv FunctionInfo(InvocationHandler handler, Function function, Class<?>[] parameterTypes, boolean isVarArgs, Map<String, ?> options) | |