Esempio n. 1
0
        ///<inheritdoc/>
        public void AddTableListenerEx(Action <ITable, string, Value, NotifyFlags> listenerDelegate, NotifyFlags flags)
        {
            List <int> adapters;

            if (!m_actionListenerMap.TryGetValue(listenerDelegate, out adapters))
            {
                adapters = new List <int>();
                m_actionListenerMap.Add(listenerDelegate, adapters);
            }

            // ReSharper disable once InconsistentNaming
            EntryListenerCallback func = (uid, key, value, flags_) =>
            {
                string relativeKey = key.Substring(m_path.Length + 1);
                if (relativeKey.IndexOf(PathSeperatorChar) != -1)
                {
                    return;
                }
                listenerDelegate(this, relativeKey, value, flags_);
            };

            int id = NtCore.AddEntryListener(m_path + PathSeperatorChar, func, flags);

            adapters.Add(id);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        ///<inheritdoc/>
        public void AddTableListenerEx(string key, Action <ITable, string, Value, NotifyFlags> listenerDelegate, NotifyFlags flags)
        {
            lock (m_actionListenerMap)
            {
                if (!m_actionListenerMap.TryGetValue(listenerDelegate, out List <int> adapters))
                {
                    adapters = new List <int>();
                    m_actionListenerMap.Add(listenerDelegate, adapters);
                }
                string fullKey = m_pathWithSeperator + key;
                // ReSharper disable once InconsistentNaming
                EntryListenerCallback func = (uid, funcKey, value, flags_) =>
                {
                    if (!funcKey.Equals(fullKey))
                    {
                        return;
                    }
                    listenerDelegate(this, key, value, flags_);
                };

                int id = NtCore.AddEntryListener(fullKey, func, flags);

                adapters.Add(id);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the IP address that will be connected to in client mode using round robin order.
        /// </summary>
        /// <param name="addresses">The IP address to connect to in client mode using round robin order.</param>
        public static void SetIPAddress(IList <string> addresses)
        {
            int port = 0;

            lock (s_lockObject)
            {
                port = Port;
            }
            List <NtIPAddress> laddresses = new List <NtIPAddress>(addresses.Count);

            foreach (string s in addresses)
            {
                laddresses.Add(new NtIPAddress(s, port));
            }

            NtCore.SetServer(laddresses);

            if (addresses.Count > 0 && (addresses[0] == "localhost" || addresses[0] == "127.0.0.1"))
            {
                NtCore.StopDSClient();
            }
            else if (s_enableDs)
            {
                NtCore.StartDSClient(port);
            }
        }
Esempio n. 5
0
        ///<inheritdoc/>
        public void AddTableListenerEx(ITableListener listener, NotifyFlags flags)
        {
            lock (m_listenerMap)
            {
                if (!m_listenerMap.TryGetValue(listener, out List <int> adapters))
                {
                    adapters = new List <int>();
                    m_listenerMap.Add(listener, adapters);
                }

                // ReSharper disable once InconsistentNaming
                EntryListenerCallback func = (uid, key, value, flags_) =>
                {
                    string relativeKey = key.Substring(m_path.Length + 1);
                    if (relativeKey.IndexOf(PathSeperatorChar) != -1)
                    {
                        return;
                    }
                    listener.ValueChanged(this, relativeKey, value, flags_);
                };

                int id = NtCore.AddEntryListener(m_pathWithSeperator, func, flags);

                adapters.Add(id);
            }
        }
Esempio n. 6
0
        public ReadOnlySpan <byte> GetResult(double timeout)
        {
            Span <byte> store  = Span <byte> .Empty;
            var         result = NtCore.GetRpcResult(Entry.Handle, Handle, timeout, store);

            return(result);
        }
Esempio n. 7
0
 public void Dispose()
 {
     if (m_owned && Handle.Get() != 0)
     {
         NtCore.DestroyInstance(Handle);
         Handle = new NtInst();
     }
 }
Esempio n. 8
0
        ///<inheritdoc/>
        public void RemoveConnectionListener(IRemoteConnectionListener listener)
        {
            int val;

            if (m_connectionListenerMap.TryGetValue(listener, out val))
            {
                NtCore.RemoveConnectionListener(val);
            }
        }
Esempio n. 9
0
        public static NetworkTableInstance Create()
        {
            var inst = new NetworkTableInstance(NtCore.CreateInstance())
            {
                m_owned = true
            };

            return(inst);
        }
Esempio n. 10
0
        /// <inheritdoc/>
        public void RemoveConnectionListener(Action <IRemote, ConnectionInfo, bool> listener)
        {
            int val;

            if (m_actionConnectionListenerMap.TryGetValue(listener, out val))
            {
                NtCore.RemoveConnectionListener(val);
            }
        }
Esempio n. 11
0
        public string GetString(string defaultValue)
        {
            var entry = NtCore.GetEntryValue(Handle);

            if (entry.Type == NtType.String)
            {
                return(entry.Data.VString !);
            }
            return(defaultValue);
        }
Esempio n. 12
0
        public double GetDouble(double defaultValue)
        {
            var entry = NtCore.GetEntryValue(Handle);

            if (entry.Type == NtType.Double)
            {
                return(entry.Data.VDouble);
            }
            return(defaultValue);
        }
Esempio n. 13
0
        public bool GetBoolean(bool defaultValue)
        {
            var entry = NtCore.GetEntryValue(Handle);

            if (entry.Type == NtType.Boolean)
            {
                return(entry.Data.VBoolean);
            }
            return(defaultValue);
        }
Esempio n. 14
0
        public ReadOnlySpan <string> GetStringArray(ReadOnlySpan <string> defaultValue)
        {
            var entry = NtCore.GetEntryValue(Handle);

            if (entry.Type == NtType.StringArray)
            {
                return(entry.Data.VStringArray.AsSpan());
            }
            return(defaultValue);
        }
Esempio n. 15
0
        public ReadOnlySpan <double> GetDoubleArray(ReadOnlySpan <double> defaultValue)
        {
            var entry = NtCore.GetEntryValue(Handle);

            if (entry.Type == NtType.DoubleArray)
            {
                return(entry.Data.VDoubleArray.AsSpan());
            }
            return(defaultValue);
        }
Esempio n. 16
0
        public ReadOnlySpan <bool> GetBooleanArray(ReadOnlySpan <bool> defaultValue)
        {
            var entry = NtCore.GetEntryValue(Handle);

            if (entry.Type == NtType.BooleanArray)
            {
                return(entry.Data.VBooleanArray.AsSpan());
            }
            return(defaultValue);
        }
Esempio n. 17
0
        public ReadOnlySpan <byte> GetRaw(ReadOnlySpan <byte> defaultValue)
        {
            var entry = NtCore.GetEntryValue(Handle);

            if (entry.Type == NtType.Raw)
            {
                return(entry.Data.VRaw.AsSpan());
            }
            return(defaultValue);
        }
Esempio n. 18
0
        public ReadOnlySpan <char> GetString(ReadOnlySpan <char> defaultValue)
        {
            var entry = NtCore.GetEntryValue(Handle);

            if (entry.Type == NtType.String)
            {
                return(entry.Data.VString.AsSpan());
            }
            return(defaultValue);
        }
Esempio n. 19
0
 /// <inheritdoc cref="RemoveConnectionListener(Action{IRemote, ConnectionInfo, bool})"/>
 public static void RemoveGlobalConnectionListener(Action <IRemote, ConnectionInfo, bool> listener)
 {
     lock (s_actionConnectionListenerMap)
     {
         if (s_actionConnectionListenerMap.TryGetValue(listener, out int val))
         {
             NtCore.RemoveConnectionListener(val);
             s_actionConnectionListenerMap.Remove(listener);
         }
     }
 }
Esempio n. 20
0
        ///<inheritdoc/>
        public Value GetValue(string key, Value defaultValue)
        {
            string localPath = m_path + PathSeperatorChar + key;
            var    v         = NtCore.GetEntryValue(localPath);

            if (v == null)
            {
                return(defaultValue);
            }
            return(v);
        }
Esempio n. 21
0
 ///<inheritdoc cref="RemoveConnectionListener(IRemoteConnectionListener)"/>
 public static void RemoveGlobalConnectionListener(IRemoteConnectionListener listener)
 {
     lock (s_connectionListenerMap)
     {
         if (s_connectionListenerMap.TryGetValue(listener, out int val))
         {
             NtCore.RemoveConnectionListener(val);
             s_connectionListenerMap.Remove(listener);
         }
     }
 }
Esempio n. 22
0
        public Value GetValue(string key)
        {
            string localPath = m_path + PathSeperatorChar + key;
            var    v         = NtCore.GetEntryValue(localPath);

            if (v == null)
            {
                throw new TableKeyNotDefinedException(localPath);
            }
            return(v);
        }
        public NtEntryListener AddEntryListener(string prefix, EntryNotificationDelegate listener, NotifyFlags flags)
        {
            var token = m_entryListenerToken.Value;

            lock (m_entryListenerLock)
            {
                var handle = NtCore.AddPolledEntryListener(m_entryListenerPoller, prefix, flags);
                m_entryListeners.Add(handle, listener);
                return(handle);
            }
        }
Esempio n. 24
0
        ///<inheritdoc/>
        public void RemoveTableListener(ITableListener listener)
        {
            List <int> adapters;

            if (m_listenerMap.TryGetValue(listener, out adapters))
            {
                foreach (int t in adapters)
                {
                    NtCore.RemoveEntryListener(t);
                }
                adapters.Clear();
            }
        }
Esempio n. 25
0
        ///<inheritdoc/>
        public void RemoveTableListener(Action <ITable, string, Value, NotifyFlags> listenerDelegate)
        {
            List <int> adapters;

            if (m_actionListenerMap.TryGetValue(listenerDelegate, out adapters))
            {
                foreach (int t in adapters)
                {
                    NtCore.RemoveEntryListener(t);
                }
                adapters.Clear();
            }
        }
Esempio n. 26
0
        public Task <byte[]> GetResultAsync(CancellationToken token = default)
        {
            NtEntry   handle = Entry.Handle;
            NtRpcCall call   = Handle;

            token.Register(() =>
            {
                NtCore.CancelRpcResult(handle, call);
            });
            return(Task.Run(() =>
            {
                return NtCore.GetRpcResult(handle, call, Span <byte> .Empty).ToArray();
            }));
        }
Esempio n. 27
0
 /// <summary>
 /// Set true to enable connection to the local robot IP address
 /// (defaults to enabled)
 /// </summary>
 /// <param name="enabled">True to enabled using the DS connection</param>
 public static void SetDSClientEnabled(bool enabled)
 {
     lock (s_lockObject)
     {
         s_enableDs = enabled;
         if (s_enableDs)
         {
             NtCore.StartDSClient(Port);
         }
         else
         {
             NtCore.StopDSClient();
         }
     }
 }
Esempio n. 28
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);
        }
Esempio n. 29
0
        /// <summary>
        /// Gets a set of all the keys contained in the table with the specified type.
        /// </summary>
        /// <param name="types">Bitmask of types to check for; 0 is treated as a "don't care".</param>
        /// <returns>A set of all keys currently in the table.</returns>
        public HashSet <string> GetKeys(NtType types)
        {
            HashSet <string> keys = new HashSet <string>();
            int prefixLen         = m_path.Length + 1;

            foreach (EntryInfo entry in NtCore.GetEntryInfo(m_path + PathSeperatorChar, types))
            {
                string relativeKey = entry.Name.Substring(prefixLen);
                if (relativeKey.IndexOf(PathSeperatorChar) != -1)
                {
                    continue;
                }
                keys.Add(relativeKey);
            }
            return(keys);
        }
Esempio n. 30
0
        /// <summary>
        /// Gets a set of all the sub-tables contained in the table.
        /// </summary>
        /// <returns>A set of all subtables currently contained in the table.</returns>
        public HashSet <string> GetSubTables()
        {
            HashSet <string> keys = new HashSet <string>();
            int prefixLen         = m_path.Length + 1;

            foreach (EntryInfo entry in NtCore.GetEntryInfo(m_path + PathSeperatorChar, 0))
            {
                string relativeKey = entry.Name.Substring(prefixLen);
                int    endSubTable = relativeKey.IndexOf(PathSeperatorChar);
                if (endSubTable == -1)
                {
                    continue;
                }
                keys.Add(relativeKey.Substring(0, endSubTable));
            }
            return(keys);
        }