public abstract class Callback extends Parameter implements PointerParameter
Callback
is a superclass for all classes representing callback functions.
A class nested from Callback
must override the callback()
method.
Example of usage:
final public class CMultiply extends Callback
{
public Int a = new Int();
public Int b = new Int();
public Int retVal = new Int();
public CMultiply()
{
init(new CParameter[] {a, b}, retVal);
}
public void callback()
{
retVal.setValue(a.getValue()*b.getValue());
}
}
void myMethod()
{
Function.call("userLib", "userFunc", null, new CMultiply());
}
Expected native code usage is:
typedef int CMultiply(int a, int b); void userFunc(CMultiply *func) { int val = func(2, 2); }
NOTE:The current implementation of callback is NOT thread-safe.
LICENSE_TYPE, V
Modifier | Constructor and Description |
---|---|
protected |
Callback()
Constructs a callback instance.
|
|
Callback(Parameter[] params,
Parameter retVal)
Constructs a callback instance.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
callback()
This method is called when callback function is called.
|
protected void |
callback(Parameter[] parameters,
Parameter returnValue) |
java.lang.Object |
clone()
Cloning is not supported by callbacks.
|
protected Parameter |
createReturnValueByFields() |
void |
dispose()
Releases resources associated with this callback.
|
byte |
getCallingConvention()
Returns callback calling convention.
|
java.lang.String |
getDebugInfo()
Return debug info for JNIWrapper parameter.
|
int |
getLength()
Returns the length of native side parameter required to represent this callback.
|
protected Parameter[] |
getParameters() |
protected Parameter |
getReturnValue() |
protected void |
init(Parameter[] params,
Parameter retVal)
Initializes callback parameters.
|
boolean |
isNull()
Tests if this pointer is null.
|
protected boolean |
isUseFieldsForCallbackParameters() |
void |
read(DataBuffer stackBuffer,
int offset,
boolean invokedByCallback)
Does nothing.
|
protected void |
restoreState() |
protected void |
saveState() |
void |
setCallingConvention(byte callingConvention)
Sets calling convention that is used to invoke this callback.
|
protected void |
setUseFieldsForCallbackParameters(boolean useFieldsForCallbackParameters) |
Pointer.Void |
toPointer()
Converts this callback to void pointer.
|
void |
write(DataBuffer stackBuffer,
int offset,
boolean invokedByCallback)
Writes pointer to the native callback function that redirects to this callback
object.
|
acceptIOPerformer, asReturnValue, dataBufferAssigned, equals, getAlignedLength, getAlignmentRequirement, getDataBuffer, getDataBufferOffset, hashCode, indent, pop, push, read, read, setDataBuffer, toByteArray, write
protected Callback()
init()
method to initialize callback arguments/return.protected boolean isUseFieldsForCallbackParameters()
protected final void setUseFieldsForCallbackParameters(boolean useFieldsForCallbackParameters)
protected final void init(Parameter[] params, Parameter retVal)
params
- callback function argumentsretVal
- callback function return valueprotected Parameter[] getParameters()
protected Parameter getReturnValue()
public abstract void callback()
Parameters of the function are stored in variables specified during callback initialization. Overriden method must store return value to the return value variable specified during initialization.
protected Parameter createReturnValueByFields()
protected void saveState()
protected void restoreState()
public int getLength()
public java.lang.Object clone()
UnsupportedOperationException
.public void dispose()
public void write(DataBuffer stackBuffer, int offset, boolean invokedByCallback) throws MemoryAccessViolationException
write
in class Parameter
MemoryAccessViolationException
public void read(DataBuffer stackBuffer, int offset, boolean invokedByCallback) throws MemoryAccessViolationException
read
in class Parameter
MemoryAccessViolationException
public final void setCallingConvention(byte callingConvention)
public byte getCallingConvention()
public java.lang.String getDebugInfo()
Parameter
getDebugInfo
in class Parameter
public Pointer.Void toPointer()
public boolean isNull()
PointerParameter
isNull
in interface PointerParameter