public class Function extends Pointer
An abstraction for a native function pointer. An instance of
Function
represents a pointer to some native function.
invoke(Class,Object[],Map)
is the primary means to call
the function.
C_CONVENTION
Use C calling convention (default)
ALT_CONVENTION
Use alternate calling convention (e.g. stdcall)
THROW_LAST_ERROR
Throw a LastErrorException
if
the native function sets the system error to a non-zero value (errno or
GetLastError). Setting this flag will cause the system error to be cleared
prior to native function invocation.
Pointer
Modifier and Type | Class and Description |
---|---|
static interface |
Function.PostCallRead
Any argument which implements this interface will have the
Function.PostCallRead.read() method called immediately after function invocation. |
Modifier and Type | Field and Description |
---|---|
static int |
ALT_CONVENTION
First alternate convention (currently used only for w32 stdcall).
|
static int |
C_CONVENTION
Standard C calling convention.
|
(package private) int |
callFlags |
(package private) java.lang.String |
encoding |
(package private) static java.lang.Integer |
INTEGER_FALSE |
(package private) static java.lang.Integer |
INTEGER_TRUE |
static int |
MAX_NARGS
Maximum number of arguments supported by a JNA function call.
|
(package private) static java.lang.String |
OPTION_INVOKING_METHOD
For internal JNA use.
|
(package private) java.util.Map<java.lang.String,?> |
options |
static int |
THROW_LAST_ERROR
Whether to throw an exception if last error is non-zero after call.
|
static int |
USE_VARARGS
Mask for number of fixed args (1-3) for varargs calls.
|
Constructor and Description |
---|
Function(NativeLibrary library,
java.lang.String functionName,
int callFlags,
java.lang.String encoding)
Create a new
Function that is linked with a native
function that follows the given calling convention. |
Function(Pointer functionAddress,
int callFlags,
java.lang.String encoding)
Create a new
Function that is linked with a native
function that follows the given calling convention. |
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.Object[] |
concatenateVarArgs(java.lang.Object[] inArgs)
Concatenate varargs with normal args to obtain a simple argument
array.
|
boolean |
equals(java.lang.Object o)
Two function pointers are equal if they share the same peer address
and calling convention.
|
(package private) static int |
fixedArgs(java.lang.reflect.Method m)
Varargs are only supported on 1.5+.
|
int |
getCallingConvention() |
static Function |
getFunction(Pointer p)
Obtain a
Function representing a native
function pointer. |
static Function |
getFunction(Pointer p,
int callFlags)
Obtain a
Function representing a native
function pointer. |
static Function |
getFunction(Pointer p,
int callFlags,
java.lang.String encoding)
Obtain a
Function representing a native
function pointer. |
static Function |
getFunction(java.lang.String libraryName,
java.lang.String functionName)
Obtain a
Function representing a native
function that follows the standard "C" calling convention. |
static Function |
getFunction(java.lang.String libraryName,
java.lang.String functionName,
int callFlags)
Obtain a
Function representing a native
function. |
static Function |
getFunction(java.lang.String libraryName,
java.lang.String functionName,
int callFlags,
java.lang.String encoding)
Obtain a
Function representing a native
function. |
java.lang.String |
getName() |
int |
hashCode()
Provide a unique hash code for
Function s which are
equivalent. |
java.lang.Object |
invoke(java.lang.Class<?> returnType,
java.lang.Object[] inArgs)
Invoke the native function with the given arguments, returning the
native result as an Object.
|
java.lang.Object |
invoke(java.lang.Class<?> returnType,
java.lang.Object[] inArgs,
java.util.Map<java.lang.String,?> options)
Invoke the native function with the given arguments, returning the
native result as an Object.
|
(package private) java.lang.Object |
invoke(java.lang.reflect.Method invokingMethod,
java.lang.Class<?>[] paramTypes,
java.lang.Class<?> returnType,
java.lang.Object[] inArgs,
java.util.Map<java.lang.String,?> options)
Invoke the native function with the given arguments, returning the
native result as an Object.
|
void |
invoke(java.lang.Object[] args)
Call the native function being represented by this object
|
(package private) java.lang.Object |
invoke(java.lang.Object[] args,
java.lang.Class<?> returnType,
boolean allowObjects) |
(package private) java.lang.Object |
invoke(java.lang.Object[] args,
java.lang.Class<?> returnType,
boolean allowObjects,
int fixedArgs) |
double |
invokeDouble(java.lang.Object[] args)
Convenience method for
invoke(Double.class, args) . |
float |
invokeFloat(java.lang.Object[] args)
Convenience method for
invoke(Float.class, args) . |
int |
invokeInt(java.lang.Object[] args)
Convenience method for
invoke(Integer.class, args) . |
long |
invokeLong(java.lang.Object[] args)
Convenience method for
invoke(Long.class, args) . |
java.lang.Object |
invokeObject(java.lang.Object[] args)
Convenience method for
invokeObject(Object.class, args) . |
Pointer |
invokePointer(java.lang.Object[] args)
Convenience method for
invoke(Pointer.class, args) . |
java.lang.String |
invokeString(java.lang.Object[] args,
boolean wide)
Convenience method for
invoke(String.class, args)
or invoke(WString.class, args) |
void |
invokeVoid(java.lang.Object[] args)
Convenience method for
invoke(Void.class, args) . |
(package private) static boolean |
isVarArgs(java.lang.reflect.Method m)
Varargs are only supported on 1.5+.
|
java.lang.String |
toString()
Provide a human-readable representation of this object.
|
(package private) static java.lang.Boolean |
valueOf(boolean b)
Implementation of Boolean.valueOf for older VMs.
|
clear, createConstant, createConstant, dump, getByte, getByteArray, getByteBuffer, getChar, getCharArray, getDouble, getDoubleArray, getFloat, getFloatArray, getInt, getIntArray, getLong, getLongArray, getNativeLong, getPointer, getPointerArray, getPointerArray, getShort, getShortArray, getString, getString, getStringArray, getStringArray, getStringArray, getStringArray, getValue, getWideString, getWideStringArray, getWideStringArray, indexOf, nativeValue, nativeValue, read, read, read, read, read, read, read, read, setByte, setChar, setDouble, setFloat, setInt, setLong, setMemory, setNativeLong, setPointer, setShort, setString, setString, setString, setValue, setWideString, share, share, write, write, write, write, write, write, write, write
@Native public static final int MAX_NARGS
@Native public static final int C_CONVENTION
@Native public static final int ALT_CONVENTION
@Native public static final int THROW_LAST_ERROR
@Native public static final int USE_VARARGS
static final java.lang.Integer INTEGER_TRUE
static final java.lang.Integer INTEGER_FALSE
final java.lang.String encoding
final int callFlags
final java.util.Map<java.lang.String,?> options
static final java.lang.String OPTION_INVOKING_METHOD
Function(NativeLibrary library, java.lang.String functionName, int callFlags, java.lang.String encoding)
Function
that is linked with a native
function that follows the given calling convention.
The allocated instance represents a pointer to the named native function from the supplied library, called with the given calling convention.
library
- NativeLibrary
in which to find the functionfunctionName
- Name of the native function to be linked withcallFlags
- Function call flagsencoding
- Encoding for conversion between Java and native strings.java.lang.UnsatisfiedLinkError
- if the given function name is
not found within the library.Function(Pointer functionAddress, int callFlags, java.lang.String encoding)
Function
that is linked with a native
function that follows the given calling convention.
The allocated instance represents a pointer to the given function address, called with the given calling convention.
functionAddress
- Address of the native functioncallFlags
- Function call flagsencoding
- Encoding for conversion between Java and native strings.public static Function getFunction(java.lang.String libraryName, java.lang.String functionName)
Function
representing a native
function that follows the standard "C" calling convention.
The allocated instance represents a pointer to the named native function from the named library, called with the standard "C" calling convention.
libraryName
- Library in which to find the native functionfunctionName
- Name of the native function to be linked withjava.lang.UnsatisfiedLinkError
- if the library is not found or
the given function name is not found within the library.public static Function getFunction(java.lang.String libraryName, java.lang.String functionName, int callFlags)
Function
representing a native
function.
The allocated instance represents a pointer to the named native function from the named library.
libraryName
- Library in which to find the functionfunctionName
- Name of the native function to be linked withcallFlags
- Function call flagsjava.lang.UnsatisfiedLinkError
- if the library is not found or
the given function name is not found within the library.public static Function getFunction(java.lang.String libraryName, java.lang.String functionName, int callFlags, java.lang.String encoding)
Function
representing a native
function.
The allocated instance represents a pointer to the named native function from the named library.
libraryName
- Library in which to find the functionfunctionName
- Name of the native function to be linked withcallFlags
- Function call flagsencoding
- Encoding to use for conversion between Java and native
strings.java.lang.UnsatisfiedLinkError
- if the library is not found or
the given function name is not found within the library.public static Function getFunction(Pointer p)
Function
representing a native
function pointer. In general, this function should be used by dynamic
languages; Java code should allow JNA to bind to a specific Callback
interface instead by defining a return type or Structure field type.
The allocated instance represents a pointer to the native function pointer.
p
- Native function pointerpublic static Function getFunction(Pointer p, int callFlags)
Function
representing a native
function pointer. In general, this function should be used by dynamic
languages; Java code should allow JNA to bind to a specific Callback
interface instead by defining a return type or Structure field type.
The allocated instance represents a pointer to the native function pointer.
p
- Native function pointercallFlags
- Function call flagspublic static Function getFunction(Pointer p, int callFlags, java.lang.String encoding)
Function
representing a native
function pointer. In general, this function should be used by dynamic
languages; Java code should allow JNA to bind to a specific Callback
interface instead by defining a return type or Structure field type.
The allocated instance represents a pointer to the native function pointer.
p
- Native function pointercallFlags
- Function call flagsencoding
- Encoding to use for conversion between Java and native
strings.public java.lang.String getName()
public int getCallingConvention()
public java.lang.Object invoke(java.lang.Class<?> returnType, java.lang.Object[] inArgs)
public java.lang.Object invoke(java.lang.Class<?> returnType, java.lang.Object[] inArgs, java.util.Map<java.lang.String,?> options)
java.lang.Object invoke(java.lang.reflect.Method invokingMethod, java.lang.Class<?>[] paramTypes, java.lang.Class<?> returnType, java.lang.Object[] inArgs, java.util.Map<java.lang.String,?> options)
invoke(Class, Object[], Map)
,
the method has to be in the options under key OPTION_INVOKING_METHOD
.java.lang.Object invoke(java.lang.Object[] args, java.lang.Class<?> returnType, boolean allowObjects)
java.lang.Object invoke(java.lang.Object[] args, java.lang.Class<?> returnType, boolean allowObjects, int fixedArgs)
public void invoke(java.lang.Object[] args)
args
- Arguments to pass to the native functionpublic java.lang.String toString()
public java.lang.Object invokeObject(java.lang.Object[] args)
invokeObject(Object.class, args)
.public Pointer invokePointer(java.lang.Object[] args)
invoke(Pointer.class, args)
.public java.lang.String invokeString(java.lang.Object[] args, boolean wide)
invoke(String.class, args)
or invoke(WString.class, args)
args
- Arguments passed to native functionwide
- Whether the return value is of type wchar_t*
;
if false, the return value is of type char*
.public int invokeInt(java.lang.Object[] args)
invoke(Integer.class, args)
.public long invokeLong(java.lang.Object[] args)
invoke(Long.class, args)
.public float invokeFloat(java.lang.Object[] args)
invoke(Float.class, args)
.public double invokeDouble(java.lang.Object[] args)
invoke(Double.class, args)
.public void invokeVoid(java.lang.Object[] args)
invoke(Void.class, args)
.public boolean equals(java.lang.Object o)
public int hashCode()
Function
s which are
equivalent.static java.lang.Object[] concatenateVarArgs(java.lang.Object[] inArgs)
static boolean isVarArgs(java.lang.reflect.Method m)
static int fixedArgs(java.lang.reflect.Method m)
static java.lang.Boolean valueOf(boolean b)