fr.emn.reactiveinput
Class Pin

java.lang.Object
  extended byfr.emn.reactiveinput.Pin
All Implemented Interfaces:
Device, MutableDevice
Direct Known Subclasses:
InPin, OutPin

public abstract class Pin
extends java.lang.Object
implements MutableDevice


Field Summary
 
Fields inherited from interface fr.emn.reactiveinput.Device
AUTO_PROPERTIES
 
Constructor Summary
Pin()
           
Pin(java.lang.String slotName)
           
 
Method Summary
 void close()
          Closes the device.
 java.lang.String getError()
          Returns a short description of the last error, if any.
 DeviceInfo getInfo()
          Optional user-oriented info.
 In[] getIns()
          Returns the device's input slots.
 Slot[] getMutationTriggers()
          Returns the mutation triggers for this mutable device, i.e. all input or output slots that trigger a mutation when they are connected to another type.
 Out[] getOuts()
          Returns the device's output slots.
 java.lang.String[] getProperties()
          Declares the device's properties, or returns AUTO_PROPERTIES if properties can be automatically deduced from accessor methods (in this case the order of properties as they appear in dialog box is not predictable).
protected abstract  Slot getSlot()
           
 int getSlotIndex()
           
 java.lang.String getSlotName()
           
 boolean hasExternalInput()
          Specifies whether this device has external (implicit) input or not.
 boolean hasExternalOutput()
          Specifies whether this device has external (implicit) output or not.
 boolean isCopiable()
          Returns true if the device is copiable (i.e. if copy() will not return null).
 boolean isOpenable()
          USE: Design.
 void mutate()
          Performs a mutation on this device.
 Processor open(OpenContext context)
          Ensures that the device will be ready for processing or producing data, and returns the Processor object that will process data, or null if an error occured.
 void setEnabled(boolean enabled)
          Enables or disables the device.
 void setSlotIndex(int index)
           
 void setSlotName(java.lang.String slotName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fr.emn.reactiveinput.Device
copy, getName
 

Constructor Detail

Pin

public Pin()

Pin

public Pin(java.lang.String slotName)
Method Detail

getSlot

protected abstract Slot getSlot()

setSlotName

public void setSlotName(java.lang.String slotName)

getSlotName

public java.lang.String getSlotName()

getSlotIndex

public int getSlotIndex()

setSlotIndex

public void setSlotIndex(int index)

getError

public java.lang.String getError()
Description copied from interface: Device
Returns a short description of the last error, if any. This method is usually called after an open has failed.

Specified by:
getError in interface Device

getInfo

public DeviceInfo getInfo()
Description copied from interface: Device
Optional user-oriented info. See DeviceInfo interface.

Specified by:
getInfo in interface Device

isCopiable

public boolean isCopiable()
Description copied from interface: Device
Returns true if the device is copiable (i.e. if copy() will not return null).

Specified by:
isCopiable in interface Device

getIns

public In[] getIns()
Description copied from interface: Device
Returns the device's input slots.

Specified by:
getIns in interface Device

getOuts

public Out[] getOuts()
Description copied from interface: Device
Returns the device's output slots.

Specified by:
getOuts in interface Device

getProperties

public java.lang.String[] getProperties()
Description copied from interface: Device
Declares the device's properties, or returns AUTO_PROPERTIES if properties can be automatically deduced from accessor methods (in this case the order of properties as they appear in dialog box is not predictable).

All declared properties must be accessible through setXXX and getXXX accessor methods.

Example: If your device has the "Value" property of integer type, you must implement the "int getValue()" and "void setValue(int)" methods. Note: Property names are case-sensitive.

Currently supported types are:

Specified by:
getProperties in interface Device

hasExternalInput

public boolean hasExternalInput()
Description copied from interface: Device
Specifies whether this device has external (implicit) input or not.

Returns false if the device is deterministic from the data & time points of view, i.e. if its output production only depend on the explicit input history (input slots) and device's initial configuration. This is the case of most of the processing devices.

Return trues if output values do not only depend on the values of input slots, or if output production takes undefined time. Examples of devices with external input are input peripherals and asynchronous devices.

This method is used by the reactive machine to determine if this device is triggered by its input slots, or if it must be triggered continuously (i.e. each tick). This method can also be used by the editor for the device's graphical representation.

Specified by:
hasExternalInput in interface Device

hasExternalOutput

public boolean hasExternalOutput()
Description copied from interface: Device
Specifies whether this device has external (implicit) output or not.

Return false if the device has no border effects. Most of input and processing devices are in this case.

Return true if the device has border effects, such as graphical feedback, or control of some external value. Examples of devices with external output are application-interfacing devices and all user feedback devices.

This method can be used by the editor for the device's graphical representation. However this makes no difference for the reactive machine.

Specified by:
hasExternalOutput in interface Device

setEnabled

public void setEnabled(boolean enabled)
Description copied from interface: Device
Enables or disables the device.

Specified by:
setEnabled in interface Device

isOpenable

public boolean isOpenable()
Description copied from interface: Device
USE: Design.

This method returns false if the device is not openable because it is not properly configured (e.g. important input slots are not connected). Reactive machines ignore devices that are not openable.

Use this method if you want some pre-conditions to be verified before the execution of your device, inside init() and update() methods.

In the default method provided in DeviceUtilities, isOpenable() returns false if one or several obligatory input slots are not valid (see In.isValid()). You may add your own pre-conditions to this method.

Example :

public boolean isOpenable() { if (DeviceUtilities.defaultIsOpenable(this)) { // Verify default pre-conditions if (...) // Put additional pre-conditions here return true; } return false; }

Specified by:
isOpenable in interface Device

open

public Processor open(OpenContext context)
Description copied from interface: Device
Ensures that the device will be ready for processing or producing data, and returns the Processor object that will process data, or null if an error occured.

Some devices may need to perform some more or less heavy initialization (such as allocating resources or opening a stream) before being able to process or produce data. This is the case for most input devices, and some I/O and output devices. All these initializations must be done in the open() method.

Because these initializations are subject to fail, open() may return null even if isOpenable() returns true. In all cases, returning a non-null Processor means that the device is now able to process or produce data.

RE-OPENING A DEVICE:

Devices always stay open during reconfiguration, in order to avoid unnecessary deallocation and reallocation of resources. However, some devices will need to be re-open before re-starting the configuration. So open() is always called on all devices before re-starting.

If open() is called on a device that is already open, it may have no effect (and the current Processor is returned), or the device may be re-open if something has changed in its configuration.

Using a Processor as a return value allows the use of different processors, each adapted to a specific device configuration.

Specified by:
open in interface Device
Returns:
a Processor if the device is openable and has been successfully open, null otherwise.

OPEN CONTEXT:

Some devices may need a context to open. For example, devices that display themselves on a swing window will need a JFrame as context. Context is handled by OpenContext class.

See Also:
Processor

close

public void close()
Description copied from interface: Device
Closes the device. Called when the device is not used any more.

Deallocate resources here.

Specified by:
close in interface Device

getMutationTriggers

public Slot[] getMutationTriggers()
Description copied from interface: MutableDevice
Returns the mutation triggers for this mutable device, i.e. all input or output slots that trigger a mutation when they are connected to another type.

Specified by:
getMutationTriggers in interface MutableDevice

mutate

public void mutate()
Description copied from interface: MutableDevice
Performs a mutation on this device. This method is called when a connection is changed on a mutation trigger.

Specified by:
mutate in interface MutableDevice