fix: harden route execution and normalize source port mapping

This commit is contained in:
Robert Sanders 2026-06-18 22:14:18 -04:00
parent 8d3edde28c
commit e209ef566d

View file

@ -92,22 +92,51 @@ namespace PepperDash.Essentials.Core
{ {
Debug.LogVerbose("ExecuteRoutes: {0}", route.ToString()); Debug.LogVerbose("ExecuteRoutes: {0}", route.ToString());
var inputSelector = route.InputPort?.Selector ?? route.InputPort?.Key;
if (route.SwitchingDevice is IRoutingSinkWithSwitching sink) if (route.SwitchingDevice is IRoutingSinkWithSwitching sink)
{ {
sink.ExecuteSwitch(route.InputPort.Selector); try
{
sink.ExecuteSwitch(inputSelector);
}
catch (Exception)
{
// Some devices expose null/unsupported selectors but can switch by port key.
if (route.InputPort?.Key != null && !Equals(inputSelector, route.InputPort.Key))
{
sink.ExecuteSwitch(route.InputPort.Key);
}
else
{
throw;
}
}
continue; continue;
} }
if (route.SwitchingDevice is IRouting switchingDevice) if (route.SwitchingDevice is IRouting switchingDevice)
{ {
switchingDevice.ExecuteSwitch(route.InputPort.Selector, route.OutputPort.Selector, SignalType); // Some sink-style routing devices can produce route descriptors without an explicit output port.
if (route.OutputPort == null)
{
switchingDevice.ExecuteSwitch(inputSelector, null, SignalType);
continue;
}
route.OutputPort.InUseTracker.AddUser(Destination, "destination-" + SignalType); var outputSelector = route.OutputPort.Selector ?? route.OutputPort.Key;
switchingDevice.ExecuteSwitch(inputSelector, outputSelector, SignalType);
route.OutputPort.InUseTracker?.AddUser(Destination, "destination-" + SignalType);
if (route.OutputPort.InUseTracker != null)
{
Debug.LogVerbose("Output port {0} routing. Count={1}", route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); Debug.LogVerbose("Output port {0} routing. Count={1}", route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue);
} }
} }
} }
}
/// <summary> /// <summary>
/// Releases the usage tracking for the route and optionally clears the route on the switching devices. /// Releases the usage tracking for the route and optionally clears the route on the switching devices.
@ -125,7 +154,7 @@ namespace PepperDash.Essentials.Core
{ {
try try
{ {
switchingDevice.ExecuteSwitch(null, route.OutputPort.Selector, SignalType); switchingDevice.ExecuteSwitch(null, route.OutputPort?.Selector, SignalType);
} }
catch (Exception e) catch (Exception e)
{ {