Ejemplo n.º 1
0
        ///<inheritdoc cref="NetworkTable.AddConnectionListener(IRemoteConnectionListener, bool)"/>
        public static void AddGlobalConnectionListener(IRemoteConnectionListener listener, bool immediateNotify)
        {
            lock (s_connectionListenerMap)
            {
                if (s_connectionListenerMap.ContainsKey(listener))
                {
                    throw new ArgumentException("Cannot add the same listener twice", nameof(listener));
                }

                ConnectionListenerCallback func = (uid, connected, conn) =>
                {
                    if (connected)
                    {
                        listener.Connected(s_staticRemote.Value, conn);
                    }
                    else
                    {
                        listener.Disconnected(s_staticRemote.Value, conn);
                    }
                };

                int id = NtCore.AddConnectionListener(func, immediateNotify);
                s_connectionListenerMap.Add(listener, id);
            }
        }
Ejemplo n.º 2
0
        /// <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));
            }

            ConnectionListenerCallback func = (uid, connected, conn) =>
            {
                listener(this, conn, connected);
            };
            int id = NtCore.AddConnectionListener(func, immediateNotify);

            m_actionConnectionListenerMap.Add(listener, id);
        }