Exemple #1
0
        public void InitAndCreateFederation()
        {
            LogAndRtiInit();

            //Build a Uri using a file path
            FileInfo file = new FileInfo(Sxta.Rti1516ResourcesNames.HelloWorldObjectModel);
            Uri fileUri = new Uri("file://" + file.FullName);
            try
            {
                //Create Federation
                rtiAmbassador.CreateFederationExecution(federationName, fileUri);
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                    log.Error(exception.Message);
            }

            try
            {
                federateAmbassador = new TestFederate(rtiAmbassador);
                mobileServices = new MobileFederateServices(new LongValuedLogicalTimeFactory(), new LongValuedLogicalTimeIntervalFactory());
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                    log.Error(exception.Message);
            }
        }
Exemple #2
0
        private void OnJoinFederationHelloWorld(object sender, EventArgs e)
        {
            try
            {
                // Join to federation
                sampleFederateAmbassador = new XrtiFederateAmbassador(rtiAmbassador);
                mobileServices = new MobileFederateServices(new DoubleValuedLogicalTimeFactory(), new DoubleValuedLogicalTimeIntervalFactory());
                IFederateHandle federateHandle = rtiAmbassador.JoinFederationExecution(peerName, federationName, sampleFederateAmbassador, mobileServices);

                EvokeCallbackMenuItem.Enabled = true;
                EvokeCallbacksMenuItem.Enabled = true;
                SetTimeConstrainedMenuItem.Enabled = true;
                SetTimeRegulatingMenuItem.Enabled = true;
                TimeAdvanceRequestMinMenuItem.Enabled = true;
                TimeAdvanceRequestMenuItem.Enabled = true;
                Example1MenuItem.Enabled = true;
                Example2MenuItem.Enabled = true;
                Example3MenuItem.Enabled = true;
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                    log.Error(exception.Message);
                MessageBox.Show(exception.Message);
            }
        }
        /// <summary>
        /// Joins a federation execution.
        /// </summary>
        /// <param name="federateType">a string describing the federate's role in the federation
        /// </param>
        /// <param name="federationExecutionName">the name of the federation to join
        /// </param>
        /// <param name="federateReference">the federate ambassador object
        /// </param>
        /// <param name="serviceReferences">the federate's mobile services
        /// </param>
        /// <exception cref="FederateAlreadyExecutionMember"> if the federate is already a member of
        /// an execution
        /// </exception>
        /// <exception cref="FederationExecutionDoesNotExist"> if the federation execution does not
        /// exist
        /// </exception>
        /// <exception cref="SaveInProgress"> if a save operation is in progress
        /// </exception>
        /// <exception cref="RestoreInProgress"> if a restore operation is in progress
        /// </exception>
        /// <exception cref="RTIinternalError"> if an internal error occurred in the
        /// run-time infrastructure
        /// </exception>
        public IFederateHandle JoinFederationExecution(string federateType,
            string federationExecutionName,
            IFederateAmbassador federateReference,
            MobileFederateServices serviceReferences)
        {
            if (!initialized)
            {
                InitializeRTI();
            }

            // TODO : + Checks if a save operation is in progress
            //        + Checks if a restore operation is in progress

            // if the federate is already a member of an execution
            if (!this.federationName.Equals(HLA_META_FEDERATION_EXECUTION))
            {
                throw new FederateAlreadyExecutionMember("joined to " + this.federationName);
            }

            // if the federation execution does not exits
            if (!federationsMap.ContainsKey(federationExecutionName))
            {
                throw new FederationExecutionDoesNotExist(federationExecutionName);
            }

            HLAfederation federation = federationsMap[federationExecutionName];

            if (serviceReferences != null)
            {
                this.logicalTimeFactory = serviceReferences._timeFactory;
                this.logicalTimeIntervalFactory = serviceReferences._intervalFactory;

                // Sets time's factory to the federation
                federation.LogicalTimeFactory = serviceReferences._timeFactory;
                federation.LogicalTimeIntervalFactory = serviceReferences._intervalFactory;

                /*
                XrtiSerializerManager serializerMngr = this.interactionManager.SerializerManager;

                Type objType = typeof(ILogicalTime);
                long handle = -1000;
                serializerMngr.RegisterSerializer(objType, handle, new ILogicalTimeXrtiSerializer(serializerMngr, logicalTimeFactory));

                objType = typeof(ILogicalTimeInterval);
                handle = -2000;
                serializerMngr.RegisterSerializer(objType, handle, new ILogicalTimeIntervalXrtiSerializer(serializerMngr, logicalTimeIntervalFactory));
                */
            }

            Sxtafederate sxtaFederate;

            try
            {
                lock (this)
                {
                    // Creates the federate;
                    this.federate = Sxtafederate.NewSxtafederate();

                    sxtaFederate = this.federate as Sxtafederate;

                    // Sets the federate's ambassador
                    sxtaFederate.FederateAmbassador = federateReference;

                    // Sets the federation
                    sxtaFederate.Federation = federation;

                    // Updates the federate's properties
                    sxtaFederate.HLAisJoined = true;

                    sxtaFederate.HLAfederationNameJoined = federationExecutionName;

                    federate.HLAfederateType = federateType;

                    String nameHost = Dns.GetHostName();
                    System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(nameHost);
                    sxtaFederate.HLAfederateHost = hostEntry.AddressList[0].ToString();

                    this.federateHandle = new XRTIFederateHandle();
                    federate.HLAfederateHandle = (HLAfederateHandle)this.federateHandle;
                    //federate.HLAfederateState = HLAfederateState.ActiveFederate;

                    // Init time management's properties
                    federate.HLAtimeConstrained = false;
                    federate.HLAtimeRegulating = false;
                    federate.HLAtimeManagerState = HLAtimeState.TimeGranted;

                    // TODO ANGEL: Posiblemente NO sea el lugar adecuado para inicializar
                    federate.HLAlogicalTime = logicalTimeFactory.MakeInitial();
                    federate.HLAGALT = logicalTimeFactory.MakeInitial();
                    federate.HLALITS = logicalTimeFactory.MakeFinal();
                    sxtaFederate.HLApendingTime = logicalTimeFactory.MakeInitial();

                    federate.HLAlookahead = logicalTimeIntervalFactory.MakeZero();
                }
            }
            catch (System.Exception e)
            {
                throw new RTIinternalError(e.ToString());
            }

            // Initializes Federate's State
            Lrc.LrcQueue queue = new Lrc.LrcQueue();
            state = new Lrc.LrcState(queue, sxtaFederate);
            lrc = new Lrc.Lrc(state, queue);

            // Sets federate ambassador
            this.federateAmbassador = federateReference;

            // Adds the new federate to the execution
            federation.HLAfederatesinFederation.Add(federate.HLAfederateHandle);

            this.federationHandle = federationsMap[federationExecutionName].InstanceHandle;
            this.joinedFederationExecutionHandle = ((XRTIObjectInstanceHandle)this.federationHandle).Identifier;
            this.federationName = federationExecutionName;

            // Set-up HLAobjectRoot static properties
            HLAobjectRoot.DefaultFederate = federate;
            HLAobjectRoot.DefaultFederateAmbassador = federateReference;
            HLAobjectRoot.DefaultFederationExecutionHandle = this.joinedFederationExecutionHandle;

            // Adds listeners to process federation's interactions
            FederationLowLevelManagementObjectModelInteractionListener federationLLMObjectModelInteractionListener = new FederationLowLevelManagementObjectModelInteractionListener(this, federationExecutionName);
            dispatcher.AddListener(joinedFederationExecutionHandle, federationLLMObjectModelInteractionListener);

            FederationManagementObjectModelInteractionListener federationMObjectModelInteractionListener = new FederationManagementObjectModelInteractionListener(this, federationExecutionName);
            dispatcher.AddListener(joinedFederationExecutionHandle, federationMObjectModelInteractionListener);

            PublishAndSubscribeFederationObjectClass(federation.HLAFDDID, this.joinedFederationExecutionHandle);

            Debug("Joined execution " + this.federationName + " [" + this.federationHandle + ")]");

            return this.federateHandle;
        }