Ejemplo n.º 1
0
        private void DoThreadWork()
        {
            //int videoFailCount = 0;
            //int audioFailCount = 0;

            while (true)
            {
                if (!threadWorking)
                {
                    return;
                }
                IAVFrame packet = null;
                if (queue.Dequeue(out packet) == false)
                {
                    return;
                }


                if (packet.Decode())
                {
                    PushToNext(packet);
                }
                packet.Close();
            }
        }
        private void MessageDistributor()
        {
            Boolean threadOk = true;

            while (_connected && threadOk)
            {
                if (_messageDistributorThreadTokenSource.IsCancellationRequested)
                {
                    return;
                }
                try
                {
                    HTSMessage response = _receivedMessagesQueue.Dequeue();
                    if (response.containsField("seq"))
                    {
                        int seqNo = response.getInt("seq");
                        if (_responseHandlers.ContainsKey(seqNo))
                        {
                            HTSResponseHandler currHTSResponseHandler = _responseHandlers[seqNo];
                            if (currHTSResponseHandler != null)
                            {
                                _responseHandlers.Remove(seqNo);
                                currHTSResponseHandler.handleResponse(response);
                            }
                        }
                        else
                        {
                            _logger.LogCritical("[TVHclient] HTSConnectionAsync.MessageDistributor: HTSResponseHandler for seq = '{seq}' not found", seqNo);
                        }
                    }
                    else
                    {
                        // auto update messages
                        if (_listener != null)
                        {
                            _listener.onMessage(response);
                        }
                    }
                }
                catch (Exception ex)
                {
                    threadOk = false;
                    if (_listener != null)
                    {
                        _listener.onError(ex);
                    }
                    else
                    {
                        _logger.LogError(ex, "[TVHclient] HTSConnectionAsync.MessageBuilder: exception caught, but no error listener is configured");
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public void ProcessQueue()
 {
     KeepProcessing = true;
     while (KeepProcessing)
     {
         while (printQueue.Count > 0)
         {
             Printer.Print(printQueue.Dequeue());
         }
         Thread.CurrentThread.Join(2 * 1000);     //2 secs
     }
 }
Ejemplo n.º 4
0
        private void MessageDistributor()
        {
            Boolean threadOk = true;

            while (_connected && threadOk)
            {
                try
                {
                    HTSMessage response = _receivedMessagesQueue.Dequeue();
                    if (response.containsField("seq"))
                    {
                        int seqNo = response.getInt("seq");
                        if (_responseHandlers.ContainsKey(seqNo))
                        {
                            HTSResponseHandler currHTSResponseHandler = _responseHandlers[seqNo];
                            if (currHTSResponseHandler != null)
                            {
                                _responseHandlers.Remove(seqNo);
                                currHTSResponseHandler.handleResponse(response);
                            }
                        }
                        else
                        {
                            _logger.Fatal("[TVHclient] MessageDistributor: HTSResponseHandler for seq = '" + seqNo + "' not found!");
                        }
                    }
                    else
                    {
                        // auto update messages
                        if (_listener != null)
                        {
                            _listener.onMessage(response);
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    threadOk = false;
                    Thread.ResetAbort();
                }
                catch (Exception ex)
                {
                    if (_listener != null)
                    {
                        _listener.onError(ex);
                    }
                    else
                    {
                        _logger.ErrorException("[TVHclient] MessageBuilder caught exception : {0} but no error listener is configured!!!", ex, ex.ToString());
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /** {@inheritDoc} */


        /** {@inheritDoc} */
        public QQActionEvent waitFinalEvent()
        {
            QQActionEvent evt = null;

            while ((evt = evtQueue.Dequeue()) != null)
            {
                if (isFinalEvent(evt))
                {
                    return(evt);
                }
            }
            throw new QQException(QQWpfApplication1.action.QQException.QQErrorCode.UNKNOWN_ERROR);
        }
Ejemplo n.º 6
0
        private void SendLoop()
        {
            while (Client.Connected && !Closed)
            {
                try
                {
                    byte[] msg = SendQueue.Dequeue();

                    SendReal(msg);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    Close();
                }
            }
        }
        private void SendingHandler()
        {
            Boolean threadOk = true;

            while (_connected && threadOk)
            {
                if (_sendingHandlerThreadTokenSource.IsCancellationRequested)
                {
                    return;
                }
                try
                {
                    HTSMessage message   = _messagesForSendQueue.Dequeue();
                    byte[]     data2send = message.BuildBytes();
                    int        bytesSent = _socket.Send(data2send);
                    if (bytesSent != data2send.Length)
                    {
                        _logger.LogError("[TVHclient] HTSConnectionAsync.SendingHandler: sending data not completed\nBytes sent: {txbytes}\nMessage bytes: " +
                                         "{msgbytes}\nMessage: {msg}", bytesSent, data2send.Length, message.ToString());
                    }
                }
                catch (Exception ex)
                {
                    threadOk = false;
                    _logger.LogError(ex, "[TVHclient] HTSConnectionAsync.SendingHandler: exception caught");
                    if (_listener != null)
                    {
                        _listener.onError(ex);
                    }
                    else
                    {
                        _logger.LogError(ex, "[TVHclient] HTSConnectionAsync.SendingHandler: exception caught, but no error listener is configured");
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void SendingHandler()
        {
            Boolean threadOk = true;

            while (_connected && threadOk)
            {
                if (_sendingHandlerThreadTokenSource.IsCancellationRequested)
                {
                    return;
                }
                try
                {
                    HTSMessage message   = _messagesForSendQueue.Dequeue();
                    byte[]     data2send = message.BuildBytes();
                    int        bytesSent = _socket.Send(data2send);
                    if (bytesSent != data2send.Length)
                    {
                        _logger.Error("[TVHclient] SendingHandler: Sending not complete! \nBytes sent: " + bytesSent + "\nMessage bytes: " +
                                      data2send.Length + "\nMessage: " + message.ToString());
                    }
                }
                catch (Exception ex)
                {
                    threadOk = false;
                    _logger.Error("[TVHclient] SendingHandler caught exception : {0}", ex.ToString());
                    if (_listener != null)
                    {
                        _listener.onError(ex);
                    }
                    else
                    {
                        _logger.ErrorException("[TVHclient] SendingHandler caught exception : {0} but no error listener is configured!!!", ex, ex.ToString());
                    }
                }
            }
        }
 public HTSMessage getResponse()
 {
     return(_responseDataQueue.Dequeue());
 }
Ejemplo n.º 10
0
 public byte[] Receive()
 {
     return(ReceiveQueue.Dequeue());
 }