/// <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; } }
/// <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); } }
/// <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; }
/// <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); } }