com.kenai.jffi
Class Invoker

java.lang.Object
  extended by com.kenai.jffi.Invoker

public abstract class Invoker
extends java.lang.Object

Provides native function invocation facilities.


Method Summary
static Invoker getInstance()
          Gets the Invoker singleton.
 ObjectParameterInvoker getObjectParameterInvoker()
          Gets the fast-path object parameter invoker.
 void invoke(CallContext ctx, long function, long returnBuffer, long[] parameters)
          Invokes a function, with the parameters loaded into native memory buffers, and the function result is stored in a native memory buffer.
 void invoke(Function function, long returnBuffer, long[] parameters)
          Invokes a function, with the parameters loaded into native memory buffers, and the function result is stored in a native memory buffer.
abstract  long invokeAddress(CallContext ctx, long function, HeapInvocationBuffer buffer)
          Invokes a function and returns a native memory address.
abstract  long invokeAddress(Function function, HeapInvocationBuffer buffer)
          Invokes a function and returns a native memory address.
 double invokeDouble(CallContext ctx, long function, HeapInvocationBuffer buffer)
          Invokes a function and returns a 64 bit floating point value.
 double invokeDouble(Function function, HeapInvocationBuffer buffer)
          Invokes a function and returns a 64 bit floating point value.
 float invokeFloat(CallContext ctx, long function, HeapInvocationBuffer buffer)
          Invokes a function and returns a 32 bit floating point value.
 float invokeFloat(Function function, HeapInvocationBuffer buffer)
          Invokes a function and returns a 32 bit floating point value.
 float invokeIIIrF(Function function, int arg1, int arg2, int arg3)
          Invokes a function with three integer arguments, and returns a 32 bit float.
 int invokeIIIrI(Function function, int arg1, int arg2, int arg3)
          Invokes a function with three integer arguments, and returns a 32 bit integer.
 float invokeIIrF(Function function, int arg1, int arg2)
          Invokes a function with two integer arguments, and returns a 32 bit float.
 int invokeIIrI(Function function, int arg1, int arg2)
          Invokes a function with two integer arguments, and returns a 32 bit integer.
 int invokeInt(CallContext ctx, long function, HeapInvocationBuffer buffer)
          Invokes a function and returns a 32 bit integer value.
 int invokeInt(Function function, HeapInvocationBuffer buffer)
          Invokes a function and returns a 32 bit integer value.
 float invokeIrF(Function function, int arg1)
          Invokes a function with one integer argument, and returns a 32 bit float.
 int invokeIrI(Function function, int arg1)
          Invokes a function with one integer argument, and returns a 32 bit integer.
 long invokeLLLLLLrL(Function function, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6)
          Invokes a function with six 64 bit integer arguments, and returns a 64 bit integer.
 long invokeLLLLLrL(Function function, long arg1, long arg2, long arg3, long arg4, long arg5)
          Invokes a function with five 64 bit integer arguments, and returns a 64 bit integer.
 long invokeLLLLrL(Function function, long arg1, long arg2, long arg3, long arg4, long arg5)
          Invokes a function with four 64 bit integer arguments, and returns a 64 bit integer.
 long invokeLLLrL(Function function, long arg1, long arg2, long arg3)
          Invokes a function with three 64 bit integer arguments, and returns a 64 bit integer.
 long invokeLLrL(Function function, long arg1, long arg2)
          Invokes a function with two 64 bit integer arguments, and returns a 64 bit integer.
 long invokeLong(CallContext ctx, long function, HeapInvocationBuffer buffer)
          Invokes a function and returns a 64 bit integer value.
 long invokeLong(Function function, HeapInvocationBuffer buffer)
          Invokes a function and returns a 64 bit integer value.
 long invokeLrL(Function function, long arg1)
          Invokes a function with one 64 bit integer argument, and returns a 64 bit integer.
 long invokeNNNNNNrN(Function function, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6)
          Invokes a function with six numeric arguments, and returns a numeric value.
 long invokeNNNNNrN(Function function, long arg1, long arg2, long arg3, long arg4, long arg5)
          Invokes a function with five numeric arguments, and returns a numeric value.
 long invokeNNNNrN(Function function, long arg1, long arg2, long arg3, long arg4)
          Invokes a function with four numeric arguments, and returns a numeric value.
 long invokeNNNO1rN(Function function, long n1, long n2, long n3, java.lang.Object o1, int o1off, int o1len, ObjectParameterInfo o1flags)
          Invokes a function with two numeric arguments, and returns a numeric value.
 long invokeNNNO2rN(Function function, long n1, long n2, long n3, java.lang.Object o1, int o1off, int o1len, ObjectParameterInfo o1flags, java.lang.Object o2, int o2off, int o2len, ObjectParameterInfo o2flags)
          Invokes a function with two numeric arguments, and returns a numeric value.
 long invokeNNNrN(Function function, long arg1, long arg2, long arg3)
          Invokes a function with three numeric arguments, and returns a numeric value.
 long invokeNNO1rN(Function function, long n1, long n2, java.lang.Object o1, int o1off, int o1len, ObjectParameterInfo o1flags)
          Invokes a function with two numeric arguments, and returns a numeric value.
 long invokeNNO2rN(Function function, long n1, long n2, java.lang.Object o1, int o1off, int o1len, ObjectParameterInfo o1flags, java.lang.Object o2, int o2off, int o2len, ObjectParameterInfo o2flags)
          Invokes a function with two numeric arguments, and returns a numeric value.
 long invokeNNrN(Function function, long arg1, long arg2)
          Invokes a function with two numeric arguments, and returns a numeric value.
 int invokeNoErrnoIIIrI(Function function, int arg1, int arg2, int arg3)
          Invokes a function with three integer arguments, and returns a 32 bit integer.
 int invokeNoErrnoIIrI(Function function, int arg1, int arg2)
          Invokes a function with two integer arguments, and returns a 32 bit integer.
 int invokeNoErrnoIrI(Function function, int arg1)
          Invokes a function with one integer argument, and returns a 32 bit integer.
 int invokeNoErrnoVrI(Function function)
          Invokes a function with no arguments, and returns a 32 bit integer.
 long invokeNrN(Function function, long arg1)
          Invokes a function with one numberic argument, and returns a numeric value.
 java.lang.Object invokeObject(Function function, HeapInvocationBuffer buffer)
           
 byte[] invokeStruct(CallContext ctx, long function, HeapInvocationBuffer buffer)
          Invokes a function that returns a C struct by value.
 void invokeStruct(CallContext ctx, long function, HeapInvocationBuffer buffer, byte[] returnBuffer, int offset)
          Invokes a function that returns a C struct by value.
 byte[] invokeStruct(Function function, HeapInvocationBuffer buffer)
          Invokes a function that returns a C struct by value.
 void invokeStruct(Function function, HeapInvocationBuffer buffer, byte[] returnBuffer, int offset)
          Invokes a function that returns a C struct by value.
 float invokeVrF(Function function)
          Invokes a function with no arguments, and returns a 32 bit float.
 int invokeVrI(Function function)
          Invokes a function with no arguments, and returns a 32 bit integer.
 long invokeVrL(Function function)
          Invokes a function with no arguments, and returns a 64 bit integer.
 long invokeVrN(Function function)
          Invokes a function with no arguments, and returns a numeric value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static final Invoker getInstance()
Gets the Invoker singleton.

Returns:
An instance of Invoker.

getObjectParameterInvoker

public final ObjectParameterInvoker getObjectParameterInvoker()
Gets the fast-path object parameter invoker.

Returns:
An instance of ObjectParameterInvoker

invokeVrI

public final int invokeVrI(Function function)
Invokes a function with no arguments, and returns a 32 bit integer.

Parameters:
function - The Function to invoke.
Returns:
A 32 bit integer value.

invokeVrF

public final float invokeVrF(Function function)
Invokes a function with no arguments, and returns a 32 bit float.

Parameters:
function - The Function to invoke.
Returns:
A 32 bit float value.

invokeNoErrnoVrI

public final int invokeNoErrnoVrI(Function function)
Invokes a function with no arguments, and returns a 32 bit integer. This method does not save the errno value.

Parameters:
function - The Function to invoke.
Returns:
A 32 bit integer value.

invokeIrI

public final int invokeIrI(Function function,
                           int arg1)
Invokes a function with one integer argument, and returns a 32 bit integer.

Parameters:
function - The Function to invoke.
arg1 - A 32 bit integer argument.
Returns:
A 32 bit integer value.

invokeNoErrnoIrI

public final int invokeNoErrnoIrI(Function function,
                                  int arg1)
Invokes a function with one integer argument, and returns a 32 bit integer. This method does not save the errno value.

Parameters:
function - The Function to invoke.
arg1 - A 32 bit integer argument.
Returns:
A 32 bit integer value.

invokeIrF

public final float invokeIrF(Function function,
                             int arg1)
Invokes a function with one integer argument, and returns a 32 bit float.

Parameters:
function - The Function to invoke.
arg1 - A 32 bit integer argument.
Returns:
A 32 bit float value.

invokeIIrI

public final int invokeIIrI(Function function,
                            int arg1,
                            int arg2)
Invokes a function with two integer arguments, and returns a 32 bit integer.

Parameters:
function - The Function to invoke.
arg1 - The first 32 bit integer argument.
arg2 - The second 32 bit integer argument.
Returns:
A 32 bit integer value.

invokeNoErrnoIIrI

public final int invokeNoErrnoIIrI(Function function,
                                   int arg1,
                                   int arg2)
Invokes a function with two integer arguments, and returns a 32 bit integer. This method does not save the errno value.

Parameters:
function - The Function to invoke.
arg1 - The first 32 bit integer argument.
arg2 - The second 32 bit integer argument.
Returns:
A 32 bit integer value.

invokeIIrF

public final float invokeIIrF(Function function,
                              int arg1,
                              int arg2)
Invokes a function with two integer arguments, and returns a 32 bit float.

Parameters:
function - The Function to invoke.
arg1 - The first 32 bit integer argument.
arg2 - The second 32 bit integer argument.
Returns:
A 32 bit float value.

invokeIIIrI

public final int invokeIIIrI(Function function,
                             int arg1,
                             int arg2,
                             int arg3)
Invokes a function with three integer arguments, and returns a 32 bit integer.

Parameters:
function - The Function to invoke.
arg1 - The first 32 bit integer argument.
arg2 - The second 32 bit integer argument.
arg3 - The third 32 bit integer argument.
Returns:
A 32 bit integer value.

invokeNoErrnoIIIrI

public final int invokeNoErrnoIIIrI(Function function,
                                    int arg1,
                                    int arg2,
                                    int arg3)
Invokes a function with three integer arguments, and returns a 32 bit integer. This method does not save the errno value.

Parameters:
function - The Function to invoke.
arg1 - The first 32 bit integer argument.
arg2 - The second 32 bit integer argument.
arg3 - The third 32 bit integer argument.
Returns:
A 32 bit integer value.

invokeIIIrF

public final float invokeIIIrF(Function function,
                               int arg1,
                               int arg2,
                               int arg3)
Invokes a function with three integer arguments, and returns a 32 bit float.

Parameters:
function - The Function to invoke.
arg1 - The first 32 bit integer argument.
arg2 - The second 32 bit integer argument.
arg3 - The third 32 bit integer argument.
Returns:
A 32 bit float value.

invokeVrL

public final long invokeVrL(Function function)
Invokes a function with no arguments, and returns a 64 bit integer.

Parameters:
function - The Function to invoke.
Returns:
A 64 bit integer value.

invokeLrL

public final long invokeLrL(Function function,
                            long arg1)
Invokes a function with one 64 bit integer argument, and returns a 64 bit integer.

Parameters:
function - The Function to invoke.
arg1 - The 64 bit integer argument.
Returns:
A 64 bit integer value.

invokeLLrL

public final long invokeLLrL(Function function,
                             long arg1,
                             long arg2)
Invokes a function with two 64 bit integer arguments, and returns a 64 bit integer.

Parameters:
function - The Function to invoke.
arg1 - The first 64 bit integer argument.
arg2 - The second 64 bit integer argument.
Returns:
A 64 bit integer value.

invokeLLLrL

public final long invokeLLLrL(Function function,
                              long arg1,
                              long arg2,
                              long arg3)
Invokes a function with three 64 bit integer arguments, and returns a 64 bit integer.

Parameters:
function - The Function to invoke.
arg1 - The first 64 bit integer argument.
arg2 - The second 64 bit integer argument.
arg3 - The third 64 bit integer argument.
Returns:
A 64 bit integer value.

invokeLLLLrL

public final long invokeLLLLrL(Function function,
                               long arg1,
                               long arg2,
                               long arg3,
                               long arg4,
                               long arg5)
Invokes a function with four 64 bit integer arguments, and returns a 64 bit integer.

Parameters:
function - The Function to invoke.
arg1 - The first 64 bit integer argument.
arg2 - The second 64 bit integer argument.
arg3 - The third 64 bit integer argument.
arg4 - The fourth 64 bit integer argument.
Returns:
A 64 bit integer value.

invokeLLLLLrL

public final long invokeLLLLLrL(Function function,
                                long arg1,
                                long arg2,
                                long arg3,
                                long arg4,
                                long arg5)
Invokes a function with five 64 bit integer arguments, and returns a 64 bit integer.

Parameters:
function - The Function to invoke.
arg1 - The first 64 bit integer argument.
arg2 - The second 64 bit integer argument.
arg3 - The third 64 bit integer argument.
arg4 - The fourth 64 bit integer argument.
arg5 - The fifth 64 bit integer argument.
Returns:
A 64 bit integer value.

invokeLLLLLLrL

public final long invokeLLLLLLrL(Function function,
                                 long arg1,
                                 long arg2,
                                 long arg3,
                                 long arg4,
                                 long arg5,
                                 long arg6)
Invokes a function with six 64 bit integer arguments, and returns a 64 bit integer.

Parameters:
function - The Function to invoke.
arg1 - The first 64 bit integer argument.
arg2 - The second 64 bit integer argument.
arg3 - The third 64 bit integer argument.
arg4 - The fourth 64 bit integer argument.
arg5 - The fifth 64 bit integer argument.
arg6 - The sixth 64 bit integer argument.
Returns:
A 64 bit integer value.

invokeVrN

public final long invokeVrN(Function function)
Invokes a function with no arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
Returns:
A numeric value.

invokeNrN

public final long invokeNrN(Function function,
                            long arg1)
Invokes a function with one numberic argument, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - The numeric argument.
Returns:
A numeric value.

invokeNNrN

public final long invokeNNrN(Function function,
                             long arg1,
                             long arg2)
Invokes a function with two numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - The first numeric argument.
arg2 - The second numeric argument.
Returns:
A numeric value.

invokeNNNrN

public final long invokeNNNrN(Function function,
                              long arg1,
                              long arg2,
                              long arg3)
Invokes a function with three numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - The first numeric argument.
arg2 - The second numeric argument.
arg3 - The third numeric argument.
Returns:
A numeric value.

invokeNNNNrN

public final long invokeNNNNrN(Function function,
                               long arg1,
                               long arg2,
                               long arg3,
                               long arg4)
Invokes a function with four numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - The first numeric argument.
arg2 - The second numeric argument.
arg3 - The third numeric argument.
arg3 - The fourth numeric argument.
Returns:
A numeric value.

invokeNNNNNrN

public final long invokeNNNNNrN(Function function,
                                long arg1,
                                long arg2,
                                long arg3,
                                long arg4,
                                long arg5)
Invokes a function with five numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - The first numeric argument.
arg2 - The second numeric argument.
arg3 - The third numeric argument.
arg4 - The fourth numeric argument.
arg5 - The fifth numeric argument.
Returns:
A numeric value.

invokeNNNNNNrN

public final long invokeNNNNNNrN(Function function,
                                 long arg1,
                                 long arg2,
                                 long arg3,
                                 long arg4,
                                 long arg5,
                                 long arg6)
Invokes a function with six numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - The first numeric argument.
arg2 - The second numeric argument.
arg3 - The third numeric argument.
arg4 - The fourth numeric argument.
arg5 - The fifth numeric argument.
arg6 - The sixth numeric argument.
Returns:
A numeric value.

invokeNNO1rN

public final long invokeNNO1rN(Function function,
                               long n1,
                               long n2,
                               java.lang.Object o1,
                               int o1off,
                               int o1len,
                               ObjectParameterInfo o1flags)
Invokes a function with two numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
n1 - first numeric argument.
idx1 - parameter index of the first numeric argument.
o1 - array or buffer, to be passed as a pointer for the first numeric parameter.
o1off - offset from the start of the array pr buffer.
o1len - length of the array to use.
o1flags - object flags (type, direction, parameter index).

invokeNNO2rN

public final long invokeNNO2rN(Function function,
                               long n1,
                               long n2,
                               java.lang.Object o1,
                               int o1off,
                               int o1len,
                               ObjectParameterInfo o1flags,
                               java.lang.Object o2,
                               int o2off,
                               int o2len,
                               ObjectParameterInfo o2flags)
Invokes a function with two numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - An array, to be passed as a pointer for the first numeric parameter.
off1 - The offset from the start of the array.
len1 - The length of the array to use.
flags1 - Array flags (direction, type).
arg2 - The second numeric argument.

invokeNNNO1rN

public final long invokeNNNO1rN(Function function,
                                long n1,
                                long n2,
                                long n3,
                                java.lang.Object o1,
                                int o1off,
                                int o1len,
                                ObjectParameterInfo o1flags)
Invokes a function with two numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - An array, to be passed as a pointer for the first numeric parameter.
off1 - The offset from the start of the array.
len1 - The length of the array to use.
flags1 - Array flags (direction, type).
arg2 - The second numeric argument.

invokeNNNO2rN

public final long invokeNNNO2rN(Function function,
                                long n1,
                                long n2,
                                long n3,
                                java.lang.Object o1,
                                int o1off,
                                int o1len,
                                ObjectParameterInfo o1flags,
                                java.lang.Object o2,
                                int o2off,
                                int o2len,
                                ObjectParameterInfo o2flags)
Invokes a function with two numeric arguments, and returns a numeric value.

Parameters:
function - The Function to invoke.
arg1 - An array, to be passed as a pointer for the first numeric parameter.
off1 - The offset from the start of the array.
len1 - The length of the array to use.
flags1 - Array flags (direction, type).
arg2 - The second numeric argument.

invokeAddress

public abstract long invokeAddress(Function function,
                                   HeapInvocationBuffer buffer)
Invokes a function and returns a native memory address.

Parameters:
function - The Function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeAddress

public abstract long invokeAddress(CallContext ctx,
                                   long function,
                                   HeapInvocationBuffer buffer)
Invokes a function and returns a native memory address.

Parameters:
ctx - The call context which describes how to call the native function.
function - The address of the native function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeInt

public final int invokeInt(Function function,
                           HeapInvocationBuffer buffer)
Invokes a function and returns a 32 bit integer value.

Parameters:
function - The Function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeInt

public final int invokeInt(CallContext ctx,
                           long function,
                           HeapInvocationBuffer buffer)
Invokes a function and returns a 32 bit integer value.

Parameters:
ctx - The call context which describes how to call the native function.
function - The address of the native function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeLong

public final long invokeLong(Function function,
                             HeapInvocationBuffer buffer)
Invokes a function and returns a 64 bit integer value.

Parameters:
function - The Function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeLong

public final long invokeLong(CallContext ctx,
                             long function,
                             HeapInvocationBuffer buffer)
Invokes a function and returns a 64 bit integer value.

Parameters:
ctx - The call context which describes how to call the native function.
function - The address of the native function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeFloat

public final float invokeFloat(Function function,
                               HeapInvocationBuffer buffer)
Invokes a function and returns a 32 bit floating point value.

Parameters:
function - The Function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeFloat

public final float invokeFloat(CallContext ctx,
                               long function,
                               HeapInvocationBuffer buffer)
Invokes a function and returns a 32 bit floating point value.

Parameters:
ctx - The call context which describes how to call the native function.
function - The address of the native function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeDouble

public final double invokeDouble(Function function,
                                 HeapInvocationBuffer buffer)
Invokes a function and returns a 64 bit floating point value.

Parameters:
function - The Function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeDouble

public final double invokeDouble(CallContext ctx,
                                 long function,
                                 HeapInvocationBuffer buffer)
Invokes a function and returns a 64 bit floating point value.

Parameters:
ctx - The call context describing how to call the native function.
function - The address of the native function to invoke.
buffer - A buffer containing the arguments to the function.
Returns:
A native memory address.

invokeStruct

public final byte[] invokeStruct(Function function,
                                 HeapInvocationBuffer buffer)
Invokes a function that returns a C struct by value.

Parameters:
function - The Function to invoke.
buffer - The parameter buffer.
Returns:
A byte array with the return value encoded in native byte order.

invokeStruct

public final byte[] invokeStruct(CallContext ctx,
                                 long function,
                                 HeapInvocationBuffer buffer)
Invokes a function that returns a C struct by value.

Parameters:
ctx - The call context which describes how to call the native function.
function - The address of the native function to invoke.
buffer - The parameter buffer.
Returns:
A byte array with the return value encoded in native byte order.

invokeStruct

public final void invokeStruct(Function function,
                               HeapInvocationBuffer buffer,
                               byte[] returnBuffer,
                               int offset)
Invokes a function that returns a C struct by value.

Parameters:
function - The Function to invoke.
buffer - The parameter buffer.
returnBuffer - The output buffer to place the return value in.
offset - The offset within returnBuffer to place the return value.

invokeStruct

public final void invokeStruct(CallContext ctx,
                               long function,
                               HeapInvocationBuffer buffer,
                               byte[] returnBuffer,
                               int offset)
Invokes a function that returns a C struct by value.

Parameters:
ctx - The call context which describes how to call the native function.
function - The address of the native function to invoke.
buffer - The parameter buffer.
returnBuffer - The output buffer to place the return value in.
offset - The offset within returnBuffer to place the return value.

invokeObject

public final java.lang.Object invokeObject(Function function,
                                           HeapInvocationBuffer buffer)

invoke

public final void invoke(Function function,
                         long returnBuffer,
                         long[] parameters)
Invokes a function, with the parameters loaded into native memory buffers, and the function result is stored in a native memory buffer.

Parameters:
function - The Function to invoke.
returnBuffer - The address of the native buffer to place the result of the function call in.
parameters - An array of addresses of the function parameters.

invoke

public final void invoke(CallContext ctx,
                         long function,
                         long returnBuffer,
                         long[] parameters)
Invokes a function, with the parameters loaded into native memory buffers, and the function result is stored in a native memory buffer.

Parameters:
ctx - The call context which describes how to call the native function.
function - The address of the native function to invoke.
returnBuffer - The address of the native buffer to place the result of the function call in.
parameters - An array of addresses of the function parameters.