예제 #1
0
        private static void AddSink(DimmableLightDiscovery sender, UPnPDevice d)
        {
            Console.WriteLine("Added Device: " + d.FriendlyName);

            // To interface with a service, instantiate the appropriate wrapper class on the appropriate service
            // Traverse the device heirarchy to the correct device, and invoke 'GetServices', passing in the static field 'SERVICE_NAME'
            // of the appropriate wrapper class. This method returns an array of all services with this service type. For most purposes,
            // there will only be one service, in which case you can use array index 0.
            // Save a reference to this instance of the wrapper class for later use.

            CpDimming Dimming = new CpDimming(d.GetServices(CpDimming.SERVICE_NAME)[0]);

            sw = new CpSwitchPower(d.GetServices(CpSwitchPower.SERVICE_NAME)[0]);

            // To subscribe to Events, call the '_subscribe' method of the wrapper class. The only parameter is
            // the duration of the event. A good value is 300 seconds.
            //Dimming._subscribe(300);

            // The wrapper class exposes all the evented state variables through events in the form 'OnStateVariable_xx', where xx is the variable name.

            // The wrapper class exposes methods in two formats. Asyncronous and Syncronous. The Async method calls are exposed simply
            // by the name of the method. The Syncronous version is the same, except with the word, 'Sync_' prepended to the name.
            // Asyncronous responses to th async method calls are dispatched through the event in the format, 'OnResult_x' where x is the method name.

            // Note: All arguments are automatically type checked. Allowed Values are abstracted through enumerations, that are defined in the wrapper class.
            // To access the list of allowed values or ranges for a given device, refer to the property 'Values_XXX' for a list of the allowed values for a
            // given state variable. Similarly, refer to the properties 'HasMaximum_XXX', 'HasMinimum_XXX', 'Maximum_XXX', and 'Minimum_XXX' where XXX is the variable name, for the Max/Min values.

            // To determine if a given service implements a particular StateVariable or Method, use the properties, 'HasStateVariableXXX' and 'HasActionXXX' where XXX is the method/variable name.
        }
		private void OnDeviceAdded(UPnPSmartControlPoint cp, UPnPDevice device)
		{
			Console.WriteLine("found player " + device);
			//players.Add(new SonosPlayer(device));
			// we need to save these for future reference
			lock (playerDevices)
			{
				playerDevices[device.UniqueDeviceName] = device;
			}

			// okay, we will try and notify the players that they have been found now.
			var player = players.FirstOrDefault(p => p.UUID == device.UniqueDeviceName);
			if (player != null)
			{
				player.SetDevice(device);
			}

			// Subscribe to events
			var topologyService = device.GetService("urn:upnp-org:serviceId:ZoneGroupTopology");
			topologyService.Subscribe(600, (service, subscribeok) =>
				{
					if (!subscribeok) return;

					var stateVariable = service.GetStateVariableObject("ZoneGroupState");
					stateVariable.OnModified += OnZoneGroupStateChanged;
				});
		}
예제 #3
0
        public Gatekeeper(int PortNumber)
        {
            A_ICB = new UPnPService.UPnPServiceInvokeHandler(A_InvokeSink);
            A_IECB = new UPnPService.UPnPServiceInvokeErrorHandler(A_InvokeErrorSink);

            Port = PortNumber;
            Root = UPnPDevice.CreateRootDevice(1000,1,"");
            Root.FriendlyName = "UPnPShare";

            Root.StandardDeviceType = "UPnPGateKeeper";
            DV = new DvGateKeeper();
            Root.AddService(DV);

            DV.External_Register = new DvGateKeeper.Delegate_Register(RegisterSink);
            DV.External_UnRegister = new DvGateKeeper.Delegate_UnRegister(UnRegisterSink);
            DV.External_GetDocument = new DvGateKeeper.Delegate_GetDocument(GetDocumentSink);
            DV.External_AddDevice = new DvGateKeeper.Delegate_AddDevice(AddDeviceSink);
            DV.External_RemoveDevice = new DvGateKeeper.Delegate_RemoveDevice(RemovedDeviceSink);
            DV.External_FireEvent = new DvGateKeeper.Delegate_FireEvent(FireEventSink);
            DV.External_GetStateTable = new DvGateKeeper.Delegate_GetStateTable(GetStateTableSink);

            DV.External_Invoke = new DvGateKeeper.Delegate_Invoke(InvokeSink);
            DV.External_InvokeAsync = new DvGateKeeper.Delegate_InvokeAsync(InvokeAsyncSink);
            DV.External_InvokeAsyncResponse = new DvGateKeeper.Delegate_InvokeAsyncResponse(InvokeAsyncResponseSink);

            (new UPnPDebugObject(Root)).SetField("NoSSDP",true);

            Root.StartDevice(PortNumber);
        }
        public override bool Generate(UPnPDevice[] devices, DirectoryInfo outputDirectory)
        {
            bool ok = false;
            bool RetVal = false;
            foreach (UPnPDevice device in devices)
            {
                if (((ServiceGenerator.Configuration)device.User).ConfigType == ServiceGenerator.ConfigurationType.CONTROLPOINT)
                {
                    ok = true;
                    if (Configuration.UPNP_1dot1)
                    {
                        device.ArchitectureVersion = "1.1";
                    }
                    else
                    {
                        device.ArchitectureVersion = "1.0";
                    }

                    device.ClearCustomFieldsInDescription();
                    ((ServiceGenerator.Configuration)device.User).AddAllCustomFieldsToDevice(device);

                    RetVal = GenerateEx(device, outputDirectory, GetServiceNameTable(device));
                    if (!RetVal) { break; }
                }
            }
            return (ok ? RetVal : true);
        }
        /// <summary>
        /// Creates a programmer-friendly object for using a device
        /// that happens implement a MediaServer.
        /// </summary>
        /// <param name="device"></param>
        public CpMediaServer(UPnPDevice device)
        {
            UPnPService sCM = device.GetServices(CpConnectionManager.SERVICE_NAME)[0];
            UPnPService sCD = device.GetServices(CpContentDirectory.SERVICE_NAME)[0];

            CpConnectionManager cpCM = new CpConnectionManager(sCM);
            CpContentDirectory cpCD = new CpContentDirectory(sCD);

            UDN = device.UniqueDeviceName;

            if (
                (cpCD.HasAction_GetSearchCapabilities == false) ||
                (cpCD.HasAction_GetSortCapabilities == false) ||
                (cpCD.HasAction_GetSystemUpdateID == false) ||
                (cpCD.HasAction_Browse == false)
                )
            {
                throw new UPnPCustomException(0, "MediaServer does not implement minimum features.");
            }

            this.m_ConnectionManager = cpCM;
            this.m_ContentDirectory = cpCD;

            //create a virtualized root container with the desired settings
            m_Root = new CpRootContainer(this);
            m_Root.UDN = device.UniqueDeviceName;
        }
예제 #6
0
        public UPnPDeviceHostServiceProxy(Assembly assembly)
        {
            this.Name = Environment.MachineName + ":" + assembly.FullName.Split(',').First();
            this.Namespace = assembly.FullName;
            var regex = new Regex("Version=(.\\..)");
            var version = regex.Match(this.Namespace).Groups[1].Value;
            this.Version = double.Parse(version);

            _device = UPnPDevice.CreateRootDevice(int.MaxValue, this.Version, "\\");
            _device.FriendlyName = this.Name;
            _device.DeviceURN = this.Namespace;
            _device.HasPresentation = false;

            var types = (from type in assembly.GetTypes()
                         let ifs = type.GetInterfaces().Where(t => t.GetCustomAttributes<ServiceContractAttribute>().Count() > 0).First()
                         select new { Type = type, Interface = ifs }).ToList();

            List<IUPnPService> services = new List<IUPnPService>();
            foreach (var tc in types)
            {
                var service = new UPnPServiceProxy(tc.Type, tc.Interface);
                services.Add(service);
                _device.AddService(service);
            }

            this.Services = services.ToList();
            _device = this.GetUPnPDevice();
        }
 public static Hashtable CreateTableOfServiceNames(UPnPDevice rootDevice)
 {
     Hashtable RetVal = new Hashtable();
     foreach (UPnPDevice d in rootDevice.EmbeddedDevices) { ProcessDevice(d, RetVal); }
     foreach (UPnPService s in rootDevice.Services) { ProcessService(s, RetVal); }
     return (RetVal);
 }
        public static string BuildDeviceDescriptionStreamer(UPnPDevice d, string templateString)
        {
            string WS = BuildDeviceDescriptionStreamer_EmbeddedDevice(d,"",SourceCodeRepository.GetTextBetweenTags(templateString,"//{{{DEVICE_BEGIN}}}","//{{{DEVICE_END}}}"));

            templateString = SourceCodeRepository.InsertTextBeforeTag(templateString,"//{{{DEVICE_BEGIN}}}",WS);
            templateString = SourceCodeRepository.RemoveAndClearTag("//{{{DEVICE_BEGIN}}}","//{{{DEVICE_END}}}",templateString);
            return(templateString);
        }
예제 #9
0
 public void ForceDisposeDevice(UPnPDevice root)
 {
     while (root.ParentDevice != null)
     {
         root = root.ParentDevice;
     }
     iSCP.SSDPNotifySink(null, null, null, false, root.UniqueDeviceName, "upnp:rootdevice", 0, null);
 }
 public void ForceDisposeDevice(UPnPDevice dev)
 {
     if (dev.ParentDevice != null)
     {
         ForceDisposeDevice(dev.ParentDevice);
     }
     else
     {
         scp.ForceDisposeDevice(dev);
     }
 }
예제 #11
0
        public ModifyDevice(UPnPDevice d)
        {
            OriginalDevice = d;
            NewDevice = OriginalDevice;

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            ShowDevice(d);
        }
 public static void GenerateStateVariableLookupTable(UPnPDevice d, Hashtable t)
 {
     foreach(UPnPDevice ed in d.EmbeddedDevices)
     {
         GenerateStateVariableLookupTable(ed,t);
     }
     foreach(UPnPService s in d.Services)
     {
         GenerateStateVariableLookupTable_Service(s,t);
     }
 }
예제 #13
0
 private void PageHandler(OpenSource.UPnP.UPnPDevice sender, OpenSource.UPnP.HTTPMessage msg, OpenSource.UPnP.HTTPSession WebSession, string VirtualDir)
 {
     if (VirtualDir.Equals("/stream", StringComparison.InvariantCultureIgnoreCase) && msg.DirectiveObj.Equals("/swyh.mp3", StringComparison.InvariantCultureIgnoreCase))
     {
         WebSession.OnStreamDone += (s, e) =>
         {
             if (sessionMp3Streams.ContainsKey(s.SessionID))
             {
                 PipeStream value;
                 sessionMp3Streams.TryRemove(s.SessionID, out value);
                 App.CurrentInstance.wasapiProvider.UpdateClientsList();
             }
         };
         PipeStream stream = sessionMp3Streams.GetOrAdd(WebSession.SessionID, new PipeStream());
         App.CurrentInstance.wasapiProvider.UpdateClientsList();
         WebSession.SendStreamObject(stream, "audio/mpeg");
     }
     else if (VirtualDir.Equals("/stream", StringComparison.InvariantCultureIgnoreCase) && msg.DirectiveObj.Equals("/swyh.wav", StringComparison.InvariantCultureIgnoreCase))
     {
         WebSession.OnStreamDone += (s, e) =>
         {
             if (sessionPcmStreams.ContainsKey(s.SessionID))
             {
                 PipeStream value;
                 sessionPcmStreams.TryRemove(s.SessionID, out value);
                 App.CurrentInstance.wasapiProvider.UpdateClientsList();
             }
         };
         PipeStream stream = sessionPcmStreams.GetOrAdd(WebSession.SessionID, new PipeStream());
         App.CurrentInstance.wasapiProvider.UpdateClientsList();
         var audioFormat = AudioSettings.GetAudioFormat();
         WebSession.SendStreamObject(stream, "audio/L16;rate=" + audioFormat.SampleRate + ";channels=" + audioFormat.Channels);
     }
     else if (VirtualDir.Equals("/about", StringComparison.InvariantCultureIgnoreCase))
     {
         OpenSource.UPnP.HTTPMessage response = new OpenSource.UPnP.HTTPMessage();
         response.StatusCode = 200;
         response.StatusData = "OK";
         response.AddTag("Content-Type", "text/html");
         response.BodyBuffer = System.Text.Encoding.UTF8.GetBytes(Properties.Resources.About);
         WebSession.Send(response);
     }
     else
     {
         OpenSource.UPnP.HTTPMessage response = new OpenSource.UPnP.HTTPMessage();
         response.StatusCode = 404;
         response.StatusData = "Not Found";
         response.AddTag("Content-Type", "text/html");
         response.BodyBuffer = System.Text.Encoding.UTF8.GetBytes(Properties.Resources.Error404);
         WebSession.Send(response);
     }
 }
        /// <summary>
        /// Eventfunction that is run when an UPnP sink is detected on the network. Only accepts sinks with the friendly name: "HiPi - Sink". 
        /// If it has the right name then it creates three stacks (AVTransport, ConnectionManager and RenderingControl)
        /// </summary>
        /// <param name="sender">The object that send the event</param>
        /// <param name="d">The discovered sink device</param>
        private void AddSink(MediaRendererDiscovery sender, UPnPDevice d)
        {
            Console.WriteLine("Added Sink Device: " + d.FriendlyName);
            if (d.FriendlyName == "HiPi - Sink")
            {
                UPnP_SinkFunctions func = new UPnP_SinkFunctions(
                    new SinkStack.CpAVTransport(d.GetServices(SinkStack.CpAVTransport.SERVICE_NAME)[0]),
                    new SinkStack.CpConnectionManager(d.GetServices(SinkStack.CpConnectionManager.SERVICE_NAME)[0]),
                    new SinkStack.CpRenderingControl(d.GetServices(SinkStack.CpRenderingControl.SERVICE_NAME)[0]));

                AddSinkEvent(func, null);
            }
        }
예제 #15
0
        public CpContentDirectory GetCDS(UPnPDevice device)
        {
            UPnPDevice d = device;

            UPnPService[] services = d.GetServices(CpContentDirectory.SERVICE_NAME);

            if (services == null || services.Length == 0)
            {
                return null;
            }

            return new CpContentDirectory(services[0]);
        }
 public override void Start(UPnPDevice device)
 {
     if (ScriptorInterface != null)
     {
         Reset();
         ScriptorInterface.SetUPnPDevice(device);
         ScriptorInterface.Execute();
         for (int i=0; i<states.Length; i++)
         {
             if (state < states[i])
                 state = states[i];
         }
     }
 }
 protected void HandleCreate(UPnPDevice device, Uri URL)
 {
     TreeNode parent = new TreeNode(device.FriendlyName,1,1);
     parent.Tag = device;
     Object[] args = new Object[1];
     args[0] = parent;
     if (this.IsHandleCreated == true)
     {
         this.Invoke(new UpdateTreeDelegate(HandleTreeUpdate),args);
     }
     else
     {
         HandleTreeUpdate(parent);
     }
 }
        public SampleDevice()
        {
            device = UPnPDevice.CreateRootDevice(1800,1.0,"\\");

            device.FriendlyName = "Media Server (CASPER-LAPTOP)";
            device.Manufacturer = "OpenSource";
            device.ManufacturerURL = "";
            device.ModelName = "Media Server";
            device.ModelDescription = "Provides content through UPnP ContentDirectory service";
            device.ModelNumber = "0.765";
            device.HasPresentation = false;
            device.DeviceURN = "urn:schemas-upnp-org:device:MediaServer:1";

            DvConnectionManager ConnectionManager = new DvConnectionManager();

            ConnectionManager.External_GetCurrentConnectionIDs = ConnectionManager_GetCurrentConnectionIDs;
            ConnectionManager.External_GetCurrentConnectionInfo = ConnectionManager_GetCurrentConnectionInfo;
            //ConnectionManager.External_GetProtocolInfo = ConnectionManager_GetProtocolInfo;

            device.AddService(ConnectionManager);

            DvContentDirectory ContentDirectory = new DvContentDirectory();

            ContentDirectory.External_Browse = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_Browse(ContentDirectory_Browse);
            ContentDirectory.External_CreateObject = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_CreateObject(ContentDirectory_CreateObject);
            ContentDirectory.External_CreateReference = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_CreateReference(ContentDirectory_CreateReference);
            ContentDirectory.External_DeleteResource = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_DeleteResource(ContentDirectory_DeleteResource);
            ContentDirectory.External_DestroyObject = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_DestroyObject(ContentDirectory_DestroyObject);
            ContentDirectory.External_ExportResource = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_ExportResource(ContentDirectory_ExportResource);
            ContentDirectory.External_GetSearchCapabilities = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_GetSearchCapabilities(ContentDirectory_GetSearchCapabilities);
            ContentDirectory.External_GetSortCapabilities = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_GetSortCapabilities(ContentDirectory_GetSortCapabilities);
            ContentDirectory.External_GetSystemUpdateID = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_GetSystemUpdateID(ContentDirectory_GetSystemUpdateID);
            ContentDirectory.External_GetTransferProgress = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_GetTransferProgress(ContentDirectory_GetTransferProgress);
            ContentDirectory.External_ImportResource = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_ImportResource(ContentDirectory_ImportResource);
            ContentDirectory.External_Search = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_Search(ContentDirectory_Search);
            ContentDirectory.External_StopTransferResource = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_StopTransferResource(ContentDirectory_StopTransferResource);
            ContentDirectory.External_UpdateObject = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_UpdateObject(ContentDirectory_UpdateObject);

            device.AddService(ContentDirectory);

            // Setting the initial value of evented variables
            ConnectionManager.Evented_SourceProtocolInfo = "Sample String";
            ConnectionManager.Evented_SinkProtocolInfo = "Sample String";
            ConnectionManager.Evented_CurrentConnectionIDs = "Sample String";
            ContentDirectory.Evented_ContainerUpdateIDs = "Sample String";
            ContentDirectory.Evented_SystemUpdateID = 0;
            ContentDirectory.Evented_TransferIDs = "Sample String";
        }
예제 #19
0
        public override void Start(UPnPDevice device)
        {
            UPnPDevice d = device;
            UPnPService[] services = d.GetServices(CpContentDirectory.SERVICE_NAME);
            if (services == null || services.Length == 0)
            {
                enabled = false;
                return;
            }

            CdsSubTestArgument arg = new CdsSubTestArgument();
            arg._Device = device;
            arg._TestGroupState = new CdsTestGroupState();
            arg._TestGroup = this;
            this.RunTests(null, arg);
        }
예제 #20
0
        private void AddDeviceToNode(TreeNode n, UPnPDevice d)
        {
            foreach(UPnPDevice ed in d.EmbeddedDevices)
            {
                AddDeviceToNode(n,ed);
            }

            TreeNode NewNode = new TreeNode(d.FriendlyName);
            NewNode.Tag = d;
            foreach(UPnPService s in d.Services)
            {
                AddServiceToNode(NewNode,s);
            }

            n.Nodes.Add(NewNode);
        }
        public ProxyDeviceFactory(CpGateKeeper home, UPnPDevice D, OnDeviceHandler Callback)
        {
            OpenSource.Utilities.InstanceTracker.Add(this);
            HOME = home;
            OnDevice += Callback;
            _D = D;

            foreach(UPnPDevice ed in D.EmbeddedDevices)
            {
                ProcessEmbeddedDevice(ed,false);
            }
            ProcessServices(D,false);

            foreach(UPnPDevice ed in D.EmbeddedDevices)
            {
                ProcessEmbeddedDevice(ed,true);
            }
            ProcessServices(D,true);
        }
예제 #22
0
		public UPnPPresenter(UPnPDevice device, string userAgent = null)
		{
			ScanForBackgroundImages = true;
			InitializeMediaReceiver(device, userAgent);
			CreateBindings();
			Dispatcher.ShutdownStarted += (sender, args) =>
				{
					Thread.Sleep(10);	// pause for the cause
					Cleanup();
				};

			//Enumerate the assembly's manifest resources
			foreach (var resourceName in GetType().Assembly.GetManifestResourceNames())
			{
				if (resourceName.StartsWith("SectionName_"))
					SectionNames[resourceName] = Presenter.Properties.Resources.ResourceManager.GetString(resourceName);
				if (resourceName.StartsWith("ActionName_"))
					ActionNames[resourceName] = Presenter.Properties.Resources.ResourceManager.GetString(resourceName);
			}
		}
        public override void Start(UPnPDevice device)
        {
            UPnPDevice d = device;
            while (d.ParentDevice != null)
            {
                d = d.ParentDevice;
            }
            TestDevice = d;

            ASocket = new AsyncSocket(4096);
            ASocket.Attach(new IPEndPoint(TestDevice.InterfaceToHost, 0), System.Net.Sockets.ProtocolType.Udp);
            ASocket.SetTTL(4);
            ASocket.AddMembership((IPEndPoint)ASocket.LocalEndPoint, IPAddress.Parse("239.255.255.250"));
            ASocket.OnReceive += new AsyncSocket.OnReceiveHandler(ReceiveSink);
            ASocket.Begin();

            ASocket2 = new AsyncSocket(4096);
            ASocket2.Attach(new IPEndPoint(TestDevice.InterfaceToHost, 1900), System.Net.Sockets.ProtocolType.Udp);
            ASocket2.SetTTL(2);
            ASocket2.AddMembership((IPEndPoint)ASocket.LocalEndPoint, IPAddress.Parse("239.255.255.250"));
            ASocket2.OnReceive += new AsyncSocket.OnReceiveHandler(ReceiveSink2);

            Validate_MSEARCH_RESPONSETIME();
            Validate_NOTIFY();
            Validate_DISCOVERY();

            UPnPTestStates RetState = UPnPTestStates.Pass;
            if (NOTIFY == UPnPTestStates.Failed || DISCOVERY == UPnPTestStates.Failed)
            {
                RetState = UPnPTestStates.Failed;
            }
            else
            {
                if (NOTIFY == UPnPTestStates.Warn || DISCOVERY == UPnPTestStates.Warn || MX == UPnPTestStates.Warn)
                {
                    RetState = UPnPTestStates.Warn;
                }
            }

            state = RetState;
        }
 public static int CalculateMaxAllowedValues(UPnPDevice d, int maxVal)
 {
     foreach(UPnPDevice ed in d.EmbeddedDevices)
     {
         maxVal = CalculateMaxAllowedValues(ed,maxVal);
     }
     foreach(UPnPService s in d.Services)
     {
         foreach(UPnPStateVariable v in s.GetStateVariables())
         {
             if (v.AllowedStringValues!=null)
             {
                 if (v.AllowedStringValues.Length>maxVal)
                 {
                     maxVal = v.AllowedStringValues.Length;
                 }
             }
         }
     }
     return(maxVal);
 }
        public UPnPRelayDevice(UPnPDevice device, CpGateKeeper _CP)
        {
            OpenSource.Utilities.InstanceTracker.Add(this);
            ILCB = new InvokeResponseHandler(InvokeResponseSink);
            CP = _CP;
            ProxyDevice = UPnPDevice.CreateRootDevice(750, double.Parse(device.Version), "");
            ProxyDevice.UniqueDeviceName = Guid.NewGuid().ToString();

            ProxyDevice.HasPresentation = false;
            ProxyDevice.FriendlyName = "*" + device.FriendlyName;
            ProxyDevice.Manufacturer = device.Manufacturer;
            ProxyDevice.ManufacturerURL = device.ManufacturerURL;
            ProxyDevice.ModelName = device.ModelName;
            ProxyDevice.DeviceURN = device.DeviceURN;

            foreach (UPnPService S in device.Services)
            {
                UPnPService S2 = (UPnPService)S.Clone();
                foreach (UPnPAction A in S2.Actions)
                {
                    A.ParentService = S2;
                    A.SpecialCase += new UPnPAction.SpecialInvokeCase(InvokeSink);
                }

                UPnPDebugObject dbg = new UPnPDebugObject(S2);

                dbg.SetField("SCPDURL", "_" + S2.ServiceID + "_scpd.xml");
                dbg.SetProperty("ControlURL", "_" + S2.ServiceID + "_control");
                dbg.SetProperty("EventURL", "_" + S2.ServiceID + "_event");
                ProxyDevice.AddService(S2);
            }

            UDNTable[device.UniqueDeviceName] = ProxyDevice;
            ReverseUDNTable[ProxyDevice.UniqueDeviceName] = device.UniqueDeviceName;
            foreach (UPnPDevice _ed in device.EmbeddedDevices)
            {
                ProcessDevice(_ed);
            }
        }
        public SinkDevice()
        {
            //Creates root device
            device = UPnPDevice.CreateRootDevice(1800, 1.0 , "\\");

            //Device information:
            device.FriendlyName = "Caspers homemade Renderer";
            device.Manufacturer = "Awesome Casper";
            device.DeviceURN = "urn:schemas-upnp-org:device:MediaRenderer:1";

            //Create stacks
            DvAVTransport AVTransport = new DvAVTransport();
            DvConnectionManager connectionManager = new DvConnectionManager();
            DvRenderingControl renderingControl = new DvRenderingControl();

            //Add stacks to device (and network visibility)
            device.AddService(AVTransport);
            device.AddService(connectionManager);
            device.AddService(renderingControl);

            AVTransport.Evented_LastChange = "Sample string";
        }
예제 #27
0
        public SampleDevice()
        {
            device = UPnPDevice.CreateRootDevice(1800, 1.0, "\\");

            device.FriendlyName = "Aquarium";
            device.Manufacturer = "Aquarium";
            device.ManufacturerURL = "http://polytech.unice.fr";
            device.ModelName = "Aquarium";
            device.ModelDescription = "Aquarium";
            device.ModelNumber = "AQUA1";
            device.HasPresentation = false;
            device.DeviceURN = "urn:schemas-upnp-org:device:Aquarium:1";
            Aquarium.DvaquariumService aquariumService = new Aquarium.DvaquariumService();
            aquariumService.External_getBrightness = new Aquarium.DvaquariumService.Delegate_getBrightness(aquariumService_getBrightness);
            aquariumService.External_getTemperature = new Aquarium.DvaquariumService.Delegate_getTemperature(aquariumService_getTemperature);
            aquariumService.External_setBrightness = new Aquarium.DvaquariumService.Delegate_setBrightness(aquariumService_setBrightness);
            aquariumService.External_setTemperature = new Aquarium.DvaquariumService.Delegate_setTemperature(aquariumService_setTemperature);
            device.AddService(aquariumService);

            // Setting the initial value of evented variables
            aquariumService.Evented_brightness = 0;
            aquariumService.Evented_temperature = 0;
        }
예제 #28
0
		private static UPnPDevice GetDevice(string deviceName)
		{
			UPnPDevice result;

			_deviceName = deviceName;
			_deviceFound = null;

			var model = MediaServerModel.GetInstance();

			model.Actions.ContentDirectory.NewDeviceFound -= GetDevice_OnNewDeviceFound;
			model.Actions.ContentDirectory.NewDeviceFound += GetDevice_OnNewDeviceFound;

			_allDoneEvent.Reset();
			model.Actions.ContentDirectory.OnCreateControlPoint();
			_allDoneEvent.WaitOne(TimeSpan.FromSeconds(30d));

			result = _deviceFound;

			model.Actions.ContentDirectory.NewDeviceFound -= GetDevice_OnNewDeviceFound;

			_allDoneEvent.Reset();
			return result;
		}
        private void AddSink(MediaRendererDiscovery sender, UPnPDevice d)
        {
            MessageBox.Show("Sink detected: " + d.FriendlyName);

            try
            {
                _avTransport = new CpAVTransport(d.GetServices(CpAVTransport.SERVICE_NAME)[0]);

                _avTransport.OnStateVariable_LastChange += new CpAVTransport.StateVariableModifiedHandler_LastChange(Eventer);
            }
            catch (Exception m)
            {
                MessageBox.Show("Couldn't initialize AVTransport: " + m.Message);
            }

            try
            {
                _connectionManagerControl = new CpConnectionManager(d.GetServices(CpConnectionManager.SERVICE_NAME)[0]);
            }
            catch (Exception m)
            {
                MessageBox.Show("Couldn't initialize ConnectionManager: " + m.Message);
            }

            try
            {
                _renderingControl = new CpRenderingControl(d.GetServices(CpRenderingControl.SERVICE_NAME)[0]);
            }
            catch (Exception m)
            {
                MessageBox.Show("Couldn't initialize RenderingControl: " + m.Message);
            }

            //MessageBox.Show(d.DeviceURN);

            //RenderingControl._subscribe(300);
        }
        /// <summary>
        /// When a MediaServer device is found, we add it to a temp list.
        /// Then we attempt to subscribe to its services.
        /// </summary>
        /// <param name="sender">the smart cp that found the device</param>
        /// <param name="device">the mediaserver device</param>
        private void Temporary_AddServer(UPnPSmartControlPoint sender, UPnPDevice device)
        {
            if (this.OnServerSeen != null)
            {
                this.OnServerSeen(this, device);
            }

            UPnPService sCD = device.GetServices(CpContentDirectory.SERVICE_NAME)[0];
            UPnPService sCM = device.GetServices(CpConnectionManager.SERVICE_NAME)[0];

            CpMediaServer newServer;
            try
            {
                newServer = new CpMediaServer(device);
            }
            catch (UPnPCustomException)
            {
                newServer = null;
            }

            if (newServer != null)
            {
                InitStatus status = new InitStatus();
                status.SubcribeCD = false;
                status.SubcribeCM = false;
                status.EventedCD = false;
                status.EventedCM = false;
                status.Server = newServer;

                lock (LockHashes)
                {
                    UdnToInitStatus[device.UniqueDeviceName] = status;
                }

                newServer.ConnectionManager.OnSubscribe += new CpConnectionManager.SubscribeHandler(this.Sink_OnCmServiceSubscribe);
                newServer.ContentDirectory.OnSubscribe += new CpContentDirectory.SubscribeHandler(this.Sink_OnCdServiceSubscribe);

                newServer.ConnectionManager.OnStateVariable_SourceProtocolInfo += new CpConnectionManager.StateVariableModifiedHandler_SourceProtocolInfo(this.Sink_OnCmEvented);
                newServer.ContentDirectory.OnStateVariable_SystemUpdateID += new CpContentDirectory.StateVariableModifiedHandler_SystemUpdateID(this.Sink_OnCdEvented);

                newServer.ConnectionManager._subscribe(600);
                newServer.ContentDirectory._subscribe(600);
            }
        }
        /// <summary>
        /// Method executes when smart control point notices that 
        /// a upnp  media server has left the network.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="device"></param>
        private void RemoveServer(UPnPSmartControlPoint sender, UPnPDevice device)
        {
            string udn = device.UniqueDeviceName;

            CpMediaServer removeThis = null;

            lock (LockHashes)
            {
                if (UdnToInitStatus.Contains(udn))
                {
                    InitStatus status = (InitStatus) UdnToInitStatus[udn];
                }

                if (UdnToServer.Contains(udn))
                {
                    removeThis = (CpMediaServer) UdnToServer[udn];
                    UdnToServer.Remove(udn);
                }
            }

            if (this.OnServerGone != null)
            {
                this.OnServerGone(this, device);
            }

            if (removeThis != null)
            {
                if (this.OnCpServerRemoved != null)
                {
                    this.OnCpServerRemoved(this, removeThis);
                }
            }

            System.GC.Collect();
        }
예제 #32
0
 private void HeaderHandler(OpenSource.UPnP.UPnPDevice sender, OpenSource.UPnP.HTTPMessage msg, OpenSource.UPnP.HTTPSession WebSession, string VirtualDir)
 {
     msg.AddTag("transferMode.dlna.org", "Streaming");
     msg.AddTag("contentFeatures.dlna.org", "DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000");
 }