de.cau.cs.kieler.sj
Class Signal

java.lang.Object
  extended by de.cau.cs.kieler.sj.Signal
Direct Known Subclasses:
ValuedSignal

public class Signal
extends Object

Class that represents a signal as a part of a synchronous java (SJ) program. The represented signal is similar to the signal used in SyncCharts.

Rating red

Field Summary
static boolean ABSENT
          One of the two possible status of a signal.
protected  boolean hasStateChecked
          Used for a causality check to find out if a signal status is first checked and then emitted in the same tick.
protected  int index
          Index to manage the last signal assignments.
protected  Boolean[] lastSignalAssignments
          The last assignment of the signal used to get older states of the signal.
protected  boolean present
          The current state of the signal.
static boolean PRESENT
          One of the two possible status of a signal.
protected  EmbeddedSJProgram<?> program
          The program that belongs to the signal.
 
Constructor Summary
  Signal(String signalName)
          Creates a new signal with a given name.
protected Signal(String signalName, boolean state, EmbeddedSJProgram<?> myProgram, Boolean[] myLastSignalAssignments)
          Creates a new signal.
  Signal(String signalName, int historyLength)
          Creates a new signal.
 
Method Summary
 void emit()
          Emits a signal.
 String getName()
          Returns the name of a the signal.
 boolean isPresent()
          Checks if a Signal is PRESENT.
 Signal pre()
          Returns the previous instance of a signal.
 void sustainCB()
          Sustains the signal.
 String toJSONString()
          Returns a simple java script object notation for this object.
 String toString()
          Returns a string representation of the signal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PRESENT

public static final boolean PRESENT
One of the two possible status of a signal.

See Also:
ABSENT, Constant Field Values

ABSENT

public static final boolean ABSENT
One of the two possible status of a signal.

See Also:
PRESENT, Constant Field Values

present

protected boolean present
The current state of the signal.


lastSignalAssignments

protected Boolean[] lastSignalAssignments
The last assignment of the signal used to get older states of the signal.


index

protected int index
Index to manage the last signal assignments.


hasStateChecked

protected boolean hasStateChecked
Used for a causality check to find out if a signal status is first checked and then emitted in the same tick.


program

protected EmbeddedSJProgram<?> program
The program that belongs to the signal.

Constructor Detail

Signal

public Signal(String signalName)
Creates a new signal with a given name. The state of a new signal is always ABSENT and if you want to get the last state you will get an Exception.

Parameters:
signalName - The name of the created signal

Signal

public Signal(String signalName,
              int historyLength)
Creates a new signal. The default state is ABSENT. The previous signal states you are able to ask for is the history length.

Parameters:
signalName - The name of the created signal.
historyLength - The length we need for the signal history.
See Also:
pre()

Signal

protected Signal(String signalName,
                 boolean state,
                 EmbeddedSJProgram<?> myProgram,
                 Boolean[] myLastSignalAssignments)
Creates a new signal.

Parameters:
signalName - The name of the signal.
state - The state of the signal
myProgram - The program belonging to the signal.
myLastSignalAssignments - The last signal assignments belonging to the signal.
Method Detail

getName

public String getName()
Returns the name of a the signal.

Returns:
the name of this signal

isPresent

public boolean isPresent()
Checks if a Signal is PRESENT. Can used like this: ... if(signal1.present()){ ... }else{ ... } Attention: Your are not allowed to change the state anymore after calling this method. This is because a signal what checked as not present in a tick is not allowed to be present during that tick.

Returns:
A Boolean that tells you if the signal is present( true) or not false.

emit

public void emit()
Emits a signal. Changes the status of the signal for the current tick to to PRESENT. It will not be checked if a signal is emitted twice in a tick or has more than one status during a tick.


sustainCB

public void sustainCB()
Sustains the signal. That means that this signal is emitted in every following tick until this is aborted. The C means that this statement has to be the first after a case. The B means that the next statement has to be a break.


pre

public Signal pre()
Returns the previous instance of a signal. In other words how it was at the last tick. To use this the historyLength must be greater than 0. The command s.pre().pre() is possible.

Returns:
The signal with the status from the last tick.
See Also:
Signal(String, int)

toJSONString

public String toJSONString()
Returns a simple java script object notation for this object. This representation can be used for example for logging or sending debug informations.

Returns:
Returns a simple JSON representation of this object

toString

public String toString()
Returns a string representation of the signal.

Overrides:
toString in class Object
Returns:
The string representation of the signal.