Class DataRequest

java.lang.Object
com.mouseviator.fsuipc.datarequest.DataRequest
Direct Known Subclasses:
ByteArrayRequest, ByteRequest, DoubleRequest, FloatRequest, FSControlRequest, IntRequest, LongRequest, LuaHelper.LuaControlRequest, LuaHelper.LuaParamRequest, LVarHelper.ByteLVarReadRequest, LVarHelper.ByteLVarWriteRequest, LVarHelper.DoubleLVarReadRequest, LVarHelper.DoubleLVarWriteRequest, LVarHelper.FloatLVarReadRequest, LVarHelper.FloatLVarWriteRequest, LVarHelper.IntegerLVarReadRequest, LVarHelper.IntegerLVarWriteRequest, LVarHelper.LVarControlRequest, LVarHelper.LVarParamRequest, LVarHelper.ShortLVarReadRequest, LVarHelper.ShortLVarWriteRequest, MacroHelper.MacroExecuteRequest, MacroHelper.MacroParamRequest, ShortRequest, StringRequest

public abstract class DataRequest
extends java.lang.Object
This is a base abstract class for FSUIPC data request. The data exchange between FSUIPC and the sim is done by storing read/write requests into memory file.... this goes down to bytes etc., that is why the exchange of data between Java wrapper and the FSUIPC library also goes down to bytes (byte arrays). This abstract class is like a bridge between the primitive data types and the byte arrays, that FSUIPCWrapper uses when sending/receiving data with FSUIPC. It would like non-handy to always work with these arrays. So, mainly, this class defines basic functions to manipulate that underlying byte array, that holds the actual data, methods and functions such as putInt(java.lang.Integer), getInt() to get primitive data to/from the buffer. Classes extending this one can use those functions, so they don't have to write them again. Why reinvent the wheel, yes? One implementation for all. What is this for? Well, the FSUIPC class is build around data requests. See also the IDataRequest interface, which every data request that should be supported by the FSUIPC class must implement.
Author:
Mouseviator
  • Field Summary

    Fields
    Modifier and Type Field Description
    static byte BUFFER_LENGTH_BYTE
    Length of the byte buffer to store one byte.
    static byte BUFFER_LENGTH_DOUBLE
    Length of the byte buffer to store double value.
    static byte BUFFER_LENGTH_FLOAT
    Length of the byte buffer to store float value.
    static byte BUFFER_LENGTH_INT
    Length of the byte buffer to store integer value.
    static byte BUFFER_LENGTH_LONG
    Length of the byte buffer to store long value.
    static byte BUFFER_LENGTH_SHORT
    Length of the byte buffer to store short value.
    protected byte[] dataBuffer
    The actual byte data buffer that will hold the value.
    static int MAX_OFFSET_VALUE
    Maximum FSUIPC offset value.
    static int MIN_OFFSET_VALUE
    Minimum offset value.
    protected int offset
    Init offset to 66C0, which is for "general use", should not cause any trouble if someone forgets to set the value
    protected IDataRequest.RequestType type
    Data request type, default to read
  • Constructor Summary

    Constructors
    Constructor Description
    DataRequest()  
  • Method Summary

    Modifier and Type Method Description
    protected void convertStringToByteArray​(java.lang.String value, int max_size, java.nio.charset.Charset charset)
    A helper function to convert given string to byte array.
    protected void copyByteArray​(byte[] data)
    This helper function will copy the given byte array into the internal byte array.
    byte[] getDataBuffer()
    Returns the actual byte buffer that holds the request data.
    protected double getDouble()
    Returns data stored in this data request as double value.
    protected float getFloat()
    Returns data stored in this data request as float value.
    protected int getInt()
    Returns data stored in this data request as integer value.
    protected long getLong()
    Returns data stored in this data request as long value.
    int getOffset()
    Returns the offset the data request is associated with.
    protected short getShort()
    Returns data stored in this data request as short value.
    int getSize()
    Returns the size of the byte buffer holding this request data.
    IDataRequest.RequestType getType()
    Returns the type of this data request (Whether READ or WRITE).
    protected java.lang.String getZeroTerminatedString​(java.nio.charset.Charset charset)
    This function will convert byte array to string ending at first zero byte.
    protected void putDouble​(double value)
    Will store given double value in this data request byte buffer.
    protected void putDouble​(java.lang.Double value)
    Will store given double value in this data request byte buffer.
    protected void putFloat​(float value)
    Will store given float value in this data request byte buffer.
    protected void putFloat​(java.lang.Float value)
    Will store given float value in this data request byte buffer.
    protected void putInt​(int value)
    Will store given integer value in this data request byte buffer.
    protected void putInt​(java.lang.Integer value)
    Will store given integer value in this data request byte buffer.
    protected void putLong​(long value)
    Will store given long value in this data request byte buffer.
    protected void putLong​(java.lang.Long value)
    Will store given long value in this data request byte buffer.
    protected void putShort​(short value)
    Will store given short value in this data request byte buffer.
    protected void putShort​(java.lang.Short value)
    Will store given short value in this data request byte buffer.
    void setOffset​(int offset)
    Sets the offset this data request is associated with.
    void setType​(IDataRequest.RequestType type)
    Sets the type of this data request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MIN_OFFSET_VALUE

      public static final int MIN_OFFSET_VALUE
      Minimum offset value.
      See Also:
      Constant Field Values
    • MAX_OFFSET_VALUE

      public static final int MAX_OFFSET_VALUE
      Maximum FSUIPC offset value.
      See Also:
      Constant Field Values
    • BUFFER_LENGTH_BYTE

      public static final byte BUFFER_LENGTH_BYTE
      Length of the byte buffer to store one byte.
      See Also:
      Constant Field Values
    • BUFFER_LENGTH_SHORT

      public static final byte BUFFER_LENGTH_SHORT
      Length of the byte buffer to store short value.
      See Also:
      Constant Field Values
    • BUFFER_LENGTH_INT

      public static final byte BUFFER_LENGTH_INT
      Length of the byte buffer to store integer value.
      See Also:
      Constant Field Values
    • BUFFER_LENGTH_LONG

      public static final byte BUFFER_LENGTH_LONG
      Length of the byte buffer to store long value.
      See Also:
      Constant Field Values
    • BUFFER_LENGTH_FLOAT

      public static final byte BUFFER_LENGTH_FLOAT
      Length of the byte buffer to store float value.
      See Also:
      Constant Field Values
    • BUFFER_LENGTH_DOUBLE

      public static final byte BUFFER_LENGTH_DOUBLE
      Length of the byte buffer to store double value.
      See Also:
      Constant Field Values
    • dataBuffer

      protected byte[] dataBuffer
      The actual byte data buffer that will hold the value.
    • offset

      protected int offset
      Init offset to 66C0, which is for "general use", should not cause any trouble if someone forgets to set the value
    • type

      protected IDataRequest.RequestType type
      Data request type, default to read
  • Constructor Details

    • DataRequest

      public DataRequest()
  • Method Details

    • getDataBuffer

      public byte[] getDataBuffer()
      Returns the actual byte buffer that holds the request data.
      Returns:
      Byte array.
    • getOffset

      public int getOffset()
      Returns the offset the data request is associated with.
      Returns:
      The offset.
    • getSize

      public int getSize()
      Returns the size of the byte buffer holding this request data.
      Returns:
      Size of the byte data buffer.
    • setOffset

      public void setOffset​(int offset) throws java.security.InvalidParameterException
      Sets the offset this data request is associated with.
      Parameters:
      offset - The offset.
      Throws:
      java.security.InvalidParameterException - If offset is outside the MIN_OFFSET_VALUE and MAX_OFFSET_VALUE.
    • getType

      public IDataRequest.RequestType getType()
      Returns the type of this data request (Whether READ or WRITE).
      Returns:
      Type of this data request.
    • setType

      public void setType​(IDataRequest.RequestType type)
      Sets the type of this data request.
      Parameters:
      type - Data request type.
    • getShort

      protected final short getShort()
      Returns data stored in this data request as short value.
      Returns:
      Value stored within the internal byte data buffer as Short value.
    • getInt

      protected final int getInt()
      Returns data stored in this data request as integer value.
      Returns:
      Value stored within the internal byte data buffer as Integer value.
    • getLong

      protected final long getLong()
      Returns data stored in this data request as long value.
      Returns:
      Value stored within the internal byte data buffer as Long value.
    • getFloat

      protected final float getFloat()
      Returns data stored in this data request as float value.
      Returns:
      Value stored within the internal byte data buffer as Float value.
    • getDouble

      protected final double getDouble()
      Returns data stored in this data request as double value.
      Returns:
      Value stored within the internal byte data buffer as Double value.
    • putShort

      protected final void putShort​(java.lang.Short value)
      Will store given short value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putInt

      protected final void putInt​(java.lang.Integer value)
      Will store given integer value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putLong

      protected final void putLong​(java.lang.Long value)
      Will store given long value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putFloat

      protected final void putFloat​(java.lang.Float value)
      Will store given float value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putDouble

      protected final void putDouble​(java.lang.Double value)
      Will store given double value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putShort

      protected final void putShort​(short value)
      Will store given short value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putInt

      protected final void putInt​(int value)
      Will store given integer value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putLong

      protected final void putLong​(long value)
      Will store given long value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putFloat

      protected final void putFloat​(float value)
      Will store given float value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • putDouble

      protected final void putDouble​(double value)
      Will store given double value in this data request byte buffer.
      Parameters:
      value - A value to store in the underlying byte data buffer.
    • convertStringToByteArray

      protected void convertStringToByteArray​(java.lang.String value, int max_size, java.nio.charset.Charset charset)
      A helper function to convert given string to byte array. The string will be 0 terminated, so the last byte of the array will be 0.
      Parameters:
      value - A string value.
      max_size - Max size of the buffer. If 0, no limit. If > 0, buffer size will be no more than max_size, but can be less if the value is shorter
      charset - A charset to use for encoding the string.
    • getZeroTerminatedString

      protected java.lang.String getZeroTerminatedString​(java.nio.charset.Charset charset)
      This function will convert byte array to string ending at first zero byte.
      Parameters:
      charset - Charset to use when encoding the string.
      Returns:
      The contents of underlying byte up to first zero byte buffer converted to String.
    • copyByteArray

      protected void copyByteArray​(byte[] data)
      This helper function will copy the given byte array into the internal byte array. This will be copy of the memory, not just reference assign!
      Parameters:
      data - A byte array to copy.