Class CFunction

java.lang.Object
  |
  +--CPointer
        |
        +--CFunction

public class CFunction
extends CPointer

An abstraction for a C function pointer. An instance of CFunction repesents a pointer to some C function. callXXX methods provide means to call the function; select a XXX variant based on the return type of the C function.

Beware that the copyIn, copyOut, setXXX, and getXXX methods inherited from the parent will indirect machine code.

Author:
Sheng Liang
See Also:
CPointer

Fields inherited from class CPointer
peer, SIZE
 
Constructor Summary
CFunction(CPointer ptr, java.lang.String conv)
          Create a new CFunction from a function pointer.
CFunction(java.lang.String lib, java.lang.String fname)
          Create a new CFunction that is linked with a C function that follows the standard "C" calling convention.
CFunction(java.lang.String lib, java.lang.String fname, java.lang.String conv)
          Create a new CFunction that is linked with a C function that follows a given calling convention.
 
Method Summary
 CPointer callCPointer(java.lang.Object[] args)
          Call the C function being represented by this object.
 double callDouble(java.lang.Object[] args)
          Call the C function being represented by this object.
 float callFloat(java.lang.Object[] args)
          Call the C function being represented by this object.
 int callInt(java.lang.Object[] args)
          Call the C function being represented by this object.
 void callVoid(java.lang.Object[] args)
          Call the C function being represented by this object.
 
Methods inherited from class CPointer
copyIn, copyIn, copyIn, copyIn, copyIn, copyIn, copyIn, copyOut, copyOut, copyOut, copyOut, copyOut, copyOut, copyOut, equals, getByte, getCPointer, getDouble, getFloat, getInt, getLong, getShort, getString, hashCode, setByte, setCPointer, setDouble, setFloat, setInt, setLong, setShort, setString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CFunction

public CFunction(java.lang.String lib,
                 java.lang.String fname,
                 java.lang.String conv)
Create a new CFunction that is linked with a C function that follows a given calling convention.

The allocated instance represents a pointer to the named C function from the named library, called with the named calling convention.

Parameters:
lib - library in which to find the C function
fname - name of the C function to be linked with
conv - calling convention used by the C function ("C" or "JNI")

CFunction

public CFunction(java.lang.String lib,
                 java.lang.String fname)
Create a new CFunction that is linked with a C function that follows the standard "C" calling convention.

The allocated instance represents a pointer to the named C function from the named library, called with the standard "C" calling convention.

Parameters:
lib - library in which to find the C function
fname - name of the C function to be linked with

CFunction

public CFunction(CPointer ptr,
                 java.lang.String conv)
Create a new CFunction from a function pointer.

Parameters:
ptr - the function pointer
conv - calling convention ("C" or "JNI")
Method Detail

callInt

public int callInt(java.lang.Object[] args)
Call the C function being represented by this object.
Parameters:
args - arguments to pass to the C function
Returns:
int value returned by the underlying C function

callVoid

public void callVoid(java.lang.Object[] args)
Call the C function being represented by this object.
Parameters:
args - arguments to pass to the C function

callFloat

public float callFloat(java.lang.Object[] args)
Call the C function being represented by this object.
Parameters:
args - arguments to pass to the C function
Returns:
float value returned by the underlying C function

callDouble

public double callDouble(java.lang.Object[] args)
Call the C function being represented by this object.
Parameters:
args - arguments to pass to the C function
Returns:
double value returned by the underlying C function

callCPointer

public CPointer callCPointer(java.lang.Object[] args)
Call the C function being represented by this object.
Parameters:
args - arguments to pass to the C function
Returns:
C pointer returned by the underlying C function