Ejemplo n.º 1
0
        /// <summary>
        /// Unregisters for events that arrive with the name of <paramref name="eventName"/>.
        /// </summary>
        /// <param name="eventName">Event name to unregister for.</param>
        /// <exception cref="ArgumentNullException"><paramref name="eventName"/> is <c>null</c>.</exception>
        /// <exception cref="ObjectDisposedException">Cannot unregister for event, <see cref="BroConnection"/> is disposed.</exception>
        public void UnregisterForEvent(string eventName)
        {
            if ((object)eventName == null)
            {
                throw new ArgumentNullException("eventName");
            }

            if (m_connectionPtr.IsInvalid())
            {
                throw new ObjectDisposedException("Cannot unregister for event, Bro connection is disposed.");
            }

            BroApi.bro_event_registry_remove(m_connectionPtr, eventName);

            // Remove any user data stored in managed memory space for specified event name
            lock (m_userData)
            {
                m_userData.Remove(eventName);
            }

            // Detach from common event handler for direct event handlers when no events are registered
            lock (m_eventHandlers)
            {
                if (m_eventHandlers.Remove(eventName) && m_eventHandlers.Count == 0)
                {
                    ReceivedEvent -= CommonDirectEventHandler;
                }
            }
        }