示例#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 = m_ntCore.AddEntryListener(m_path + PathSeperatorChar, func, flags);

            adapters.Add(id);
        }
示例#2
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);
            }
        }
示例#3
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);
            }
        }
示例#4
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);
        }
示例#5
0
 public EntryNotification(string name, Value value, NotifyFlags flags,
                          EntryListenerCallback only)
 {
     Name  = name;
     Value = value;
     Flags = flags;
     Only  = only;
 }
示例#6
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);
        }
示例#8
0
 public void NotifyEntries(string prefix, EntryListenerCallback only = null)
 {
     using (m_monitor.Enter())
     {
         foreach (var i in m_entries)
         {
             if (!i.Key.StartsWith(prefix))
             {
                 continue;
             }
             m_notifier.NotifyEntry(i.Key, i.Value.Value, NotifyFlags.NotifyImmediate, only);
         }
     }
 }
示例#9
0
        /// <summary>
        /// Adds a listener for a specified prefix in the table
        /// </summary>
        /// <param name="prefix">The prefix to listen for in the table</param>
        /// <param name="callback">The callback to call when any entry with the specified prefix is updated</param>
        /// <param name="flags">The flags to use for notifying</param>
        /// <returns>The id of the entry listener</returns>
        public static int AddEntryListener(string prefix, EntryListenerCallback callback, NotifyFlags flags)
        {
#if CORE
            return(CoreMethods.AddEntryListener(prefix, callback, flags));
#else
            Notifier notifier = Notifier.Instance;
            int      uid      = notifier.AddEntryListener(prefix, callback, flags);
            notifier.Start();
            if ((flags & NotifyFlags.NotifyImmediate) != 0)
            {
                Storage.Instance.NotifyEntries(prefix, callback);
            }
            return(uid);
#endif
        }
示例#10
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);
            }
示例#11
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();
 }
示例#12
0
        ///<inheritdoc/>
        public void AddTableListenerEx(string key, ITableListener listener, NotifyFlags flags)
        {
            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 = m_ntCore.AddEntryListener(fullKey, func, flags);

            adapters.Add(id);
        }
示例#13
0
        internal static int AddEntryListener(string prefix, EntryListenerCallback listener, NotifyFlags flags)
        {
            // ReSharper disable once InconsistentNaming
            Interop.NT_EntryListenerCallback modCallback = (uid, data, name, len, value, flags_) =>
            {
                NtType  type = Interop.NT_GetValueType(value);
                Value   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 = Value.MakeBoolean(boolean != 0);
                    break;

                case NtType.Double:
                    double val = 0;
                    Interop.NT_GetValueDouble(value, ref lastChange, ref val);
                    obj = Value.MakeDouble(val);
                    break;

                case NtType.String:
                    ptr = Interop.NT_GetValueString(value, ref lastChange, ref size);
                    obj = Value.MakeString(ReadUTF8String(ptr, size));
                    break;

                case NtType.Raw:
                    ptr = Interop.NT_GetValueRaw(value, ref lastChange, ref size);
                    obj = Value.MakeRaw(GetRawDataFromPtr(ptr, size));
                    break;

                case NtType.BooleanArray:
                    ptr = Interop.NT_GetValueBooleanArray(value, ref lastChange, ref size);
                    obj = Value.MakeBooleanArray(GetBooleanArrayFromPtr(ptr, size));
                    break;

                case NtType.DoubleArray:
                    ptr = Interop.NT_GetValueDoubleArray(value, ref lastChange, ref size);
                    obj = Value.MakeDoubleArray(GetDoubleArrayFromPtr(ptr, size));
                    break;

                case NtType.StringArray:
                    ptr = Interop.NT_GetValueStringArray(value, ref lastChange, ref size);
                    obj = Value.MakeStringArray(GetStringArrayFromPtr(ptr, size));
                    break;

                case NtType.Rpc:
                    ptr = Interop.NT_GetValueRaw(value, ref lastChange, ref size);
                    obj = Value.MakeRpc(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);
        }
示例#14
0
 public EntryListener(string prefix, EntryListenerCallback callback, NotifyFlags flags)
 {
     Prefix   = prefix;
     Callback = callback;
     Flags    = flags;
 }