/// <summary> /// The search for channel. /// </summary> /// <param name="clientChanId"> /// The client chan id. /// </param> /// <param name="ChannelName"> /// The channel name. /// </param> /// <param name="iep"> /// The iep. /// </param> internal void SearchForChannel(uint clientChanId, string ChannelName, EndPoint iep) { if (this.Rules.GetAccessRights(iep, "*", ChannelName) == AccessRights.NoAccess) { return; } // check if we already have the channel if (this.ChannelListIocName.ContainsKey(ChannelName)) { this.UdpConnFrom.Send(this.receiverCodec.channelFoundMessage(clientChanId), (IPEndPoint)iep); } else { lock (this.ChannelSearchIdWait) { if (!this.ChannelSearchNameWait.ContainsKey(ChannelName)) { var tmpChannel = new EpicsGateWayIocChannel(ChannelName, ++this.GWIocChanId, this, iep, clientChanId); this.ChannelSearchIdWait.Add(tmpChannel.GWIocChanId, tmpChannel); this.ChannelSearchNameWait.Add(ChannelName, tmpChannel); lock (this.ChannelQueue) { this.ChannelQueue.Enqueue(new KeyValuePair <uint, string>(tmpChannel.GWIocChanId, ChannelName)); } } } } }
/// <summary> /// The found channel. /// </summary> /// <param name="gWIocChanId"> /// The g w ioc chan id. /// </param> /// <param name="iep"> /// The iep. /// </param> /// <param name="port"> /// The port. /// </param> internal void FoundChannel(uint gWIocChanId, EndPoint iep, ushort port) { EpicsGateWayIocChannel tmpChannel = null; // remove from search List lock (this.ChannelSearchIdWait) { if (this.ChannelSearchIdWait.ContainsKey(gWIocChanId)) { tmpChannel = this.ChannelSearchIdWait[gWIocChanId]; this.ChannelSearchIdWait.Remove(gWIocChanId); this.ChannelSearchNameWait.Remove(tmpChannel.ChannelName); } } if (tmpChannel == null) { return; } if (this.ChannelListIocName.ContainsKey(tmpChannel.ChannelName)) { return; } // add to the translation dictionary lock (this.ChannelListIocId) { this.ChannelListIocId.Add(gWIocChanId, tmpChannel); this.ChannelListIocName.Add(tmpChannel.ChannelName, tmpChannel); } tmpChannel.Connection = this.getConnection(new IPEndPoint(((IPEndPoint)iep).Address, port)); }
/// <summary> /// Initializes a new instance of the <see cref="EpicsGateWayMonitor"/> class. /// </summary> /// <param name="channel"> /// The channel. /// </param> /// <param name="gateWay"> /// The gate way. /// </param> /// <param name="key"> /// The key. /// </param> /// <param name="header"> /// The header. /// </param> /// <param name="payload"> /// The payload. /// </param> internal EpicsGateWayMonitor( EpicsGateWayIocChannel channel, EpicsGateWay gateWay, long key, byte[] header, byte[] payload) { this.Channel = channel; this.GateWay = gateWay; this.Key = key; this.SubscriptionId = this.GateWay.RegisterNewMonitor(this); this.Channel.Connection.Send( this.GateWay.ConnectorCodec.createSubscriptionMessage(header, payload, this.SubscriptionId, this.Channel.IocChanId)); }
/// <summary> /// Initializes a new instance of the <see cref="EpicsGateWayClientChannel"/> class. /// </summary> /// <param name="gateWay"> /// The gate way. /// </param> /// <param name="clientChanId"> /// The client chan id. /// </param> /// <param name="channelName"> /// The channel name. /// </param> /// <param name="ipAddress"> /// The ip address. /// </param> /// <param name="gWClientChanId"> /// The g w client chan id. /// </param> internal EpicsGateWayClientChannel( EpicsGateWay gateWay, uint clientChanId, string channelName, EndPoint ipAddress, uint gWClientChanId) { this.GateWay = gateWay; this.IpAddress = ipAddress.ToString(); this.ClientChanId = clientChanId; this.GWClientChanId = gWClientChanId; this.ChannelName = channelName; try { this.Conn = this.GateWay.TCPConnections[this.IpAddress]; } catch (Exception e) { Trace.Write("ITCP Connection for Channel was closed before Channel was established (IP: " + this.IpAddress + ")"); this.Dispose(); return; } try { this.Channel = this.GateWay.ChannelListIocName[channelName]; } catch (Exception e) { // if it was not yet established, give it a second to find, if not it's to slow and it shall be found next time var timeout = new TimeSpan(0, 0, 1); var wtch = new Stopwatch(); wtch.Start(); while (this.GateWay.ChannelSearchNameWait.ContainsKey(channelName)) { Thread.Sleep(0); if (wtch.Elapsed > timeout) { break; } } wtch.Stop(); try { this.Channel = this.GateWay.ChannelListIocName[channelName]; } catch { Trace.Write("IChannel creation to fast, finding to slow."); this.Conn.Send(this.GateWay.ReceiverCodec.channelCreationFailMessage(this.ClientChanId)); this.Dispose(); return; } } this.IpAddressEndpoint = ipAddress; var calcRights = this.GateWay.Rules.GetAccessRights(this.IpAddressEndpoint, this.Conn.Username, this.ChannelName); if (calcRights < this.Channel.AccessRights) { this.Access = calcRights; } else { this.Access = this.Channel.AccessRights; } gateWay.Rules.RulesChanged += this.Rules_RulesChanged; this.Conn.ConnectionStateChanged += this.EpicsGateWayClientChannel_ConnectionStateChanged; this.Conn.Send( this.GateWay.ReceiverCodec.channelCreatedMessage( this.ClientChanId, this.GWClientChanId, this.Access, this.Channel.CreateMessageAnswer)); this.GateWay.Statistic.OpenClientChannels++; }
/// <summary> /// The search for channel. /// </summary> /// <param name="clientChanId"> /// The client chan id. /// </param> /// <param name="ChannelName"> /// The channel name. /// </param> /// <param name="iep"> /// The iep. /// </param> internal void SearchForChannel(uint clientChanId, string ChannelName, EndPoint iep) { if (this.Rules.GetAccessRights(iep, "*", ChannelName) == AccessRights.NoAccess) { return; } // check if we already have the channel if (this.ChannelListIocName.ContainsKey(ChannelName)) { this.UdpConnFrom.Send(this.receiverCodec.channelFoundMessage(clientChanId), (IPEndPoint)iep); } else { lock (this.ChannelSearchIdWait) { if (!this.ChannelSearchNameWait.ContainsKey(ChannelName)) { var tmpChannel = new EpicsGateWayIocChannel(ChannelName, ++this.GWIocChanId, this, iep, clientChanId); this.ChannelSearchIdWait.Add(tmpChannel.GWIocChanId, tmpChannel); this.ChannelSearchNameWait.Add(ChannelName, tmpChannel); lock (this.ChannelQueue) { this.ChannelQueue.Enqueue(new KeyValuePair<uint, string>(tmpChannel.GWIocChanId, ChannelName)); } } } } }