#if !BESTHTTP_DISABLE_SIGNALR_CORE && !BESTHTTP_DISABLE_WEBSOCKET using System; using System.Collections.Generic; namespace BestHTTP.SignalRCore { public enum TransportTypes { WebSocket } public enum TransferModes { Binary, Text } public enum TransportStates { Initial, Connecting, Connected, Closing, Failed, Closed } /// /// Possible states of a HubConnection /// public enum ConnectionStates { Initial, Authenticating, Negotiating, Connected, CloseInitiated, Closed } public interface ITransport { TransferModes TransferMode { get; } TransportTypes TransportType { get; } TransportStates State { get; } string ErrorReason { get; } event Action OnStateChanged; void StartConnect(); void StartClose(); void Send(byte[] msg); } public interface IEncoder { string Name { get; } string EncodeAsText(T value); T DecodeAs(string text); byte[] EncodeAsBinary(T value); T DecodeAs(byte[] data); object ConvertTo(Type toType, object obj); } public class StreamItemContainer { public readonly long id; public List Items { get; private set; } public T LastAdded { get; private set; } //public int newIdx; //public int newCount; public bool IsCanceled; public StreamItemContainer(long _id) { this.id = _id; this.Items = new List(); } public void AddItem(T item) { if (this.Items == null) this.Items = new List(); //this.newIdx = this.Items.Count; //this.newCount = 1; this.Items.Add(item); this.LastAdded = item; } //public void AddItems(T[] items) //{ // if (this.Items == null) // this.Items = new List(); // // this.newIdx = this.Items.Count; // this.newCount = items.Length; // // this.Items.AddRange(items); //} } struct CallbackDescriptor { public readonly Type[] ParamTypes; public readonly Action Callback; public CallbackDescriptor(Type[] paramTypes, Action callback) { this.ParamTypes = paramTypes; this.Callback = callback; } } internal sealed class Subscription { public List callbacks = new List(1); public void Add(Type[] paramTypes, Action callback) { lock(callbacks) this.callbacks.Add(new CallbackDescriptor(paramTypes, callback)); } public void Remove(Action callback) { lock (callbacks) { int idx = -1; for (int i = 0; i < this.callbacks.Count && idx == -1; ++i) if (this.callbacks[i].Callback == callback) idx = i; if (idx != -1) this.callbacks.RemoveAt(idx); } } } } #endif