Exemple #1
0
        ///<inheritdoc/>
        public void AddTableListenerEx(string key, 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);
                }
                string fullKey = m_pathWithSeperator + key;
                // ReSharper disable once InconsistentNaming
                EntryListenerCallback func = (uid, funcKey, value, flags_) =>
                {
                    if (!funcKey.Equals(fullKey))
                    {
                        return;
                    }
                    listener.ValueChanged(this, key, value, flags_);
                };

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

                adapters.Add(id);
            }
        }
        public void TestAddSubTableListenerListenerLocalNotifyDelegate()
        {
            ITable      Source = null;
            string      Key    = null;
            object      Value  = null;
            NotifyFlags Flags  = 0;

            Action <ITable, string, object, NotifyFlags> listener = (s, k, v, f) =>
            {
                Source = s;
                Key    = k;
                Value  = v;
                Flags  = f;
            };

            string subTableName = "SubTable";

            ITable subTable = m_table.GetSubTable("SubTable");

            m_table.AddSubTableListener(listener, true);

            string key   = "key";
            string value = "Value";

            subTable.PutString(key, value);

            Thread.Sleep(20);

            Assert.That(Source, Is.EqualTo(m_table));
            Assert.That(Key, Is.EqualTo(subTableName));
            Assert.That(Value.ToString(), Is.EqualTo(subTable.ToString()));
            Assert.That(Flags, Is.EqualTo(NotifyFlags.NotifyLocal | NotifyFlags.NotifyNew));

            m_table.RemoveTableListener(listener);
        }
Exemple #3
0
        ///<inheritdoc/>
        public void AddSubTableListener(Action <ITable, string, Value, NotifyFlags> listenerDelegate, bool localNotify)
        {
            if (!m_actionListenerMap.TryGetValue(listenerDelegate, out List <int> adapters))
            {
                adapters = new List <int>();
                m_actionListenerMap.Add(listenerDelegate, adapters);
            }
            HashSet <string> notifiedTables = new HashSet <string>();
            // ReSharper disable once InconsistentNaming
            EntryListenerCallback func = (uid, key, value, flags_) =>
            {
                string relativeKey = key.Substring(m_path.Length + 1);
                int    endSubTable = relativeKey.IndexOf(PathSeperatorChar);
                if (endSubTable == -1)
                {
                    return;
                }
                string subTableKey = relativeKey.Substring(0, endSubTable);
                if (notifiedTables.Contains(subTableKey))
                {
                    return;
                }
                notifiedTables.Add(subTableKey);
                listenerDelegate(this, subTableKey, null, flags_);
            };
            NotifyFlags flags = NotifyFlags.NotifyNew | NotifyFlags.NotifyUpdate;

            if (localNotify)
            {
                flags |= NotifyFlags.NotifyLocal;
            }
            int id = m_ntCore.AddEntryListener(m_pathWithSeperator, func, flags);

            adapters.Add(id);
        }
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     Source = source;
     Key    = key;
     Value  = value;
     Flags  = flags;
 }
Exemple #5
0
 ///<inheritdoc/>
 public void ValueChanged(ITable source, string key, Value value, NotifyFlags flags)
 {
     if (key == ("p") || key == ("i") || key == ("d") || key == ("f"))
     {
         if (P != Table.GetNumber("p", 0.0) || I != Table.GetNumber("i", 0.0) ||
             D != Table.GetNumber("d", 0.0) || F != Table.GetNumber("f", 0.0))
         {
             SetPID(Table.GetNumber("p", 0.0), Table.GetNumber("i", 0.0), Table.GetNumber("d", 0.0), Table.GetNumber("f", 0.0));
         }
     }
     else if (key == ("setpoint"))
     {
         double val = value.GetDouble();
         if (Setpoint != val)
         {
             Setpoint = val;
         }
     }
     else if (key == ("enabled"))
     {
         bool val = value.GetBoolean();
         if (Enabled != val)
         {
             if (val)
             {
                 Enable();
             }
             else
             {
                 Disable();
             }
         }
     }
 }
        public void TestAddTableListenerExListenerFlags()
        {
            MockTableListener listener = new MockTableListener();

            NotifyFlags f = NotifyFlags.NotifyNew | NotifyFlags.NotifyLocal | NotifyFlags.NotifyImmediate;

            string key   = "key";
            string value = "Value";

            m_table.PutString(key, value);

            m_table.AddTableListenerEx(listener, f);

            Thread.Sleep(20);

            Assert.That(listener.Source, Is.EqualTo(m_table));
            Assert.That(listener.Key, Is.EqualTo(key));
            Assert.That(listener.Value, Is.EqualTo(value));
            Assert.That(listener.Flags, Is.EqualTo(NotifyFlags.NotifyImmediate));

            string key2 = "key2";
            string val2 = "value2";

            m_table.PutString(key2, val2);

            Thread.Sleep(20);

            Assert.That(listener.Source, Is.EqualTo(m_table));
            Assert.That(listener.Key, Is.EqualTo(key2));
            Assert.That(listener.Value, Is.EqualTo(val2));
            Assert.That(listener.Flags, Is.EqualTo(NotifyFlags.NotifyNew | NotifyFlags.NotifyLocal));

            m_table.RemoveTableListener(listener);
        }
        public void TestAddTableListenerExKeyListenerFlagsDelegate()
        {
            ITable      Source = null;
            string      Key    = null;
            object      Value  = null;
            NotifyFlags Flags  = 0;

            Action <ITable, string, object, NotifyFlags> listener = (s, k, v, _f) =>
            {
                Source = s;
                Key    = k;
                Value  = v;
                Flags  = _f;
            };

            NotifyFlags f = NotifyFlags.NotifyNew | NotifyFlags.NotifyLocal | NotifyFlags.NotifyImmediate;

            string key   = "key";
            string value = "Value";

            m_table.PutString(key, value);

            m_table.AddTableListenerEx(key, listener, f);

            m_table.PutString("Key2", "Value2");

            Thread.Sleep(20);

            Assert.That(Source, Is.EqualTo(m_table));
            Assert.That(Key, Is.EqualTo(key));
            Assert.That(Value, Is.EqualTo(value));
            Assert.That(Flags, Is.EqualTo(NotifyFlags.NotifyImmediate));

            m_table.RemoveTableListener(listener);
        }
Exemple #8
0
        ///////////////////////////////////////////////////////////////////////

        public override ReturnCode Terminate(
            Interpreter interpreter,
            IClientData clientData,
            ref Result result
            )
        {
            if (interpreter != null)
            {
                if (savedNotifyFlags != NotifyFlags.None)
                {
                    //
                    // NOTE: Remove the notify flags that we added to the
                    //       interpreter earlier.
                    //
                    interpreter.GlobalNotifyFlags &= ~savedNotifyFlags;
                    savedNotifyFlags = NotifyFlags.None;
                }

                ///////////////////////////////////////////////////////////////

                if (savedNotifyTypes != NotifyType.None)
                {
                    //
                    // NOTE: Remove the notify types that we added to the
                    //       interpreter earlier.
                    //
                    interpreter.GlobalNotifyTypes &= ~savedNotifyTypes;
                    savedNotifyTypes = NotifyType.None;
                }
            }

            ///////////////////////////////////////////////////////////////////

            return(base.Terminate(interpreter, clientData, ref result));
        }
Exemple #9
0
 public ScriptEventArgs(
     long id,
     NotifyType types,
     NotifyFlags flags,
     Interpreter interpreter,
     IClientData clientData,
     ArgumentList arguments,
     Result result,
     ScriptException exception,
     InterruptType interruptType,
     string resourceName,
     ResourceManager resourceManager,
     params object[] messageArgs
     )
     : base(null, id, resourceName, messageArgs)
 {
     this.notifyTypes     = types;
     this.notifyFlags     = flags;
     this.interpreter     = interpreter;
     this.clientData      = clientData;
     this.arguments       = arguments;
     this.result          = result;
     this.exception       = exception;
     this.interruptType   = interruptType;
     this.resourceManager = resourceManager;
 }
Exemple #10
0
        ///<inheritdoc/>
        public void AddTableListenerEx(ITableListener listener, NotifyFlags flags)
        {
            List <int> adapters;

            if (!m_listenerMap.TryGetValue(listener, out 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 = m_ntCore.AddEntryListener(m_path + PathSeperatorChar, func, flags);

            adapters.Add(id);
        }
Exemple #11
0
        ///////////////////////////////////////////////////////////////////////

        #region INotify Members
        public override ReturnCode Notify(
            Interpreter interpreter,
            IScriptEventArgs eventArgs,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            if (eventArgs == null)
            {
                return(ReturnCode.Ok);
            }

            if (!Utility.HasFlags(
                    eventArgs.NotifyTypes, NotifyType.Command, false))
            {
                return(ReturnCode.Ok);
            }

            NotifyFlags notifyFlags = eventArgs.NotifyFlags;

            if (!Utility.HasFlags(
                    notifyFlags, NotifyFlags.Executed, false))
            {
                return(ReturnCode.Ok);
            }

            Thread.Sleep(500); /* TODO: Fine tune? */
            return(ReturnCode.Ok);
        }
Exemple #12
0
 public EntryNotification(string name, Value value, NotifyFlags flags,
                          EntryListenerCallback only)
 {
     Name  = name;
     Value = value;
     Flags = flags;
     Only  = only;
 }
 /// <summary>
 /// Listens for changes in the SmartDashboard table and then calls the function listening.
 /// </summary>
 /// <param name="table"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <param name="arg4"></param>
 private void OnTableValuesChanged(ITable table, string key, Value value, NotifyFlags arg4)
 {
     key = string.Format("{0}/{1}", GetTableName(table), key);
     if (!ListenerFunctions.ContainsKey(key))
     {
         return;
     }
     mainDispatcher.Invoke(() => NTValueChanged(key, value));
 }
 private static void OnNetworkTableChange(ITable table, string key, Value v, NotifyFlags flags)
 {
     try
     {
         //multiple objects could be bound to this key
         foreach (INotifyPropertyChanged source in propertyLookup.Keys)
         {
             OneToOneConversionMap <string, string> conversionMap = propertyLookup[source];
             ITable boundTable    = customTables[source];
             object bindingSource = (source is DependencyNotifyListener) ? (object)(source as DependencyNotifyListener).source : source;
             if (table.ToString() != boundTable.ToString())
             {
                 continue;
             }
             if (conversionMap.TryGetBySecond(key, out string property))
             {
                 //the property that changed is bound to this object
                 //grab the converter and use it if needed
                 IValueConverter converter = conversionMap.GetConverterByFirst(property);
                 PropertyInfo    inf       = bindingSource.GetType().GetProperty(property);
                 //issue using v for some reason
                 object value = NetworkUtil.ReadValue(boundTable.GetValue(key, null));
                 if (converter != null)
                 {
                     //in an NTConverter (required in API) the null values are never used so we don't need to set them
                     object attemptedVal = converter.ConvertBack(value, null, null, null);
                     //in case the conversion was invalid
                     if (attemptedVal != DependencyProperty.UnsetValue)
                     {
                         value = attemptedVal;
                     }
                 }
                 //correct any type inconsistencies (eg if we want to display an integer from the network, which only stores doubles)
                 if (value != null && value.GetType() != inf.PropertyType)
                 {
                     Type targetType = inf.PropertyType;
                     if (targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable <>))
                     {
                         targetType = targetType.GetGenericArguments()[0];
                     }
                     //anything still here can make an invalid cast to let them know to use a converter
                     value = Convert.ChangeType(value, targetType);
                 }
                 //write to the object
                 assignmentDispatch.Invoke(() => inf.SetValue(bindingSource, value));
             }
         }
     }
     catch (InvalidOperationException e)
     {
         if (!e.Message.StartsWith("Collection was modified"))
         {
             throw e;
         }
     }
 }
Exemple #15
0
        ///<inheritdoc/>
        public void AddTableListener(string key, Action <ITable, string, Value, NotifyFlags> listenerDelegate, bool immediateNotify = false)
        {
            NotifyFlags flags = NotifyFlags.NotifyNew | NotifyFlags.NotifyUpdate;

            if (immediateNotify)
            {
                flags |= NotifyFlags.NotifyImmediate;
            }
            AddTableListenerEx(key, listenerDelegate, flags);
        }
Exemple #16
0
        ///<inheritdoc/>
        public void AddTableListener(string key, ITableListener listener, bool immediateNotify = false)
        {
            NotifyFlags flags = NotifyFlags.NotifyNew | NotifyFlags.NotifyUpdate;

            if (immediateNotify)
            {
                flags |= NotifyFlags.NotifyImmediate;
            }
            AddTableListenerEx(key, listener, flags);
        }
Exemple #17
0
 /// <inheritdoc/>
 public void ValueChanged(ITable source, string key, Value value, NotifyFlags flags)
 {
     if (value.GetBoolean())
     {
         Start();
     }
     else
     {
         Cancel();
     }
 }
Exemple #18
0
 public int AddEntryListener(string prefix, EntryListenerCallback callback, NotifyFlags flags)
 {
     lock (m_mutex)
     {
         if ((flags & NotifyFlags.NotifyLocal) != 0)
         {
             m_localNotifiers = true;
         }
         return(m_entryListeners.Add(prefix, callback, flags));
     }
 }
        /// <inheritdoc cref="NtCore.AddEntryListener"/>
        public int AddEntryListener(string prefix, EntryListenerCallback callback, NotifyFlags flags)
        {
            Notifier notifier = m_notifier;
            int      uid      = notifier.AddEntryListener(prefix, callback, flags);

            notifier.Start();
            if ((flags & NotifyFlags.NotifyImmediate) != 0)
            {
                m_storage.NotifyEntries(prefix, callback);
            }
            return(uid);
        }
Exemple #20
0
        public NtEntryListener AddEntryListener(TableEntryListener listener, NotifyFlags flags)
        {
            int prefixLen = Path.Length + 1;

            return(Instance.AddEntryListener(m_pathWithSep, (in RefEntryNotification evnt) =>
            {
                ReadOnlySpan <char> relativeKey = evnt.Name.AsSpan().Slice(prefixLen);
                if (relativeKey.IndexOf(PathSeparator) != -1)
                {
                    return;
                }
                listener(this, relativeKey, evnt.Entry, evnt.Value, evnt.Flags);
            }, flags));
Exemple #21
0
        ///////////////////////////////////////////////////////////////////////

#if NOTIFY || NOTIFY_OBJECT
        public static bool HasFlags(
            NotifyFlags flags,
            NotifyFlags hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != NotifyFlags.None);
            }
        }
Exemple #22
0
        public void TestAddEntryListener()
        {
            string key1     = "testKey";
            string toWrite1 = "written";

            NtCore.SetEntryValue(key1, Value.MakeString(toWrite1));

            int         count         = 0;
            string      recievedKey   = "";
            Value       recievedValue = null;
            NotifyFlags receivedFlags = 0;

            NotifyFlags f = NotifyFlags.NotifyNew | NotifyFlags.NotifyUpdate;

            if (true)
            {
                f |= NotifyFlags.NotifyLocal;
            }

            int listener = NtCore.AddEntryListener(key1, (uid, key, value, flags) =>
            {
                count++;
                recievedKey   = key;
                recievedValue = value;
                receivedFlags = flags;
            }, f);

            string toWrite2 = "NewNumber";

            NtCore.SetEntryValue(key1, Value.MakeString(toWrite2));

            Thread.Sleep(20);

            Assert.That(count, Is.GreaterThanOrEqualTo(1));
            Assert.That(recievedKey, Is.EqualTo(key1));
            Assert.That(recievedValue, Is.Not.Null);

            Assert.That(recievedValue.IsString);

            var retValue = recievedValue.GetString();

            Assert.That(retValue, Is.Not.Null);
            Assert.That(retValue, Is.EqualTo(toWrite2));

            Assert.That(receivedFlags.HasFlag(NotifyFlags.NotifyLocal));

            NtCore.RemoveEntryListener(listener);
        }
        public void TestEntryListenerBooleanArray()
        {
            string key1 = "testKey";

            bool[] toWrite1 = { true, true, true };
            CoreMethods.SetEntryBooleanArray(key1, toWrite1);

            int         count         = 0;
            string      recievedKey   = "";
            Value       receivedValue = null;
            NotifyFlags receivedFlags = 0;

            NotifyFlags f = NotifyFlags.NotifyNew | NotifyFlags.NotifyUpdate;

            if (true)
            {
                f |= NotifyFlags.NotifyImmediate;
            }

            int listener = CoreMethods.AddEntryListener(key1, (uid, key, value, flags) =>
            {
                count++;
                recievedKey   = key;
                receivedValue = value;
                receivedFlags = flags;
            }, f);

            Thread.Sleep(300);

            Assert.That(count, Is.EqualTo(1));
            Assert.That(recievedKey, Is.EqualTo(key1));
            Assert.That(receivedValue, Is.Not.Null);

            Assert.That(receivedValue.IsBooleanArray());
            bool[] retValue = receivedValue.GetBooleanArray();
            Assert.That(retValue, Is.Not.Null);

            for (int i = 0; i < retValue.Length; i++)
            {
                Assert.That(retValue[i], Is.EqualTo(toWrite1[i]));
            }
            //Assert.That(retValue, Is.EqualTo(toWrite1));

            Assert.That(receivedFlags.HasFlag(NotifyFlags.NotifyImmediate));

            CoreMethods.RemoveEntryListener(listener);
        }
Exemple #24
0
            public int Add(string prefix, EntryListenerCallback callback, NotifyFlags flags)
            {
                int uid;
                var listener = new EntryListener(prefix, callback, flags);

                if (m_free.Count == 0)
                {
                    uid = m_list.Count;
                    m_list.Add(listener);
                }
                else
                {
                    uid         = m_free.Dequeue();
                    m_list[uid] = listener;
                }
                return(uid + 1);
            }
        public void TestAddEntryListener()
        {
            string key1     = "testKey";
            string toWrite1 = "written";

            CoreMethods.SetEntryString(key1, toWrite1);

            int         count         = 0;
            string      recievedKey   = "";
            object      recievedValue = null;
            NotifyFlags receivedFlags = 0;

            NotifyFlags f = NotifyFlags.NotifyNew | NotifyFlags.NotifyUpdate;

            if (true)
            {
                f |= NotifyFlags.NotifyLocal;
            }

            int listener = CoreMethods.AddEntryListener(key1, (uid, key, value, flags) =>
            {
                count++;
                recievedKey   = key;
                recievedValue = value;
                receivedFlags = flags;
            }, f);

            string toWrite2 = "NewNumber";

            CoreMethods.SetEntryString(key1, toWrite2);

            Thread.Sleep(20);

            Assert.That(count, Is.EqualTo(1));
            Assert.That(recievedKey, Is.EqualTo(key1));
            Assert.That(recievedValue, Is.Not.Null);

            string retValue = recievedValue as string;

            Assert.That(retValue, Is.Not.Null);
            Assert.That(retValue, Is.EqualTo(toWrite2));

            Assert.That(receivedFlags.HasFlag(NotifyFlags.NotifyLocal));

            CoreMethods.RemoveEntryListener(listener);
        }
        public void ValueChanged(ITable source, string key, Value value, NotifyFlags flags)
        {
            switch (key)
            {
            case @"AUTON_OPTIONS":
                updateAutonOptions(value.GetStringArray());
                break;

            case @"POSITION_OPTIONS":
                updatePositionOptions(value.GetStringArray());
                break;

            case @"AUTON_FOUND":
                updateAutonFound(value.GetString());
                break;
            }
        }
Exemple #27
0
        public void TestEntryListenerDoubleArray()
        {
            string key1 = "testKey";

            double[] toWrite1 = { 3.58, 6.825, 454.54 };
            NtCore.SetEntryValue(key1, Value.MakeDoubleArray(toWrite1));

            int         count         = 0;
            string      recievedKey   = "";
            Value       recievedValue = null;
            NotifyFlags receivedFlags = 0;

            NotifyFlags f = NotifyFlags.NotifyNew | NotifyFlags.NotifyUpdate;

            if (true)
            {
                f |= NotifyFlags.NotifyImmediate;
            }

            int listener = NtCore.AddEntryListener(key1, (uid, key, value, flags) =>
            {
                count++;
                recievedKey   = key;
                recievedValue = value;
                receivedFlags = flags;
            }, f);

            Thread.Sleep(300);

            Assert.That(count, Is.EqualTo(1));
            Assert.That(recievedKey, Is.EqualTo(key1));
            Assert.That(recievedValue, Is.Not.Null);

            Assert.That(recievedValue.IsDoubleArray);

            double[] retValue = recievedValue.GetDoubleArray();

            for (int i = 0; i < retValue.Length; i++)
            {
                Assert.That(retValue[i], Is.EqualTo(toWrite1[i]));
            }

            Assert.That(receivedFlags.HasFlag(NotifyFlags.NotifyImmediate));

            NtCore.RemoveEntryListener(listener);
        }
Exemple #28
0
 public void NotifyEntry(string name, Value value, NotifyFlags flags, EntryListenerCallback only = null)
 {
     if (!m_active)
     {
         return;
     }
     // optimization: don't generate needless local queue entries if we have
     // no local listeners (as this is a common case on the server side)
     if ((flags & NotifyFlags.NotifyLocal) != 0 && !m_localNotifiers)
     {
         return;
     }
     lock (m_mutex)
     {
         m_entryNotifications.Enqueue(new EntryNotification(name, value, flags, only));
     }
     m_cond.Set();
 }
Exemple #29
0
 public void ValueChanged(ITable source, string key, Value value, NotifyFlags flags)
 {
     if (key != @"AUTON_SELECT")
     {
         return;
     }
     foreach (
         var auton in Assembly.GetExecutingAssembly().GetTypes().Where(t => string.Equals(t.Namespace,
                                                                                          @"Trephine.Autonomi", StringComparison.Ordinal)))
     {
         if (auton.Name != value.GetString())
         {
             continue;
         }
         parent.auton = (Autonomous)Activator.CreateInstance(auton);
         FrameworkCommunication.Instance.SendData(@"MESSAGE", $"{auton.Name} auton selected.");
         Report.General($"{auton.Name} auton selected.");
         return;
     }
 }
Exemple #30
0
        ///////////////////////////////////////////////////////////////////////

        public override ReturnCode Initialize(
            Interpreter interpreter,
            IClientData clientData,
            ref Result result
            )
        {
            if (interpreter != null)
            {
                NotifyType notifyTypes = GetTypes(interpreter);

                if (!FlagOps.HasFlags(
                        interpreter.NotifyTypes, notifyTypes, true))
                {
                    //
                    // NOTE: Add the notify types that we need to the
                    //       interpreter.
                    //
                    interpreter.GlobalNotifyTypes |= notifyTypes;
                    savedNotifyTypes = notifyTypes;
                }

                ///////////////////////////////////////////////////////////////

                NotifyFlags notifyFlags = GetFlags(interpreter);

                if (!FlagOps.HasFlags(
                        interpreter.NotifyFlags, notifyFlags, true))
                {
                    //
                    // NOTE: Add the notify flags that we need to the
                    //       interpreter.
                    //
                    interpreter.GlobalNotifyFlags |= notifyFlags;
                    savedNotifyFlags = notifyFlags;
                }
            }

            ///////////////////////////////////////////////////////////////////

            return(base.Initialize(interpreter, clientData, ref result));
        }
Exemple #31
0
 /// <inheritdoc/>
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     m_table.SetPersistent(key);
 }
Exemple #32
0
 /// <inheritdoc/>
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     if ((bool)value)
     {
         Start();
     }
     else
     {
         Cancel();
     }
 }
        /// <summary>
        /// Function create struct which used Shell_NotifyIcon API function
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        private NOTIFYICONDATA CreateNotifyStruct( NotifyFlags flags, bool bSkip )
        {
            NOTIFYICONDATA data = new NOTIFYICONDATA();
              data.cbSize = (uint)Marshal.SizeOf( data );

              data.hWnd = m_handle;
              data.uID = m_id;

              data.uCallbackMessage = 0x400;
              data.uFlags |= flags;

              if( m_icon != null )
              {
            data.hIcon = m_icon.Handle; // this should always be valid
              }
              else
              {
            if( m_imgList != null && m_imgList.Images.Count > 0 )
            {
              Bitmap bmp = new Bitmap( m_imgList.Images[ 0 ], 16, 16 );
              data.hIcon = bmp.GetHicon();
            }
              }

              data.szTip = m_text;

              if( !bSkip )
              {
            if( !m_visible ) data.dwState = NotifyState.NIS_HIDDEN;
            data.dwStateMask |= NotifyState.NIS_HIDDEN;
              }

              return data;
        }
 /// <summary>
 /// Function create struct which used Shell_NotifyIcon API function
 /// </summary>
 /// <param name="flags"></param>
 /// <returns></returns>
 private NOTIFYICONDATA CreateNotifyStruct( NotifyFlags flags )
 {
     return CreateNotifyStruct( flags, false );
 }
Exemple #35
0
 ///<inheritdoc/>
 public override void ValueChanged(ITable table, string key, object value, NotifyFlags flags)
 {
     Set((double)value);
 }
        /// <summary>
        /// Adds a Table Listener for the entire table, using the extended entry flags.
        /// </summary>
        /// <param name="listener">The <see cref="ITableListener"/> to add.</param>
        /// <param name="flags">The <see cref="EntryFlags"/> flags to use for the listener</param>
        public void AddTableListenerEx(ITableListener listener, NotifyFlags flags)
        {
            List<int> adapters;
            if (!m_listenerMap.TryGetValue(listener, out adapters))
            {
                adapters = new List<int>();
                m_listenerMap.Add(listener, adapters);
            }

            // ReSharper disable once InconsistentNaming
            EntryListenerFunction 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 = CoreMethods.AddEntryListener(m_path + PathSeperatorChar, func, flags);

            adapters.Add(id);
        }
 public void AddTableListenerEx(ITableListener listener, NotifyFlags flags)
 {
     
 }
 public void AddTableListenerEx(string key, ITableListener listener, NotifyFlags flags)
 {
     
 }
 public void AddTableListenerEx(string key, Action<ITable, string, object, NotifyFlags> listenerDelegate, NotifyFlags flags)
 {
     
 }
Exemple #40
0
 ///<inheritdoc/>
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     if (key == ("p") || key == ("i") || key == ("d") || key == ("f"))
     {
         if (P != Table.GetNumber("p", 0.0) || I != Table.GetNumber("i", 0.0) ||
                 D != Table.GetNumber("d", 0.0) || F != Table.GetNumber("f", 0.0))
             SetPID(Table.GetNumber("p", 0.0), Table.GetNumber("i", 0.0), Table.GetNumber("d", 0.0), Table.GetNumber("f", 0.0));
     }
     else if (key == ("setpoint"))
     {
         if (Setpoint != (double)value)
             Setpoint = (double)value;
     }
     else if (key == ("enabled"))
     {
         if (Enabled != (bool)value)
         {
             if ((bool)value)
             {
                 Enable();
             }
             else
             {
                 Disable();
             }
         }
     }
 }
Exemple #41
0
 ///<inheritdoc/>
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     string val = ((string)value);
     if (val.Equals("Off"))
     {
         Set(Value.Off);
     }
     else if (val.Equals("On"))
     {
         Set(Value.On);
     }
     else if (val.Equals("Forward"))
     {
         Set(Value.Forward);
     }
     else if (val.Equals("Reverse"))
     {
         Set(Value.Reverse);
     }
 }
Exemple #42
0
 /// <inheritdoc/>
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     if (value.ToString().Equals("Reverse"))
         Set(Value.Reverse);
     else if (value.ToString().Equals("Forward"))
         Set(Value.Forward);
     else
         Set(Value.Off);
 }
        /// <summary>
        /// Adds a Table Listener for a specified key, using the extended entry flags.
        /// </summary>
        /// <param name="key">The key to listen for.</param>
        /// <param name="listener">The <see cref="ITableListener"/> to add.</param>
        /// <param name="flags">The <see cref="EntryFlags"/> flags to use for the listener</param>
        public void AddTableListenerEx(string key, ITableListener listener, NotifyFlags flags)
        {
            List<int> adapters;
            if (!m_listenerMap.TryGetValue(listener, out adapters))
            {
                adapters = new List<int>();
                m_listenerMap.Add(listener, adapters);
            }
            string fullKey = m_path + PathSeperatorChar + key;
            // ReSharper disable once InconsistentNaming
            EntryListenerFunction func = (uid, funcKey, value, flags_) =>
            {
                if (!funcKey.Equals(fullKey))
                    return;
                listener.ValueChanged(this, key, value, flags_);
            };

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

            adapters.Add(id);
        }
 internal static int AddEntryListener(string prefix, EntryListenerFunction listener, NotifyFlags flags)
 {
     // ReSharper disable once InconsistentNaming
     Interop.NT_EntryListenerCallback modCallback = (uid, data, name, len, value, flags_) =>
     {
         NtType type = Interop.NT_GetValueType(value);
         object obj;
         ulong lastChange = 0;
         UIntPtr size = UIntPtr.Zero;
         IntPtr ptr;
         switch (type)
         {
             case NtType.Unassigned:
                 obj = null;
                 break;
             case NtType.Boolean:
                 int boolean = 0;
                 Interop.NT_GetValueBoolean(value, ref lastChange, ref boolean);
                 obj = boolean != 0;
                 break;
             case NtType.Double:
                 double val = 0;
                 Interop.NT_GetValueDouble(value, ref lastChange, ref val);
                 obj = val;
                 break;
             case NtType.String:
                 ptr = Interop.NT_GetValueString(value, ref lastChange, ref size);
                 obj = ReadUTF8String(ptr, size);
                 break;
             case NtType.Raw:
                 ptr = Interop.NT_GetValueRaw(value, ref lastChange, ref size);
                 obj = GetRawDataFromPtr(ptr, size);
                 break;
             case NtType.BooleanArray:
                 ptr = Interop.NT_GetValueBooleanArray(value, ref lastChange, ref size);
                 obj = GetBooleanArrayFromPtr(ptr, size);
                 break;
             case NtType.DoubleArray:
                 ptr = Interop.NT_GetValueDoubleArray(value, ref lastChange, ref size);
                 obj = GetDoubleArrayFromPtr(ptr, size);
                 break;
             case NtType.StringArray:
                 ptr = Interop.NT_GetValueStringArray(value, ref lastChange, ref size);
                 obj = GetStringArrayFromPtr(ptr, size);
                 break;
             case NtType.Rpc:
                 ptr = Interop.NT_GetValueRaw(value, ref lastChange, ref size);
                 obj = GetRawDataFromPtr(ptr, size);
                 break;
             default:
                 obj = null;
                 break;
         }
         string key = ReadUTF8String(name, len);
         listener((int)uid, key, obj, (NotifyFlags)flags_);
     };
     UIntPtr prefixSize;
     byte[] prefixStr = CreateUTF8String(prefix, out prefixSize);
     int retVal = (int)Interop.NT_AddEntryListener(prefixStr, prefixSize, IntPtr.Zero, modCallback, (uint)flags);
     s_entryCallbacks.Add(retVal, modCallback);
     return retVal;
 }
Exemple #45
0
 ///<inheritdoc/>
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     Set((bool)value);
 }
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     Source = source;
     Key = key;
     Value = value;
     Flags = flags;
 }
Exemple #47
0
 ///<inheritdoc/>
 public virtual void ValueChanged(ITable table, string key, object value, NotifyFlags flags)
 {
     SetSpeed((double)value);
 }
Exemple #48
0
 /// <inheritdoc/>
 public void ValueChanged(ITable source, string key, object value, NotifyFlags flags)
 {
     switch (key)
     {
         case "Enabled":
             if ((bool)value)
                 Enable();
             else
                 Disable();
             break;
         case "Value":
             Set((double)value);
             break;
         case "Mode":
             MotorControlMode = (ControlMode)(int)((double)value);
             break;
     }
     if (MotorControlMode.IsPID())
     {
         switch (key)
         {
             case "p":
                 P = (double)value;
                 break;
             case "i":
                 I = (double)value;
                 break;
             case "d":
                 D = (double)value;
                 break;
             case "f":
                 F = (double)value;
                 break;
         }
     }
 }