internal static CpService ConnectService(DeviceConnection connection, CpDevice parentDevice, ServiceDescriptor serviceDescriptor, DataTypeResolverDlgt dataTypeResolver) { lock (connection.CPData.SyncObj) { CpService result = new CpService(connection, parentDevice, serviceDescriptor.ServiceType, serviceDescriptor.ServiceTypeVersion, serviceDescriptor.ServiceId); XPathNavigator serviceNav = serviceDescriptor.ServiceDescription.CreateNavigator(); serviceNav.MoveToChild(XPathNodeType.Element); XmlNamespaceManager nsmgr = new XmlNamespaceManager(serviceNav.NameTable); nsmgr.AddNamespace("s", UPnPConsts.NS_SERVICE_DESCRIPTION); XPathNodeIterator svIt = serviceNav.Select("s:serviceStateTable/s:stateVariable", nsmgr); // State variables must be connected first because they are needed from the action's arguments while (svIt.MoveNext()) { result.AddStateVariable(CpStateVariable.ConnectStateVariable(connection, result, svIt.Current, nsmgr, dataTypeResolver)); } XPathNodeIterator acIt = serviceNav.Select("s:actionList/s:action", nsmgr); while (acIt.MoveNext()) { result.AddAction(CpAction.ConnectAction(connection, result, acIt.Current, nsmgr)); } return(result); } }
private void OnStateVariableChanged(CpStateVariable statevariable, object newValue) { if (statevariable.Name == SV_ATTACHED_CLIENTS_CHANGE_COUNTER) FireAttachedClientsChanged(); else if (statevariable.Name == SV_CONNECTED_CLIENTS_CHANGE_COUNTER) FireConnectedClientsChanged(); }
protected CpStateVariable _relatedStateVariable; // References the related state variable in our parent action's parent service public CpArgument(CpAction parentAction, string name, CpStateVariable relatedStateVariable, ArgumentDirection direction, bool isReturnValue) { _parentAction = parentAction; _name = name; _relatedStateVariable = relatedStateVariable; _direction = direction; _isReturnValue = isReturnValue; }
private void OnTableSection(CpStateVariable stateVariable, object newValue) { try { if (!stateVariable.Name.Equals("TableSection")) { return; } byte[] section = (byte[])newValue; if (section == null || section.Length < 3) { return; } int pid = (section[0] << 8) + section[1]; byte tableId = section[2]; Log.Log.Debug("DRI CC: scan stage = {0}, PID = 0x{1:x}, table ID = 0x{2:x}, size = {3}", _scanStage, pid, tableId, section.Length); //DVB_MMI.DumpBinary(section, 0, section.Length); switch (_scanStage) { case ScanStage.Mgt: if (tableId == 0xc7) { _mgtParser.Decode(section); } break; case ScanStage.Nit: if (tableId == 0xc2) { _nitParser.Decode(section); } break; case ScanStage.Ntt: if (tableId == 0xc3) { _nttParser.Decode(section); } break; case ScanStage.Vct: if (tableId == 0xc8 || tableId == 0xc9) { _lvctParser.Decode(section); } else if (tableId == 0xc4) { _svctParser.Decode(section); } break; } } catch (Exception ex) { Log.Log.Error("DRI CC: failed to handle table section\r\n{0}", ex); } }
private void OnStateVariableChanged(CpStateVariable statevariable, object newValue) { if (statevariable.Name == SV_PLAYLISTS_CHANGE_COUNTER) FirePlaylistsChanged(); else if (statevariable.Name == SV_MIA_TYPE_REGISTRATIONS_CHANGE_COUNTER) FireMIATypeRegistrationsChanged(); else if (statevariable.Name == SV_REGISTERED_SHARES_CHANGE_COUNTER) FireRegisteredSharesChangeCounterChanged(); else if (statevariable.Name == SV_CURRENTLY_IMPORTING_SHARES_CHANGE_COUNTER) FireCurrentlyImportingSharesChanged(); }
internal void InvokeStateVariableChanged(CpStateVariable variable, object newValue) { try { StateVariableChangedDlgt stateVariableChanged = StateVariableChanged; if (stateVariableChanged != null) { stateVariableChanged(variable, newValue); } } catch (Exception e) { UPnPConfiguration.LOGGER.Warn("CpService: Error invoking StateVariableChanged delegate", e); } }
internal static CpStateVariable ConnectStateVariable(DeviceConnection connection, CpService parentService, XPathNavigator svIt, IXmlNamespaceResolver nsmgr, DataTypeResolverDlgt dataTypeResolver) { string name = ParserHelper.SelectText(svIt, "s:name/text()", nsmgr); XPathNodeIterator dtIt = svIt.Select("s:dataType", nsmgr); if (!dtIt.MoveNext()) { throw new ArgumentException("Error evaluating data type element"); } CpDataType dataType = CpDataType.CreateDataType(dtIt.Current, nsmgr, dataTypeResolver); CpStateVariable result = new CpStateVariable(connection, parentService, name, dataType); XPathNodeIterator dvIt = svIt.Select("s:defaultValue", nsmgr); if (dvIt.MoveNext()) { XmlReader reader = dvIt.Current.ReadSubtree(); reader.MoveToContent(); result.DefaultValue = dataType.SoapDeserializeValue(reader, true); // Default value is always simple value (see DevArch) } XPathNodeIterator avlIt = svIt.Select("s:allowedValueList/s:allowedValue", nsmgr); if (avlIt.Count > 0) { IList <string> allowedValueList = new List <string>(); while (avlIt.MoveNext()) { allowedValueList.Add(ParserHelper.SelectText(avlIt.Current, "text()", null)); } result.AllowedValueList = allowedValueList; } XPathNodeIterator avrIt = svIt.Select("s:allowedValueRange", nsmgr); if (avrIt.MoveNext()) { result.AllowedValueRange = CpAllowedValueRange.CreateAllowedValueRange(avrIt.Current, nsmgr); } return(result); }
public CpArgument(CpAction parentAction, string name, CpStateVariable relatedStateVariable, ArgumentDirection direction) : this(parentAction, name, relatedStateVariable, direction, false) { }
/// <summary> /// Adds the specified state <paramref name="variable"/> instance to match to this service template. /// </summary> /// <param name="variable">UPnP state variable to add.</param> internal void AddStateVariable(CpStateVariable variable) { _stateVariables.Add(variable.Name, variable); }
internal void InvokeStateVariableChanged(CpStateVariable variable, object newValue) { try { StateVariableChangedDlgt stateVariableChanged = StateVariableChanged; if (stateVariableChanged != null) stateVariableChanged(variable, newValue); } catch (Exception e) { UPnPConfiguration.LOGGER.Warn("CpService: Error invoking StateVariableChanged delegate", e); } }
internal static CpStateVariable ConnectStateVariable(DeviceConnection connection, CpService parentService, XPathNavigator svIt, IXmlNamespaceResolver nsmgr, DataTypeResolverDlgt dataTypeResolver) { string name = ParserHelper.SelectText(svIt, "s:name/text()", nsmgr); XPathNodeIterator dtIt = svIt.Select("s:dataType", nsmgr); if (!dtIt.MoveNext()) throw new ArgumentException("Error evaluating data type element"); CpDataType dataType = CpDataType.CreateDataType(dtIt.Current, nsmgr, dataTypeResolver); CpStateVariable result = new CpStateVariable(connection, parentService, name, dataType); XPathNodeIterator dvIt = svIt.Select("s:defaultValue", nsmgr); if (dvIt.MoveNext()) { XmlReader reader = dvIt.Current.ReadSubtree(); reader.MoveToContent(); result.DefaultValue = dataType.SoapDeserializeValue(reader, true); // Default value is always simple value (see DevArch) } XPathNodeIterator avlIt = svIt.Select("s:allowedValueList/s:allowedValue", nsmgr); if (avlIt.Count > 0) { IList<string> allowedValueList = new List<string>(); while (avlIt.MoveNext()) allowedValueList.Add(ParserHelper.SelectText(avlIt.Current, "text()", null)); result.AllowedValueList = allowedValueList; } XPathNodeIterator avrIt = svIt.Select("s:allowedValueRange", nsmgr); if (avrIt.MoveNext()) result.AllowedValueRange = CpAllowedValueRange.CreateAllowedValueRange(avrIt.Current, nsmgr); return result; }
/// <summary> /// Handle UPnP evented state variable changes. /// </summary> /// <param name="stateVariable">The state variable that has changed.</param> /// <param name="newValue">The new value of the state variable.</param> private void OnStateVariableChanged(CpStateVariable stateVariable, object newValue) { try { if (stateVariable.Name.Equals("PCRLock") || stateVariable.Name.Equals("Lock")) { _tunerLocked = (bool)newValue; if (_eventSignalLock != null) { _eventSignalLock.Set(); } } else if (stateVariable.Name.Equals("CardStatus")) { DriCasCardStatus oldStatus = _cardStatus; _cardStatus = (DriCasCardStatus)(string)newValue; if (oldStatus != _cardStatus) { Log.Log.Info("DRI CC: device {0} CableCARD status update, old status = {1}, new status = {2}", _cardId, oldStatus, _cardStatus); } } else if (stateVariable.Name.Equals("CardMessage")) { if (!string.IsNullOrEmpty(newValue.ToString())) { Log.Log.Info("DRI CC: device {0} received message from the CableCARD, current status = {1}, message = {2}", _cardId, _cardStatus, newValue); } } else if (stateVariable.Name.Equals("MMIMessage")) { HandleMmiMessage((byte[])newValue); } else if (stateVariable.Name.Equals("DescramblingStatus")) { DriCasDescramblingStatus oldStatus = _descramblingStatus; _descramblingStatus = (DriCasDescramblingStatus)(string)newValue; if (oldStatus != _descramblingStatus) { Log.Log.Info("DRI CC: device {0} descrambling status update, old status = {1}, new status = {2}", _cardId, oldStatus, _descramblingStatus); } } else if (stateVariable.Name.Equals("DrmPairingStatus")) { DriSecurityPairingStatus oldStatus = _pairingStatus; _pairingStatus = (DriSecurityPairingStatus)(string)newValue; if (oldStatus != _pairingStatus) { Log.Log.Info("DRI CC: device {0} pairing status update, old status = {1}, new status = {2}", _cardId, oldStatus, _pairingStatus); } } else { Log.Log.Debug("DRI CC: device {0} state variable {1} for service {2} changed to {3}", _cardId, stateVariable.Name, stateVariable.ParentService.FullQualifiedName, newValue ?? "[null]"); } } catch (Exception ex) { Log.Log.Error("DRI CC: failed to handle state variable change\r\n{0}", ex); } }