Top Description Fields Constructors Methods
com.kenai.jffi

public final Class CallContext

extends Object
Class Inheritance
Imports
java.util.Arrays, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, java.util.logging.Level, java.util.logging.Logger

Native function call context This class holds all the information that JFFI needs to correctly call a native function, or to implement a callback from native code to java.

Field Summary

Modifier and TypeField and Description
pack-priv final long
contextAddress

The native address of the context

pack-priv volatile int
pack-priv final int
pack-priv final int
private final Foreign
foreign

A handle to the foreign interface to keep it alive as long as this object is alive

private final int
parameterCount

The number of parameters this function takes

pack-priv final long[]
pack-priv final Type[]
parameterTypes

The parameter types of this function

private final int
rawParameterSize

The size of buffer required when packing parameters

pack-priv final Type
returnType

The return type of this function

pack-priv final AtomicIntegerFieldUpdater<CallContext>

Constructor Summary

AccessConstructor and Description
public
CallContext(Type
The return type of the native function.
returnType
,
Type...
The parameter types the function accepts.
parameterTypes
)

Creates a new instance of Function with default calling convention.

public
CallContext(Type
The return type of the native function.
returnType
,
Type[]
The parameter types the function accepts.
parameterTypes
,
CallingConvention
The calling convention of the function.
convention
)

Creates a new instance of Function.

public
CallContext(Type returnType, Type[] parameterTypes, CallingConvention convention, boolean saveErrno)

pack-priv
CallContext(Type
The return type of the native function.
returnType
,
int
The number of parameters that are fixed, for varargs calls
fixedParamCount
,
Type[]
The parameter types the function accepts.
parameterTypes
,
CallingConvention
The calling convention of the function.
convention
,
boolean
Whether the errno should be saved or not
saveErrno
,
boolean faultProtect)

Creates a new instance of Function.

Method Summary

Modifier and TypeMethod and Description
public final void
dispose()

Deprecated
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
pack-priv final long

Returns:

The address of the native function context struct.
getAddress
()

Gets the address of the function context.

public static CallContext

Returns:

An instance of CallContext
getCallContext
(Type
The return type of the native function.
returnType
,
Type[]
The parameter types the function accepts.
parameterTypes
,
CallingConvention
The calling convention of the function.
convention
,
boolean
Indicates that the errno should be saved
saveErrno
)

Returns a CallContext instance.

public static CallContext
getCallContext(Type returnType, int fixedParamCount, Type[] parameterTypes, CallingConvention convention, boolean saveErrno)

public static CallContext
getCallContext(Type returnType, Type[] parameterTypes, CallingConvention convention, boolean saveErrno, boolean faultProtect)

public final int

Returns:

The number of parameters the native function accepts.
getParameterCount
()

Gets the number of parameters the native function accepts.

public final Type

Returns:

The Type of the parameter.
getParameterType
(int
The index of the parameter in the function signature
index
)

Gets the type of a parameter.

public final int

Returns:

The number of bytes required to store all paraameters of this function.
getRawParameterSize
()

Gets the number of bytes required to pack all the parameters this function accepts, into a region of memory.

public final Type

Returns:

The native return type of this function.
getReturnType
()

Gets the native return type of this function.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

contextAddressback to summary
pack-priv final long contextAddress

The native address of the context

disposedback to summary
pack-priv volatile int disposed
fixedParamCountback to summary
pack-priv final int fixedParamCount
flagsback to summary
pack-priv final int flags
foreignback to summary
private final Foreign foreign

A handle to the foreign interface to keep it alive as long as this object is alive

Annotations
@SuppressWarnings:FieldCanBeLocal, UnusedDeclaration
parameterCountback to summary
private final int parameterCount

The number of parameters this function takes

parameterTypeHandlesback to summary
pack-priv final long[] parameterTypeHandles
parameterTypesback to summary
pack-priv final Type[] parameterTypes

The parameter types of this function

rawParameterSizeback to summary
private final int rawParameterSize

The size of buffer required when packing parameters

returnTypeback to summary
pack-priv final Type returnType

The return type of this function

UPDATERback to summary
pack-priv final AtomicIntegerFieldUpdater<CallContext> UPDATER

Constructor Detail

CallContextback to summary
public CallContext(Type returnType, Type... parameterTypes)

Creates a new instance of Function with default calling convention.

Parameters
returnType:Type

The return type of the native function.

parameterTypes:Type[]

The parameter types the function accepts.

CallContextback to summary
public CallContext(Type returnType, Type[] parameterTypes, CallingConvention convention)

Creates a new instance of Function. Function instances created with this constructor will save the C errno contents after each call.

Parameters
returnType:Type

The return type of the native function.

parameterTypes:Type[]

The parameter types the function accepts.

convention:CallingConvention

The calling convention of the function.

CallContextback to summary
public CallContext(Type returnType, Type[] parameterTypes, CallingConvention convention, boolean saveErrno)
CallContextback to summary
pack-priv CallContext(Type returnType, int fixedParamCount, Type[] parameterTypes, CallingConvention convention, boolean saveErrno, boolean faultProtect)

Creates a new instance of Function.

Parameters
returnType:Type

The return type of the native function.

fixedParamCount:int

The number of parameters that are fixed, for varargs calls

parameterTypes:Type[]

The parameter types the function accepts.

convention:CallingConvention

The calling convention of the function.

saveErrno:boolean

Whether the errno should be saved or not

Method Detail

disposeback to summary
public final void dispose()

Deprecated

Annotations
@Deprecated
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
getAddressback to summary
pack-priv final long getAddress()

Gets the address of the function context.

Returns:long

The address of the native function context struct.

getCallContextback to summary
public static CallContext getCallContext(Type returnType, Type[] parameterTypes, CallingConvention convention, boolean saveErrno)

Returns a CallContext instance. This may return a previously cached instance that matches the signature requested, and should be used in preference to instantiating new instances.

Parameters
returnType:Type

The return type of the native function.

parameterTypes:Type[]

The parameter types the function accepts.

convention:CallingConvention

The calling convention of the function.

saveErrno:boolean

Indicates that the errno should be saved

Returns:CallContext

An instance of CallContext

getCallContextback to summary
public static CallContext getCallContext(Type returnType, int fixedParamCount, Type[] parameterTypes, CallingConvention convention, boolean saveErrno)
getCallContextback to summary
public static CallContext getCallContext(Type returnType, Type[] parameterTypes, CallingConvention convention, boolean saveErrno, boolean faultProtect)
getParameterCountback to summary
public final int getParameterCount()

Gets the number of parameters the native function accepts.

Returns:int

The number of parameters the native function accepts.

getParameterTypeback to summary
public final Type getParameterType(int index)

Gets the type of a parameter.

Parameters
index:int

The index of the parameter in the function signature

Returns:Type

The Type of the parameter.

getRawParameterSizeback to summary
public final int getRawParameterSize()

Gets the number of bytes required to pack all the parameters this function accepts, into a region of memory.

Returns:int

The number of bytes required to store all paraameters of this function.

getReturnTypeback to summary
public final Type getReturnType()

Gets the native return type of this function.

Returns:Type

The native return type of this function.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override