connectIO method
- Module module,
- Interface srcInterface,
- {Iterable<
PairDirection> ? inputTags, - Iterable<
PairDirection> ? outputTags, - String uniquify(
- String original
override
Connects module
's inputs and outputs up to srcInterface
and this
Interface.
The srcInterface
should be a new instance of the Interface to be used
by module
for all input and output connectivity. All signals in the
interface with specified TagType
will be connected to the Module via
Module.addInput or Module.addOutput based on inputTags
and
outputTags
, respectively. uniquify
can be used to uniquifiy
port names by manipulating the original name of the port.
If inputTags
or outputTags
is not specified, then, respectively,
no inputs or outputs will be added.
Implementation
@override
void connectIO(Module module, Interface<dynamic> srcInterface,
{Iterable<PairDirection>? inputTags,
Iterable<PairDirection>? outputTags,
String Function(String original)? uniquify}) {
final nonNullUniquify = uniquify ?? (original) => original;
final nonNullModify = modify ?? (original) => original;
String newUniquify(String original) =>
nonNullUniquify(nonNullModify(original));
super.connectIO(module, srcInterface,
inputTags: inputTags, outputTags: outputTags, uniquify: newUniquify);
if (subInterfaces.isNotEmpty) {
if (srcInterface is! PairInterface) {
throw InterfaceTypeException(
srcInterface,
'an Interface with subInterfaces'
' can only connect to a PairInterface');
}
for (final subInterfaceEntry in _subInterfaces.entries) {
final subInterface = subInterfaceEntry.value.interface;
final subInterfaceName = subInterfaceEntry.key;
if (!srcInterface._subInterfaces.containsKey(subInterfaceName)) {
throw InterfaceTypeException(
srcInterface, 'missing a sub-interface named $subInterfaceName');
}
// handle possible reversal as best as we can
Iterable<PairDirection>? subIntfInputTags;
Iterable<PairDirection>? subIntfOutputTags;
if (subInterfaceEntry.value.reverse) {
// swap consumer tag
if (inputTags?.contains(PairDirection.fromConsumer) ?? false) {
subIntfOutputTags = {PairDirection.fromConsumer};
}
if (outputTags?.contains(PairDirection.fromConsumer) ?? false) {
subIntfInputTags = {PairDirection.fromConsumer};
}
// swap provider tag
if (outputTags?.contains(PairDirection.fromProvider) ?? false) {
subIntfInputTags = {PairDirection.fromProvider};
}
if (inputTags?.contains(PairDirection.fromProvider) ?? false) {
subIntfOutputTags = {PairDirection.fromProvider};
}
// keep sharedInputs, if it's there
if (inputTags?.contains(PairDirection.sharedInputs) ?? false) {
subIntfInputTags = {
if (subIntfInputTags != null) ...subIntfInputTags,
PairDirection.sharedInputs,
};
}
} else {
subIntfInputTags = inputTags;
subIntfOutputTags = outputTags;
}
subInterface.connectIO(
module,
srcInterface._subInterfaces[subInterfaceName]!.interface,
inputTags: subIntfInputTags,
outputTags: subIntfOutputTags,
uniquify: newUniquify,
);
}
}
}