///<summary> Reads this CommunicationMessage from the specified stream.</summary>
        ///<param name="reader"> the input stream to read from</param>
        ///<returns> the object</returns>
        ///<exception cref="System.IO.IOException"> if an error occurs</exception>
        public override object Deserialize(HlaEncodingReader reader, ref object msg)
        {
            CommunicationMessage decodedValue;

            if (!(msg is CommunicationMessage))
            {
                decodedValue = new CommunicationMessage();
                BaseInteractionMessage baseMsg = msg as BaseInteractionMessage;
                decodedValue.InteractionClassHandle    = baseMsg.InteractionClassHandle;
                decodedValue.FederationExecutionHandle = baseMsg.FederationExecutionHandle;
                decodedValue.UserSuppliedTag           = baseMsg.UserSuppliedTag;
            }
            else
            {
                decodedValue = msg as CommunicationMessage;
            }
            //object tmp = decodedValue;
            //decodedValue = base.Deserialize(reader, ref tmp) as CommunicationMessage;
            try
            {
                decodedValue.Message = reader.ReadHLAunicodeString();
            }
            catch (System.IO.IOException ioe)
            {
                throw new RTIinternalError(ioe.ToString());
            }
            return(decodedValue);
        }
Exemplo n.º 2
0
 public void OnReceiveCommunication(CommunicationMessage msg)
 {
     if (log.IsInfoEnabled)
     {
         log.Info("On receive a new communication msg : " + msg);
     }
 }
Exemplo n.º 3
0
        public void SimulationLoop()
        {
            ((XrtiExecutiveAmbassador)rtiAmbassador).interactionManager.AddInteractionListener(this);

            List <ExternalCountry> countriesList = new List <ExternalCountry>();
            Random ran = new Random();

            for (int i = 0; i < 1; i++)
            {
                ExternalCountry aCountry = ExternalCountry.NewExternalCountry();
                aCountry.Name       = "Country[" + i + "]";
                aCountry.Population = ran.Next(1000, 2000);
                countriesList.Add(aCountry);
            }

            SimulationTime = new LongValuedLogicalTime(0);
            ILogicalTime finalTime = new LongValuedLogicalTime(1000);

            while (SimulationTime.CompareTo(finalTime) < 0)
            {
                federateAmbassador.DumpObjects();

                foreach (ExternalCountry country in countriesList)
                {
                    country.Population *= 1.0 + ran.NextDouble() * 0.1; // some random increase in range (1.00 and 1.10)
                }
                CommunicationMessage msg = new CommunicationMessage();
                msg.Message = "Hi, I finished my time " + SimulationTime.ToString();
                Thread.Sleep(4 * 1000);
                ((XrtiExecutiveAmbassador)rtiAmbassador).SendInteraction(msg);
                AdvanceTime();
            }

            if (log.IsInfoEnabled)
            {
                log.Info("Finaliza el bucle de simulación");
            }

            // clean up for the next test
            ResignAndDestroy();
        }