Esempio n. 1
0
        private void DumpFederationObjects(MetaFederateAmbassador metaFederateAmbassador, IList <HLAobjectRoot> objects, String parentNodeName, String federationName)
        {
            TreeNode parentNode = FindNode(treeView1.Nodes, parentNodeName);

            if (parentNode == null)
            {
                parentNode                    = new TreeNode(parentNodeName);
                parentNode.ImageIndex         = 3;
                parentNode.SelectedImageIndex = 3;
                parentNode.Tag                = parentNodeName;
                this.treeView1.Nodes.Add(parentNode);

                HLAfederation federationObject = metaFederateAmbassador.GetFederation(federationName);

                if (federationObject != null)
                {
                    DescriptorManager descriptorManager = new DescriptorManager();
                    descriptorManager.AddDescriptors(federationObject.HLAFDDID);

                    ShowInformationFromDescriptorManager(descriptorManager, parentNodeName);
                }
            }

            AddHLAobjectRootNodes(parentNode, objects);
        }
        // END PATCH

        #region IRTIambassador Members

        /// <summary>
        ///  Creates a new federation execution.
        /// </summary>
        /// <param name="federationExecutionName">
        /// the name of the new federation execution
        /// </param>
        /// <param name="fdd">
        /// the location of the federation description document
        /// </param>
        /// <exception cref="FederationExecutionAlreadyExists">
        /// if the execution already exists
        /// </exception>
        /// <exception cref="CouldNotOpenFDD">
        /// if the federation description document could not
        /// be opened
        /// </exception>
        /// <exception cref="ErrorReadingFDD">
        /// if an error occurred while reading the federation
        /// description document
        /// </exception>
        /// <exception cref="RTIinternalError">
        /// if an internal error occurred in the
        /// run-time infrastructure
        /// </exception>
        public void CreateFederationExecution(string federationExecutionName, Uri fdd)
        {
            if (!initialized)
            {
                InitializeRTI();
            }

            lock (this)
            {
                if (string.IsNullOrEmpty(federationExecutionName))
                {
                    throw new RTIinternalError("Can't create federation: Name was empty or null");
                }
                if (federationsMap.ContainsKey(federationExecutionName))
                {
                    throw new FederationExecutionAlreadyExists(federationExecutionName);
                }

                if (fdd == null)
                {
                    throw new CouldNotOpenFDD("The URI for the federation description documentis null");
                }
                try
                {
                    string uri = System.Net.WebRequest.Create(fdd).GetResponse().ResponseUri.AbsolutePath;

                    interactionManager.RegisterHelperClass(uri); //PREGUNTAR A ANGEL SI PUEDO MOVERLO AL JOIN ??

                    //HLAfederation tmp = new HLAfederation();
                    HLAfederation tmp = HLAfederation.NewHLAfederation();

                    tmp.HLAfederationName = federationExecutionName;
                    tmp.HLAFDDID          = uri;

                    federationsMap.Add(federationExecutionName, tmp);

                    Debug("Created execution " + federationExecutionName);
                }
                catch (System.Exception e)
                {
                    throw new RTIinternalError(e.ToString());
                }
            }
        }
        /// <summary>
        /// Destroys a federation execution.
        /// </summary>
        /// <param name="federationExecutionName">the name of the federation execution to destroy
        /// </param>
        /// <exception cref="FederatesCurrentlyJoined"> if federates are still participating in the
        /// execution
        /// </exception>
        /// <exception cref="FederationExecutionDoesNotExist"> if the federation execution does not
        /// exist
        /// </exception>
        /// <exception cref="RTIinternalError"> if an internal error occurred in the
        /// run-time infrastructure
        /// </exception>
        public void DestroyFederationExecution(string federationExecutionName)
        {
            if (!initialized)
            {
                InitializeRTI();
            }

            if (federationsMap.ContainsKey(federationExecutionName))
            {
                HLAfederation federation = federationsMap[federationExecutionName];

                //if federates are still participating in the execution
                if (federation.HLAfederatesinFederation.Count > 0)
                {
                    throw new FederatesCurrentlyJoined(federation.HLAfederatesinFederation.Count + " federates are still participating in " + federation.HLAfederationName);
                }
            }
            // if the federation execution does not exits
            else
            {
                throw new FederationExecutionDoesNotExist(federationExecutionName);
            }

            try
            {
                // Creates and sends the destroy federation message

                /*
                 * HLAdestroyFederationExecutionMessage destroyFederationMsg = new HLAdestroyFederationExecutionMessage();
                 * destroyFederationMsg.FederationExecutionName = federationExecutionName;
                 * destroyFederationMsg.FederationExecutionHandle = this.joinedFederationExecutionHandle;
                 * interactionManager.SendInteraction(destroyFederationMsg);
                 */
            }
            catch (RTIexception rtie)
            {
                throw new RTIinternalError(rtie.ToString());
            }
        }
Esempio n. 4
0
        public override void ReflectAttributeValuesExt(IObjectInstanceHandle theObject, HLAattributeHandleValuePair[] theAttributes, byte[] userSuppliedTag, OrderType sentOrdering, TransportationType theTransport)
        {
            // TODO ANGEL: LOCK DUDOSO
            lock (this)
            {
                base.ReflectAttributeValuesExt(theObject, theAttributes, userSuppliedTag, sentOrdering, theTransport);

                if (objectInstanceHandleProxyMap.ContainsKey(theObject))
                {
                    object instance = objectInstanceHandleProxyMap[theObject];

                    // TODO ANGEL: ¿Esto debería estar aquí o dentro de la funcionalidad del objectManager?
                    //             El problema es que si lo hace objectManager debe poder acceder al federationsMap del rti
                    foreach (HLAattributeHandleValuePair entry in theAttributes)
                    {
                        string attributeName = GetAttributeName(instance, entry.AttributeHandle);

                        // Checks if the object created is an instance of HLAfederation and its properties are modificated
                        if (instance is HLAfederation)
                        {
                            if (attributeName == "HLAfederationName")
                            {
                                rti.federationsMap.Add((string)entry.AttributeValue, instance as HLAfederation);
                            }
                            else if (attributeName == "HLAFDDID")
                            {
                                rti.interactionManager.RegisterHelperClass((string)entry.AttributeValue);
                            }
                        }

                        // Checks if the object created is an instance of HLAfederate and its properties are modificated
                        if (instance is HLAfederate)
                        {
                            if (attributeName == "HLAfederateHandle")
                            {
                                if (instance is Sxtafederate)
                                {
                                    Sxtafederate federate = instance as Sxtafederate;

                                    // TODO ANGEL: OJO! Implica que la propiedad HLAfederationNameJoined se haya recibido antes que ésta
                                    HLAfederateHandle federateHandle = (HLAfederateHandle)entry.AttributeValue;
                                    rti.federationsMap[federate.HLAfederationNameJoined].HLAfederatesinFederation.Add(federateHandle);
                                }
                            }

                            if (attributeName == "HLAfederationNameJoined")
                            {
                                if (instance is Sxtafederate)
                                {
                                    Sxtafederate federate = instance as Sxtafederate;

                                    HLAfederation federation = rti.federationsMap[federate.HLAfederationNameJoined];
                                    federate.Federation = federation;
                                }
                            }

                            /*
                             * if (attributeName == "HLAlogicalTime" || attributeName == "HLApendingTime"
                             || attributeName == "HLAlookahead" || attributeName == "HLAGALT" || attributeName == "HLALITS")
                             ||{
                             || //System.Threading.Monitor.Pulse(rti);
                             || //rti.PushFederates();
                             ||}
                             */
                        }
                    }
                }
            }
        }
        /// <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);
        }