using PepperDash.Core; using PepperDash.Essentials.Core.Queues; using System; using Serilog.Events; namespace PepperDash.Essentials.Core.Routing { /// /// Represents a RouteRequestQueueItem /// public class RouteRequestQueueItem : IQueueMessage { /// /// The action to perform for the route request. /// private readonly Action action; /// /// The route request data. /// private readonly RouteRequest routeRequest; /// /// Initializes a new instance of the class. /// /// The action to perform. /// The route request data. public RouteRequestQueueItem(Action routeAction, RouteRequest request) { action = routeAction; routeRequest = request; } /// /// Dispatches the route request action. /// public void Dispatch() { Debug.LogMessage(LogEventLevel.Information, "Dispatching route request {routeRequest}", null, routeRequest); action(routeRequest); } } /// /// Represents a ReleaseRouteQueueItem /// public class ReleaseRouteQueueItem : IQueueMessage { /// /// The action to perform for releasing the route. /// private readonly Action action; /// /// The destination device whose route is being released. /// private readonly IRoutingInputs destination; /// /// The specific input port key on the destination to release, or null/empty for any/default. /// private readonly string inputPortKey; /// /// Indicates whether to clear the route (send null) or just release the usage tracking. /// private readonly bool clearRoute; /// /// Initializes a new instance of the class. /// /// The action to perform. /// The destination device. /// The input port key. /// True to clear the route, false to just release. public ReleaseRouteQueueItem(Action action, IRoutingInputs destination, string inputPortKey, bool clearRoute) { this.action = action; this.destination = destination; this.inputPortKey = inputPortKey; this.clearRoute = clearRoute; } /// /// Dispatch method /// public void Dispatch() { Debug.LogMessage(LogEventLevel.Information, "Dispatching release route request for {destination}:{inputPortKey}", null, destination?.Key ?? "no destination", string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey); action(destination, inputPortKey, clearRoute); } } }