mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-11 19:44:52 +00:00
fix: GenericSink implements ICurrentSources
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
using PepperDash.Essentials.Core.Config;
|
using PepperDash.Essentials.Core.Config;
|
||||||
|
using PepperDash.Essentials.Core.Routing;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Devices.Common.Generic
|
namespace PepperDash.Essentials.Devices.Common.Generic
|
||||||
@@ -10,8 +12,17 @@ namespace PepperDash.Essentials.Devices.Common.Generic
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a GenericSink
|
/// Represents a GenericSink
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GenericSink : EssentialsDevice, IRoutingSinkWithSwitchingWithInputPort
|
public class GenericSink : EssentialsDevice, IRoutingSinkWithSwitchingWithInputPort, ICurrentSources
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public Dictionary<eRoutingSignalType, SourceListItem> CurrentSources { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event EventHandler CurrentSourcesChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the GenericSink class
|
/// Initializes a new instance of the GenericSink class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -26,6 +37,53 @@ namespace PepperDash.Essentials.Devices.Common.Generic
|
|||||||
InputPorts.Add(inputPort);
|
InputPorts.Add(inputPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem)
|
||||||
|
{
|
||||||
|
foreach (eRoutingSignalType type in Enum.GetValues(typeof(eRoutingSignalType)))
|
||||||
|
{
|
||||||
|
var flagValue = Convert.ToInt32(type);
|
||||||
|
// Skip if flagValue is 0 or not a power of two (i.e., not a single-bit flag).
|
||||||
|
// (flagValue & (flagValue - 1)) != 0 checks if more than one bit is set.
|
||||||
|
if (flagValue == 0 || (flagValue & (flagValue - 1)) != 0)
|
||||||
|
{
|
||||||
|
this.LogDebug("Skipping {type}", type);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.LogDebug("setting {type}", type);
|
||||||
|
|
||||||
|
if (signalType.HasFlag(type))
|
||||||
|
{
|
||||||
|
UpdateCurrentSources(type, sourceListKey, sourceListItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Raise the CurrentSourcesChanged event
|
||||||
|
CurrentSourcesChanged?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateCurrentSources(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem)
|
||||||
|
{
|
||||||
|
if (CurrentSources.ContainsKey(signalType))
|
||||||
|
{
|
||||||
|
CurrentSources[signalType] = sourceListItem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CurrentSources.Add(signalType, sourceListItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the current source key for the specified signal type
|
||||||
|
if (CurrentSourceKeys.ContainsKey(signalType))
|
||||||
|
{
|
||||||
|
CurrentSourceKeys[signalType] = sourceListKey;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CurrentSourceKeys.Add(signalType, sourceListKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the InputPorts
|
/// Gets or sets the InputPorts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user