Exemple #1
0
 public static bool Unsubscribe(Topic t, SubRec sr)
 {
     if (RemoveSubscripton(t, sr))
     {
         var c = Perform.Create(t, Perform.Art.unsubscribe, null);
         c.o = sr;
         _repo.DoCmd(c, false);
         return(true);
     }
     return(false);
 }
Exemple #2
0
            public static bool RemoveSubscripton(Topic t, SubRec sr)
            {
                if (t._subRecords == null)
                {
                    return(false);
                }
                bool fl;

                lock (t._subRecords) {
                    fl = t._subRecords.Remove(sr);
                }
                return(fl);
            }
Exemple #3
0
 public static void Subscribe(Topic t, SubRec sr)
 {
     if (t._subRecords == null)
     {
         lock (t) {
             if (t._subRecords == null)
             {
                 t._subRecords = new List <SubRec>();
             }
         }
     }
     lock (t._subRecords) {
         if (!t._subRecords.Any(z => z.func == sr.func && z.setTopic == sr.setTopic && z.mask == sr.mask && ((z.mask & SubRec.SubMask.Field) == SubRec.SubMask.None || z.prefix == sr.prefix)))
         {
             t._subRecords.Add(sr);
         }
     }
 }
Exemple #4
0
        public SubRec Subscribe(SubRec.SubMask mask, string prefix, Action <Perform, SubRec> func)
        {
            if (func == null)
            {
                throw new ArgumentNullException(this.path + ".Subscribe(func == NULL, " + mask.ToString() + (prefix == null ? string.Empty : ", " + prefix) + ")");
            }
            SubRec sb;
            bool   exist = true;

            if (_subRecords == null)
            {
                lock (this._sync) {
                    if (_subRecords == null)
                    {
                        var srs = new List <SubRec>();
                        _subRecords = srs; // PVS V3054. Potentially unsafe double-checked locking.
                    }
                }
            }
            lock (_subRecords) {
                sb = _subRecords.FirstOrDefault(z => z.func == func && z.setTopic == this && z.mask == mask && ((z.mask & SubRec.SubMask.Field) == SubRec.SubMask.None || z.prefix == prefix));
                if (sb == null)
                {
                    exist = false;
                    sb    = new SubRec(this, func, mask, prefix);
                    _subRecords.Add(sb);
                }
            }
            if (!exist)
            {
                var c = Perform.Create(this, Perform.Art.subscribe, this);
                c.o = sb;
                _repo.DoCmd(c, false);
            }
            else
            {
                var c = Perform.Create(this, Perform.Art.subAck, this);
                c.o = sb;
                _repo.DoCmd(c, false);
            }
            return(sb);
        }