addInterface<InterfaceType extends PairInterface> method

InterfaceReference<InterfaceType> addInterface<InterfaceType extends PairInterface>(
  1. InterfaceType intf, {
  2. required String name,
  3. required PairRole role,
  4. bool connect = true,
  5. bool allowNameUniquification = false,
  6. String portUniquify(
    1. String logical
    )?,
})

Adds an interface to this module with comprehensive configuration options.

This method creates an interface reference within this module, providing a connection point for interface-based communication. The interface can be automatically connected to module ports or left unconnected for manual configuration.

The intf specifies the interface instance to add, name provides the name for the interface reference (subject to uniquification), and role sets the interface role (consumer or provider) determining port directions. The connect controls whether to auto-connect interface ports via connectIO, allowNameUniquification determines whether to allow automatic name resolution, and portUniquify provides a custom function for generating unique port names.

When connect is true, the interface ports are automatically mapped to module ports using the default naming scheme. When false, port mappings must be established manually using addPortMap.

The portUniquify function receives the logical port name and should return a unique physical port name. If not provided, defaults to "${interfaceName}_${logicalPortName}" format.

Returns an InterfaceReference for accessing interface ports and methods.

Throws an Exception if an interface with the same name already exists.

Implementation

InterfaceReference<InterfaceType>
    addInterface<InterfaceType extends PairInterface>(
  InterfaceType intf, {
  required String name,
  required PairRole role,
  bool connect = true,
  bool allowNameUniquification = false,
  String Function(String logical)? portUniquify,
}) {
  name = _interfaceUniquifier.getUniqueName(
    initialName: name,
    reserved: !allowUniquification || !allowNameUniquification,
  );

  if (_interfaces.containsKey(name)) {
    throw RohdBridgeException('Interface $name already exists in $this');
  }

  final ref = InterfaceReference(name, this, intf, role,
      connect: connect,
      portUniquify: portUniquify ?? (original) => '${name}_$original');

  _interfaces[name] = ref;

  return ref;
}