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.
| Modifier and Type | Class and Description |
|---|---|
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| 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_STRUCTURE_ALIGNMENT
Option key for structure alignment type ( |
| public static final String | OPTION_TYPE_MAPPER
Option key for a |
| 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_STRUCTURE_ALIGNMENT | back to summary |
|---|---|
| public static final String OPTION_STRUCTURE_ALIGNMENT Option key for structure alignment type ( | |
| 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 | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private FunctionMapper | |
| private final Map | |
| private final Class | |
| private 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. |
| callingConvention | back to summary |
|---|---|
| private int callingConvention | |
| functionMapper | back to summary |
|---|---|
| private FunctionMapper functionMapper | |
| functions | back to summary |
|---|---|
| private final Map<K, V> functions | |
| interfaceClass | back to summary |
|---|---|
| private final Class<T> interfaceClass | |
| invocationMapper | back to summary |
|---|---|
| private 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<K, V> options | |
| Handler | back to summary |
|---|---|
| public Handler(String libname, Class<T> interfaceClass, Map<K, V> 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.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv Function | |
| pack-priv InvocationHandler | |
| pack-priv boolean | |
| pack-priv Map |
| Access | Constructor and Description |
|---|---|
| private |
| function | back to summary |
|---|---|
| pack-priv Function function | |
| handler | back to summary |
|---|---|
| pack-priv InvocationHandler handler | |
| isVarArgs | back to summary |
|---|---|
| pack-priv boolean isVarArgs | |
| options | back to summary |
|---|---|
| pack-priv Map<K, V> options | |
| FunctionInfo | back to summary |
|---|---|
| private FunctionInfo() | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | getFunctionName(NativeLibrary library, Method method)
Implements com. |
| map | back to summary |
|---|---|
| private final Map<K, V> map | |
| FunctionNameMap | back to summary |
|---|---|
| public FunctionNameMap(Map<K, V> map) | |
| getFunctionName | back to summary |
|---|---|
| public String getFunctionName(NativeLibrary library, Method method) Implements com. | |