public void TestAddRemoveConnectionListener() { ConnectionListenerCallback callback = (uid, connected, conn) => { }; int id = CoreMethods.AddConnectionListener(callback, true); Assert.That(id, Is.Not.EqualTo(0)); CoreMethods.RemoveConnectionListener(id); }
/// <summary> /// Adds a connection listener to the table /// </summary> /// <param name="callback">The callback to call when a new remote connects or disconnects</param> /// <param name="immediateNotify">True to notify immediately with all connected remotes</param> /// <returns>The id of the connection listener</returns> public static int AddConnectionListener(ConnectionListenerCallback callback, bool immediateNotify) { #if CORE return(CoreMethods.AddConnectionListener(callback, immediateNotify)); #else Notifier notifier = Notifier.Instance; int uid = notifier.AddConnectionListener(callback); notifier.Start(); if (immediateNotify) { Dispatcher.Instance.NotifyConnections(callback); } return(uid); #endif }
/// <inheritdoc/> public void AddConnectionListener(Action <IRemote, ConnectionInfo, bool> listener, bool immediateNotify) { if (m_actionConnectionListenerMap.ContainsKey(listener)) { throw new ArgumentException("Cannot add the same listener twice", nameof(listener)); } ConnectionListenerFunction func = (uid, connected, conn) => { listener(this, conn, connected); }; int id = CoreMethods.AddConnectionListener(func, immediateNotify); m_actionConnectionListenerMap.Add(listener, id); }
///<inheritdoc/> public void AddConnectionListener(IRemoteConnectionListener listener, bool immediateNotify) { if (m_connectionListenerMap.ContainsKey(listener)) { throw new ArgumentException("Cannot add the same listener twice", nameof(listener)); } ConnectionListenerFunction func = (uid, connected, conn) => { if (connected) { listener.Connected(this, conn); } else { listener.Disconnected(this, conn); } }; int id = CoreMethods.AddConnectionListener(func, immediateNotify); m_connectionListenerMap.Add(listener, id); }