Skip to content

Commit

Permalink
fix: remove route request once the request has been handled
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Welker committed Jul 18, 2024
1 parent fb60683 commit 5a9b876
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
15 changes: 12 additions & 3 deletions src/PepperDash.Essentials.Core/Routing/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using Debug = PepperDash.Core.Debug;


Expand All @@ -22,8 +21,7 @@ public static class Extensions
/// 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
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)] // REMOVE ME
/// </summary>
public static void ReleaseAndMakeRoute(this IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, string destinationPortKey = "", string sourcePortKey = "")
{
// Remove this line before committing!!!!!
Expand All @@ -36,6 +34,17 @@ public static void ReleaseAndMakeRoute(this IRoutingInputs destination, IRouting
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));
Expand Down
35 changes: 9 additions & 26 deletions src/PepperDash.Essentials.Core/Routing/RouteRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,21 @@ public void HandleCooldown(object sender, FeedbackEventArgs args)
{
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);

if (sender == null) return;

coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
return;
}
}
}

/*public class RouteRequest<TInputSelector, TOutputSelector>
{
public IRoutingSink<TInputSelector> Destination { get; set; }
public IRoutingOutputs<TOutputSelector> Source { get; set; }
public eRoutingSignalType SignalType { get; set; }
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);

public void HandleCooldown(object sender, FeedbackEventArgs args)
{
var coolingDevice = sender as IWarmingCooling;
if (args.BoolValue == false)
if (sender is IWarmingCooling coolingDevice)
{
Destination.ReleaseAndMakeRoute(Source, SignalType);
if (sender == null) return;
Debug.LogMessage(LogEventLevel.Debug, "Unsubscribing from cooling feedback for {destination}", null, Destination.Key);
coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
}

Extensions.RemoveRouteRequestForDestination(Destination.Key);
}
}*/
}
}

0 comments on commit 5a9b876

Please sign in to comment.