connectTo method

void connectTo(
  1. InterfaceReference<PairInterface> other, {
  2. Set<String> exceptPorts = const {},
})

Connects two interfaces at the same hierarchical level, sharing a parent.

Establishes a peer-to-peer connection between this interface and other. The interfaces must have opposite roles (one provider, one consumer) to ensure proper signal directionality.

The exceptPorts parameter allows excluding specific ports from the connection. When ports are excluded, individual port connections are made rather than using bulk interface connection methods.

Throws an exception if both interfaces have the same role.

Implementation

void connectTo(InterfaceReference other,
    {Set<String> exceptPorts = const {}}) {
  // TODO(mkorbel1): remove restriction that it must be adjacent (https://github.com/intel/rohd-bridge/issues/13)
  if (other.module.parent != module.parent) {
    throw RohdBridgeException('Both interfaces must be on modules that share'
        ' the same parent module.');
  }

  if (other.role == role) {
    throw RohdBridgeException('Cannot connect interfaces of the same roles');
  }

  _connectAllPortMaps(exceptPorts: exceptPorts);
  other._connectAllPortMaps(exceptPorts: exceptPorts);

  final provider = role == PairRole.provider ? this : other;
  final consumer = role == PairRole.consumer ? this : other;

  if (exceptPorts.isNotEmpty) {
    provider.interface.getPorts([
      PairDirection.fromProvider,
      PairDirection.commonInOuts,
    ]).forEach((portName, thisPort) {
      if (!exceptPorts.contains(portName)) {
        consumer.interface.port(portName) <= thisPort;
      }
    });

    consumer.interface.getPorts([
      PairDirection.fromConsumer,
    ]).forEach((portName, thisPort) {
      if (!exceptPorts.contains(portName)) {
        provider.interface.port(portName) <= thisPort;
      }
    });
  } else {
    provider.interface.driveOther(consumer.interface, [
      PairDirection.fromProvider,
      PairDirection.commonInOuts,
    ]);

    consumer.interface.driveOther(provider.interface, [
      PairDirection.fromConsumer,
    ]);
  }
}