Esempio n. 1
0
        /// <summary>
        /// A piece of a fragmented interaction.
        /// </summary>
        /// <param name="msg">a fragmented interaction message
        /// </param>
        /// <exception cref="InteractionClassNotRecognized">  if the interaction class was not recognized
        /// </exception>
        /// <exception cref="InteractionParameterNotRecognized">  if a parameter of the interaction was not
        /// recognized
        /// </exception>
        /// <exception cref="InteractionClassNotSubscribed">  if the federate had not subscribed to the
        /// interaction class
        /// </exception>
        /// <exception cref="FederateInternalError"> if an error occurs in the federate
        /// </exception>
        public void OnReceiveHLAinteractionFragment(HLAinteractionFragmentMessage msg)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("Received Message = " + msg.ToString());
            }

            if (incomingInteractionBuffer == null || incomingInteractionNumber != msg.InteractionNumber)
            {
                incomingInteractionBuffer       = new byte[msg.InteractionSize];
                incomingInteractionNumber       = msg.InteractionNumber;
                incomingInteractionBufferFilled = 0;
            }

            Array.Copy(msg.FragmentContents, 0, incomingInteractionBuffer, msg.FragmentOffset, msg.FragmentContents.Length);

            incomingInteractionBufferFilled += msg.FragmentContents.Length;

            if (incomingInteractionBufferFilled == msg.InteractionSize)
            {
                System.IO.MemoryStream buffer = new System.IO.MemoryStream(incomingInteractionBuffer);
                object tmp        = BaseInteractionMessage.NullBaseInteractionMessage;
                object newMessage = serializer.Deserialize(buffer, ref tmp);
                if (newMessage is BaseInteractionMessage)
                {
                    ReceiveInteraction(newMessage as BaseInteractionMessage);
                }
            }
        }
        ///<summary> Reads this HLAinteractionFragmentMessage from the specified stream.</summary>
        ///<param name="reader"> the input stream to read from</param>
        ///<returns> the object</returns>
        ///<exception cref="IOException"> if an error occurs</exception>
        public override object Deserialize(HlaEncodingReader reader, ref object msg2)
        {
            HLAinteractionFragmentMessage msg = new HLAinteractionFragmentMessage();

            msg.CopyTo((BaseInteractionMessage)msg2);
            try
            {
                msg.InteractionNumber = reader.ReadHLAinteger32BE();
                msg.InteractionSize   = reader.ReadHLAinteger32BE();
                msg.FragmentOffset    = reader.ReadHLAinteger32BE();
                msg.FragmentContents  = reader.ReadHLAopaqueData();
            }
            catch (IOException ioe)
            {
                throw new RTIinternalError(ioe.ToString());
            }
            return(msg);
        }
Esempio n. 3
0
 public void OnReceiveHLAinteractionFragment(HLAinteractionFragmentMessage msg)
 {
     message = msg;
     if (log.IsDebugEnabled) log.Debug("Received LastMessage =  " + msg.ToString());
 }
Esempio n. 4
0
        private void SendBestEffortInteraction(IMessageChannel messageChannel, byte[] buffer)
        {
            /*
             * if (log.IsInfoEnabled)
             *  log.Info("On " + System.Reflection.MethodBase.GetCurrentMethod());
             */

            try
            {
                if (buffer.Length <= messageChannel.MaximumPacketSize)
                {
                    lock (messageChannel.SyncObject)
                    {
                        if (messageChannel is DGramMessageChannel)
                        {
                            (messageChannel as DGramMessageChannel).SendPacket(buffer);
                        }
                        else if (messageChannel is MemoryMessageChannel)
                        {
                            (messageChannel as MemoryMessageChannel).SendPacket(buffer);
                        }
                    }
                }
                else
                {
                    //We substract 45 because we need some space for the headers
                    //HlaEncodingSerializer needs 4 for MAGICNUMBER + 4 for version = 8 bytes
                    //BaseInteractionMessage needs 8 for FederationExecutionHandle + 4 UserSuppliedTag + 8 for InteractionClassHandle = 20 bytes
                    //HLAinteractionFragment needs 4 for InteractionNumber + 4 for InteractionSize +
                    //                             4 for FragmentOffset + 4 for length of fragment = 16 bytes
                    int packetSize = messageChannel.MaximumPacketSize - 45;

                    byte[] fragment = new byte[packetSize];

                    for (int i = 0; i < buffer.Length; i += packetSize)
                    {
                        if ((buffer.Length - i) >= packetSize)
                        {
                            Array.Copy(buffer, i, fragment, 0, packetSize);
                        }
                        else
                        {
                            fragment = new byte[buffer.Length - i];

                            Array.Copy(buffer, i, fragment, 0, fragment.Length);
                        }

                        HLAinteractionFragmentMessage fragmentMessage = new HLAinteractionFragmentMessage();
                        //fragmentMessage.FederationExecutionHandle = msg.FederationExecutionHandle;
                        //fragmentMessage.UserSuppliedTag = msg.UserSuppliedTag;
                        fragmentMessage.InteractionClassHandle = serializerManager.GetHandle(typeof(HLAinteractionFragmentMessage));
                        fragmentMessage.InteractionNumber      = outgoingInteractionCounter;
                        fragmentMessage.InteractionSize        = buffer.Length;
                        fragmentMessage.FragmentOffset         = i;
                        fragmentMessage.FragmentContents       = fragment;

                        SendBestEffortInteraction(messageChannel, fragmentMessage);
                    }

                    outgoingInteractionCounter++;
                }
            }
            catch (System.Exception e)
            {
                throw new RTIinternalError(e.Message);
            }
        }
Esempio n. 5
0
        private void SendBestEffortInteraction(IMessageChannel messageChannel, byte[] buffer)
        {
            /*
            if (log.IsInfoEnabled)
                log.Info("On " + System.Reflection.MethodBase.GetCurrentMethod());
            */

            try
            {
                if (buffer.Length <= messageChannel.MaximumPacketSize)
                {
                    lock (messageChannel.SyncObject)
                    {
                        if (messageChannel is DGramMessageChannel)
                            (messageChannel as DGramMessageChannel).SendPacket(buffer);
                        else if (messageChannel is MemoryMessageChannel)
                            (messageChannel as MemoryMessageChannel).SendPacket(buffer);

                    }
                }
                else
                {
                    //We substract 45 because we need some space for the headers
                    //HlaEncodingSerializer needs 4 for MAGICNUMBER + 4 for version = 8 bytes
                    //BaseInteractionMessage needs 8 for FederationExecutionHandle + 4 UserSuppliedTag + 8 for InteractionClassHandle = 20 bytes
                    //HLAinteractionFragment needs 4 for InteractionNumber + 4 for InteractionSize +
                    //                             4 for FragmentOffset + 4 for length of fragment = 16 bytes
                    int packetSize = messageChannel.MaximumPacketSize - 45;

                    byte[] fragment = new byte[packetSize];

                    for (int i = 0; i < buffer.Length; i += packetSize)
                    {
                        if ((buffer.Length - i) >= packetSize)
                        {
                            Array.Copy(buffer, i, fragment, 0, packetSize);
                        }
                        else
                        {
                            fragment = new byte[buffer.Length - i];

                            Array.Copy(buffer, i, fragment, 0, fragment.Length);
                        }

                        HLAinteractionFragmentMessage fragmentMessage = new HLAinteractionFragmentMessage();
                        //fragmentMessage.FederationExecutionHandle = msg.FederationExecutionHandle;
                        //fragmentMessage.UserSuppliedTag = msg.UserSuppliedTag;
                        fragmentMessage.InteractionClassHandle = serializerManager.GetHandle(typeof(HLAinteractionFragmentMessage));
                        fragmentMessage.InteractionNumber = outgoingInteractionCounter;
                        fragmentMessage.InteractionSize = buffer.Length;
                        fragmentMessage.FragmentOffset = i;
                        fragmentMessage.FragmentContents = fragment;

                        SendBestEffortInteraction(messageChannel, fragmentMessage);
                    }

                    outgoingInteractionCounter++;
                }
            }
            catch (System.Exception e)
            {
                throw new RTIinternalError(e.Message);
            }
        }
Esempio n. 6
0
        /// <summary> 
        /// A piece of a fragmented interaction. 
        /// </summary>
        /// <param name="msg">a fragmented interaction message
        /// </param>
        /// <exception cref="InteractionClassNotRecognized">  if the interaction class was not recognized
        /// </exception>
        /// <exception cref="InteractionParameterNotRecognized">  if a parameter of the interaction was not
        /// recognized
        /// </exception>
        /// <exception cref="InteractionClassNotSubscribed">  if the federate had not subscribed to the
        /// interaction class
        /// </exception>
        /// <exception cref="FederateInternalError"> if an error occurs in the federate
        /// </exception>
        public void OnReceiveHLAinteractionFragment(HLAinteractionFragmentMessage msg)
        {
            if (log.IsDebugEnabled)
                log.Debug("Received Message = " + msg.ToString());

            if (incomingInteractionBuffer == null || incomingInteractionNumber != msg.InteractionNumber)
            {
                incomingInteractionBuffer = new byte[msg.InteractionSize];
                incomingInteractionNumber = msg.InteractionNumber;
                incomingInteractionBufferFilled = 0;
            }

            Array.Copy(msg.FragmentContents, 0, incomingInteractionBuffer, msg.FragmentOffset, msg.FragmentContents.Length);

            incomingInteractionBufferFilled += msg.FragmentContents.Length;

            if (incomingInteractionBufferFilled == msg.InteractionSize)
            {
                System.IO.MemoryStream buffer = new System.IO.MemoryStream(incomingInteractionBuffer);
                object tmp = BaseInteractionMessage.NullBaseInteractionMessage;
                object newMessage = serializer.Deserialize(buffer, ref tmp);
                if (newMessage is BaseInteractionMessage)
                {
                    ReceiveInteraction(newMessage as BaseInteractionMessage);
                }
            }
        }
 ///<summary> Reads this HLAinteractionFragmentMessage from the specified stream.</summary>
 ///<param name="reader"> the input stream to read from</param>
 ///<returns> the object</returns>
 ///<exception cref="IOException"> if an error occurs</exception>
 public override object Deserialize(HlaEncodingReader reader, ref object msg2)
 {
     HLAinteractionFragmentMessage msg = new HLAinteractionFragmentMessage();
     msg.CopyTo((BaseInteractionMessage)msg2);
     try
     {
         msg.InteractionNumber = reader.ReadHLAinteger32BE();
         msg.InteractionSize = reader.ReadHLAinteger32BE();
         msg.FragmentOffset = reader.ReadHLAinteger32BE();
         msg.FragmentContents = reader.ReadHLAopaqueData();
     }
     catch (IOException ioe)
     {
         throw new RTIinternalError(ioe.ToString());
     }
     return msg;
 }
Esempio n. 8
0
 public override void OnReceiveHLAinteractionFragment(HLAinteractionFragmentMessage msg)
 {
     if (log.IsDebugEnabled)
         log.Debug("Received HLAinteractionFragment =  " + msg.ToString());
 }