Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
        internal static CpDevice ConnectDevice(DeviceConnection connection, DeviceDescriptor deviceDescriptor, DataTypeResolverDlgt dataTypeResolver)
        {
            lock (connection.CPData.SyncObj)
            {
                string type;
                int    version;
                if (!deviceDescriptor.GetTypeAndVersion(out type, out version))
                {
                    throw new ArgumentException(string.Format("Invalid device type/version URN '{0}'", deviceDescriptor.TypeVersion_URN));
                }
                CpDevice result = new CpDevice(connection, type, version, deviceDescriptor.DeviceUUID);

                foreach (DeviceDescriptor childDevice in deviceDescriptor.ChildDevices)
                {
                    result.AddEmbeddedDevice(ConnectDevice(connection, childDevice, dataTypeResolver));
                }
                IDictionary <string, ServiceDescriptor> serviceDescriptors;
                if (deviceDescriptor.RootDescriptor.ServiceDescriptors.TryGetValue(deviceDescriptor.DeviceUUID, out serviceDescriptors))
                {
                    foreach (ServiceDescriptor serviceDescriptor in serviceDescriptors.Values)
                    {
                        if (serviceDescriptor.State == ServiceDescriptorState.Ready)
                        {
                            result.AddService(CpService.ConnectService(connection, result, serviceDescriptor, dataTypeResolver));
                        }
                        else
                        {
                            UPnPConfiguration.LOGGER.Warn("CpDevice.ConnectDevice: Unable to connect to service '{0}' (type '{1}', version '{2}') - the service descriptor was not initialized properly",
                                                          serviceDescriptor.ServiceId, serviceDescriptor.ServiceType, serviceDescriptor.ServiceTypeVersion);
                        }
                    }
                }
                return(result);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new <see cref="CpStateVariable"/> instance.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentService">Instance of the service which contains the new state variable.</param>
 /// <param name="name">Name of the state variable.</param>
 /// <param name="dataType">Data type of the state variable.</param>
 public CpStateVariable(DeviceConnection connection, CpService parentService, string name, CpDataType dataType)
 {
   _connection = connection;
   _parentService = parentService;
   _name = name;
   _dataType = dataType;
 }
Esempio n. 4
0
 public EventSubscription(string sid, ServiceDescriptor serviceDescriptor, CpService service, DateTime expiration)
 {
   _sid = sid;
   _serviceDescriptor = serviceDescriptor;
   _service = service;
   _expiration = expiration;
 }
 /// <summary>
 /// Creates a new <see cref="CpStateVariable"/> instance.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentService">Instance of the service which contains the new state variable.</param>
 /// <param name="name">Name of the state variable.</param>
 /// <param name="dataType">Data type of the state variable.</param>
 public CpStateVariable(DeviceConnection connection, CpService parentService, string name, CpDataType dataType)
 {
     _connection    = connection;
     _parentService = parentService;
     _name          = name;
     _dataType      = dataType;
 }
Esempio n. 6
0
        internal static CpArgument CreateArgument(CpAction parentAction, CpService parentService, XPathNavigator argumentNav,
                                                  IXmlNamespaceResolver nsmgr)
        {
            string          name = ParserHelper.SelectText(argumentNav, "s:name/text()", nsmgr);
            string          relatedStateVariableName = ParserHelper.SelectText(argumentNav, "s:relatedStateVariable/text()", nsmgr);
            CpStateVariable relatedStateVariable;

            if (!parentService.StateVariables.TryGetValue(relatedStateVariableName, out relatedStateVariable))
            {
                throw new ArgumentException("Related state variable '{0}' is not present in service", relatedStateVariableName);
            }
            string            direction = ParserHelper.SelectText(argumentNav, "s:direction/text()", nsmgr);
            XPathNodeIterator retValIt  = argumentNav.Select("s:retval", nsmgr);
            CpArgument        result    = new CpArgument(parentAction, name, relatedStateVariable, ParseArgumentDirection(direction), retValIt.MoveNext());

            return(result);
        }
Esempio n. 7
0
 internal static CpAction ConnectAction(DeviceConnection connection, CpService parentService, XPathNavigator actionNav, IXmlNamespaceResolver nsmgr)
 {
     using (connection.CPData.Lock.EnterWrite())
     {
         string            name       = ParserHelper.SelectText(actionNav, "s:name/text()", nsmgr);
         CpAction          result     = new CpAction(connection, parentService, name);
         XPathNodeIterator argumentIt = actionNav.Select("s:argumentList/s:argument", nsmgr);
         while (argumentIt.MoveNext())
         {
             CpArgument argument = CpArgument.CreateArgument(result, parentService, argumentIt.Current, nsmgr);
             if (argument.Direction == ArgumentDirection.In)
             {
                 result.AddInAgrument(argument);
             }
             else
             {
                 result.AddOutAgrument(argument);
             }
         }
         return(result);
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Adds the specified <paramref name="service"/>.
 /// </summary>
 /// <param name="service">Service to add to this device.</param>
 internal void AddService(CpService service)
 {
     _services.Add(service.ServiceId, service);
 }
Esempio n. 9
0
 public NativeTvProxy(CpService serviceStub)
   : base(serviceStub, "NativeTv")
 {
   ServiceRegistration.Set<ITvProvider>(this);
 }
 protected UPnPServiceProxyBase(CpService serviceStub, string serviceName)
 {
   _serviceName = serviceName;
   _serviceStub = serviceStub;
   _serviceStub.SubscribeStateVariables();
 }
Esempio n. 11
0
 /// <summary>
 /// Returns the information whether the specified <paramref name="service"/> is registered for event notifications.
 /// </summary>
 /// <remarks>
 /// When subscribing for state variable changes of a given service s, this method doesn't return <c>true</c> when invoked
 /// for that service s immediately. The subscription must first be confirmed by the UPnP network service.
 /// </remarks>
 /// <param name="service">The service instance to check.</param>
 /// <returns><c>true</c>, if the <paramref name="service"/> is subscribed for receiving event notifications, else
 /// <c>false</c>.</returns>
 public bool IsServiceSubscribedForEvents(CpService service)
 {
   lock (_cpData.SyncObj)
     return _genaClientController.FindEventSubscriptionByService(service) != null;
 }
Esempio n. 12
0
    internal void OnUnsubscribeEvents(CpService service)
    {
      if (!service.IsConnected)
        throw new IllegalCallException("Service '{0}' is not connected to a UPnP network service", service.FullQualifiedName);

      EventSubscription subscription = _genaClientController.FindEventSubscriptionByService(service);
      if (subscription == null)
        throw new IllegalCallException("Service '{0}' is not subscribed to receive events", service.FullQualifiedName);
      _genaClientController.UnsubscribeEvents(subscription);
    }
Esempio n. 13
0
 public ChangeEventSubscriptionState(ServiceDescriptor serviceDescriptor, CpService service, HttpWebRequest request) :
     base(request)
 {
   _serviceDescriptor = serviceDescriptor;
   _service = service;
 }
 public UPnPUserProfileDataManagementServiceProxy(CpService serviceStub) : base(serviceStub, "UserProfileDataManagement") { }
 public UPnPContentDirectoryServiceProxy(CpService serviceStub) : base(serviceStub, "ContentDirectory")
 {
   serviceStub.StateVariableChanged += OnStateVariableChanged;
   serviceStub.SubscribeStateVariables();
 }
Esempio n. 16
0
 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 UPnPServerControllerServiceProxy(CpService serviceStub) : base(serviceStub, "ServerController")
 {
   serviceStub.StateVariableChanged += OnStateVariableChanged;
   serviceStub.SubscribeStateVariables();
 }
Esempio n. 18
0
 protected static void HandleVariableChangeNotification(XmlReader reader, CpService service, UPnPVersion upnpVersion)
 {
   string variableName = reader.LocalName;
   CpStateVariable stateVariable;
   if (!service.StateVariables.TryGetValue(variableName, out stateVariable))
     // We don't know that variable - this is an error case but we won't raise an exception here
     return;
   object value = stateVariable.DataType.SoapDeserializeValue(reader, upnpVersion.VerMin == 0);
   service.InvokeStateVariableChanged(stateVariable, value);
 }
Esempio n. 19
0
 /// <summary>
 /// Creates a new instance of <see cref="CpAction"/>.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentService">Instance of the service which contains the new action.</param>
 /// <param name="name">The name of the new action template.</param>
 public CpAction(DeviceConnection connection, CpService parentService, string name)
 {
   _connection = connection;
   _parentService = parentService;
   _name = name;
 }
Esempio n. 20
0
    internal void OnSubscribeEvents(CpService service)
    {
      if (!service.IsConnected)
        throw new IllegalCallException("Service '{0}' is not connected to a UPnP network service", service.FullQualifiedName);
      if (IsServiceSubscribedForEvents(service))
        throw new IllegalCallException("Service '{0}' is already subscribed to receive state variable change events", service.FullQualifiedName);

      ServiceDescriptor serviceDescriptor = GetServiceDescriptor(service);
      _genaClientController.SubscribeEvents(service, serviceDescriptor);
    }
Esempio n. 21
0
 internal static CpAction ConnectAction(DeviceConnection connection, CpService parentService, XPathNavigator actionNav,
     IXmlNamespaceResolver nsmgr)
 {
   lock (connection.CPData.SyncObj)
   {
     string name = ParserHelper.SelectText(actionNav, "s:name/text()", nsmgr);
     CpAction result = new CpAction(connection, parentService, name);
     XPathNodeIterator argumentIt = actionNav.Select("s:argumentList/s:argument", nsmgr);
     while (argumentIt.MoveNext())
     {
       CpArgument argument = CpArgument.CreateArgument(result, parentService, argumentIt.Current, nsmgr);
       if (argument.Direction == ArgumentDirection.In)
         result.AddInAgrument(argument);
       else
         result.AddOutAgrument(argument);
     }
     return result;
   }
 }
Esempio n. 22
0
 protected ServiceDescriptor GetServiceDescriptor(CpService service)
 {
   if (!service.IsConnected)
     throw new IllegalCallException("Service '{0}' is not connected to a UPnP network service", service.FullQualifiedName);
   IDictionary<string, ServiceDescriptor> serviceDescriptors;
   string deviceUUID = service.ParentDevice.UUID;
   if (!_rootDescriptor.ServiceDescriptors.TryGetValue(deviceUUID, out serviceDescriptors))
     throw new IllegalCallException("Device '{0}' is not connected to a UPnP network device", deviceUUID);
   ServiceDescriptor sd;
   if (!serviceDescriptors.TryGetValue(service.ServiceTypeVersion_URN, out sd))
     throw new IllegalCallException("Service '{0}' in device '{1}' is not connected to a UPnP network service", service.ServiceTypeVersion_URN, deviceUUID);
   return sd;
 }
 public UPnPClientControllerServiceProxy(CpService serviceStub) : base(serviceStub, "ClientController") { }
Esempio n. 24
0
 /// <summary>
 /// Adds the specified <paramref name="service"/>.
 /// </summary>
 /// <param name="service">Service to add to this device.</param>
 internal void AddService(CpService service)
 {
   _services.Add(service.ServiceId, service);
 }
Esempio n. 25
0
 internal static CpArgument CreateArgument(CpAction parentAction, CpService parentService, XPathNavigator argumentNav,
     IXmlNamespaceResolver nsmgr)
 {
   string name = ParserHelper.SelectText(argumentNav, "s:name/text()", nsmgr);
   string relatedStateVariableName = ParserHelper.SelectText(argumentNav, "s:relatedStateVariable/text()", nsmgr);
   CpStateVariable relatedStateVariable;
   if (!parentService.StateVariables.TryGetValue(relatedStateVariableName, out relatedStateVariable))
     throw new ArgumentException("Related state variable '{0}' is not present in service", relatedStateVariableName);
   string direction = ParserHelper.SelectText(argumentNav, "s:direction/text()", nsmgr);
   XPathNodeIterator retValIt = argumentNav.Select("s:retval", nsmgr);
   CpArgument result = new CpArgument(parentAction, name, relatedStateVariable, ParseArgumentDirection(direction), retValIt.MoveNext());
   return result;
 }
Esempio n. 26
0
 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;
   }
 }
Esempio n. 27
0
 public FanArtServiceProxy(CpService serviceStub) : base(serviceStub, "FanArt")
 {
   ServiceRegistration.Set<IFanArtService>(this);
 }
Esempio n. 28
0
        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);
        }
Esempio n. 29
0
 internal void SubscribeEvents(CpService service, ServiceDescriptor serviceDescriptor)
 {
   lock (_cpData.SyncObj)
   {
     HttpWebRequest request = CreateEventSubscribeRequest(serviceDescriptor);
     ChangeEventSubscriptionState state = new ChangeEventSubscriptionState(serviceDescriptor, service, request);
     _pendingCalls.Add(state);
     IAsyncResult result = state.Request.BeginGetResponse(OnSubscribeOrRenewSubscriptionResponseReceived, state);
     NetworkHelper.AddTimeout(request, result, EVENT_SUBSCRIPTION_CALL_TIMEOUT * 1000);
   }
 }
 public UPnPResourceInformationServiceProxy(CpService serviceStub) : base(serviceStub, "ResourceInformation") { }
Esempio n. 31
0
 public EventSubscription FindEventSubscriptionByService(CpService service)
 {
   lock (_cpData.SyncObj)
     foreach (EventSubscription subscription in _subscriptions.Values)
       if (subscription.Service == service)
         return subscription;
   return null;
 }
Esempio n. 32
0
 /// <summary>
 /// Creates a new instance of <see cref="CpAction"/>.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentService">Instance of the service which contains the new action.</param>
 /// <param name="name">The name of the new action template.</param>
 public CpAction(DeviceConnection connection, CpService parentService, string name)
 {
     _connection    = connection;
     _parentService = parentService;
     _name          = name;
 }
Esempio n. 33
0
 protected bool TryGetService(string usn, string svcid, out CpService service)
 {
   string deviceUUID;
   string serviceTypeVersion;
   service = null;
   if (!ParserHelper.TryParseUSN(usn, out deviceUUID, out serviceTypeVersion))
     return false;
   string type;
   int version;
   if (!ParserHelper.TryParseTypeVersion_URN(serviceTypeVersion, out type, out version))
     return false;
   foreach (CpService matchingService in _connection.Device.FindServicesByServiceTypeAndVersion(type, version, false))
   {
     if (matchingService.ServiceId == svcid)
     {
       service = matchingService;
       return true;
     }
   }
   return false;
 }
Esempio n. 34
0
 public static HttpStatusCode HandleEventNotification(Stream stream, Encoding streamEncoding, CpService service,
     UPnPVersion upnpVersion)
 {
   try
   {
     // Parse XML document
     using (StreamReader streamReader = new StreamReader(stream, streamEncoding))
       using (XmlReader reader = XmlReader.Create(streamReader, UPnPConfiguration.DEFAULT_XML_READER_SETTINGS))
       {
         reader.MoveToContent();
         reader.ReadStartElement("propertyset", UPnPConsts.NS_UPNP_EVENT);
         while (reader.LocalName == "property" && reader.NamespaceURI == UPnPConsts.NS_UPNP_EVENT)
         {
           reader.ReadStartElement("property", UPnPConsts.NS_UPNP_EVENT);
           HandleVariableChangeNotification(reader, service, upnpVersion);
           reader.ReadEndElement(); // property
         }
         reader.Close();
       }
     return HttpStatusCode.OK;
   }
   catch (Exception e)
   {
     UPnPConfiguration.LOGGER.Warn("GENAClientController: Error handling event notification", e);
     return HttpStatusCode.BadRequest;
   }
 }
Esempio n. 35
0
 private void SubscribeFailed(CpService service, UPnPError error)
 {
   Log.Log.Error("DRI: failed to subscribe to state variable events for service {0}, code = {1}, description = {2}", _unqualifiedServiceName, error.ErrorCode, error.ErrorDescription);
 }