コード例 #1
0
        SendToState GetMessageToSend(out Message messageToSend)
        {
            SendToState result = SendToState.NoMessageToSendError;

            messageToSend = null;
            lock (m_OutgoingMessages)
            {
                if (m_QueueOverflowUnsentCounter > 0)
                {
                    //This means that we can't send message to ROS as fast as we're generating them.
                    //This could potentially be bad as it means that we are dropping messages!
                    m_QueueOverflowUnsentCounter--;
                    messageToSend = null;
                    result        = SendToState.QueueFullWarning;
                }
                else if (m_OutgoingMessages.Count > 0)
                {
                    //Retrieve the next message and populate messageToSend.
                    messageToSend = m_OutgoingMessages.First.Value;
                    m_OutgoingMessages.RemoveFirst();
                    result = SendToState.Normal;
                }
            }

            return(result);
        }
コード例 #2
0
        public override SendToState SendInternal(MessageSerializer messageSerializer, Stream stream)
        {
            SendToState sendToState = GetMessageToSend(out Message toSend);

            if (sendToState == SendToState.Normal)
            {
                SendMessageWithStream(messageSerializer, stream, toSend);

                //Recycle the message (if applicable).
                if (m_LastMessageSent != null && m_LastMessageSent != toSend)
                {
                    TryRecycleMessage(m_LastMessageSent);
                }

                m_LastMessageSent = toSend;
            }

            return(sendToState);
        }