示例#1
0
文件: RdmRouter.cs 项目: ming-hai/ACN
 internal void UnBind(RdmRouteBinding binding)
 {
     if (running)
     {
         socket.UnBind(binding.Transport.Socket);
     }
 }
示例#2
0
        /// <summary>
        /// Gets the transport binding for a specific device.
        /// </summary>
        /// <remarks>
        /// Each device will have a transport binding which determines the transport used to comunicate with that device.
        /// </remarks>
        /// <param name="targetId">The ID of the device we wish to get the binding for.</param>
        /// <returns>The transport binding for the specified device.</returns>
        public RdmRouteBinding GetBindingForDevice(UId targetId)
        {
            if (targetId == UId.Broadcast)
            {
                throw new InvalidOperationException("Target device UId can not be broadcast.");
            }

            RdmRouteBinding route = GetTransportsRoutes(targetId).FirstOrDefault();

            return(route);
        }
示例#3
0
        void Transport_NewDeviceFound(object sender, DeviceFoundEventArgs e)
        {
            RdmRouteBinding binding = Transports.FirstOrDefault <RdmRouteBinding>(item => item.Transport == sender);

            if (binding != null)
            {
                RegisterDevice(e.Id, binding);
            }

            RaiseNewDeviceFound(e);
        }
示例#4
0
 internal void UnBind(RdmRouteBinding binding)
 {
     if (running)
     {
         foreach (IRdmSocket transportSocket in binding.Transport.Sockets)
         {
             foreach (var socket in sockets)
             {
                 socket.UnBind(transportSocket);
             }
         }
     }
 }
示例#5
0
        protected void RegisterDevice(UId deviceId, RdmRouteBinding transport)
        {
            lock (deviceTable)
            {
                RdmRouteBinding existingTransport;
                if (deviceTable.TryGetValue(deviceId, out existingTransport))
                {
                    //Already registered.
                    if (existingTransport == transport)
                    {
                        return;
                    }

                    //Only register transports with a higher priority.
                    if (existingTransport.Priority >= transport.Priority)
                    {
                        return;
                    }
                }

                //Register device in device table.
                deviceTable[deviceId] = transport;
            }
        }
示例#6
0
        public void RegisterTransport(RdmRouteBinding routeDescription)
        {
            if (running)
            {
                throw new InvalidOperationException("The router is already running. You can not register a transport while the router is running. You must Stop it first.");
            }

            if (transports.ContainsKey(routeDescription.Priority))
            {
                throw new InvalidOperationException("A transport with the priority {0} already exists. Each transport must have a unique priority.");
            }

            if (transports.Values.Any <RdmRouteBinding>(item => item.Transport == routeDescription.Transport))
            {
                throw new InvalidOperationException("This transport has already been registered. You may only register a transport once.");
            }

            routeDescription.Transport.NewDeviceFound += new EventHandler <DeviceFoundEventArgs>(Transport_NewDeviceFound);

            lock (transports)
            {
                transports.Add(routeDescription.Priority, routeDescription);
            }
        }