/// <summary> /// /// </summary> /// <param name="sourcePort"></param> /// <param name="destinationPort"></param> public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort) { if (sourcePort == null || destinationPort == null) { throw new ArgumentNullException("source or destination port"); } SourcePort = sourcePort; DestinationPort = destinationPort; }
/// <summary> /// The recursive part of this. Will stop on each device, search its inputs for the /// desired source and if not found, invoke this function for the each input port /// hoping to find the source. /// </summary> /// <param name="destination"></param> /// <param name="source"></param> /// <param name="onSuccessOutputPort"></param> /// <param name="alreadyCheckedDevices"></param> /// <param name="signalType"></param> /// <param name="cycle"></param> /// <param name="routeTable"></param> /// <returns>true if source is hit</returns> static bool GetRouteToSource(this IRoutingInputs destination, IRoutingOutputs source, RoutingOutputPort onSuccessOutputPort, List <IRoutingInputsOutputs> alreadyCheckedDevices, eRoutingSignalType signalType, int cycle, RouteDescriptor routeTable) { cycle++; Debug.Console(0, destination, "SelectInput-cycle {1}. Finding {2} route back to {0}", source.Key, cycle, signalType); var destDevInputTies = TieLineCollection.Default.Where(t => t.DestinationPort.ParentDevice == destination && (t.Type == signalType || t.Type == eRoutingSignalType.AudioVideo)); // find a direct tie var directTie = destDevInputTies.FirstOrDefault( t => !(t.SourcePort.ParentDevice is IRoutingInputsOutputs) && t.DestinationPort.ParentDevice == destination && t.SourcePort.ParentDevice == source); RoutingInputPort inputPort = null; if (directTie != null) // Found a tie directly to the source { Debug.Console(0, destination, "Found direct tie to {0}**", source.Key); inputPort = directTie.DestinationPort; } else // no direct-connect. Walk back devices. { Debug.Console(0, destination, "is not directly connected to {0}. Walking down tie lines", source.Key); // No direct tie? Run back out on the inputs' attached devices... // Only the ones that are routing devices var attachedMidpoints = destDevInputTies.Where(t => t.SourcePort.ParentDevice is IRoutingInputsOutputs); foreach (var inputTieToTry in attachedMidpoints) { Debug.Console(0, destination, "Trying to find route on {0}", inputTieToTry.SourcePort.ParentDevice.Key); var upstreamDeviceOutputPort = inputTieToTry.SourcePort; var upstreamRoutingDevice = upstreamDeviceOutputPort.ParentDevice as IRoutingInputsOutputs; // Check if this previous device has already been walked if (!(alreadyCheckedDevices != null && alreadyCheckedDevices.Contains(upstreamRoutingDevice))) { // haven't seen this device yet. Do it. Pass the output port to the next // level to enable switching on success var upstreamRoutingSuccess = upstreamRoutingDevice.GetRouteToSource(source, upstreamDeviceOutputPort, alreadyCheckedDevices, signalType, cycle, routeTable); if (upstreamRoutingSuccess) { Debug.Console(0, destination, "Upstream device route found"); inputPort = inputTieToTry.DestinationPort; break; // Stop looping the inputs in this cycle } } } } // we have a route on corresponding inputPort. *** Do the route *** if (inputPort != null) { Debug.Console(0, destination, "adding route:"); if (onSuccessOutputPort == null) { // it's a sink device routeTable.Routes.Add(new RouteSwitchDescriptor(inputPort)); } else if (destination is IRouting) { routeTable.Routes.Add(new RouteSwitchDescriptor(onSuccessOutputPort, inputPort)); } else // device is merely IRoutingInputOutputs { Debug.Console(0, destination, " No routing. Passthrough device"); } Debug.Console(0, destination, "Exiting cycle {0}", cycle); return(true); } if (alreadyCheckedDevices == null) { alreadyCheckedDevices = new List <IRoutingInputsOutputs>(); } alreadyCheckedDevices.Add(destination as IRoutingInputsOutputs); Debug.Console(0, destination, "No route found to {0}", source.Key); return(false); }
public RouteSwitchDescriptor(RoutingOutputPort outputPort, RoutingInputPort inputPort) { InputPort = inputPort; OutputPort = outputPort; }
/// <summary> /// Creates a tie line with an overriding Type. See help for OverrideType property for info /// </summary> /// <param name="overrideType">The signal type to limit the link to. Overrides DestinationPort.Type</param> public TieLine(RoutingOutputPort sourcePort, RoutingInputPort destinationPort, eRoutingSignalType overrideType) : this(sourcePort, destinationPort) { OverrideType = overrideType; }