refactor: routing interfaces and implementations to support current sources

- Updated ICurrentSources interface to use IRoutingSource instead of SourceListItem.
- Introduced CurrentSourcesChangedEventArgs for detailed event notifications.
- Modified IRoutingOutputs and IRoutingSource interfaces to include JSON properties for serialization.
- Enhanced IRoutingSink and related interfaces to implement ICurrentSources for better source management.
- Refactored RoutingFeedbackManager to utilize new current source handling.
- Updated GenericAudioOut, GenericSink, and BlueJeansPc classes to implement new current source logic.
- Adjusted MobileControl messengers to accommodate changes in current source handling.
- Removed deprecated destination handling in MobileControlEssentialsRoomBridge.
This commit is contained in:
Neil Dorin 2026-03-26 13:49:23 -06:00
parent 43a9661e08
commit b4d53dbe0e
19 changed files with 439 additions and 350 deletions

View file

@ -131,12 +131,6 @@ public class GenericTcpIpClient : Device, ISocketStatusWithStreamDebugging, IAut
/// </summary> /// </summary>
public string ClientStatusText { get { return ClientStatus.ToString(); } } public string ClientStatusText { get { return ClientStatus.ToString(); } }
/// <summary>
/// Ushort representation of client status
/// </summary>
[Obsolete]
public ushort UClientStatus { get { return (ushort)ClientStatus; } }
/// <summary> /// <summary>
/// Connection failure reason /// Connection failure reason
/// </summary> /// </summary>

View file

@ -2,6 +2,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Routing;
namespace PepperDash.Essentials.Core; namespace PepperDash.Essentials.Core;
@ -11,23 +12,22 @@ namespace PepperDash.Essentials.Core;
/// </summary> /// </summary>
public class DestinationListItem public class DestinationListItem
{ {
/// <summary> /// <summary>
/// Gets or sets the key identifier for the sink device that this destination represents. /// Gets or sets the key identifier for the sink device that this destination represents.
/// </summary> /// </summary>
[JsonProperty("sinkKey")] [JsonProperty("sinkKey")]
public string SinkKey { get; set; } public string SinkKey { get; set; }
private EssentialsDevice _sinkDevice; private IRoutingSink _sinkDevice;
/// <summary> /// <summary>
/// Gets the actual device instance for this destination. /// Gets the actual device instance for this destination.
/// Lazily loads the device from the DeviceManager using the SinkKey. /// Lazily loads the device from the DeviceManager using the SinkKey.
/// </summary> /// </summary>
[JsonIgnore] [JsonIgnore]
public EssentialsDevice SinkDevice public IRoutingSink SinkDevice
{ {
get { return _sinkDevice ?? (_sinkDevice = DeviceManager.GetDeviceForKey(SinkKey) as EssentialsDevice); } get { return _sinkDevice ?? (_sinkDevice = DeviceManager.GetDeviceForKey(SinkKey) as IRoutingSink); }
} }
/// <summary> /// <summary>

View file

@ -43,17 +43,17 @@ public class SourceListItem
/// Returns the source Device for this, if it exists in DeviceManager /// Returns the source Device for this, if it exists in DeviceManager
/// </summary> /// </summary>
[JsonIgnore] [JsonIgnore]
public Device SourceDevice public IRoutingSource SourceDevice
{ {
get get
{ {
if (_SourceDevice == null) if (_SourceDevice == null)
_SourceDevice = DeviceManager.GetDeviceForKey(SourceKey) as Device; _SourceDevice = DeviceManager.GetDeviceForKey<IRoutingSource>(SourceKey);
return _SourceDevice; return _SourceDevice;
} }
} }
private Device _SourceDevice; private IRoutingSource _SourceDevice;
/// <summary> /// <summary>
/// Gets either the source's Name or this AlternateName property, if /// Gets either the source's Name or this AlternateName property, if

View file

@ -1236,11 +1236,14 @@ namespace PepperDash.Essentials.Core.Fusion
uint i = 0; uint i = 0;
foreach (var kvp in setTopBoxes) foreach (var kvp in setTopBoxes)
{ {
TryAddRouteActionSigs(JoinMap.Display1SetTopBoxSourceStart.AttributeName + " " + (i + 1), JoinMap.Display1SetTopBoxSourceStart.JoinNumber + i, kvp.Key, kvp.Value.SourceDevice); if (kvp.Value.SourceDevice is Device device)
i++;
if (i > JoinMap.Display1SetTopBoxSourceStart.JoinSpan) // We only have five spots
{ {
break; TryAddRouteActionSigs(JoinMap.Display1SetTopBoxSourceStart.AttributeName + " " + (i + 1), JoinMap.Display1SetTopBoxSourceStart.JoinNumber + i, kvp.Key, device);
i++;
if (i > JoinMap.Display1SetTopBoxSourceStart.JoinSpan) // We only have five spots
{
break;
}
} }
} }
@ -1248,11 +1251,14 @@ namespace PepperDash.Essentials.Core.Fusion
i = 0; i = 0;
foreach (var kvp in discPlayers) foreach (var kvp in discPlayers)
{ {
TryAddRouteActionSigs(JoinMap.Display1DiscPlayerSourceStart.AttributeName + " " + (i + 1), JoinMap.Display1DiscPlayerSourceStart.JoinNumber + i, kvp.Key, kvp.Value.SourceDevice); if (kvp.Value.SourceDevice is Device device)
i++;
if (i > JoinMap.Display1DiscPlayerSourceStart.JoinSpan) // We only have five spots
{ {
break; TryAddRouteActionSigs(JoinMap.Display1DiscPlayerSourceStart.AttributeName + " " + (i + 1), JoinMap.Display1DiscPlayerSourceStart.JoinNumber + i, kvp.Key, device);
i++;
if (i > JoinMap.Display1DiscPlayerSourceStart.JoinSpan) // We only have five spots
{
break;
}
} }
} }
@ -1260,11 +1266,14 @@ namespace PepperDash.Essentials.Core.Fusion
i = 0; i = 0;
foreach (var kvp in laptops) foreach (var kvp in laptops)
{ {
TryAddRouteActionSigs(JoinMap.Display1LaptopSourceStart.AttributeName + " " + (i + 1), JoinMap.Display1LaptopSourceStart.JoinNumber + i, kvp.Key, kvp.Value.SourceDevice); if (kvp.Value.SourceDevice is Device device)
i++;
if (i > JoinMap.Display1LaptopSourceStart.JoinSpan) // We only have ten spots???
{ {
break; TryAddRouteActionSigs(JoinMap.Display1LaptopSourceStart.AttributeName + " " + (i + 1), JoinMap.Display1LaptopSourceStart.JoinNumber + i, kvp.Key, device);
i++;
if (i > JoinMap.Display1LaptopSourceStart.JoinSpan) // We only have ten spots???
{
break;
}
} }
} }
@ -1745,22 +1754,24 @@ namespace PepperDash.Essentials.Core.Fusion
return; return;
} }
var dev = info.SourceDevice; if (info.SourceDevice is Device dev)
if (type == ChangeType.WillChange)
{ {
if (_sourceToFeedbackSigs.ContainsKey(dev)) if (type == ChangeType.WillChange)
{ {
_sourceToFeedbackSigs[dev].BoolValue = false; if (_sourceToFeedbackSigs.ContainsKey(dev))
{
_sourceToFeedbackSigs[dev].BoolValue = false;
}
} }
} else
else
{
if (_sourceToFeedbackSigs.ContainsKey(dev))
{ {
_sourceToFeedbackSigs[dev].BoolValue = true; if (_sourceToFeedbackSigs.ContainsKey(dev))
{
_sourceToFeedbackSigs[dev].BoolValue = true;
}
//var name = (room == null ? "" : room.Name);
CurrentRoomSourceNameSig.InputSig.StringValue = dev.Name;
} }
//var name = (room == null ? "" : room.Name);
CurrentRoomSourceNameSig.InputSig.StringValue = info.SourceDevice.Name;
} }
} }

View file

@ -28,18 +28,6 @@ public interface IHasDefaultDisplay
IRoutingSink DefaultDisplay { get; } IRoutingSink DefaultDisplay { get; }
} }
/// <summary>
/// For rooms with multiple displays
/// </summary>
[Obsolete("This interface is being deprecated in favor of using destination lists for routing to multiple displays.")]
public interface IHasMultipleDisplays
{
/// <summary>
/// A dictionary of displays in the room with the key being the type of display (presentation, calling, etc.) and the value being the display device
/// </summary>
Dictionary<eSourceListItemDestinationTypes, IRoutingSink> Displays { get; }
}
/// <summary> /// <summary>
/// For rooms with routing /// For rooms with routing
/// </summary> /// </summary>

View file

@ -6,6 +6,7 @@ namespace PepperDash.Essentials.Core.Routing
/// <summary> /// <summary>
/// The current sources for the room, keyed by eRoutingSignalType. /// The current sources for the room, keyed by eRoutingSignalType.
/// This allows for multiple sources to be tracked, such as audio and video. /// This allows for multiple sources to be tracked, such as audio and video.
/// Intended to be implemented on a DestinationListItem to provide access to the current sources for the room in its context.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This interface is used to provide access to the current sources in a room, /// This interface is used to provide access to the current sources in a room,
@ -17,7 +18,7 @@ namespace PepperDash.Essentials.Core.Routing
/// Gets the current sources for the room, keyed by eRoutingSignalType. /// Gets the current sources for the room, keyed by eRoutingSignalType.
/// This dictionary contains the current source for each signal type, such as audio, video, and control signals. /// This dictionary contains the current source for each signal type, such as audio, video, and control signals.
/// </summary> /// </summary>
Dictionary<eRoutingSignalType, SourceListItem> CurrentSources { get; } Dictionary<eRoutingSignalType, IRoutingSource> CurrentSources { get; }
/// <summary> /// <summary>
/// Gets the current source keys for the room, keyed by eRoutingSignalType. /// Gets the current source keys for the room, keyed by eRoutingSignalType.
@ -28,16 +29,51 @@ namespace PepperDash.Essentials.Core.Routing
/// <summary> /// <summary>
/// Event raised when the current sources change. /// Event raised when the current sources change.
/// </summary> /// </summary>
event EventHandler CurrentSourcesChanged; event EventHandler<CurrentSourcesChangedEventArgs> CurrentSourcesChanged;
/// <summary> /// <summary>
/// Sets the current source for a specific signal type. /// Sets the current source for a specific signal type.
/// This method updates the current source for the specified signal type and notifies any subscribers of the change. /// This method updates the current source for the specified signal type and notifies any subscribers of the change.
/// </summary> /// </summary>
/// <param name="signalType">The signal type to update.</param> /// <param name="signalType">The signal type to update.</param>
/// <param name="sourceListKey">The key for the source list.</param> /// <param name="sourceDevice">The source device to set as the current source.</param>
/// <param name="sourceListItem">The source list item to set as the current source.</param> void SetCurrentSource(eRoutingSignalType signalType, IRoutingSource sourceDevice);
void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem);
} }
}
/// <summary>
/// Event arguments for the CurrentSourcesChanged event, providing details about the signal type and the previous and new sources.
/// </summary>
public class CurrentSourcesChangedEventArgs : EventArgs
{
/// <summary>
/// Gets the signal type for which the current source has changed.
/// </summary>
public eRoutingSignalType SignalType { get; }
/// <summary>
/// Gets the previous source for the signal type before the change occurred.
/// </summary>
public IRoutingSource PreviousSource { get; }
/// <summary>
/// Gets the new source for the signal type after the change occurred.
/// </summary>
public IRoutingSource NewSource { get; }
/// <summary>
/// Initializes a new instance of the CurrentSourcesChangedEventArgs class with the specified signal type, previous source, and new source.
/// </summary>
/// <param name="signalType">The signal type for which the current source has changed.</param>
/// <param name="previousSource">The previous source for the signal type before the change occurred.</param>
/// <param name="newSource">The new source for the signal type after the change occurred.</param>
public CurrentSourcesChangedEventArgs(eRoutingSignalType signalType, IRoutingSource previousSource, IRoutingSource newSource)
{
SignalType = signalType;
PreviousSource = previousSource;
NewSource = newSource;
}
}
}

View file

@ -1,4 +1,5 @@
using PepperDash.Core; using Newtonsoft.Json;
using PepperDash.Core;
namespace PepperDash.Essentials.Core; namespace PepperDash.Essentials.Core;
@ -11,6 +12,7 @@ public interface IRoutingOutputs : IKeyed
/// <summary> /// <summary>
/// Collection of Output Ports /// Collection of Output Ports
/// </summary> /// </summary>
[JsonProperty("outputPorts")]
RoutingPortCollection<RoutingOutputPort> OutputPorts { get; } RoutingPortCollection<RoutingOutputPort> OutputPorts { get; }
} }

View file

@ -1,3 +1,4 @@
using PepperDash.Core;
using PepperDash.Essentials.Core.Routing; using PepperDash.Essentials.Core.Routing;
namespace PepperDash.Essentials.Core; namespace PepperDash.Essentials.Core;
@ -5,7 +6,7 @@ namespace PepperDash.Essentials.Core;
/// <summary> /// <summary>
/// Defines the contract for IRoutingSink /// Defines the contract for IRoutingSink
/// </summary> /// </summary>
public interface IRoutingSink : IRoutingInputs, IHasCurrentSourceInfoChange public interface IRoutingSink : IRoutingInputs, IKeyName, ICurrentSources
{ {
} }
@ -20,10 +21,4 @@ public interface IRoutingSinkWithInputPort : IRoutingSink
RoutingInputPort CurrentInputPort { get; } RoutingInputPort CurrentInputPort { get; }
} }
/// <summary>
/// Interface for routing sinks that have access to the current source information.
/// </summary>
public interface IRoutingSinkWithCurrentSources : IRoutingSink, ICurrentSources
{
}

View file

@ -5,8 +5,9 @@
/// <summary> /// <summary>
/// Defines the contract for IRoutingSinkWithFeedback /// Defines the contract for IRoutingSinkWithFeedback
/// </summary> /// </summary>
public interface IRoutingSinkWithFeedback : IRoutingSinkWithSwitching public interface IRoutingSinkWithFeedback : IRoutingSink
{ {
} }

View file

@ -1,8 +1,10 @@
namespace PepperDash.Essentials.Core; using PepperDash.Core;
namespace PepperDash.Essentials.Core;
/// <summary> /// <summary>
/// Marker interface to identify a device that acts as the origin of a signal path (<see cref="IRoutingOutputs"/>). /// Marker interface to identify a device that acts as the origin of a signal path (<see cref="IRoutingOutputs"/>).
/// </summary> /// </summary>
public interface IRoutingSource : IRoutingOutputs public interface IRoutingSource : IRoutingOutputs, IKeyName
{ {
} }

View file

@ -9,15 +9,15 @@ namespace PepperDash.Essentials.Core.Routing;
/// Manages routing feedback by subscribing to route changes on midpoint and sink devices, /// Manages routing feedback by subscribing to route changes on midpoint and sink devices,
/// tracing the route back to the original source, and updating the CurrentSourceInfo on sink devices. /// tracing the route back to the original source, and updating the CurrentSourceInfo on sink devices.
/// </summary> /// </summary>
public class RoutingFeedbackManager: EssentialsDevice public class RoutingFeedbackManager : EssentialsDevice
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RoutingFeedbackManager"/> class. /// Initializes a new instance of the <see cref="RoutingFeedbackManager"/> class.
/// </summary> /// </summary>
/// <param name="key">The unique key for this manager device.</param> /// <param name="key">The unique key for this manager device.</param>
/// <param name="name">The name of this manager device.</param> /// <param name="name">The name of this manager device.</param>
public RoutingFeedbackManager(string key, string name): base(key, name) public RoutingFeedbackManager(string key, string name) : base(key, name)
{ {
AddPreActivationAction(SubscribeForMidpointFeedback); AddPreActivationAction(SubscribeForMidpointFeedback);
AddPreActivationAction(SubscribeForSinkFeedback); AddPreActivationAction(SubscribeForSinkFeedback);
} }
@ -41,12 +41,12 @@ public class RoutingFeedbackManager: EssentialsDevice
/// </summary> /// </summary>
private void SubscribeForSinkFeedback() private void SubscribeForSinkFeedback()
{ {
var sinkDevices = DeviceManager.AllDevices.OfType<IRoutingSinkWithSwitchingWithInputPort>(); var sinkDevices = DeviceManager.AllDevices.OfType<IRoutingSinkWithSwitchingWithInputPort>();
foreach (var device in sinkDevices) foreach (var device in sinkDevices)
{ {
device.InputChanged += HandleSinkUpdate; device.InputChanged += HandleSinkUpdate;
} }
} }
/// <summary> /// <summary>
@ -59,7 +59,7 @@ public class RoutingFeedbackManager: EssentialsDevice
{ {
try try
{ {
var devices = DeviceManager.AllDevices.OfType<IRoutingSinkWithSwitchingWithInputPort>(); var devices = DeviceManager.AllDevices.OfType<IRoutingSinkWithInputPort>();
foreach (var device in devices) foreach (var device in devices)
{ {
@ -96,13 +96,13 @@ public class RoutingFeedbackManager: EssentialsDevice
/// </summary> /// </summary>
/// <param name="destination">The destination sink device to update.</param> /// <param name="destination">The destination sink device to update.</param>
/// <param name="inputPort">The currently selected input port on the destination device.</param> /// <param name="inputPort">The currently selected input port on the destination device.</param>
private void UpdateDestination(IRoutingSinkWithSwitching destination, RoutingInputPort inputPort) private void UpdateDestination(IRoutingSink destination, RoutingInputPort inputPort)
{ {
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Updating destination {destination} with inputPort {inputPort}", this,destination?.Key, inputPort?.Key); // Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Updating destination {destination} with inputPort {inputPort}", this,destination?.Key, inputPort?.Key);
if(inputPort == null) if (inputPort == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "Destination {destination} has not reported an input port yet", this,destination.Key); Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "Destination {destination} has not reported an input port yet", this, destination.Key);
return; return;
} }
@ -116,19 +116,10 @@ public class RoutingFeedbackManager: EssentialsDevice
if (firstTieLine == null) if (firstTieLine == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No tieline found for inputPort {inputPort}. Clearing current source", this, inputPort); Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No tieline found for inputPort {inputPort}. Clearing current source", this, inputPort);
var tempSourceListItem = new SourceListItem
{
SourceKey = "$transient",
Name = inputPort.Key,
};
destination.CurrentSourceInfo = tempSourceListItem; ;
destination.CurrentSourceInfoKey = "$transient";
return; return;
} }
} catch (Exception ex) }
catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error getting first tieline: {Exception}", this, ex); Debug.LogMessage(ex, "Error getting first tieline: {Exception}", this, ex);
return; return;
@ -136,6 +127,7 @@ public class RoutingFeedbackManager: EssentialsDevice
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Getting source for first TieLine {tieLine}", this, firstTieLine); // Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Getting source for first TieLine {tieLine}", this, firstTieLine);
TieLine sourceTieLine; TieLine sourceTieLine;
try try
{ {
@ -145,91 +137,34 @@ public class RoutingFeedbackManager: EssentialsDevice
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No route found to source for inputPort {inputPort}. Clearing current source", this, inputPort); Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No route found to source for inputPort {inputPort}. Clearing current source", this, inputPort);
var tempSourceListItem = new SourceListItem
{
SourceKey = "$transient",
Name = "None",
};
destination.CurrentSourceInfo = tempSourceListItem; destination.SetCurrentSource(sourceTieLine.Type, null);
destination.CurrentSourceInfoKey = string.Empty;
return; return;
} }
} catch(Exception ex) }
catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error getting sourceTieLine: {Exception}", this, ex); Debug.LogMessage(ex, "Error getting sourceTieLine: {Exception}", this, ex);
return; return;
} }
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found root TieLine {tieLine}", this, sourceTieLine); if (sourceTieLine.SourcePort.ParentDevice == null)
// Does not handle combinable scenarios or other scenarios where a display might be part of multiple rooms yet.
var room = DeviceManager.AllDevices.OfType<IEssentialsRoom>().FirstOrDefault((r) => {
if(r is IHasMultipleDisplays roomMultipleDisplays)
{
return roomMultipleDisplays.Displays.Any(d => d.Value.Key == destination.Key);
}
if(r is IHasDefaultDisplay roomDefaultDisplay)
{
return roomDefaultDisplay.DefaultDisplay.Key == destination.Key;
}
return false;
});
if(room == null)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "No room found for display {destination}", this, destination.Key);
return;
}
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found room {room} for destination {destination}", this, room.Key, destination.Key);
var sourceList = ConfigReader.ConfigObject.GetSourceListForKey(room.SourceListKey);
if (sourceList == null)
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Warning, "No source list found for source list key {key}. Unable to find source for tieLine {sourceTieLine}", this, room.SourceListKey, sourceTieLine);
return;
}
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found sourceList for room {room}", this, room.Key);
var sourceListItem = sourceList.FirstOrDefault(sli => {
//// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose,
// "SourceListItem {sourceListItem}:{sourceKey} tieLine sourceport device key {sourcePortDeviceKey}",
// this,
// sli.Key,
// sli.Value.SourceKey,
// sourceTieLine.SourcePort.ParentDevice.Key);
return sli.Value.SourceKey.Equals(sourceTieLine.SourcePort.ParentDevice.Key,StringComparison.InvariantCultureIgnoreCase);
});
var source = sourceListItem.Value;
var sourceKey = sourceListItem.Key;
if (source == null)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No source found for device {key}. Creating transient source for {destination}", this, sourceTieLine.SourcePort.ParentDevice.Key, destination); Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "No source found for device {key}. Creating transient source for {destination}", this, sourceTieLine.SourcePort.ParentDevice.Key, destination);
var tempSourceListItem = new SourceListItem destination.SetCurrentSource(sourceTieLine.Type, null);
{
SourceKey = "$transient",
Name = sourceTieLine.SourcePort.Key,
};
destination.CurrentSourceInfoKey = "$transient";
destination.CurrentSourceInfo = tempSourceListItem;
return; return;
} }
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Got Source {@source} with key {sourceKey}", this, source, sourceKey); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Got Source {@source} with key {sourceKey}", this, source, sourceKey);
destination.CurrentSourceInfoKey = sourceKey; if (sourceTieLine.SourcePort.ParentDevice is IRoutingSource sourceDevice)
destination.CurrentSourceInfo = source; {
destination.SetCurrentSource(sourceTieLine.Type, sourceDevice);
}
} }
/// <summary> /// <summary>
@ -249,13 +184,14 @@ public class RoutingFeedbackManager: EssentialsDevice
{ {
// Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "TieLine Source device {sourceDevice} is midpoint", this, midpoint); // Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "TieLine Source device {sourceDevice} is midpoint", this, midpoint);
if(midpoint.CurrentRoutes == null || midpoint.CurrentRoutes.Count == 0) if (midpoint.CurrentRoutes == null || midpoint.CurrentRoutes.Count == 0)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Midpoint {midpointKey} has no routes",this, midpoint.Key); Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Midpoint {midpointKey} has no routes", this, midpoint.Key);
return null; return null;
} }
var currentRoute = midpoint.CurrentRoutes.FirstOrDefault(route => { var currentRoute = midpoint.CurrentRoutes.FirstOrDefault(route =>
{
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", this, route, tieLine); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", this, route, tieLine);
return route.OutputPort != null && route.InputPort != null && route.OutputPort?.Key == tieLine.SourcePort.Key && route.OutputPort?.ParentDevice.Key == tieLine.SourcePort.ParentDevice.Key; return route.OutputPort != null && route.InputPort != null && route.OutputPort?.Key == tieLine.SourcePort.Key && route.OutputPort?.ParentDevice.Key == tieLine.SourcePort.ParentDevice.Key;
@ -269,9 +205,11 @@ public class RoutingFeedbackManager: EssentialsDevice
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found currentRoute {currentRoute} through {midpoint}", this, currentRoute, midpoint); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Found currentRoute {currentRoute} through {midpoint}", this, currentRoute, midpoint);
nextTieLine = TieLineCollection.Default.FirstOrDefault(tl => { nextTieLine = TieLineCollection.Default.FirstOrDefault(tl =>
{
//Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", tl.DestinationPort.Key, currentRoute.InputPort.Key); //Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Checking {route} against {tieLine}", tl.DestinationPort.Key, currentRoute.InputPort.Key);
return tl.DestinationPort.Key == currentRoute.InputPort.Key && tl.DestinationPort.ParentDevice.Key == currentRoute.InputPort.ParentDevice.Key; }); return tl.DestinationPort.Key == currentRoute.InputPort.Key && tl.DestinationPort.ParentDevice.Key == currentRoute.InputPort.ParentDevice.Key;
});
if (nextTieLine != null) if (nextTieLine != null)
{ {
@ -292,13 +230,14 @@ public class RoutingFeedbackManager: EssentialsDevice
return tieLine; return tieLine;
} }
nextTieLine = TieLineCollection.Default.FirstOrDefault(tl => tl.DestinationPort.Key == tieLine.SourcePort.Key && tl.DestinationPort.ParentDevice.Key == tieLine.SourcePort.ParentDevice.Key ); nextTieLine = TieLineCollection.Default.FirstOrDefault(tl => tl.DestinationPort.Key == tieLine.SourcePort.Key && tl.DestinationPort.ParentDevice.Key == tieLine.SourcePort.ParentDevice.Key);
if (nextTieLine != null) if (nextTieLine != null)
{ {
return GetRootTieLine(nextTieLine); return GetRootTieLine(nextTieLine);
} }
} catch (Exception ex) }
catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error walking tieLines: {Exception}", this, ex); Debug.LogMessage(ex, "Error walking tieLines: {Exception}", this, ex);
return null; return null;

View file

@ -1,9 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using PepperDash.Core; using PepperDash.Core;
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; namespace PepperDash.Essentials.Devices.Common;
@ -13,33 +14,19 @@ namespace PepperDash.Essentials.Devices.Common;
/// </summary> /// </summary>
public class GenericAudioOut : EssentialsDevice, IRoutingSink public class GenericAudioOut : EssentialsDevice, IRoutingSink
{ {
/// <inheritdoc/>
public RoutingInputPort CurrentInputPort => AnyAudioIn; public RoutingInputPort CurrentInputPort => AnyAudioIn;
public event SourceInfoChangeHandler CurrentSourceChange;
public string CurrentSourceInfoKey { get; set; } /// <inheritdoc/>
public SourceListItem CurrentSourceInfo public Dictionary<eRoutingSignalType, IRoutingSource> CurrentSources { get; private set; }
{
get
{
return _CurrentSourceInfo;
}
set
{
if (value == _CurrentSourceInfo) return;
var handler = CurrentSourceChange; /// <inheritdoc/>
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; }
if (handler != null) /// <inheritdoc />
handler(_CurrentSourceInfo, ChangeType.WillChange); public event System.EventHandler<CurrentSourcesChangedEventArgs> CurrentSourcesChanged;
_CurrentSourceInfo = value;
if (handler != null)
handler(_CurrentSourceInfo, ChangeType.DidChange);
}
}
SourceListItem _CurrentSourceInfo;
/// <summary> /// <summary>
/// Gets or sets the AnyAudioIn /// Gets or sets the AnyAudioIn
@ -56,6 +43,66 @@ public class GenericAudioOut : EssentialsDevice, IRoutingSink
{ {
AnyAudioIn = new RoutingInputPort(RoutingPortNames.AnyAudioIn, eRoutingSignalType.Audio, AnyAudioIn = new RoutingInputPort(RoutingPortNames.AnyAudioIn, eRoutingSignalType.Audio,
eRoutingPortConnectionType.LineAudio, null, this); eRoutingPortConnectionType.LineAudio, null, this);
CurrentSources = new Dictionary<eRoutingSignalType, IRoutingSource>
{
{ eRoutingSignalType.Audio, null },
};
CurrentSourceKeys = new Dictionary<eRoutingSignalType, string>
{
{ eRoutingSignalType.Audio, string.Empty },
};
}
/// <inheritdoc />
public virtual void SetCurrentSource(eRoutingSignalType signalType, IRoutingSource sourceDevice)
{
foreach (eRoutingSignalType type in System.Enum.GetValues(typeof(eRoutingSignalType)))
{
var flagValue = System.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);
var previousSource = CurrentSources[type];
if (signalType.HasFlag(type))
{
UpdateCurrentSources(type, previousSource, sourceDevice);
}
}
}
private void UpdateCurrentSources(eRoutingSignalType signalType, IRoutingSource previousSource, IRoutingSource sourceDevice)
{
if (CurrentSources.ContainsKey(signalType))
{
CurrentSources[signalType] = sourceDevice;
}
else
{
CurrentSources.Add(signalType, sourceDevice);
}
// Update the current source key for the specified signal type
if (CurrentSourceKeys.ContainsKey(signalType))
{
CurrentSourceKeys[signalType] = sourceDevice.Key;
}
else
{
CurrentSourceKeys.Add(signalType, sourceDevice.Key);
}
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, new CurrentSourcesChangedEventArgs(signalType, previousSource, sourceDevice));
} }
#region IRoutingInputs Members #region IRoutingInputs Members
@ -116,13 +163,20 @@ public class GenericAudioOutWithVolume : GenericAudioOut, IHasVolumeDevice
} }
/// <summary>
/// Factory for creating GenericAudioOutWithVolume devices
/// </summary>
public class GenericAudioOutWithVolumeFactory : EssentialsDeviceFactory<GenericAudioOutWithVolume> public class GenericAudioOutWithVolumeFactory : EssentialsDeviceFactory<GenericAudioOutWithVolume>
{ {
/// <summary>
/// Constructor for GenericAudioOutWithVolumeFactory
/// </summary>
public GenericAudioOutWithVolumeFactory() public GenericAudioOutWithVolumeFactory()
{ {
TypeNames = new List<string>() { "genericaudiooutwithvolume" }; TypeNames = new List<string>() { "genericaudiooutwithvolume" };
} }
/// <inheritdoc />
public override EssentialsDevice BuildDevice(DeviceConfig dc) public override EssentialsDevice BuildDevice(DeviceConfig dc)
{ {
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new GenericAudioOutWithVolumeFactory Device"); Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new GenericAudioOutWithVolumeFactory Device");

View file

@ -48,48 +48,20 @@ public abstract class DisplayBase : EssentialsDevice, IDisplay, ICurrentSources,
/// </summary> /// </summary>
public event InputChangedEventHandler InputChanged; public event InputChangedEventHandler InputChanged;
/// <summary>
/// Event that is raised when the current source information changes.
/// </summary>
public event SourceInfoChangeHandler CurrentSourceChange;
/// <summary> /// <summary>
/// Gets or sets the CurrentSourceInfoKey /// Gets or sets the CurrentSourceInfoKey
/// </summary> /// </summary>
public string CurrentSourceInfoKey { get; set; } public string CurrentSourceInfoKey { get; set; }
/// <summary>
/// Gets or sets the current source information for the display.
/// </summary>
public SourceListItem CurrentSourceInfo
{
get
{
return _CurrentSourceInfo;
}
set
{
if (value == _CurrentSourceInfo) return;
var handler = CurrentSourceChange;
handler?.Invoke(_CurrentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value;
handler?.Invoke(_CurrentSourceInfo, ChangeType.DidChange);
}
}
SourceListItem _CurrentSourceInfo;
/// <inheritdoc/> /// <inheritdoc/>
public Dictionary<eRoutingSignalType, SourceListItem> CurrentSources { get; private set; } public Dictionary<eRoutingSignalType, IRoutingSource> CurrentSources { get; private set; }
/// <inheritdoc/> /// <inheritdoc/>
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; } public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public event EventHandler CurrentSourcesChanged; public event EventHandler<CurrentSourcesChangedEventArgs> CurrentSourcesChanged;
/// <summary> /// <summary>
/// Gets feedback indicating whether the display is currently cooling down after being powered off. /// Gets feedback indicating whether the display is currently cooling down after being powered off.
@ -163,7 +135,7 @@ public abstract class DisplayBase : EssentialsDevice, IDisplay, ICurrentSources,
InputPorts = new RoutingPortCollection<RoutingInputPort>(); InputPorts = new RoutingPortCollection<RoutingInputPort>();
CurrentSources = new Dictionary<eRoutingSignalType, SourceListItem> CurrentSources = new Dictionary<eRoutingSignalType, IRoutingSource>
{ {
{ eRoutingSignalType.Audio, null }, { eRoutingSignalType.Audio, null },
{ eRoutingSignalType.Video, null }, { eRoutingSignalType.Video, null },
@ -388,7 +360,7 @@ public abstract class DisplayBase : EssentialsDevice, IDisplay, ICurrentSources,
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem) public virtual void SetCurrentSource(eRoutingSignalType signalType, IRoutingSource sourceDevice)
{ {
foreach (eRoutingSignalType type in Enum.GetValues(typeof(eRoutingSignalType))) foreach (eRoutingSignalType type in Enum.GetValues(typeof(eRoutingSignalType)))
{ {
@ -403,35 +375,38 @@ public abstract class DisplayBase : EssentialsDevice, IDisplay, ICurrentSources,
this.LogDebug("setting {type}", type); this.LogDebug("setting {type}", type);
var previousSource = CurrentSources[type];
if (signalType.HasFlag(type)) if (signalType.HasFlag(type))
{ {
UpdateCurrentSources(type, sourceListKey, sourceListItem); UpdateCurrentSources(type, previousSource, sourceDevice);
} }
} }
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, EventArgs.Empty);
} }
private void UpdateCurrentSources(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem) private void UpdateCurrentSources(eRoutingSignalType signalType, IRoutingSource previousSource, IRoutingSource sourceDevice)
{ {
if (CurrentSources.ContainsKey(signalType)) if (CurrentSources.ContainsKey(signalType))
{ {
CurrentSources[signalType] = sourceListItem; CurrentSources[signalType] = sourceDevice;
} }
else else
{ {
CurrentSources.Add(signalType, sourceListItem); CurrentSources.Add(signalType, sourceDevice);
} }
// Update the current source key for the specified signal type // Update the current source key for the specified signal type
if (CurrentSourceKeys.ContainsKey(signalType)) if (CurrentSourceKeys.ContainsKey(signalType))
{ {
CurrentSourceKeys[signalType] = sourceListKey; CurrentSourceKeys[signalType] = sourceDevice.Key;
} }
else else
{ {
CurrentSourceKeys.Add(signalType, sourceListKey); CurrentSourceKeys.Add(signalType, sourceDevice.Key);
} }
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, new CurrentSourcesChangedEventArgs(signalType, previousSource, sourceDevice));
} }
} }

View file

@ -14,14 +14,14 @@ namespace PepperDash.Essentials.Devices.Common.Generic;
/// </summary> /// </summary>
public class GenericSink : EssentialsDevice, IRoutingSinkWithSwitchingWithInputPort, ICurrentSources public class GenericSink : EssentialsDevice, IRoutingSinkWithSwitchingWithInputPort, ICurrentSources
{ {
/// <inheritdoc/> /// <inheritdoc/>
public Dictionary<eRoutingSignalType, SourceListItem> CurrentSources { get; private set; } public Dictionary<eRoutingSignalType, IRoutingSource> CurrentSources { get; private set; }
/// <inheritdoc/> /// <inheritdoc/>
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; } public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public event EventHandler CurrentSourcesChanged; public event EventHandler<CurrentSourcesChangedEventArgs> CurrentSourcesChanged;
/// <summary> /// <summary>
/// Initializes a new instance of the GenericSink class /// Initializes a new instance of the GenericSink class
@ -36,7 +36,7 @@ public class GenericSink : EssentialsDevice, IRoutingSinkWithSwitchingWithInputP
InputPorts.Add(inputPort); InputPorts.Add(inputPort);
CurrentSources = new Dictionary<eRoutingSignalType, SourceListItem> CurrentSources = new Dictionary<eRoutingSignalType, IRoutingSource>
{ {
{ eRoutingSignalType.Audio, null }, { eRoutingSignalType.Audio, null },
{ eRoutingSignalType.Video, null }, { eRoutingSignalType.Video, null },
@ -49,36 +49,55 @@ public class GenericSink : EssentialsDevice, IRoutingSinkWithSwitchingWithInputP
}; };
} }
/// <inheritdoc /> /// <inheritdoc />
public void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem) public virtual void SetCurrentSource(eRoutingSignalType signalType, IRoutingSource sourceDevice)
{ {
foreach (eRoutingSignalType type in Enum.GetValues(typeof(eRoutingSignalType))) foreach (eRoutingSignalType type in Enum.GetValues(typeof(eRoutingSignalType)))
{ {
var flagValue = Convert.ToInt32(type); var flagValue = Convert.ToInt32(type);
// Skip if flagValue is 0 or not a power of two (i.e., not a single-bit flag). // 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. // (flagValue & (flagValue - 1)) != 0 checks if more than one bit is set.
if (flagValue == 0 || (flagValue & (flagValue - 1)) != 0) if (flagValue == 0 || (flagValue & (flagValue - 1)) != 0)
{ {
this.LogDebug("Skipping {type}", type); this.LogDebug("Skipping {type}", type);
continue; continue;
} }
this.LogDebug("setting {type}", type); this.LogDebug("setting {type}", type);
if (signalType.HasFlag(type)) var previousSource = CurrentSources[type];
{
UpdateCurrentSources(type, sourceListKey, sourceListItem);
}
}
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, EventArgs.Empty);
}
private void UpdateCurrentSources(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem) if (signalType.HasFlag(type))
{ {
CurrentSources[signalType] = sourceListItem; UpdateCurrentSources(type, previousSource, sourceDevice);
CurrentSourceKeys[signalType] = sourceListKey; }
} }
}
private void UpdateCurrentSources(eRoutingSignalType signalType, IRoutingSource previousSource, IRoutingSource sourceDevice)
{
if (CurrentSources.ContainsKey(signalType))
{
CurrentSources[signalType] = sourceDevice;
}
else
{
CurrentSources.Add(signalType, sourceDevice);
}
// Update the current source key for the specified signal type
if (CurrentSourceKeys.ContainsKey(signalType))
{
CurrentSourceKeys[signalType] = sourceDevice.Key;
}
else
{
CurrentSourceKeys.Add(signalType, sourceDevice.Key);
}
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, new CurrentSourcesChangedEventArgs(signalType, previousSource, sourceDevice));
}
/// <summary> /// <summary>
/// Gets or sets the InputPorts /// Gets or sets the InputPorts

View file

@ -1,8 +1,11 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using PepperDash.Core; using PepperDash.Core;
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 PepperDash.Essentials.Devices.Common.Sources; using PepperDash.Essentials.Devices.Common.Sources;
using Serilog.Events; using Serilog.Events;
@ -22,10 +25,19 @@ public class BlueJeansPc : InRoomPc, IRunRouteAction, IRoutingSink
/// <summary> /// <summary>
/// The currently active input port, which for this device is always AnyVideoIn /// The currently active input port, which for this device is always AnyVideoIn
/// This is used by the routing system to determine where to route video sources when this device is a destination /// This is used by the routing system to determine where to route video sources when this device is a destination
/// </summary> /// </summary>
public RoutingInputPort CurrentInputPort => AnyVideoIn; public RoutingInputPort CurrentInputPort => AnyVideoIn;
/// <inheritdoc/>
public Dictionary<eRoutingSignalType, IRoutingSource> CurrentSources { get; private set; }
/// <inheritdoc/>
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; }
/// <inheritdoc />
public event EventHandler<CurrentSourcesChangedEventArgs> CurrentSourcesChanged;
#region IRoutingInputs Members #region IRoutingInputs Members
/// <summary> /// <summary>
@ -47,15 +59,77 @@ public class BlueJeansPc : InRoomPc, IRunRouteAction, IRoutingSink
{ {
(AnyVideoIn = new RoutingInputPort(RoutingPortNames.AnyVideoIn, eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.None, 0, this)) (AnyVideoIn = new RoutingInputPort(RoutingPortNames.AnyVideoIn, eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.None, 0, this))
}; };
CurrentSources = new Dictionary<eRoutingSignalType, IRoutingSource>
{
{ eRoutingSignalType.Audio, null },
{ eRoutingSignalType.Video, null },
};
CurrentSourceKeys = new Dictionary<eRoutingSignalType, string>
{
{ eRoutingSignalType.Audio, string.Empty },
{ eRoutingSignalType.Video, string.Empty },
};
}
/// <inheritdoc />
public virtual void SetCurrentSource(eRoutingSignalType signalType, IRoutingSource sourceDevice)
{
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);
var previousSource = CurrentSources[type];
if (signalType.HasFlag(type))
{
UpdateCurrentSources(type, previousSource, sourceDevice);
}
}
}
private void UpdateCurrentSources(eRoutingSignalType signalType, IRoutingSource previousSource, IRoutingSource sourceDevice)
{
if (CurrentSources.ContainsKey(signalType))
{
CurrentSources[signalType] = sourceDevice;
}
else
{
CurrentSources.Add(signalType, sourceDevice);
}
// Update the current source key for the specified signal type
if (CurrentSourceKeys.ContainsKey(signalType))
{
CurrentSourceKeys[signalType] = sourceDevice.Key;
}
else
{
CurrentSourceKeys.Add(signalType, sourceDevice.Key);
}
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, new CurrentSourcesChangedEventArgs(signalType, previousSource, sourceDevice));
} }
#region IRunRouteAction Members #region IRunRouteAction Members
/// <summary> /// <summary>
/// Runs a route action for the specified route key and source list key. Optionally, a callback can be provided to be executed upon successful completion. /// Runs a route action for the specified route key and source list key. Optionally, a callback can be provided to be executed upon successful completion.
/// </summary> /// </summary>
/// <param name="routeKey"></param> /// <param name="routeKey"></param>
/// <param name="sourceListKey"></param> /// <param name="sourceListKey"></param>
public void RunRouteAction(string routeKey, string sourceListKey) public void RunRouteAction(string routeKey, string sourceListKey)
{ {
RunRouteAction(routeKey, sourceListKey, null); RunRouteAction(routeKey, sourceListKey, null);

View file

@ -1,6 +1,9 @@
using System.Linq; using System.Collections.Generic;
using System.Linq;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Routing;
using Serilog.Events; using Serilog.Events;
namespace PepperDash.Essentials.Devices.Common.SoftCodec; namespace PepperDash.Essentials.Devices.Common.SoftCodec;
@ -27,6 +30,15 @@ public class GenericSoftCodec : EssentialsDevice, IRoutingSource, IRoutingSinkWi
} }
} }
/// <inheritdoc/>
public Dictionary<eRoutingSignalType, IRoutingSource> CurrentSources { get; private set; }
/// <inheritdoc/>
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; }
/// <inheritdoc />
public event System.EventHandler<CurrentSourcesChangedEventArgs> CurrentSourcesChanged;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GenericSoftCodec"/> class /// Initializes a new instance of the <see cref="GenericSoftCodec"/> class
/// </summary> /// </summary>
@ -49,6 +61,18 @@ public class GenericSoftCodec : EssentialsDevice, IRoutingSource, IRoutingSinkWi
InputPorts.Add(inputPort); InputPorts.Add(inputPort);
} }
CurrentSources = new Dictionary<eRoutingSignalType, IRoutingSource>
{
{ eRoutingSignalType.Audio, null },
{ eRoutingSignalType.Video, null },
};
CurrentSourceKeys = new Dictionary<eRoutingSignalType, string>
{
{ eRoutingSignalType.Audio, string.Empty },
{ eRoutingSignalType.Video, string.Empty },
};
if (!props.HasCameraInputs) if (!props.HasCameraInputs)
{ {
return; return;
@ -62,6 +86,56 @@ public class GenericSoftCodec : EssentialsDevice, IRoutingSource, IRoutingSinkWi
} }
} }
/// <inheritdoc />
public virtual void SetCurrentSource(eRoutingSignalType signalType, IRoutingSource sourceDevice)
{
foreach (eRoutingSignalType type in System.Enum.GetValues(typeof(eRoutingSignalType)))
{
var flagValue = System.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);
var previousSource = CurrentSources[type];
if (signalType.HasFlag(type))
{
UpdateCurrentSources(type, previousSource, sourceDevice);
}
}
}
private void UpdateCurrentSources(eRoutingSignalType signalType, IRoutingSource previousSource, IRoutingSource sourceDevice)
{
if (CurrentSources.ContainsKey(signalType))
{
CurrentSources[signalType] = sourceDevice;
}
else
{
CurrentSources.Add(signalType, sourceDevice);
}
// Update the current source key for the specified signal type
if (CurrentSourceKeys.ContainsKey(signalType))
{
CurrentSourceKeys[signalType] = sourceDevice.Key;
}
else
{
CurrentSourceKeys.Add(signalType, sourceDevice.Key);
}
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, new CurrentSourcesChangedEventArgs(signalType, previousSource, sourceDevice));
}
/// <summary> /// <summary>
/// Gets or sets the InputPorts /// Gets or sets the InputPorts
/// </summary> /// </summary>

View file

@ -69,7 +69,6 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// </summary> /// </summary>
public class CurrentSourcesStateMessage : DeviceStateMessageBase public class CurrentSourcesStateMessage : DeviceStateMessageBase
{ {
/// <summary> /// <summary>
/// Gets or sets the CurrentSourceKey /// Gets or sets the CurrentSourceKey
/// </summary> /// </summary>
@ -81,6 +80,6 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// Gets or sets the CurrentSource /// Gets or sets the CurrentSource
/// </summary> /// </summary>
[JsonProperty("currentSources")] [JsonProperty("currentSources")]
public Dictionary<eRoutingSignalType, SourceListItem> CurrentSources { get; set; } public Dictionary<eRoutingSignalType, IRoutingSource> CurrentSources { get; set; }
} }
} }

View file

@ -1,7 +1,5 @@
using System; using System;
using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
@ -17,29 +15,22 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// </summary> /// </summary>
public IRunRouteAction RoutingDevice { get; private set; } public IRunRouteAction RoutingDevice { get; private set; }
/// <summary>
/// Initializes a new instance of the RunRouteActionMessenger class
/// </summary>
/// <param name="key">The key.</param>
/// <param name="routingDevice">The routing device.</param>
/// <param name="messagePath">The message path.</param>
/// <exception cref="ArgumentNullException"></exception>
public RunRouteActionMessenger(string key, IRunRouteAction routingDevice, string messagePath) public RunRouteActionMessenger(string key, IRunRouteAction routingDevice, string messagePath)
: base(key, messagePath, routingDevice as IKeyName) : base(key, messagePath, routingDevice as IKeyName)
{ {
RoutingDevice = routingDevice ?? throw new ArgumentNullException("routingDevice"); RoutingDevice = routingDevice ?? throw new ArgumentNullException("routingDevice");
if (RoutingDevice is IRoutingSink routingSink)
{
routingSink.CurrentSourceChange += RoutingSink_CurrentSourceChange;
}
}
private void RoutingSink_CurrentSourceChange(SourceListItem info, ChangeType type)
{
SendRoutingFullMessageObject();
} }
/// <inheritdoc />
protected override void RegisterActions() protected override void RegisterActions()
{ {
AddAction("/fullStatus", (id, content) => SendRoutingFullMessageObject(id));
AddAction("/routingStatus", (id, content) => SendRoutingFullMessageObject(id));
AddAction("/source", (id, content) => AddAction("/source", (id, content) =>
{ {
var c = content.ToObject<SourceSelectMessageContent>(); var c = content.ToObject<SourceSelectMessageContent>();
@ -55,41 +46,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
RoutingDevice.RunRouteAction(c.SourceListItemKey, sourceListKey); RoutingDevice.RunRouteAction(c.SourceListItemKey, sourceListKey);
}); });
if (RoutingDevice is IRoutingSink sinkDevice)
{
sinkDevice.CurrentSourceChange += (o, a) => SendRoutingFullMessageObject();
}
}
/// <summary>
/// Helper method to update full status of the routing device
/// </summary>
private void SendRoutingFullMessageObject(string id = null)
{
if (RoutingDevice is IRoutingSink sinkDevice)
{
var sourceKey = sinkDevice.CurrentSourceInfoKey;
if (string.IsNullOrEmpty(sourceKey))
sourceKey = "none";
PostStatusMessage(new RoutingStateMessage
{
SelectedSourceKey = sourceKey
});
}
} }
} }
/// <summary>
/// Represents a RoutingStateMessage
/// </summary>
public class RoutingStateMessage : DeviceStateMessageBase
{
/// <summary>
/// Gets or sets the SelectedSourceKey
/// </summary>
[JsonProperty("selectedSourceKey")]
public string SelectedSourceKey { get; set; }
}
} }

View file

@ -719,29 +719,6 @@ namespace PepperDash.Essentials.RoomBridges
} }
} }
if (room is IHasDefaultDisplay defDisplayRoom)
{
this.LogVerbose("Getting default display config");
configuration.DefaultDisplayKey = defDisplayRoom.DefaultDisplay.Key;
configuration.Destinations.Add(eSourceListItemDestinationTypes.defaultDisplay, defDisplayRoom.DefaultDisplay.Key);
}
if (room is IHasMultipleDisplays multiDisplayRoom)
{
this.LogVerbose("Getting multiple display config");
if (multiDisplayRoom.Displays == null)
{
this.LogVerbose("Displays collection is null");
}
else
{
this.LogVerbose("Displays collection exists");
configuration.Destinations = multiDisplayRoom.Displays.ToDictionary(kv => kv.Key, kv => kv.Value.Key);
}
}
if (room is IHasAccessoryDevices accRoom) if (room is IHasAccessoryDevices accRoom)
{ {
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Getting accessory devices config", this); Debug.LogMessage(Serilog.Events.LogEventLevel.Information, "Getting accessory devices config", this);
@ -1015,13 +992,6 @@ namespace PepperDash.Essentials.RoomBridges
[JsonProperty("defaultDisplayKey", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty("defaultDisplayKey", NullValueHandling = NullValueHandling.Ignore)]
public string DefaultDisplayKey { get; set; } public string DefaultDisplayKey { get; set; }
/// <summary>
/// Gets or sets the destinations dictionary keyed by destination type
/// </summary>
[JsonProperty("destinations", NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<eSourceListItemDestinationTypes, string> Destinations { get; set; }
/// <summary> /// <summary>
/// Gets or sets the EnvironmentalDevices /// Gets or sets the EnvironmentalDevices
/// </summary> /// </summary>
@ -1106,7 +1076,6 @@ namespace PepperDash.Essentials.RoomBridges
/// </summary> /// </summary>
public RoomConfiguration() public RoomConfiguration()
{ {
Destinations = new Dictionary<eSourceListItemDestinationTypes, string>();
EnvironmentalDevices = new List<EnvironmentalDeviceConfiguration>(); EnvironmentalDevices = new List<EnvironmentalDeviceConfiguration>();
SourceList = new Dictionary<string, SourceListItem>(); SourceList = new Dictionary<string, SourceListItem>();
TouchpanelKeys = new List<string>(); TouchpanelKeys = new List<string>();