コード例 #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);
            }
        }
コード例 #2
0
        ///<inheritdoc/>
        public void AddConnectionListener(IRemoteConnectionListener listener, bool immediateNotify)
        {
            if (m_connectionListenerMap.ContainsKey(listener))
            {
                throw new ArgumentException("Cannot add the same listener twice", nameof(listener));
            }

            ConnectionListenerCallback func = (uid, connected, conn) =>
            {
                if (connected)
                {
                    listener.Connected(this, conn);
                }
                else
                {
                    listener.Disconnected(this, conn);
                }
            };
            int id = m_ntCore.AddConnectionListener(func, immediateNotify);

            m_connectionListenerMap.Add(listener, id);
        }
コード例 #3
0
        /// <summary>
        /// Adds a connection listener to the network table.
        /// </summary>
        /// <param name="listener">The <see cref="IRemoteConnectionListener"/> to add.</param>
        /// <param name="immediateNotify">True whether to notify the listener immediately, 
        /// otherwise false.</param>
        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);
                else listener.Disconnected(this);
            };

            int id = CoreMethods.AddConnectionListener(func, immediateNotify);

            m_connectionListenerMap.Add(listener, id);
        }