From 5a9b876d8052f0a08a07c71e65261b14dc1db738 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 18 Jul 2024 13:46:40 -0500 Subject: [PATCH] fix: remove route request once the request has been handled --- .../Routing/Extensions.cs | 15 ++++++-- .../Routing/RouteRequest.cs | 37 +++++-------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Routing/Extensions.cs b/src/PepperDash.Essentials.Core/Routing/Extensions.cs index b612796a..66c0dac3 100644 --- a/src/PepperDash.Essentials.Core/Routing/Extensions.cs +++ b/src/PepperDash.Essentials.Core/Routing/Extensions.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Runtime.CompilerServices; using Debug = PepperDash.Core.Debug; @@ -22,8 +21,7 @@ namespace PepperDash.Essentials.Core /// Gets any existing RouteDescriptor for a destination, clears it using ReleaseRoute /// and then attempts a new Route and if sucessful, stores that RouteDescriptor /// in RouteDescriptorCollection.DefaultCollection - /// - [MethodImpl(MethodImplOptions.NoInlining)] // REMOVE ME + /// public static void ReleaseAndMakeRoute(this IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, string destinationPortKey = "", string sourcePortKey = "") { // Remove this line before committing!!!!! @@ -36,6 +34,17 @@ namespace PepperDash.Essentials.Core ReleaseAndMakeRoute(destination, source, signalType, inputPort, outputPort); } + public static void RemoveRouteRequestForDestination(string destinationKey) + { + Debug.LogMessage(LogEventLevel.Information, "Removing route request for {destination}", null, destinationKey); + + var result = RouteRequests.Remove(destinationKey); + + var messageTemplate = result ? "Route Request for {destination} removed" : "Route Request for {destination} not found"; + + Debug.LogMessage(LogEventLevel.Information, messageTemplate, null, destinationKey); + } + private static void ReleaseAndMakeRoute(IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, RoutingInputPort destinationPort = null, RoutingOutputPort sourcePort = null) { if (destination == null) throw new ArgumentNullException(nameof(destination)); diff --git a/src/PepperDash.Essentials.Core/Routing/RouteRequest.cs b/src/PepperDash.Essentials.Core/Routing/RouteRequest.cs index 02b7ff3c..f8679b9d 100644 --- a/src/PepperDash.Essentials.Core/Routing/RouteRequest.cs +++ b/src/PepperDash.Essentials.Core/Routing/RouteRequest.cs @@ -16,38 +16,21 @@ namespace PepperDash.Essentials.Core { Debug.LogMessage(LogEventLevel.Information, "Handling cooldown route request: {destination}:{destinationPort} -> {source}:{sourcePort} {type}", null, Destination.Key, DestinationPort.Key, Source.Key, SourcePort.Key, SignalType.ToString()); - var coolingDevice = sender as IWarmingCooling; - - if (args.BoolValue == false) + if (args.BoolValue == true) { - Debug.LogMessage(LogEventLevel.Information, "Cooldown complete. Making route from {destination} to {source}", Destination.Key, Source.Key); - Destination.ReleaseAndMakeRoute(Source, SignalType); + return; + } - if (sender == null) return; + Debug.LogMessage(LogEventLevel.Information, "Cooldown complete. Making route from {destination} to {source}", Destination.Key, Source.Key); + Destination.ReleaseAndMakeRoute(Source, SignalType, DestinationPort?.Key ?? string.Empty, SourcePort?.Key ?? string.Empty); + if (sender is IWarmingCooling coolingDevice) + { + Debug.LogMessage(LogEventLevel.Debug, "Unsubscribing from cooling feedback for {destination}", null, Destination.Key); coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown; } + + Extensions.RemoveRouteRequestForDestination(Destination.Key); } } - - /*public class RouteRequest - { - public IRoutingSink Destination { get; set; } - public IRoutingOutputs Source { get; set; } - public eRoutingSignalType SignalType { get; set; } - - public void HandleCooldown(object sender, FeedbackEventArgs args) - { - var coolingDevice = sender as IWarmingCooling; - - if (args.BoolValue == false) - { - Destination.ReleaseAndMakeRoute(Source, SignalType); - - if (sender == null) return; - - coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown; - } - } - }*/ } \ No newline at end of file