private void EventSink(UPnPStateVariable sender, object val)
        {
            lock (RegisteredTable)
            {
                IDictionaryEnumerator en = RegisteredTable.GetEnumerator();
                while (en.MoveNext())
                {
                    CpGateKeeper cp = (CpGateKeeper)en.Value;

                    cp.FireEvent(sender.OwningService.ParentDevice.UniqueDeviceName,
                                 sender.OwningService.ServiceID,
                                 sender.Name,
                                 UPnPService.SerializeObjectInstance(val));
                }
            }

            if (this.OnEvent != null)
            {
                UPnPDevice _d = sender.OwningService.ParentDevice;
                while (_d.ParentDevice != null)
                {
                    _d = _d.ParentDevice;
                }

                OnEvent(_d, sender.Name);
            }
        }
        private void ProxySink_NoReverse(UPnPDeviceFactory sender, UPnPDevice d, Uri LocationUri)
        {
            FactoryTable.Remove(sender);
            sender.Shutdown();
            CpGateKeeper CP = new CpGateKeeper(d.GetServices(CpGateKeeper.SERVICE_NAME)[0]);

            lock (RegisteredTable)
            {
                RegisteredTable[CP.GetUPnPService().ParentDevice.UniqueDeviceName] = CP;
                object[] PL = (object[])ProcessLaterList.ToArray(typeof(object));
                foreach (object PL2 in PL)
                {
                    object[] PL3       = (object[])PL2;
                    string   SenderUDN = (string)PL3[0];
                    string   DeviceUDN = (string)PL3[1];

                    if (RegisteredTable.ContainsKey(SenderUDN))
                    {
                        CpGateKeeper HOME = (CpGateKeeper)RegisteredTable[SenderUDN];
                        HOME.GetDocument(DeviceUDN, "", null, new CpGateKeeper.Delegate_OnResult_GetDocument(CPGetDocumentSink));
                        ProcessLaterList.Remove(PL2);
                    }
                }
            }
            foreach (UPnPDevice t in ShareList)
            {
                CP.AddDevice(Root.UniqueDeviceName, t.UniqueDeviceName);
            }
        }
 private void RemovedSink(UPnPDevice d)
 {
     lock (RegisteredTable)
     {
         IDictionaryEnumerator en = RegisteredTable.GetEnumerator();
         while (en.MoveNext())
         {
             CpGateKeeper cp = (CpGateKeeper)en.Value;
             cp.RemoveDevice(d.UniqueDeviceName);
         }
     }
 }
        private void A_InvokeErrorSink(UPnPService sender, String MethodName, UPnPArgument[] Args, UPnPInvokeException e, object Tag)
        {
            object[] state  = (object[])Tag;
            string   Caller = (string)state[0];
            int      Handle = (int)state[1];

            CpGateKeeper C = (CpGateKeeper)RegisteredTable[Caller];

            if (e.UPNP != null)
            {
                C.InvokeAsyncResponse(Handle, new byte[0], e.UPNP.ErrorCode, e.UPNP.ErrorDescription);
            }
            else
            {
                C.InvokeAsyncResponse(Handle, new byte[0], 500, e.Message);
            }
        }
 private void AddDeviceSink(string SenderUDN, System.String DeviceUDN)
 {
     lock (RegisteredTable)
     {
         if (RegisteredTable.ContainsKey(SenderUDN) == true)
         {
             CpGateKeeper HOME = (CpGateKeeper)RegisteredTable[SenderUDN];
             HOME.GetDocument(DeviceUDN, "", null, new CpGateKeeper.Delegate_OnResult_GetDocument(CPGetDocumentSink));
         }
         else
         {
             ProcessLaterList.Add(new object[2] {
                 SenderUDN, DeviceUDN
             });
         }
     }
 }
Пример #6
0
        private void ConnectSink(UPnPDeviceFactory sender, UPnPDevice d, Uri ConnectUri)
        {
            string useIP = d.InterfaceToHost.ToString();

            disconnectMenuItem.Enabled = false;
            CheckIconState();

            if (this.overrideIP != "")
            {
                useIP = this.overrideIP;
            }

            statusBar.Text = "Connected to Peer Relay";
            devicefactory  = null;
            home           = new CpGateKeeper(d.GetServices(CpGateKeeper.SERVICE_NAME)[0]);
            home.Register(new Uri("http://" + useIP + ":" + this.PortNumber.ToString()), true);
        }
        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);
        }
Пример #8
0
        private void disconnectMenuItem_Click(object sender, System.EventArgs e)
        {
            if (home != null)
            {
                home.UnRegister(new Uri(shareuri));
                home.Dispose();
                home = null;
            }
            IDictionaryEnumerator en = gk.ProxyTable.GetEnumerator();

            while (en.MoveNext())
            {
                ((UPnPRelayDevice)en.Value).StopDevice();
            }
            gk.ProxyTable.Clear();

            connectMenuItem.Enabled = true;
            inboundListView.Enabled = false;
            CheckIconState();
        }
        private void CPGetDocumentSink(CpGateKeeper sender, System.String DeviceUDN, System.String ServiceID, System.Byte[] Document, UPnPInvokeException e, object _Tag)
        {
            if (e != null)
            {
                return;
            }
            UTF8Encoding U = new UTF8Encoding();

            string    XML       = U.GetString(Document);
            Uri       SourceUri = new Uri("http://127.0.0.1");
            IPAddress Intfce    = null;

            UPnPDevice d = (UPnPDevice)(new UPnPDebugObject(typeof(OpenSource.UPnP.UPnPDevice))).InvokeStaticMethod("Parse", new object[3]
            {
                XML, SourceUri, Intfce
            });

            ProxyDeviceFactory df = new ProxyDeviceFactory(sender, d, new ProxyDeviceFactory.OnDeviceHandler(NewDeviceSink));

            ProxyFactoryTable[df] = df;
        }
        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);
            }
        }
        private void ProxySink(UPnPDeviceFactory sender, UPnPDevice d, Uri LocationUri)
        {
            FactoryTable.Remove(sender);
            sender.Shutdown();
            CpGateKeeper CP        = new CpGateKeeper(d.GetServices(CpGateKeeper.SERVICE_NAME)[0]);
            string       useThisIP = d.InterfaceToHost.ToString();

            if (this.PublicIP != "")
            {
                useThisIP = PublicIP;
            }


            lock (RegisteredTable)
            {
                RegisteredTable[CP.GetUPnPService().ParentDevice.UniqueDeviceName] = CP;
                object[] PL = (object[])ProcessLaterList.ToArray(typeof(object));
                foreach (object PL2 in PL)
                {
                    object[] PL3       = (object[])PL2;
                    string   SenderUDN = (string)PL3[0];
                    string   DeviceUDN = (string)PL3[1];

                    if (RegisteredTable.ContainsKey(SenderUDN))
                    {
                        CpGateKeeper HOME = (CpGateKeeper)RegisteredTable[SenderUDN];
                        HOME.GetDocument(DeviceUDN, "", null, new CpGateKeeper.Delegate_OnResult_GetDocument(CPGetDocumentSink));
                        ProcessLaterList.Remove(PL2);
                    }
                }
            }
            foreach (UPnPDevice t in ShareList)
            {
                CP.AddDevice(Root.UniqueDeviceName, t.UniqueDeviceName);
            }

            CP.Register(new Uri("http://" + useThisIP + ":" + Port.ToString()), false);
        }
        private void GetDocumentSink(CpGateKeeper sender, System.String DeviceUDN, System.String ServiceID, System.Byte[] Document, UPnPInvokeException e, object _Tag)
        {
            if (e != null)
            {
                return;
            }
            UTF8Encoding U = new UTF8Encoding();

            string      XML = U.GetString(Document);
            UPnPService S   = (UPnPService)_Tag;

            (new UPnPDebugObject(S)).InvokeNonStaticMethod("ParseSCPD", new object[1] {
                XML
            });
            --Counter;
            if (Counter == 0)
            {
                if (OnDevice != null)
                {
                    OnDevice(this, new UPnPRelayDevice(_D, HOME));
                }
            }
        }
        private void GetStateTableSink(CpGateKeeper sender, System.String DeviceUDN, System.String ServiceID, System.Byte[] Variables, UPnPInvokeException e, object _Tag)
        {
            UPnPService s = (UPnPService)_Tag;

            UPnPArgument[] Vars = Gatekeeper.ParseArguments(Variables);
            foreach (UPnPArgument var in Vars)
            {
                (new UPnPDebugObject(s)).SetProperty("ValidationMode", false);
                s.SetStateVariable(var.Name, var.DataValue);
            }
            if (Interlocked.Decrement(ref InitCounter) == 0)
            {
                ProxyDevice.StartDevice();
            }
            if (Vars.Length > 0)
            {
                EventCounter += Vars.Length;
                if (this.OnEvent != null)
                {
                    OnEvent(this, EventCounter);
                }
            }
        }