Esempio n. 1
0
        /// <summary>
        /// Remove an existing callback.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="cb"></param>
        public void RemoveNodeHandler(string node, ItemCB cb)
        {
            CBHolder holder = null;

            if (m_callbacks.TryGetValue(node, out holder))
            {
                // tests indicate removing from a list that doesn't contain this callback is safe.
                holder.OnAdd    -= cb;
                holder.OnRemove -= cb;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a handler for the OnItemAdd event, and calls the handler for any existing
        /// items.  To prevent races, use this rather than .OnItemAdd +=.
        /// </summary>
        /// <param name="callback">Callback to call with every item.</param>
        public void AddItemAddCallback(ItemCB callback)
        {
            if (callback == null)
            {
                throw new ArgumentException("Must not be null", "callback");
            }

            OnItemAdd += callback;
            foreach (PubSubItem item in m_items)
            {
                callback(this, item);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Add a handler for all inbound notifications with the given node name.
        /// This is handy for PEP implicit subscriptions.
        /// </summary>
        /// <param name="node">PEP node URI</param>
        /// <param name="addCB">Callback when items added</param>
        /// <param name="removeCB">Callbacks when items removed</param>
        /// <param name="maxNumber">Maximum number of items to store per node in this namespace</param>
        public void AddNodeHandler(string node, ItemCB addCB, ItemCB removeCB, int maxNumber)
        {
            CBHolder holder = null;

            if (!m_callbacks.TryGetValue(node, out holder))
            {
                holder            = new CBHolder();
                holder.Node       = node;
                holder.Max        = maxNumber;
                m_callbacks[node] = holder;
            }
            holder.OnAdd    += addCB;
            holder.OnRemove += removeCB;
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a handler for the OnItemAdd event, and calls the handler for any existing
        /// items.  To prevent races, use this rather than .OnItemAdd +=.
        /// </summary>
        /// <param name="callback">Callback to call with every item.</param>
        public void AddItemAddCallback(ItemCB callback)
        {
            if (callback == null)
                throw new ArgumentException("Must not be null", "callback");

            OnItemAdd += callback;
            foreach (PubSubItem item in m_items)
            {
                callback(this, item);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Remove an existing callback.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="cb"></param>
 public void RemoveNodeHandler(string node, ItemCB cb)
 {
     CBHolder holder = null;
     if (m_callbacks.TryGetValue(node, out holder))
     {
         // tests indicate removing from a list that doesn't contain this callback is safe.
         holder.OnAdd -= cb;
         holder.OnRemove -= cb;
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Add a handler for all inbound notifications with the given node name.
 /// This is handy for PEP implicit subscriptions.
 /// </summary>
 /// <param name="node">PEP node URI</param>
 /// <param name="addCB">Callback when items added</param>
 /// <param name="removeCB">Callbacks when items removed</param>
 /// <param name="maxNumber">Maximum number of items to store per node in this namespace</param>
 public void AddNodeHandler(string node, ItemCB addCB, ItemCB removeCB, int maxNumber)
 {
     CBHolder holder = null;
     if (!m_callbacks.TryGetValue(node, out holder))
     {
         holder = new CBHolder();
         holder.Node = node;
         holder.Max = maxNumber;
         m_callbacks[node] = holder;
     }
     holder.OnAdd += addCB;
     holder.OnRemove += removeCB;
 }