internal void SendReadNotify <TType> (uint nbElements) { if (Client.Configuration.DebugTiming) { lock ( ElapsedTimings ) { if (!ElapsedTimings.ContainsKey("SendReadNotify")) { ElapsedTimings.Add( "SendReadNotify", Stopwatch.Elapsed ); } } } DataPacket packet = DataPacket.Create(16); packet.Command = (ushort)CommandID.CA_PROTO_READ_NOTIFY; Type t = typeof(TType); if (typeof(TType).IsArray) { t = typeof(TType).GetElementType(); } else if (t.IsGenericType) { if (t.GetGenericArguments().First() == typeof(object)) { t = t.GetGenericTypeDefinition().MakeGenericType( new Type[] { channelDefinedType } ); } } if (t == typeof(object)) { t = channelDefinedType; } packet.DataType = (ushort)TypeHandling.Lookup[t]; packet.DataCount = nbElements; packet.Parameter1 = SID; uint ioid = (NextIoId++); packet.Parameter2 = ioid; lock (ioc.PendingIo) { ioc.PendingIo.Add(ioid, this); } ioc.Send(packet); }
internal virtual void Disconnect( ) { if (Disposed) { return; } if (ioc != null) { ioc.RemoveChannel(this); } lock ( ConnectionLock ) { if (Status != ChannelStatus.CONNECTED) { return; } Status = ChannelStatus.DISCONNECTED; StartSearchTime = DateTime.Now; ioc = null; SID = 0; if (PrivMonitorChanged != null) { AfterConnect( action => { if (MonitoredType == null) { return; } DataPacket p = DataPacket.Create( 16 + 16 ); p.Command = (ushort)CommandID.CA_PROTO_EVENT_ADD; p.DataType = (ushort)TypeHandling.Lookup[MonitoredType]; p.DataCount = ChannelDataCount; p.Parameter1 = SID; p.Parameter2 = CID; p.SetUInt16( 12 + 16, (ushort)MonitorMask ); if (ioc != null) { ioc.Send(p); } else { Disconnect(); } } ); } } }
internal void SetIoc(DataPipe pipe) { ClientTcpReceiver tcpReceiver = (ClientTcpReceiver)pipe[0]; tcpReceiver.AddChannel(this); lock ( ConnectionLock ) { if (!Client.Searcher.Contains(this)) { return; } Client.Searcher.Remove(this); SID = 0; ioc = tcpReceiver; lock (ioc.ChannelSID) { // Console.WriteLine(ioc.ChannelSID.Count) ; // Channel already known if (ioc.ChannelSID.ContainsKey(ChannelName)) { SID = ioc.ChannelSID[ChannelName]; // Console.WriteLine("Here") ; Channel chan = ioc.ConnectedChannels.FirstOrDefault( row => row.ChannelName == ChannelName && row.ChannelDataCount != 0 ); if (chan != null) { this.ChannelDataCount = chan.ChannelDataCount; this.channelDefinedType = chan.channelDefinedType; this.ChannelDataCount = chan.ChannelDataCount; this.channelDefinedType = chan.ChannelDefinedType; Status = ChannelStatus.CONNECTED; ConnectionEvent.Set(); } } } } if (SID != 0) { // Console.WriteLine("SID " + SID + " STATUS CHANGED") ; StatusChanged?.Invoke(this, Status); return; } if (Client.Configuration.DebugTiming) { lock ( ElapsedTimings ) { if (!ElapsedTimings.ContainsKey("IocConnection")) { ElapsedTimings.Add( "IocConnection", Stopwatch.Elapsed ); } } } // We need to create the channel int padding; if (ChannelName.Length % 8 == 0) { padding = 8; } else { padding = ( 8 - (ChannelName.Length % 8) ); } DataPacket packet = DataPacket.Create( 16 + ChannelName.Length + padding ); packet.Command = (ushort)CommandID.CA_PROTO_CREATE_CHAN; packet.DataType = 0; packet.DataCount = 0; packet.Parameter1 = cid; packet.Parameter2 = (uint)CAConstants.CA_MINOR_PROTOCOL_REVISION; packet.SetDataAsString(ChannelName); if (ioc != null) { ioc.Send(packet); } else { Disconnect(); return; } lock ( ElapsedTimings ) { if (!ElapsedTimings.ContainsKey("SendCreateChannel")) { ElapsedTimings.Add( "SendCreateChannel", Stopwatch.Elapsed ); } } }