Exemplo n.º 1
0
        /// <summary>
        /// Registers for events that arrive with the name of <paramref name="eventName"/>.
        /// </summary>
        /// <param name="eventName">Event name to register for.</param>
        /// <param name="userData">Any user-data to be passed to event.</param>
        /// <exception cref="ArgumentNullException"><paramref name="eventName"/> is <c>null</c>.</exception>
        /// <exception cref="ObjectDisposedException">Cannot register for event, <see cref="BroConnection"/> is disposed.</exception>
        public unsafe void RegisterForEvent(string eventName, object userData = null)
        {
            if ((object)eventName == null)
            {
                throw new ArgumentNullException("eventName");
            }

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

            if (userData != null)
            {
                // Track user data in managed memory space associated with event name
                lock (m_userData)
                {
                    m_userData[eventName] = userData;
                }
            }

            BroApi.bro_event_registry_add_compact(m_connectionPtr, eventName, BroCompactEventCallBack, IntPtr.Zero);
        }