Ejemplo 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);
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
        }
Ejemplo n.º 7
0
 public void Dispose()
 {
     if (m_owned && Handle.Get() != 0)
     {
         NtCore.DestroyInstance(Handle);
         Handle = new NtInst();
     }
 }
Ejemplo n.º 8
0
        ///<inheritdoc/>
        public void RemoveConnectionListener(IRemoteConnectionListener listener)
        {
            int val;

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

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

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

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

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

            if (entry.Type == NtType.Boolean)
            {
                return(entry.Data.VBoolean);
            }
            return(defaultValue);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
         }
     }
 }
Ejemplo 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);
        }
Ejemplo 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);
         }
     }
 }
Ejemplo 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);
            }
        }
Ejemplo 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();
            }
        }
Ejemplo 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();
            }
        }
Ejemplo 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();
            }));
        }
Ejemplo 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();
         }
     }
 }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }