Esempio n. 1
0
        ///<inheritdoc/>
        public void AddTableListenerEx(Action <ITable, string, object, 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
            EntryListenerFunction 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 = CoreMethods.AddEntryListener(m_path + PathSeperatorChar, func, flags);

            adapters.Add(id);
        }
Esempio n. 2
0
        ///<inheritdoc/>
        public void AddSubTableListener(Action <ITable, string, object, NotifyFlags> listenerDelegate, bool localNotify)
        {
            List <int> adapters;

            if (!m_actionListenerMap.TryGetValue(listenerDelegate, out adapters))
            {
                adapters = new List <int>();
                m_actionListenerMap.Add(listenerDelegate, adapters);
            }
            HashSet <string> notifiedTables = new HashSet <string>();
            // ReSharper disable once InconsistentNaming
            EntryListenerFunction 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, GetSubTable(subTableKey), flags_);
            };
            NotifyFlags flags = NotifyFlags.NotifyNew | NotifyFlags.NotifyUpdate;

            if (localNotify)
            {
                flags |= NotifyFlags.NotifyLocal;
            }
            int id = CoreMethods.AddEntryListener(m_path + PathSeperatorChar, func, flags);

            adapters.Add(id);
        }
Esempio n. 3
0
        ///<inheritdoc/>
        public void AddTableListenerEx(string key, Action <ITable, string, object, NotifyFlags> listenerDelegate, NotifyFlags flags)
        {
            List <int> adapters;

            if (!m_actionListenerMap.TryGetValue(listenerDelegate, out adapters))
            {
                adapters = new List <int>();
                m_actionListenerMap.Add(listenerDelegate, adapters);
            }
            string fullKey = m_path + PathSeperatorChar + key;
            // ReSharper disable once InconsistentNaming
            EntryListenerFunction func = (uid, funcKey, value, flags_) =>
            {
                if (!funcKey.Equals(fullKey))
                {
                    return;
                }
                listenerDelegate(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;
 }
Esempio n. 5
0
        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);
        }