jmce - 1_02

jmce.sim
Class Device<E>

java.lang.Object
  extended by jmce.sim.AbstractHardware
      extended by jmce.sim.AbstractPeripheral
          extended by jmce.sim.Device<E>
All Implemented Interfaces:
Hardware, Peripheral
Direct Known Subclasses:
Serial, Uart

public class Device<E>
extends AbstractPeripheral

The core class for device implementation.

This class implement a standard method to send / receive data between two or more devices.

The class Device use two DeviceProducer to implements full duplex communications between the two or more class involved to produce and consume data.

Version:
1.01
Author:
Mario Viara
See Also:
DeviceProducer, DeviceConsumer

Field Summary
 
Fields inherited from class jmce.sim.AbstractPeripheral
cpu
 
Constructor Summary
Device()
          Default constructor
Device(java.lang.String name)
          Constructor with name
 
Method Summary
 void addInputConsumer(DeviceConsumer<E> c)
          Add a new consumer for data received.
 void addInputProducer(DeviceProducer<E> c)
          Add a new producer for input
 void addOutputConsumer(DeviceConsumer<E> c)
          Add new output consumer
 void addOutputProducer(DeviceProducer<E> c)
          Add new output producer
 Device<E> getConnected()
          Return the connected device
 E read()
          Read data from input.
 E readOutput()
           
 boolean readyRead()
          Check if data area available on input.
 boolean readyReadOutput()
           
 boolean readyWrite()
          Check if the output buffer is full.
 void removeInputConsumer(DeviceConsumer<E> c)
          Remove an input consumer
 void removeOutputConsumer(DeviceConsumer<E> c)
          Remove a consumer from the output queue.
 void setConnected(Device<E> c)
          Connect another device to this.
 void write(E c)
          Write data in the output buffer
 void writeInput(E c)
          Write data in the input buffer
 
Methods inherited from class jmce.sim.AbstractPeripheral
idle, registerCPU, setIdle, setLive
 
Methods inherited from class jmce.sim.AbstractHardware
addHardware, createFrame, destroy, getHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareForName, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jmce.sim.Hardware
addHardware, destroy, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName
 

Constructor Detail

Device

public Device(java.lang.String name)
Constructor with name


Device

public Device()
Default constructor

Method Detail

removeInputConsumer

public void removeInputConsumer(DeviceConsumer<E> c)
Remove an input consumer

Since:
1.01

addInputConsumer

public void addInputConsumer(DeviceConsumer<E> c)
Add a new consumer for data received.


addInputProducer

public void addInputProducer(DeviceProducer<E> c)
                      throws SIMException
Add a new producer for input

Throws:
SIMException

removeOutputConsumer

public void removeOutputConsumer(DeviceConsumer<E> c)
Remove a consumer from the output queue.


addOutputConsumer

public void addOutputConsumer(DeviceConsumer<E> c)
                       throws SIMException
Add new output consumer

Throws:
SIMException

addOutputProducer

public void addOutputProducer(DeviceProducer<E> c)
                       throws SIMException
Add new output producer

Throws:
SIMException

readyRead

public boolean readyRead()
Check if data area available on input.

Returns:
true - If data are avaiilable.

read

public E read()
       throws SIMException
Read data from input.

Read the next available data. If no data is available wait for new one.

Returns:
the next available data.
Throws:
SIMException

readyWrite

public boolean readyWrite()
Check if the output buffer is full.

Returns:
true if the output buffer is full.

write

public void write(E c)
           throws SIMException
Write data in the output buffer

Throws:
SIMException

readyReadOutput

public boolean readyReadOutput()

readOutput

public E readOutput()
             throws SIMException
Throws:
SIMException

writeInput

public void writeInput(E c)
                throws SIMException
Write data in the input buffer

Throws:
SIMException

getConnected

public Device<E> getConnected()
Return the connected device

Returns:
Connected device.

setConnected

public void setConnected(Device<E> c)
                  throws SIMException
Connect another device to this. After this method is called all data produced from this Device sill be sent to the connected device and all data produced from the connected device will be sent to this device.

Parameters:
c - Device to connect.
Throws:
SIMException

jmce - 1_02