From dca78b13411db96366dddfa0d68bb6d36d28ad14 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 29 Oct 2016 18:22:20 -0400 Subject: rework dlna project --- Emby.Dlna/ConnectionManager/ConnectionManager.cs | 37 ++++ .../ConnectionManagerXmlBuilder.cs | 106 +++++++++++ Emby.Dlna/ConnectionManager/ControlHandler.cs | 41 +++++ .../ConnectionManager/ServiceActionListBuilder.cs | 205 +++++++++++++++++++++ 4 files changed, 389 insertions(+) create mode 100644 Emby.Dlna/ConnectionManager/ConnectionManager.cs create mode 100644 Emby.Dlna/ConnectionManager/ConnectionManagerXmlBuilder.cs create mode 100644 Emby.Dlna/ConnectionManager/ControlHandler.cs create mode 100644 Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs (limited to 'Emby.Dlna/ConnectionManager') diff --git a/Emby.Dlna/ConnectionManager/ConnectionManager.cs b/Emby.Dlna/ConnectionManager/ConnectionManager.cs new file mode 100644 index 0000000000..62cd3904dc --- /dev/null +++ b/Emby.Dlna/ConnectionManager/ConnectionManager.cs @@ -0,0 +1,37 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Dlna; +using MediaBrowser.Dlna.Service; +using MediaBrowser.Model.Logging; +using System.Collections.Generic; + +namespace MediaBrowser.Dlna.ConnectionManager +{ + public class ConnectionManager : BaseService, IConnectionManager + { + private readonly IDlnaManager _dlna; + private readonly ILogger _logger; + private readonly IServerConfigurationManager _config; + + public ConnectionManager(IDlnaManager dlna, IServerConfigurationManager config, ILogger logger, IHttpClient httpClient) + : base(logger, httpClient) + { + _dlna = dlna; + _config = config; + _logger = logger; + } + + public string GetServiceXml(IDictionary headers) + { + return new ConnectionManagerXmlBuilder().GetXml(); + } + + public ControlResponse ProcessControlRequest(ControlRequest request) + { + var profile = _dlna.GetProfile(request.Headers) ?? + _dlna.GetDefaultProfile(); + + return new ControlHandler(_logger, profile, _config).ProcessControlRequest(request); + } + } +} diff --git a/Emby.Dlna/ConnectionManager/ConnectionManagerXmlBuilder.cs b/Emby.Dlna/ConnectionManager/ConnectionManagerXmlBuilder.cs new file mode 100644 index 0000000000..4efa111591 --- /dev/null +++ b/Emby.Dlna/ConnectionManager/ConnectionManagerXmlBuilder.cs @@ -0,0 +1,106 @@ +using MediaBrowser.Dlna.Common; +using MediaBrowser.Dlna.Service; +using System.Collections.Generic; + +namespace MediaBrowser.Dlna.ConnectionManager +{ + public class ConnectionManagerXmlBuilder + { + public string GetXml() + { + return new ServiceXmlBuilder().GetXml(new ServiceActionListBuilder().GetActions(), GetStateVariables()); + } + + private IEnumerable GetStateVariables() + { + var list = new List(); + + list.Add(new StateVariable + { + Name = "SourceProtocolInfo", + DataType = "string", + SendsEvents = true + }); + + list.Add(new StateVariable + { + Name = "SinkProtocolInfo", + DataType = "string", + SendsEvents = true + }); + + list.Add(new StateVariable + { + Name = "CurrentConnectionIDs", + DataType = "string", + SendsEvents = true + }); + + list.Add(new StateVariable + { + Name = "A_ARG_TYPE_ConnectionStatus", + DataType = "string", + SendsEvents = false, + + AllowedValues = new List + { + "OK", + "ContentFormatMismatch", + "InsufficientBandwidth", + "UnreliableChannel", + "Unknown" + } + }); + + list.Add(new StateVariable + { + Name = "A_ARG_TYPE_ConnectionManager", + DataType = "string", + SendsEvents = false + }); + + list.Add(new StateVariable + { + Name = "A_ARG_TYPE_Direction", + DataType = "string", + SendsEvents = false, + + AllowedValues = new List + { + "Output", + "Input" + } + }); + + list.Add(new StateVariable + { + Name = "A_ARG_TYPE_ProtocolInfo", + DataType = "string", + SendsEvents = false + }); + + list.Add(new StateVariable + { + Name = "A_ARG_TYPE_ConnectionID", + DataType = "ui4", + SendsEvents = false + }); + + list.Add(new StateVariable + { + Name = "A_ARG_TYPE_AVTransportID", + DataType = "ui4", + SendsEvents = false + }); + + list.Add(new StateVariable + { + Name = "A_ARG_TYPE_RcsID", + DataType = "ui4", + SendsEvents = false + }); + + return list; + } + } +} diff --git a/Emby.Dlna/ConnectionManager/ControlHandler.cs b/Emby.Dlna/ConnectionManager/ControlHandler.cs new file mode 100644 index 0000000000..958d71a2b6 --- /dev/null +++ b/Emby.Dlna/ConnectionManager/ControlHandler.cs @@ -0,0 +1,41 @@ +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Dlna.Server; +using MediaBrowser.Dlna.Service; +using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.Logging; +using System; +using System.Collections.Generic; + +namespace MediaBrowser.Dlna.ConnectionManager +{ + public class ControlHandler : BaseControlHandler + { + private readonly DeviceProfile _profile; + + public ControlHandler(ILogger logger, DeviceProfile profile, IServerConfigurationManager config) + : base(config, logger) + { + _profile = profile; + } + + protected override IEnumerable> GetResult(string methodName, Headers methodParams) + { + if (string.Equals(methodName, "GetProtocolInfo", StringComparison.OrdinalIgnoreCase)) + { + return HandleGetProtocolInfo(); + } + + throw new ResourceNotFoundException("Unexpected control request name: " + methodName); + } + + private IEnumerable> HandleGetProtocolInfo() + { + return new Headers(true) + { + { "Source", _profile.ProtocolInfo }, + { "Sink", "" } + }; + } + } +} diff --git a/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs b/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs new file mode 100644 index 0000000000..9dbd4e0e23 --- /dev/null +++ b/Emby.Dlna/ConnectionManager/ServiceActionListBuilder.cs @@ -0,0 +1,205 @@ +using MediaBrowser.Dlna.Common; +using System.Collections.Generic; + +namespace MediaBrowser.Dlna.ConnectionManager +{ + public class ServiceActionListBuilder + { + public IEnumerable GetActions() + { + var list = new List + { + GetCurrentConnectionInfo(), + GetProtocolInfo(), + GetCurrentConnectionIDs(), + ConnectionComplete(), + PrepareForConnection() + }; + + return list; + } + + private ServiceAction PrepareForConnection() + { + var action = new ServiceAction + { + Name = "PrepareForConnection" + }; + + action.ArgumentList.Add(new Argument + { + Name = "RemoteProtocolInfo", + Direction = "in", + RelatedStateVariable = "A_ARG_TYPE_ProtocolInfo" + }); + + action.ArgumentList.Add(new Argument + { + Name = "PeerConnectionManager", + Direction = "in", + RelatedStateVariable = "A_ARG_TYPE_ConnectionManager" + }); + + action.ArgumentList.Add(new Argument + { + Name = "PeerConnectionID", + Direction = "in", + RelatedStateVariable = "A_ARG_TYPE_ConnectionID" + }); + + action.ArgumentList.Add(new Argument + { + Name = "Direction", + Direction = "in", + RelatedStateVariable = "A_ARG_TYPE_Direction" + }); + + action.ArgumentList.Add(new Argument + { + Name = "ConnectionID", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_ConnectionID" + }); + + action.ArgumentList.Add(new Argument + { + Name = "AVTransportID", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_AVTransportID" + }); + + action.ArgumentList.Add(new Argument + { + Name = "RcsID", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_RcsID" + }); + + return action; + } + + private ServiceAction GetCurrentConnectionInfo() + { + var action = new ServiceAction + { + Name = "GetCurrentConnectionInfo" + }; + + action.ArgumentList.Add(new Argument + { + Name = "ConnectionID", + Direction = "in", + RelatedStateVariable = "A_ARG_TYPE_ConnectionID" + }); + + action.ArgumentList.Add(new Argument + { + Name = "RcsID", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_RcsID" + }); + + action.ArgumentList.Add(new Argument + { + Name = "AVTransportID", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_AVTransportID" + }); + + action.ArgumentList.Add(new Argument + { + Name = "ProtocolInfo", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_ProtocolInfo" + }); + + action.ArgumentList.Add(new Argument + { + Name = "PeerConnectionManager", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_ConnectionManager" + }); + + action.ArgumentList.Add(new Argument + { + Name = "PeerConnectionID", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_ConnectionID" + }); + + action.ArgumentList.Add(new Argument + { + Name = "Direction", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_Direction" + }); + + action.ArgumentList.Add(new Argument + { + Name = "Status", + Direction = "out", + RelatedStateVariable = "A_ARG_TYPE_ConnectionStatus" + }); + + return action; + } + + private ServiceAction GetProtocolInfo() + { + var action = new ServiceAction + { + Name = "GetProtocolInfo" + }; + + action.ArgumentList.Add(new Argument + { + Name = "Source", + Direction = "out", + RelatedStateVariable = "SourceProtocolInfo" + }); + + action.ArgumentList.Add(new Argument + { + Name = "Sink", + Direction = "out", + RelatedStateVariable = "SinkProtocolInfo" + }); + + return action; + } + + private ServiceAction GetCurrentConnectionIDs() + { + var action = new ServiceAction + { + Name = "GetCurrentConnectionIDs" + }; + + action.ArgumentList.Add(new Argument + { + Name = "ConnectionIDs", + Direction = "out", + RelatedStateVariable = "CurrentConnectionIDs" + }); + + return action; + } + + private ServiceAction ConnectionComplete() + { + var action = new ServiceAction + { + Name = "ConnectionComplete" + }; + + action.ArgumentList.Add(new Argument + { + Name = "ConnectionID", + Direction = "in", + RelatedStateVariable = "A_ARG_TYPE_ConnectionID" + }); + + return action; + } + } +} -- cgit v1.2.3