com.smardec.j2native
Class Argument

java.lang.Object
  |
  +--com.smardec.j2native.Argument
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ArrayArgument, Callback, DelegatedArgument, NumericArgument, PointerArgument, StructuralArgument, Structure, Union, ZeroTerminatedString

public abstract class Argument
extends java.lang.Object
implements java.lang.Cloneable

Argument class is wrapper through which Java interacts with native part. It is common parent class for all types of function arguments.


Field Summary
protected static byte JAVA_SIDE
          Shows that java part should be updated
protected static byte NATIVE_SIDE
          Shows that native part should be updated
 
Constructor Summary
protected Argument()
          Default constructor of Argument
 
Method Summary
abstract  java.lang.Object clone()
          Creates and returns a copy of this object.
protected  void finalize()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
 void free()
          To avoid memory leaks in native memory should be used this method.
abstract  void fromBytesValue(byte[] bytes, int offset)
          Restores itself from provided array of bytes.
protected  int getAlignedLength()
          Returns aligned to mashine word lenght of the Argument.
abstract  int getLength()
          Returns length in bytes.
protected  int getResultFlags()
          Returns result specific flags.
protected abstract  boolean isFixedLength()
          Identify if Argument is a fixed length variable.
protected abstract  void read(long handle, int offset)
          Reads itself from the memory.
 void readFromRAM(long handle, int offset)
          Public method to read Argument from the native memmory.
protected abstract  void readFromStack(byte[] stack, int offset)
          Read itself from stack.
protected  void restoreFromRAM()
          Restores itself from native memory.
protected  long storeToRAM()
          Stores itself to the native memory.
abstract  byte[] toBytesValue()
          Encodes itself and returns it's representation as array of bytes.
protected abstract  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 abstract  void write(long handle, int offset)
          Writes itself to the memory.
 void writeToRAM(long handle, int offset)
          Public method to write Argument to the native memmory.
protected abstract  void writeToStack(byte[] stack, int offset)
          Writes itself to stack.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA_SIDE

protected static final byte JAVA_SIDE
Shows that java part should be updated

See Also:
Constant Field Values

NATIVE_SIDE

protected static final byte NATIVE_SIDE
Shows that native part should be updated

See Also:
Constant Field Values
Constructor Detail

Argument

protected Argument()
Default constructor of Argument

Method Detail

write

protected abstract void write(long handle,
                              int offset)
                       throws MemoryException
Writes itself to the memory. Exact memory address specified by params.

Parameters:
handle - identifies location in memory where Argument will be written
offset - memory address offset
Throws:
MemoryException - if memory manipulations or memory access failed

read

protected abstract void read(long handle,
                             int offset)
                      throws MemoryException
Reads itself from the memory. Exact memory address specified by params.

Parameters:
handle - identifies location in memory from which Argument will be read
offset - memory address offset
Throws:
MemoryException - if memory manipulations or memory access failed

writeToStack

protected abstract void writeToStack(byte[] stack,
                                     int offset)
Writes itself to stack.

Parameters:
stack - it's byte array, where Argument will be written
offset - offset in stack

readFromStack

protected abstract void readFromStack(byte[] stack,
                                      int offset)
Read itself from stack.

Parameters:
stack - it's byte array, from which Argument will be restored
offset - offset in stack

isFixedLength

protected abstract boolean isFixedLength()
Identify if Argument is a fixed length variable.

Returns:
true if it is so, and false otherwise

getLength

public abstract int getLength()
Returns length in bytes.

Returns:
an int

toBytesValue

public abstract byte[] toBytesValue()
Encodes itself and returns it's representation as array of bytes.

Returns:
byte[] representation of Argument

toBytesValue

protected abstract void toBytesValue(byte[] bytes,
                                     int offset)
Encodes itself to the provided array of bytes.

Parameters:
bytes - array of bytes to which Argument will be written
offset - offset in array

fromBytesValue

public abstract void fromBytesValue(byte[] bytes,
                                    int offset)
Restores itself from provided array of bytes.

Parameters:
bytes - array of bytes from which Argument will be restored
offset - offset in array

getAlignedLength

protected int getAlignedLength()
Returns aligned to mashine word lenght of the Argument.

Returns:
length in bytes

getResultFlags

protected int getResultFlags()
Returns result specific flags.

Returns:
flags

storeToRAM

protected long storeToRAM()
Stores itself to the native memory. Argument takes care of memory allocation and writes itself to this allocated memory. After all operations complete method returns this memory address.

Returns:
memory address

restoreFromRAM

protected void restoreFromRAM()
Restores itself from native memory. To perform this operation Argument should be written to native memory previously.


writeToRAM

public void writeToRAM(long handle,
                       int offset)
Public method to write Argument to the native memmory. This method uses void write(long handle, int offset) method to perform operation.

Parameters:
handle - identifies location in memory where Argument will be written
offset - memory address offset
See Also:
write(long, int)

readFromRAM

public void readFromRAM(long handle,
                        int offset)
Public method to read Argument from the native memmory. This method uses void read(long handle, int offset) method to perform operation.

Parameters:
handle - identifies location in memory from which Argument will be read
offset - memory address offset
See Also:
read(long, int)

free

public void free()
To avoid memory leaks in native memory should be used this method.


update

protected void update(byte side)
This method is used to synchronize Java side and native part.

Parameters:
side - identifies part that should be updated

finalize

protected void finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. Method frees native memory if it was used.

Overrides:
finalize in class java.lang.Object

clone

public abstract java.lang.Object clone()
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.


Copyright © 2004-2005 Smardec. All Rights Reserved.