Refactored for source change handler updates

This commit is contained in:
Neil Dorin
2019-11-08 12:30:49 -07:00
parent c22e95cad2
commit 3560880e50
19 changed files with 178 additions and 73 deletions

View File

@@ -334,7 +334,7 @@ namespace PepperDash.Essentials
}
void Room_CurrentSingleSourceChange(EssentialsRoomBase room, PepperDash.Essentials.Core.SourceListItem info, ChangeType type)
void Room_CurrentSingleSourceChange(PepperDash.Essentials.Core.SourceListItem info, ChangeType type)
{
/* Example message
* {
@@ -395,11 +395,14 @@ namespace PepperDash.Essentials
if (dev is ITransport)
(dev as ITransport).LinkActions(Parent);
var srcRm = room as IHasCurrentSourceInfoChange;
PostStatusMessage(new
{
selectedSourceKey = srcRm.CurrentSourceInfoKey
});
var srcRm = Room as IHasCurrentSourceInfoChange;
if (srcRm != null)
{
PostStatusMessage(new
{
selectedSourceKey = srcRm.CurrentSourceInfoKey
});
}
}
}
}

View File

@@ -12,6 +12,32 @@ namespace PepperDash.Essentials
{
public class Amplifier : Device, IRoutingSinkNoSwitching
{
public event SourceInfoChangeHandler CurrentSourceChange;
public string CurrentSourceInfoKey { get; set; }
public SourceListItem CurrentSourceInfo
{
get
{
return _CurrentSourceInfo;
}
set
{
if (value == _CurrentSourceInfo) return;
var handler = CurrentSourceChange;
if (handler != null)
handler(_CurrentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value;
if (handler != null)
handler(_CurrentSourceInfo, ChangeType.DidChange);
}
}
SourceListItem _CurrentSourceInfo;
public RoutingInputPort AudioIn { get; private set; }
public Amplifier(string key, string name)

View File

@@ -11,7 +11,5 @@ namespace PepperDash.Essentials.Room.Config
public class EssentialsDualDisplayRoomPropertiesConfig : EssentialsNDisplayRoomPropertiesConfig
{
public const string LeftDisplayId = "leftDisplay";
public const string RightDisplayId = "rightDisplay";
}
}

View File

@@ -4,6 +4,9 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using Newtonsoft.Json;
namespace PepperDash.Essentials.Room.Config
@@ -18,13 +21,19 @@ namespace PepperDash.Essentials.Room.Config
[JsonProperty("defaultVideoBehavior")]
public string DefaultVideoBehavior { get; set; }
[JsonProperty("displays")]
public Dictionary<string, string> Displays { get; set; }
public Dictionary<eSourceListItemDestinationTypes, DisplayItem> Displays { get; set; }
public EssentialsNDisplayRoomPropertiesConfig()
{
Displays = new Dictionary<string, string>();
Displays = new Dictionary<eSourceListItemDestinationTypes, DisplayItem>();
}
}
public class DisplayItem : IKeyName
{
public string Key { get; set; }
public string Name { get; set; }
}
}

View File

@@ -44,8 +44,8 @@ namespace PepperDash.Essentials.Room.Types
/// </summary>
public BoolFeedback IsSharingFeedback { get; private set; }
IRoutingSinkWithSwitching LeftDisplay { get; private set; }
IRoutingSinkWithSwitching RightDisplay { get; private set; }
public IRoutingSinkWithSwitching LeftDisplay { get; private set; }
public IRoutingSinkWithSwitching RightDisplay { get; private set; }
protected override Func<bool> OnFeedbackFunc
@@ -171,19 +171,25 @@ namespace PepperDash.Essentials.Room.Types
PropertiesConfig = JsonConvert.DeserializeObject<EssentialsDualDisplayRoomPropertiesConfig>
(config.Properties.ToString());
var leftDispKey = PropertiesConfig.Displays[EssentialsDualDisplayRoomPropertiesConfig.LeftDisplayId];
var leftDisp = PropertiesConfig.Displays[eSourceListItemDestinationTypes.leftDisplay];
if (leftDisp != null)
{
if (!string.IsNullOrEmpty(leftDispKey))
LeftDisplay = DeviceManager.GetDeviceForKey(leftDispKey) as IRoutingSinkWithSwitching;
else
Debug.Console(0, this, "Unable to get LeftDisplay for Room");
if (!string.IsNullOrEmpty(leftDisp.Key))
LeftDisplay = DeviceManager.GetDeviceForKey(leftDisp.Key) as IRoutingSinkWithSwitching;
else
Debug.Console(0, this, "Unable to get LeftDisplay for Room");
}
var rightDispKey = PropertiesConfig.Displays[EssentialsDualDisplayRoomPropertiesConfig.RightDisplayId];
var rightDisp = PropertiesConfig.Displays[eSourceListItemDestinationTypes.rightDisplay];
if (rightDisp != null)
{
if (!string.IsNullOrEmpty(rightDispKey))
LeftDisplay = DeviceManager.GetDeviceForKey(rightDispKey) as IRoutingSinkWithSwitching;
else
Debug.Console(0, this, "Unable to get LeftDisplay for Room");
if (!string.IsNullOrEmpty(rightDisp.Key))
LeftDisplay = DeviceManager.GetDeviceForKey(rightDisp.Key) as IRoutingSinkWithSwitching;
else
Debug.Console(0, this, "Unable to get LeftDisplay for Room");
}
VideoCodec = DeviceManager.GetDeviceForKey(PropertiesConfig.VideoCodecKey) as
PepperDash.Essentials.Devices.Common.VideoCodec.VideoCodecBase;
@@ -428,12 +434,12 @@ namespace PepperDash.Essentials.Room.Types
LastSourceKey = routeKey;
}
else
CurrentSourceInfoKey = null;
//else
// CurrentSourceInfoKey = null;
// hand off the individual routes to this helper
foreach (var route in item.RouteList)
DoRouteItem(route);
DoRouteItem(route, item, routeKey);
// Start usage timer on routed source
var usageNewSource = item.SourceDevice as IUsageTracking;
@@ -451,8 +457,7 @@ namespace PepperDash.Essentials.Room.Types
if (string.IsNullOrEmpty(item.VolumeControlKey)
|| item.VolumeControlKey.Equals("$defaultAudio", StringComparison.OrdinalIgnoreCase))
volDev = DefaultVolumeControls;
else if (item.VolumeControlKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
volDev = DefaultDisplay as IBasicVolumeControls;
// Or a specific device, probably rarely used.
else
{
@@ -489,14 +494,17 @@ namespace PepperDash.Essentials.Room.Types
// store the name and UI info for routes
if (item.SourceKey == "$off")
{
CurrentSourceInfoKey = routeKey;
CurrentSourceInfo = null;
}
else if (item.SourceKey != null)
{
CurrentSourceInfoKey = routeKey;
CurrentSourceInfo = item;
LeftDisplay.CurrentSourceInfoKey = routeKey;
LeftDisplay.CurrentSourceInfo = null;
RightDisplay.CurrentSourceInfoKey = routeKey;
RightDisplay.CurrentSourceInfo = null;
}
//else if (item.SourceKey != null)
//{
// if(item.RouteList
// CurrentSourceInfoKey = routeKey;
// CurrentSourceInfo = item;
//}
OnFeedback.FireUpdate();
@@ -518,7 +526,7 @@ namespace PepperDash.Essentials.Room.Types
///
/// </summary>
/// <param name="route"></param>
void DoRouteItem(SourceRouteListItem route)
void DoRouteItem(SourceRouteListItem route, SourceListItem sourceItem, string sourceItemKey)
{
// if there is a $defaultAll on route, run two separate
if (route.DestinationKey.Equals("$defaultAll", StringComparison.OrdinalIgnoreCase))
@@ -530,10 +538,10 @@ namespace PepperDash.Essentials.Room.Types
SourceKey = route.SourceKey,
Type = eRoutingSignalType.Video
};
DoRoute(tempVideo);
DoRoute(tempVideo, sourceItem, sourceItemKey);
}
else
DoRoute(route);
DoRoute(route, sourceItem, sourceItemKey);
}
/// <summary>
@@ -541,14 +549,16 @@ namespace PepperDash.Essentials.Room.Types
/// </summary>
/// <param name="route"></param>
/// <returns></returns>
bool DoRoute(SourceRouteListItem route)
bool DoRoute(SourceRouteListItem route, SourceListItem sourceItem, string sourceItemKey)
{
IRoutingSinkNoSwitching dest = null;
if (route.DestinationKey.Equals("$defaultaudio", StringComparison.OrdinalIgnoreCase))
dest = DefaultAudioDevice as IRoutingSinkNoSwitching;
else if (route.DestinationKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
dest = DefaultDisplay;
else if (route.DestinationKey.Equals(LeftDisplay.Key, StringComparison.OrdinalIgnoreCase))
dest = LeftDisplay;
else if (route.DestinationKey.Equals(RightDisplay.Key, StringComparison.OrdinalIgnoreCase))
dest = RightDisplay;
else
dest = DeviceManager.GetDeviceForKey(route.DestinationKey) as IRoutingSinkNoSwitching;
@@ -561,6 +571,9 @@ namespace PepperDash.Essentials.Room.Types
if (route.SourceKey.Equals("$off", StringComparison.OrdinalIgnoreCase))
{
dest.ReleaseRoute();
if (dest is IPower)
(dest as IPower).PowerOff();
}
@@ -573,6 +586,9 @@ namespace PepperDash.Essentials.Room.Types
return false;
}
dest.ReleaseAndMakeRoute(source, route.Type);
dest.CurrentSourceInfoKey = sourceItemKey;
dest.CurrentSourceInfo = sourceItem;
}
return true;
}

View File

@@ -119,7 +119,7 @@ namespace PepperDash.Essentials
public SourceListItem CurrentSourceInfo
{
get { return _CurrentSourceInfo; }
private set
set
{
if (value == _CurrentSourceInfo) return;
@@ -129,7 +129,7 @@ namespace PepperDash.Essentials
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.RemoveUser(this, "control");
if (handler != null)
handler(this, _CurrentSourceInfo, ChangeType.WillChange);
handler(_CurrentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value;
@@ -137,12 +137,12 @@ namespace PepperDash.Essentials
if (_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking)
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.AddUser(this, "control");
if (handler != null)
handler(this, _CurrentSourceInfo, ChangeType.DidChange);
handler( _CurrentSourceInfo, ChangeType.DidChange);
}
}
SourceListItem _CurrentSourceInfo;
public string CurrentSourceInfoKey { get; private set; }
public string CurrentSourceInfoKey { get; set; }
public EssentialsHuddleSpaceRoom(DeviceConfig config)
: base(config)

View File

@@ -157,7 +157,7 @@ namespace PepperDash.Essentials
public SourceListItem CurrentSourceInfo
{
get { return _CurrentSourceInfo; }
private set
set
{
if (value == _CurrentSourceInfo) return;
@@ -167,7 +167,7 @@ namespace PepperDash.Essentials
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.RemoveUser(this, "control");
if (handler != null)
handler(this, _CurrentSourceInfo, ChangeType.WillChange);
handler(_CurrentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value;
@@ -175,12 +175,12 @@ namespace PepperDash.Essentials
if (_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking)
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.AddUser(this, "control");
if (handler != null)
handler(this, _CurrentSourceInfo, ChangeType.DidChange);
handler(_CurrentSourceInfo, ChangeType.DidChange);
}
}
SourceListItem _CurrentSourceInfo;
public string CurrentSourceInfoKey { get; private set; }
public string CurrentSourceInfoKey { get; set; }
/// <summary>
/// "codecOsd"

View File

@@ -21,22 +21,13 @@ namespace PepperDash.Essentials.Room.Types
{
//public event SourceInfoChangeHandler CurrentSingleSourceChange;
public Dictionary<string, IRoutingSinkWithSwitching> Displays { get; protected set; }
public EssentialsNDisplayRoomBase(DeviceConfig config)
: base (config)
{
Displays = new Dictionary<string, IRoutingSinkWithSwitching>();
var propertiesConfig = JsonConvert.DeserializeObject<EssentialsNDisplayRoomPropertiesConfig>(config.Properties.ToString());
foreach (var display in propertiesConfig.Displays)
{
var displayDevice = DeviceManager.GetDeviceForKey(display.Value) as IRoutingSinkWithSwitching;
if (displayDevice != null)
Displays.Add(display.Key, displayDevice);
}
}
}
}

View File

@@ -29,7 +29,7 @@ namespace PepperDash.Essentials
room.CurrentSourceChange += room_CurrentSourceInfoChange;
}
void room_CurrentSourceInfoChange(EssentialsRoomBase room, SourceListItem info, ChangeType type)
void room_CurrentSourceInfoChange(SourceListItem info, ChangeType type)
{
if (type == ChangeType.WillChange && info == SourceItem)
ClearFeedback();

View File

@@ -1064,8 +1064,7 @@ namespace PepperDash.Essentials
/// <summary>
/// Handles source change
/// </summary>
void CurrentRoom_SourceInfoChange(EssentialsRoomBase room,
SourceListItem info, ChangeType change)
void CurrentRoom_SourceInfoChange(SourceListItem info, ChangeType change)
{
if (change == ChangeType.WillChange)
DisconnectSource(info);

View File

@@ -1050,7 +1050,7 @@ namespace PepperDash.Essentials
/// <param name="room"></param>
/// <param name="info"></param>
/// <param name="type"></param>
void CurrentRoom_CurrentSingleSourceChange(EssentialsRoomBase room, SourceListItem info, ChangeType type)
void CurrentRoom_CurrentSingleSourceChange(SourceListItem info, ChangeType type)
{
if (_CurrentRoom.VideoCodec.SharingContentIsOnFeedback.BoolValue && _CurrentRoom.CurrentSourceInfo != null)
TriList.StringInput[UIStringJoin.CallSharedSourceNameText].StringValue = _CurrentRoom.CurrentSourceInfo.PreferredName;
@@ -1363,8 +1363,7 @@ namespace PepperDash.Essentials
/// <summary>
/// Handles source change
/// </summary>
void CurrentRoom_SourceInfoChange(EssentialsRoomBase room,
SourceListItem info, ChangeType change)
void CurrentRoom_SourceInfoChange(SourceListItem info, ChangeType change)
{
if (change == ChangeType.WillChange)
DisconnectSource(info);

View File

@@ -68,7 +68,7 @@ namespace PepperDash.Essentials
parent.SetItemButtonAction(index, buttonAction);
}
void room_CurrentSourceInfoChange(EssentialsRoomBase room, SourceListItem info, ChangeType type)
void room_CurrentSourceInfoChange(SourceListItem info, ChangeType type)
{
UpdateItem(info);
}

View File

@@ -95,6 +95,9 @@ namespace PepperDash.Essentials.Core
[JsonProperty("disableRoutedSharing")]
public bool DisableRoutedSharing { get; set; }
[JsonProperty("destinations")]
public List<eSourceListItemDestinationTypes> Destinations { get; set; }
public SourceListItem()
{
Icon = "Blank";
@@ -112,4 +115,16 @@ namespace PepperDash.Essentials.Core
[JsonProperty("type")]
public eRoutingSignalType Type { get; set; }
}
/// <summary>
/// Defines the valid destination types for SourceListItems in a room
/// </summary>
public enum eSourceListItemDestinationTypes
{
defaultDisplay,
leftDisplay,
rightDisplay,
programAudio,
codecContent
}
}

View File

@@ -12,7 +12,7 @@ using PepperDash.Essentials.Core.Routing;
namespace PepperDash.Essentials.Core
{
public class BasicIrDisplay : DisplayBase, IBasicVolumeControls, IPower, IWarmingCooling, IRoutingSinkWithSwitching
public class BasicIrDisplay : DisplayBase, IBasicVolumeControls, IPower, IWarmingCooling
{
public IrOutputPortController IrPort { get; private set; }
public ushort IrPulseTime { get; set; }

View File

@@ -20,8 +20,29 @@ namespace PepperDash.Essentials.Core
{
public event SourceInfoChangeHandler CurrentSourceChange;
public string CurrentSourceInfoKey { get; protected set; }
public SourceListItem CurrentSourceInfo { get; protected set; }
public string CurrentSourceInfoKey { get; set; }
public SourceListItem CurrentSourceInfo
{
get
{
return _CurrentSourceInfo;
}
set
{
if (value == _CurrentSourceInfo) return;
var handler = CurrentSourceChange;
if (handler != null)
handler(_CurrentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value;
if (handler != null)
handler(_CurrentSourceInfo, ChangeType.DidChange);
}
}
SourceListItem _CurrentSourceInfo;
public BoolFeedback PowerIsOnFeedback { get; protected set; }
public BoolFeedback IsCoolingDownFeedback { get; protected set; }

View File

@@ -1387,7 +1387,7 @@ namespace PepperDash.Essentials.Core.Fusion
/// <summary>
/// Event handler for when room source changes
/// </summary>
protected void Room_CurrentSourceInfoChange(EssentialsRoomBase room, SourceListItem info, ChangeType type)
protected void Room_CurrentSourceInfoChange(SourceListItem info, ChangeType type)
{
// Handle null. Nothing to do when switching from or to null
if (info == null || info.SourceDevice == null)
@@ -1403,7 +1403,7 @@ namespace PepperDash.Essentials.Core.Fusion
{
if (SourceToFeedbackSigs.ContainsKey(dev))
SourceToFeedbackSigs[dev].BoolValue = true;
var name = (room == null ? "" : room.Name);
//var name = (room == null ? "" : room.Name);
CurrentRoomSourceNameSig.InputSig.StringValue = info.SourceDevice.Name;
}
}

View File

@@ -30,6 +30,8 @@ namespace PepperDash.Essentials.Core
void RunRouteAction(string routeKey);
void RunRouteAction(string routeKey, Action successCallback);
}
/// <summary>

View File

@@ -15,7 +15,7 @@ namespace PepperDash.Essentials.Core
/// <summary>
/// The handler type for a Room's SourceInfoChange
/// </summary>
public delegate void SourceInfoChangeHandler(EssentialsRoomBase room, SourceListItem info, ChangeType type);
public delegate void SourceInfoChangeHandler(/*EssentialsRoomBase room,*/ SourceListItem info, ChangeType type);
//*******************************************************************************************
@@ -26,8 +26,8 @@ namespace PepperDash.Essentials.Core
/// </summary>
public interface IHasCurrentSourceInfoChange
{
string CurrentSourceInfoKey { get; }
SourceListItem CurrentSourceInfo { get; }
string CurrentSourceInfoKey { get; set; }
SourceListItem CurrentSourceInfo { get; set; }
event SourceInfoChangeHandler CurrentSourceChange;
}
@@ -52,7 +52,7 @@ namespace PepperDash.Essentials.Core
/// <summary>
/// For fixed-source endpoint devices
/// </summary>
public interface IRoutingSinkNoSwitching : IRoutingInputs
public interface IRoutingSinkNoSwitching : IRoutingInputs, IHasCurrentSourceInfoChange
{
}

View File

@@ -15,6 +15,32 @@ namespace PepperDash.Essentials.Devices.Common
/// </summary>
public class GenericAudioOut : Device, IRoutingSinkNoSwitching
{
public event SourceInfoChangeHandler CurrentSourceChange;
public string CurrentSourceInfoKey { get; set; }
public SourceListItem CurrentSourceInfo
{
get
{
return _CurrentSourceInfo;
}
set
{
if (value == _CurrentSourceInfo) return;
var handler = CurrentSourceChange;
if (handler != null)
handler(_CurrentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value;
if (handler != null)
handler(_CurrentSourceInfo, ChangeType.DidChange);
}
}
SourceListItem _CurrentSourceInfo;
public RoutingInputPort AnyAudioIn { get; private set; }
public GenericAudioOut(string key, string name)