private void _checkDirectInputOutputConnection(CompositeActor container,
Map externalRates) {
Iterator inputPorts = container.inputPortList().iterator();
while (inputPorts.hasNext()) {
IOPort inputPort = (IOPort) inputPorts.next();
Fraction rate = (Fraction) externalRates.get(inputPort);
if (rate.equals(Fraction.ZERO)) {
// Check to make sure that if this port is an external
// input port, then it does not drive the same relation as some
// other output port or some other external input port.
// This results in a non-deterministic merge and is illegal.
Iterator connectedPorts = inputPort.deepInsidePortList()
.iterator();
// Make sure any connected output ports are connected on
// the inside.
while (connectedPorts.hasNext()) {
IOPort connectedPort = (IOPort) connectedPorts.next();
// connectPort might be connected on the inside to the
// currentPort, which is legal. The container argument
// is always the container of the director, so any port
// that has that container must be connected on the inside.
if (connectedPort.isOutput()
&& (connectedPort.getContainer() != container)) {
throw new NotSchedulableException(inputPort,
connectedPort,
"External input port drive the same relation "
+ "as an output port. "
+ "This is not legal in SDF.");
} else if (connectedPort.isInput()
&& (connectedPort.getContainer() == container)) {
throw new NotSchedulableException(inputPort,
connectedPort,
"External input port drives the same relation "
+ "as another external input port. "
+ "This is not legal in SDF.");
}
}
boolean isDirectionConnection = true;
List insideSinkPorts = inputPort.insideSinkPortList();
// A dangling port has zero rate.
if (insideSinkPorts.isEmpty()) {
isDirectionConnection = false;
} else {
// If the zero external port rate is due to the rate
// propagation from a contained actor (i.e., connected to the
// zero rate port of the actor), then the zero external rate
// must be preserved.
Iterator sinkPorts = insideSinkPorts.iterator();
while (sinkPorts.hasNext()) {
IOPort sinkPort = (IOPort) sinkPorts.next();
if (sinkPort.getContainer() != container) {
isDirectionConnection = false;
break;
}
}
}
if (isDirectionConnection) {
externalRates.put(inputPort, new Fraction(1));
Iterator sinkPorts = insideSinkPorts.iterator();
while (sinkPorts.hasNext()) {
IOPort sinkPort = (IOPort) sinkPorts.next();
externalRates.put(sinkPort, new Fraction(1));
}
}
}
}