|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object
|
+--com.smardec.j2native.Argument
|
+--com.smardec.j2native.Callback
Callback is a superclass for all classes representing callback functions.
A class nested from Callback must override the callback() method.
final public class TestCallback extends Callback{
public Int a = new Int();
public Int b = new Int();
public Int retVal = new Int();
public TestCallback(){
initialize(retVal, new Argument[] {a, b});
}
public void callback(){
System.out.println("a = " + a.intValue());
retVal.setValue(b.intValue() >> 2);
}
}
void myMethod(){
Function.call("userLib", "userFunc", null, new TestCallback());
}
Expected native code usage is:
typedef int TestCallback(int a, int b);
void userFunc(TestCallback *func){
int val = func(1, 2);
}
| Field Summary |
| Fields inherited from class com.smardec.j2native.Argument |
JAVA_SIDE, NATIVE_SIDE |
| Constructor Summary | |
protected |
Callback()
Constructs a Callback instance. |
protected |
Callback(Argument returnArgument,
Argument[] arguments)
Constructs a Callback instance. |
| Method Summary | |
abstract void |
callback()
This method is called when callback function is called. |
java.lang.Object |
clone()
This method throws UnsupportedOperationException because we cannot provide default behaviour as creating simple Callback object, when creation of
child is unavaliable. |
void |
dispose()
Releases resources associated with this callback. |
void |
fromBytesValue(byte[] bytes,
int offset)
Restores itself from provided array of bytes. |
protected Argument[] |
getArguments()
Returns callback function's arguments. |
byte |
getCallingConvention()
Returns calling convention for callback function. |
int |
getLength()
Returns length in bytes. |
int |
getResultFlags()
Callback function return value mechanizm. |
protected Argument |
getReturnArgument()
Returns callback function's return value. |
protected void |
initialize(Argument returnArgument,
Argument[] arguments)
Initializes callback arguments. |
protected boolean |
isFixedLength()
Identify if Argument is a fixed length variable. |
protected void |
read(long handle,
int offset)
do nothing |
protected void |
readFromStack(byte[] stack,
int offset)
Read itself from stack. |
protected void |
setCallingConvention(byte callingConvention)
Sets calling convention for callback function |
void |
setReturnFlags(int resultFlags)
In most cases this method will be never used, because return value Argument wrapper fully describes behaviour of the native
function. |
byte[] |
toBytesValue()
Encodes itself and returns it's representation as array of bytes. |
protected void |
toBytesValue(byte[] bytes,
int offset)
Encodes itself to the provided array of bytes. |
protected void |
update(byte side)
This method is used to synchronize Java side and native part. |
protected void |
write(long handle,
int offset)
Writes itself to the memory. |
protected void |
writeToStack(byte[] stack,
int offset)
Writes itself to stack. |
| Methods inherited from class com.smardec.j2native.Argument |
finalize, free, getAlignedLength, readFromRAM, restoreFromRAM, storeToRAM, writeToRAM |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
protected Callback()
Callback instance. If a subclass uses this method to
construct a callback, it must then invoke the initialize()<> method
to initialize callback arguments/return.
protected Callback(Argument returnArgument,
Argument[] arguments)
Callback instance.
returnArgument - callback function return valuearguments - callback function arguments| Method Detail |
public byte getCallingConvention()
protected void setCallingConvention(byte callingConvention)
callingConvention - calling convention
protected void initialize(Argument returnArgument,
Argument[] arguments)
returnArgument - callback function return valuearguments - callback function argumentsprotected Argument[] getArguments()
protected Argument getReturnArgument()
public void dispose()
public abstract void callback()
public int getLength()
Argument
getLength in class Argument
protected void writeToStack(byte[] stack,
int offset)
Argument
writeToStack in class Argumentstack - it's byte array, where Argument will be writtenoffset - offset in stack
protected void readFromStack(byte[] stack,
int offset)
Argument
readFromStack in class Argumentstack - it's byte array, from which Argument will be restoredoffset - offset in stackpublic int getResultFlags()
Callback uses
com.smardec.j2native.Function#ARGUMENT_DEFINED_RESULTING_MECHANIZM flag.
That means that if callback has defined return value, it's result flags will be used.
If different flags value will be set, this value will override return argument flags.
getResultFlags in class Argumentpublic void setReturnFlags(int resultFlags)
Argument wrapper fully describes behaviour of the native
function. But sometimes native libraries are compiled with some keys, that
change function default behaviour. So you need this method to set appropriate
flag to define correct interaction with the such function.
resultFlags - public byte[] toBytesValue()
Argument
toBytesValue in class ArgumentArgument
protected void toBytesValue(byte[] bytes,
int offset)
Argument
toBytesValue in class Argumentbytes - array of bytes to which Argument will be writtenoffset - offset in array
public void fromBytesValue(byte[] bytes,
int offset)
Argument
fromBytesValue in class Argumentbytes - array of bytes from which Argument will be restoredoffset - offset in arraypublic java.lang.Object clone()
Callback object, when creation of
child is unavaliable. So, any child class disired to be cloneable
should override clone() method. Good luck.
clone in class Argumentjava.lang.UnsupportedOperationException
protected void write(long handle,
int offset)
throws MemoryException
Argument
write in class Argumenthandle - identifies location in memory where Argument
will be writtenoffset - memory address offset
MemoryException - if memory manipulations or memory access failed
protected void read(long handle,
int offset)
read in class Argumenthandle - identifies location in memory from which Argument
will be readoffset - memory address offsetprotected boolean isFixedLength()
ArgumentArgument is a fixed length variable.
isFixedLength in class Argumenttrue if it is so, and false otherwiseprotected void update(byte side)
Argument
update in class Argumentside - identifies part that should be updated
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||