/// <summary> Allow outside entities to listen for incoming DMessages.  We
 /// make no presumptions about the ordering and do not filter
 /// anything at this level
 /// </summary>
 public virtual bool addListener(DProtocolNotifierIF n)
 {
     if (m_listeners.Count == 0)
     {
         m_listeners.Add(n);
     }
     else
     {
         // The DMessageCounter must always be the LAST listener, so that the message has
         // been fully processed before we wake up any threads that were waiting until a
         // message comes in.  So, insert this listener at the second-to-last position in
         // the list of listeners.
         m_listeners.Insert(m_listeners.Count - 1, n);
     }
     return(true);
 }
        /// <summary> Main rx loop which waits for commands and then issues them to anyone listening.</summary>
        internal virtual void  listenForMessages()
        {
            DProtocolNotifierIF[] listeners = new DProtocolNotifierIF[0];

            while (!m_stopRx)
            {
                /* read the data */
                try
                {
                    DMessage msg = rxMessage();

                    /* Now traverse our list of interested parties and let them deal with the message */
                    listeners = (DProtocolNotifierIF[])m_listeners.ToArray(typeof(DProtocolNotifierIF)); // copy the array to avoid multithreading problems
                    for (int i = 0; i < listeners.Length; ++i)
                    {
                        DProtocolNotifierIF elem = listeners[i];
                        try
                        {
                            elem.messageArrived(msg, this);
                        }
                        catch (Exception exc)
                        /* catch unchecked exceptions */
                        {
                            if (Trace.error)
                            {
                                Console.Error.WriteLine("Error in listener parsing incoming message :"); //$NON-NLS-1$
                                Console.Error.WriteLine(msg.inToString(16));
                                Console.Error.Write(exc.StackTrace);
                                Console.Error.Flush();
                            }
                        }
                        msg.reset(); /* allow others to reparse the message */
                    }

                    /* now dispose with the message */
                    DMessageCache.free(msg);
                }
                //catch (IOException e)
                //{
                //    // this is a healthy exception that we simply ignore, since it means we haven't seen
                //    // data for a while; is all.
                //}
                finally
                {
                }
            }
        }
        /// <summary> Entry point for our receive thread </summary>
        public virtual void  Run()
        {
            try
            {
                m_stopRx = false;
                listenForMessages();
            }
            catch (Exception ex)
            {
                if (Trace.error && !(ex is System.Net.Sockets.SocketException && ex.Message.ToUpper().Equals("socket closed".ToUpper())))
                // closed-socket is not an error //$NON-NLS-1$
                {
                    Console.Error.Write(ex.StackTrace);
                    Console.Error.Flush();
                }
            }

            /* notify our listeners that we are no longer listening;  game over */
            Object[] listeners = m_listeners.ToArray();             // copy the list to avoid multithreading problems
            for (int i = 0; i < listeners.Length; ++i)
            {
                DProtocolNotifierIF elem = (DProtocolNotifierIF)listeners[i];
                try
                {
                    elem.disconnected();
                }
                catch (Exception exc)
                /* catch unchecked exceptions */
                {
                    if (Trace.error)
                    {
                        Console.Error.Write(exc.StackTrace);
                        Console.Error.Flush();
                    }
                }
            }

            // final notice that this thread is dead!
            m_rxThread = null;
        }
Exemple #4
0
		/// <summary> Allow outside entities to listen for incoming DMessages.  We
		/// make no presumptions about the ordering and do not filter
		/// anything at this level
		/// </summary>
		public virtual bool addListener(DProtocolNotifierIF n)
		{
			if (m_listeners.Count == 0)
			{
				m_listeners.Add(n);
			}
			else
			{
				// The DMessageCounter must always be the LAST listener, so that the message has
				// been fully processed before we wake up any threads that were waiting until a
				// message comes in.  So, insert this listener at the second-to-last position in
				// the list of listeners.
				m_listeners.Insert(m_listeners.Count - 1, n);
			}
			return true;
		}
Exemple #5
0
		/// <summary> Main rx loop which waits for commands and then issues them to anyone listening.</summary>
		internal virtual void  listenForMessages()
		{
			DProtocolNotifierIF[] listeners = new DProtocolNotifierIF[0];
			
			while (!m_stopRx)
			{
				/* read the data */
                try
                {
                    DMessage msg = rxMessage();

                    /* Now traverse our list of interested parties and let them deal with the message */
                    listeners = (DProtocolNotifierIF[])m_listeners.ToArray(typeof(DProtocolNotifierIF)); // copy the array to avoid multithreading problems
                    for (int i = 0; i < listeners.Length; ++i)
                    {
                        DProtocolNotifierIF elem = listeners[i];
                        try
                        {
                            elem.messageArrived(msg, this);
                        }
                        catch (Exception exc)
                        /* catch unchecked exceptions */
                        {
                            if (Trace.error)
                            {
                                Console.Error.WriteLine("Error in listener parsing incoming message :"); //$NON-NLS-1$
                                Console.Error.WriteLine(msg.inToString(16));
                                Console.Error.Write(exc.StackTrace);
                                Console.Error.Flush();
                            }
                        }
                        msg.reset(); /* allow others to reparse the message */
                    }

                    /* now dispose with the message */
                    DMessageCache.free(msg);
                }
                //catch (IOException e)
                //{
                //    // this is a healthy exception that we simply ignore, since it means we haven't seen
                //    // data for a while; is all.
                //}
                finally
                {
                }
			}
		}
Exemple #6
0
		public virtual bool removeListener(DProtocolNotifierIF n)
		{
			m_listeners.Remove(n);
			return true;
		}
 public virtual bool removeListener(DProtocolNotifierIF n)
 {
     m_listeners.Remove(n);
     return(true);
 }