jp.go.aist.rtm.RTC.buffer
Class RingBuffer<DataType>

java.lang.Object
  extended by jp.go.aist.rtm.RTC.buffer.RingBuffer<DataType>
Type Parameters:
DataType - Data type to store in the buffer
All Implemented Interfaces:
BufferBase<DataType>

public class RingBuffer<DataType>
extends java.lang.Object
implements BufferBase<DataType>

Ring buffer implementation class

[@.ja 指定した長さのリング状バッファを持つバッファ実装クラス。 バッファ全体にデータが格納された場合、以降のデータは古いデータから 順次上書きされる。 従って、バッファ内には直近のバッファ長分のデータのみ保持される。 注)現在の実装では、一番最後に格納したデータのみバッファから読み出し可能} This is the buffer implementation class with ring shaped buffer of specified length. If data is stored in the entire buffer, data from now on will be overwritten from old data one by one. Therefore, only the length of latest data is stored in the buffer. Note: In the current implementation, only last stored data can be read from the buffer.


Nested Class Summary
protected  class RingBuffer.condition
           class for condition variable
 
Field Summary
(package private)  int m_wcount
           Counter for writing
 
Constructor Summary
RingBuffer()
           Constructor
RingBuffer(int length)
           Constructor
 
Method Summary
 ReturnCode advanceRptr()
           advances the reading pointer.
 ReturnCode advanceRptr(int n)
           advances the reading pointer.
 ReturnCode advanceWptr()
           advances the writing pointer.
 ReturnCode advanceWptr(int n)
           Get the buffer length
 boolean empty()
           Check on whether the buffer is empty.
 boolean full()
           Check on whether the buffer is full.
 DataType get()
           Reading data from the buffer
 ReturnCode get(DataRef<DataType> value)
           Write data into the buffer
 void init(Properties prop)
           Sets the buffer.
 boolean isFull()
           Check on whether the buffer is full.
 int length()
           Get the buffer length
 ReturnCode length(int n)
           Get the buffer length
 ReturnCode put(DataType data)
           Write data into the buffer
 ReturnCode read(DataRef<DataType> valueRef)
           Readout data from the buffer
 ReturnCode read(DataRef<DataType> valueRef, int sec)
           Readout data from the buffer
 ReturnCode read(DataRef<DataType> valueRef, int sec, int nsec)
           Readout data from the buffer
 int readable()
           returns the number of elements that can be read.
 ReturnCode reset()
           Get the buffer length
 DataType rptr()
           returns the pointer of a present reading element.
 DataType rptr(int n)
           returns the pointer of a present reading element.
 DataType wptr()
           Returns the pointer of a present writing element.
 DataType wptr(int n)
           Returns the pointer of a present writing element.
 int writable()
           Write data into the buffer
 ReturnCode write(DataType value)
           Write data into the buffer
 ReturnCode write(DataType value, int sec)
           Write data into the buffer
 ReturnCode write(DataType value, int sec, int nsec)
           Write data into the buffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_wcount

int m_wcount
Counter for writing

Constructor Detail

RingBuffer

public RingBuffer()
Constructor


RingBuffer

public RingBuffer(int length)
Constructor

Initialize the buffer by specified buffer length. However, if the specified length is less than two, the buffer should be initialized by two in length.

Parameters:
length - Buffer length
Method Detail

length

public int length()
Get the buffer length

Specified by:
length in interface BufferBase<DataType>
Returns:
Buffer length

length

public ReturnCode length(int n)
Get the buffer length

Pure virtual function to get the buffer length.

Specified by:
length in interface BufferBase<DataType>
Returns:
BUFFER_OK

write

public ReturnCode write(DataType value)
Write data into the buffer

Write data which is given argument into the buffer.

Specified by:
write in interface BufferBase<DataType>
Parameters:
value - Target data for writing
Returns:
BUFFER_OK Normal return BUFFER_FULL Buffer full TIMEOUT Timeout PRECONDITION_NOT_MET Unknown condition

write

public ReturnCode write(DataType value,
                        int sec)
Write data into the buffer

Write data which is given argument into the buffer.

Parameters:
value - Target data for writing
sec - Timeout sec
Returns:
BUFFER_OK Normal return BUFFER_FULL Buffer full TIMEOUT Timeout PRECONDITION_NOT_MET Unknown condition

write

public ReturnCode write(DataType value,
                        int sec,
                        int nsec)
Write data into the buffer

Write data which is given argument into the buffer.

Specified by:
write in interface BufferBase<DataType>
Parameters:
value - Target data for writing
sec - Timeout sec
nsec - Timeout nsec
Returns:
BUFFER_OK Normal return BUFFER_FULL Buffer full TIMEOUT Timeout PRECONDITION_NOT_MET Unknown condition

read

public ReturnCode read(DataRef<DataType> valueRef)
Readout data from the buffer

Readout data stored into the buffer.

Specified by:
read in interface BufferBase<DataType>
Parameters:
valueRef - Readout data
Returns:
BUFFER_OK BUFFER_EMPTY TIMEOUT PRECONDITION_NOT_MET

read

public ReturnCode read(DataRef<DataType> valueRef,
                       int sec)
Readout data from the buffer

Readout data stored into the buffer.

Parameters:
valueRef - Readout data
sec - TimeOut sec order
Returns:
BUFFER_OK BUFFER_EMPTY TIMEOUT PRECONDITION_NOT_MET

read

public ReturnCode read(DataRef<DataType> valueRef,
                       int sec,
                       int nsec)
Readout data from the buffer

Readout data stored into the buffer.

Specified by:
read in interface BufferBase<DataType>
Parameters:
valueRef - Readout data
sec - TimeOut sec order
nsec - TimeOut nsec order
Returns:
BUFFER_OK BUFFER_EMPTY TIMEOUT PRECONDITION_NOT_MET

isFull

public boolean isFull()
Check on whether the buffer is full.

This is not implemented.

Returns:
True if the buffer is full, else false.

put

public ReturnCode put(DataType data)
Write data into the buffer

Pure virtual function to write data into the buffer. Always BUFFER_OK will be returned in this implementation.

Specified by:
put in interface BufferBase<DataType>
Parameters:
data - Target data to write.
Returns:
BUFFER_ERROR: 異常終了} BUFFER_OK: Successful BUFFER_ERROR: Failed

get

public DataType get()
Reading data from the buffer

The position of the pointer for reading is not changed.

Specified by:
get in interface BufferBase<DataType>
Returns:
Read data

get

public ReturnCode get(DataRef<DataType> value)
Write data into the buffer

The position of the pointer for reading is not changed.

Specified by:
get in interface BufferBase<DataType>
Parameters:
value - Target data to write.
Returns:
Result of having written in data (true:Successful, false:Failed)

init

public void init(Properties prop)
Sets the buffer.

Initializes the setting of the buffer according to the property given by Properties.

  • buffer.length: Length of buffer
  • buffer.write.full_policy: Policy whether overwrite.Default is overwrite.
  • buffer.write.timeout: The timeout period is specified every second. Default is 1.0 seconds.
  • buffer.read.empty_policy: Reading policy when buffer is empty.Default is readback.
  • buffer.read.timeout: The timeout period is specified every second. Default is 1.0 seconds.

    Specified by:
    init in interface BufferBase<DataType>
    Parameters:
    prop - Property to set buffer

  • reset

    public ReturnCode reset()
    Get the buffer length

    Pure virtual function to get the buffer length.

    Specified by:
    reset in interface BufferBase<DataType>
    Returns:
    BUFFER_OK: Normal termination NOT_SUPPORTED:Reset failure BUFFER_ERROR:Abnormal termination

    wptr

    public DataType wptr(int n)
    Returns the pointer of a present writing element.

    This function returns the object of a present writing element of the buffer.

    Specified by:
    wptr in interface BufferBase<DataType>
    Parameters:
    n - Pointer for writing
    Returns:
    Object at writing position

    wptr

    public DataType wptr()
    Returns the pointer of a present writing element.

    This function returns the pointer of a present writing element of the buffer.

    Specified by:
    wptr in interface BufferBase<DataType>
    Returns:
    Object at writing position

    advanceWptr

    public ReturnCode advanceWptr(int n)
    Get the buffer length

    This function advances the writing pointer.

    Specified by:
    advanceWptr in interface BufferBase<DataType>
    Parameters:
    n - write pinter + n pointer
    Returns:
    BUFFER_OK:Normal termination PRECONDITION_NOT_MET: n > writable()

    advanceWptr

    public ReturnCode advanceWptr()
    advances the writing pointer.

    This function advances the writing pointer.

    Specified by:
    advanceWptr in interface BufferBase<DataType>
    Returns:
    BUFFER_OK: Normal termination PRECONDITION_NOT_MET: n > writable()

    writable

    public int writable()
    Write data into the buffer

    This function returns the number of elements that can be written in the buffer.

    Specified by:
    writable in interface BufferBase<DataType>
    Returns:
    Recordable number of elements

    full

    public boolean full()
    Check on whether the buffer is full.

    Pure virtual function to check on whether the buffer is full.

    Specified by:
    full in interface BufferBase<DataType>
    Returns:
    True if the buffer is full, else false.

    rptr

    public DataType rptr(int n)
    returns the pointer of a present reading element.

    This function returns the pointer of a present reading element of the buffer.

    Specified by:
    rptr in interface BufferBase<DataType>
    Parameters:
    n - reading position
    Returns:
    Object at reading position

    rptr

    public DataType rptr()
    returns the pointer of a present reading element.

    This function returns the pointer of a present reading element of the buffer.

    Specified by:
    rptr in interface BufferBase<DataType>
    Returns:
    Object at reading position

    advanceRptr

    public ReturnCode advanceRptr(int n)
    advances the reading pointer.

    This function advances the reading pointer.

    Specified by:
    advanceRptr in interface BufferBase<DataType>
    Parameters:
    n - Advanced number of points
    Returns:
    BUFFER_OK: Normal termination BUFFER_ERROR: Abnormal termination

    advanceRptr

    public ReturnCode advanceRptr()
    advances the reading pointer.

    This function advances the reading pointer.

    Specified by:
    advanceRptr in interface BufferBase<DataType>
    Returns:
    BUFFER_OK: Normal termination BUFFER_ERROR: Abnormal termination

    readable

    public int readable()
    returns the number of elements that can be read.

    This function returns the number of elements that can be read from the buffer.

    Specified by:
    readable in interface BufferBase<DataType>
    Returns:
    Number of elements that can be read

    empty

    public boolean empty()
    Check on whether the buffer is empty.

    Pure virtual function to check on whether the buffer is empty.

    Specified by:
    empty in interface BufferBase<DataType>
    Returns:
    True if the buffer is empty, else false.