Beispiel #1
0
        private void OnNewBytes(int size)
        {
            try
            {
                // Debug support
                if (Globals.TRACE_RECEIVE)
                {
                    Logger.ExceptionLogger.LogMessage("TRACE: ReceiveDataHandler.OnNewBytes() [" + topic.GetName() + "], got " + size + " bytes");
                }

                bytesReceived += size - headerBytes.Length;

                ReadByteBuffer readBuf = new ReadByteBuffer(headerBytes);

                if (readBuf.CheckProtocol())
                {
                    int nrOfFragments   = readBuf.ReadInt();
                    int currentFragment = readBuf.ReadInt();

                    if (currentFragment == (nrOfFragments - 1) && currentFragment == expectedFragment)
                    {
                        // We have received a full message, let's deserialize it and send
                        // it to subscribers.
                        SendBytesToSubscribers(new ReadByteBuffer(bytes));
                        expectedFragment = 0;
                        bytesReceived    = 0;
                    }
                    else
                    {
                        if (currentFragment == expectedFragment)
                        {
                            expectedFragment++;
                        }
                        else
                        {
                            // Not so good. Sample will be lost here.
                            if (Globals.REPORT_DATA_FRAGMENT_LOST_ERRORS)
                            {
                                Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", Fragment error, sample lost");
                            }
                            expectedFragment = 0;
                            bytesReceived    = 0;
                        }
                    }
                }
            }
            catch (System.IO.IOException)
            {
                expectedFragment = 0;
            }
        }
Beispiel #2
0
        private void SendBytesToSubscribers(ReadByteBuffer readBuf)
        {
            OPSArchiverIn archiverIn = new OPSArchiverIn(readBuf, this.participant.getObjectFactory());
            OPSMessage    message    = null;

            // If the proper typesupport has not been added, the message may have content, but some fields may be null. How do we handle this
            // How do we make the user realize that he needs to add typesupport?
            message = (OPSMessage)archiverIn.Inout("message", message);

            //Console.WriteLine("Bytes received = " + bytesReceived);
            //Console.WriteLine("Bytes read     = " + readBuf.position());

            if (message == null)
            {
                Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", message was unexpectedly null");
                return;
            }

            if (message.GetData() == null)
            {
                Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", message.getData() was unexpectedly null");
                return;
            }

            CalculateAndSetSpareBytes(message, readBuf, FRAGMENT_HEADER_SIZE, bytesReceived);

            string IP   = "";
            int    port = 0;

            receiver.GetSource(ref IP, ref port);
            message.SetSource(IP, port);

            //TODO: error checking
            foreach (Subscriber subscriber in subscribers)
            {
                try
                {
                    subscriber.NotifyNewOPSMessage(message);
                } catch (Exception ex)
                {
                    Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", Exception thrown in event notification thread " + ex.ToString());
                }
            }
        }
Beispiel #3
0
        private void CalculateAndSetSpareBytes(OPSMessage message, ReadByteBuffer readBuf, int segmentPaddingSize, int bytesReceived)
        {
            //NOT needed since 'bytesReceived' already is compensated for all headers and 'readBuf' is all data except header data
            //// We must calculate how many unserialized segment headers we have and substract
            //// that total header size from the size of spareBytes.
            //int nrOfSerializedBytes = readBuf.Position();
            //int totalNrOfSegments = (int) (bytesReceived /fragmentSize);
            //int nrOfSerializedSegements = (int) (nrOfSerializedBytes /fragmentSize);
            //int nrOfUnserializedSegments = totalNrOfSegments - nrOfSerializedSegements;

            int nrOfSpareBytes = bytesReceived - readBuf.Position(); ///See comment above: -(nrOfUnserializedSegments * segmentPaddingSize);

            if (nrOfSpareBytes > 0)
            {
                message.GetData().spareBytes = new byte[nrOfSpareBytes];
                // This will read the rest of the bytes as raw bytes and put
                // them into spareBytes field of data.
                readBuf.ReadBytes(message.GetData().spareBytes);
            }
        }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="buf"></param>
 /// <param name="factory"></param>
 public OPSArchiverIn(ReadByteBuffer buf, OPSObjectFactory factory)
 {
     compositeFactory = factory;
     readBuf          = buf;
 }
Beispiel #5
0
 ///
 /// <param name="buf"></param>
 public OPSArchiverIn(ReadByteBuffer buf)
 {
     compositeFactory = OPSObjectFactory.GetInstance();
     readBuf          = buf;
 }