Beispiel #1
0
        private string GetAttributeName(object instance, long attributeHandle)
        {
            IObjectClassHandle whichClass = ((HLAobjectRoot)instance).ClassHandle;
            IAttributeHandle   theHandle  = new XRTIAttributeHandle(attributeHandle);

            ObjectClassDescriptor ocd = rti.descriptorManager.GetObjectClassDescriptor(whichClass);

            if (ocd == null)
            {
                throw new InvalidObjectClassHandle(whichClass.ToString());
            }
            else
            {
                AttributeDescriptor ad = ocd.GetAttributeDescriptor(theHandle);

                if (ad == null)
                {
                    throw new InvalidAttributeHandle(theHandle.ToString());
                }
                else
                {
                    return(ad.Name);
                }
            }
        }
Beispiel #2
0
 public DiscoverObjectInstanceCallback(IFederateAmbassador federate, IObjectInstanceHandle theObjectParam, IObjectClassHandle theObjectClassParam, string objectNameParam)
     : base(federate)
 {
     this.theObject      = theObjectParam;
     this.theObjectClass = theObjectClassParam;
     this.objectName     = objectNameParam;
 }
Beispiel #3
0
        public void TestObjectInstanceName()
        {
            // get the FOM handles //
            try
            {
                JoinFederation();

                IObjectClassHandle countryHandle = rtiAmbassador.GetObjectClassHandle("Country");
#if TODO
                IObjectClassHandle countryHandle = rtiAmbassador.GetObjectClassHandle("HLAobjectRoot.Country");
#endif
                rtiAmbassador.ReserveObjectInstanceName("Country1");
                IObjectInstanceHandle objHandle1 = rtiAmbassador.RegisterObjectInstance(countryHandle, "Country1");
                string objName = rtiAmbassador.GetObjectInstanceName(objHandle1);
                Assert.AreEqual("Country1", objName);

                IObjectInstanceHandle objHandle2 = rtiAmbassador.RegisterObjectInstance(countryHandle);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(e.Message);
                }
                Assert.Fail("Unexpected exception while testing object instances:" + e);
            }

            // clean up for the next test
            Resign();
        }
        public void TestAttributeHandles2()
        {
            // get the FOM handles //
            try
            {
                JoinFederation();

                IObjectClassHandle countryHandle = rtiAmbassador.GetObjectClassHandle("HLAobjectRoot");

                IAttributeHandle attrHandle = rtiAmbassador.GetAttributeHandle(countryHandle, "HLAprivilegeToDelete");

                string privilegeToDeleteName = rtiAmbassador.GetAttributeName(countryHandle, attrHandle);
                Assert.AreEqual("HLAprivilegeToDelete", privilegeToDeleteName);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(e.Message);
                }
                Assert.Fail("Unexpected exception while fetching the object model handles:" + e);
            }

            // clean up for the next test
            Resign();
        }
        public void TestFetchWithQualifiedName()
        {
            // get the FOM handles //
            try
            {
                JoinFederation();

                IObjectClassHandle rootHandle     = rtiAmbassador.GetObjectClassHandle("HLAobjectRoot");
                IObjectClassHandle countryHandle  = rtiAmbassador.GetObjectClassHandle("HLAobjectRoot.Country");
                IObjectClassHandle boidHandle     = rtiAmbassador.GetObjectClassHandle("HLAobjectRoot.Boid");
                IObjectClassHandle goodBoidHandle = rtiAmbassador.GetObjectClassHandle("HLAobjectRoot.Boid.GoodBoid");
                IObjectClassHandle badBoidHandle  = rtiAmbassador.GetObjectClassHandle("HLAobjectRoot.Boid.DepredatorBoid");

                string className = rtiAmbassador.GetObjectClassName(countryHandle);
                Assert.AreEqual("HLAobjectRoot.Country", className);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(e.Message);
                }
                Assert.Fail("Exception while fetching object class handles with qualified names :" + e);
            }

            // clean up for the next test
            Resign();
        }
Beispiel #6
0
        public void TestObjectUsingAOP()
        {
            // get the FOM handles //
            try
            {
                JoinFederation();

                Country country = Country.NewCountry();

                string             objName     = rtiAmbassador.GetObjectInstanceName(country.InstanceHandle);
                IObjectClassHandle classHandle = rtiAmbassador.GetKnownObjectClassHandle(country.InstanceHandle);
                string             className   = rtiAmbassador.GetObjectClassName(classHandle);
                Assert.AreEqual("Country", className);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(e.Message);
                }
                Assert.Fail("Unexpected exception while testing creation object instances:" + e);
            }

            // clean up for the next test
            Resign();
        }
        public void TestAttributeHandles()
        {
            // get the FOM handles //
            try
            {
                JoinFederation();

                IObjectClassHandle countryHandle = rtiAmbassador.GetObjectClassHandle("Country");

                IAttributeHandle nameHandle       = rtiAmbassador.GetAttributeHandle(countryHandle, "Name");
                IAttributeHandle populationHandle = rtiAmbassador.GetAttributeHandle(countryHandle, "Population");

                string nameAttribute = rtiAmbassador.GetAttributeName(countryHandle, nameHandle);
                Assert.AreEqual("Name", nameAttribute);

                string populationAttribute = rtiAmbassador.GetAttributeName(countryHandle, populationHandle);
                Assert.AreEqual("Population", populationAttribute);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(e.Message);
                }
                Assert.Fail("Unexpected exception while fetching the object model handles:" + e);
            }

            // clean up for the next test
            Resign();
        }
Beispiel #8
0
        private HLAattributeHandleValuePair[] CreateAttributesHandleValuePairList(IDictionary <string, object> methodNameValueMap, IObjectInstanceHandle instanceHandle)
        {
            HLAattributeHandleValuePair[] attributeHandleValuePairList = new HLAattributeHandleValuePair[methodNameValueMap.Count];

            ObjectInstanceDescriptor oid = rti.descriptorManager.GetObjectInstanceDescriptor(instanceHandle);
            IObjectClassHandle       och = oid.ClassHandle;
            ObjectClassDescriptor    ocd = rti.descriptorManager.GetObjectClassDescriptor(och);

            int count = 0;

            foreach (KeyValuePair <string, object> entry in methodNameValueMap)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("The method " + entry.Key + " from object " + instanceHandle + " has been called; new value:" + entry.Value + "; parameter type = " + entry.Value.GetType());
                }

                attributeHandleValuePairList[count] = new HLAattributeHandleValuePair();
                attributeHandleValuePairList[count].AttributeHandle = ((XRTIAttributeHandle)ocd.GetAttributeDescriptor(entry.Key).Handle).Identifier;
                attributeHandleValuePairList[count].AttributeValue  = entry.Value;
                count++;
            }

            return(attributeHandleValuePairList);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="pName">the name of the object class
 /// </param>
 /// <param name="pHandle">the handle of the object class
 /// </param>
 /// <param name="pParentDescriptors">the descriptors of the object class's parents
 /// </param>es
 public ObjectClassDescriptor(XmlElement objClassElement, IObjectClassHandle pHandle, List <ObjectClassDescriptor> pParentDescriptors)
 {
     objectDescription = new Sxta.Rti1516.Reflection.HLAObjectClass(objClassElement);
     //nativeName = Assembly.GetExecutingAssembly().GetType(objectDescription.Name);
     handle            = pHandle;
     parentDescriptors = pParentDescriptors;
 }
 /// <summary> 
 /// Constructor.
 /// </summary>
 /// <param name="pName">the name of the object class
 /// </param>
 /// <param name="pHandle">the handle of the object class
 /// </param>
 /// <param name="pParentDescriptors">the descriptors of the object class's parents
 /// </param>es
 public ObjectClassDescriptor(XmlElement objClassElement, IObjectClassHandle pHandle, List<ObjectClassDescriptor> pParentDescriptors)
 {
     objectDescription = new Sxta.Rti1516.Reflection.HLAObjectClass(objClassElement);
     //nativeName = Assembly.GetExecutingAssembly().GetType(objectDescription.Name);
     handle = pHandle;
     parentDescriptors = pParentDescriptors;
 }
Beispiel #11
0
 public DiscoverObjectInstanceCallback(IFederateAmbassador federate, ILogicalTime time, long federateHandle, long interactionIndex, IObjectInstanceHandle theObjectParam, IObjectClassHandle theObjectClassParam, string objectNameParam)
     : base(federate, time, federateHandle, interactionIndex)
 {
     this.theObject      = theObjectParam;
     this.theObjectClass = theObjectClassParam;
     this.objectName     = objectNameParam;
 }
Beispiel #12
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="pName">the name of the object instance
        /// </param>
        /// <param name="pHandle">the handle of the object instance
        /// </param>
        /// <param name="pClassHandle">the handle of the object instance class
        /// </param>
        public ObjectInstanceDescriptor(System.String pName, IObjectInstanceHandle pHandle, IObjectClassHandle pClassHandle, long pFederationHandle)
        {
            name        = pName;
            handle      = pHandle;
            classHandle = pClassHandle;
            federationExecutionHandle = pFederationHandle;

            ownedAttributes = new XRTIAttributeHandleSet();
        }
Beispiel #13
0
        private HLAattributeHandleValuePair[] CreateAttributeHandleValuePairList(string methodName, object newValue, IObjectInstanceHandle instanceHandle)
        {
            ObjectInstanceDescriptor oid = rti.descriptorManager.GetObjectInstanceDescriptor(instanceHandle);
            IObjectClassHandle       och = oid.ClassHandle;
            ObjectClassDescriptor    ocd = rti.descriptorManager.GetObjectClassDescriptor(och);

            HLAattributeHandleValuePair[] attributeHandleValuePairList = new HLAattributeHandleValuePair[1];
            attributeHandleValuePairList[0] = new HLAattributeHandleValuePair();
            attributeHandleValuePairList[0].AttributeHandle = ((XRTIAttributeHandle)ocd.GetAttributeDescriptor(methodName).Handle).Identifier;
            attributeHandleValuePairList[0].AttributeValue  = newValue;

            return(attributeHandleValuePairList);
        }
Beispiel #14
0
        ///<summary> Writes this HLAsubscribeObjectClassAttributesMessage to the specified stream.</summary>
        ///<param name="writer"> the output stream to write to</param>
        ///<param name="obj"> the object to serialize</param>
        ///<exception cref="System.IO.IOException"> if an error occurs</exception>
        public override void Serialize(HlaEncodingWriter writer, object obj)
        {
            try
            {
                base.Serialize(writer, obj);

                IObjectClassHandle objectClass          = ((HLAsubscribeObjectClassAttributesMessage)obj).HLAobjectClass;
                byte[]             objectClassByteArray = new byte[objectClass.EncodedLength()];
                objectClass.Encode(objectClassByteArray, 0);

                writer.WriteHLAopaqueData(objectClassByteArray);

                IAttributeHandleSet attributeHandleSet = ((HLAsubscribeObjectClassAttributesMessage)obj).HLAattributeList;
                writer.WriteHLAinteger32BE(attributeHandleSet.Count);

                foreach (IAttributeHandle attributeHandle in attributeHandleSet)
                {
                    byte[] attributeHandleByteArray = new byte[attributeHandle.EncodedLength()];
                    attributeHandle.Encode(attributeHandleByteArray, 0);

                    writer.WriteHLAopaqueData(attributeHandleByteArray);
                }

                writer.WriteHLAboolean(((HLAsubscribeObjectClassAttributesMessage)obj).HLAactive);

                /*
                 * writer.WriteHLAinteger32BE((((HLAsubscribeObjectClassAttributesMessage)obj).HLAobjectClass).Length);
                 *
                 * for (int i = 0; i < (((HLAsubscribeObjectClassAttributesMessage)obj).HLAobjectClass).Length; i++)
                 * {
                 *  writer.WriteHLAoctet((((HLAsubscribeObjectClassAttributesMessage)obj).HLAobjectClass)[i]);
                 * }
                 * writer.WriteHLAinteger32BE((((HLAsubscribeObjectClassAttributesMessage)obj).HLAattributeList).Length);
                 *
                 * for (int i = 0; i < (((HLAsubscribeObjectClassAttributesMessage)obj).HLAattributeList).Length; i++)
                 * {
                 *  writer.WriteHLAinteger32BE(((((HLAsubscribeObjectClassAttributesMessage)obj).HLAattributeList)[i]).Length);
                 *
                 *  for (int j = 0; j < ((((HLAsubscribeObjectClassAttributesMessage)obj).HLAattributeList)[i]).Length; j++)
                 *  {
                 *      writer.WriteHLAoctet(((((HLAsubscribeObjectClassAttributesMessage)obj).HLAattributeList)[i])[j]);
                 *  }
                 * }
                 * writer.WriteHLAboolean(((HLAsubscribeObjectClassAttributesMessage)obj).HLAactive);
                 */
            }
            catch (System.IO.IOException ioe)
            {
                throw new RTIinternalError(ioe.ToString());
            }
        }
        public override void DiscoverObjectInstance(IObjectInstanceHandle theObject, IObjectClassHandle theObjectClass, string objectName)
        {
            long instanceHandle = ((XRTIObjectInstanceHandle)theObject).Identifier;
            long classHandle = ((XRTIObjectClassHandle)theObjectClass).Identifier;

            object proxy = rti.objectManager.CreateProxyObject(objectName, instanceHandle, classHandle);

            if (proxy != null)
            {
                RegisterObjectInstance(proxy);
            }
            else
            {
                throw new RTIinternalError("Type not found: " + objectName + ".");
            }
            if (OnNewObject != null)
            {
                if (log.IsInfoEnabled)
                    log.Info("Discovered a new object: " + proxy);
                OnNewObject(proxy);
            }
        }
        ///<summary>
        ///Notifies that the box is already in its house
        ///</summary>
        ///<param name="msg"> the message associated with the interaction</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 OnReceiveBoxInHouse(BoxInHouseMessage msg)
        {
            ILogicalTime time = timeFactory.Decode(msg.Time, 0);

            if (log.IsDebugEnabled)
            {
                log.Debug("Received BoxInHouseMessage [time = " + time + "]");
            }

            form.UpdateBoxInHouseTimeLabel(time);

            ObjectInstanceDescriptor oid = rti.descriptorManager.GetObjectInstanceDescriptor(home.InstanceHandle);
            IObjectClassHandle       och = oid.ClassHandle;
            ObjectClassDescriptor    ocd = rti.descriptorManager.GetObjectClassDescriptor(och);

            HLAattributeHandleValuePair[] handleValuePairList = new HLAattributeHandleValuePair[1];
            handleValuePairList[0] = new HLAattributeHandleValuePair();
            handleValuePairList[0].AttributeHandle = ((XRTIAttributeHandle)ocd.GetAttributeDescriptor("BoxesCount").Handle).Identifier;
            handleValuePairList[0].AttributeValue  = 1;

            rti.UpdateAttributeValues(home.InstanceHandle, handleValuePairList, new byte[1], time);
        }
Beispiel #17
0
        public override void DiscoverObjectInstance(IObjectInstanceHandle theObject, IObjectClassHandle theObjectClass, string objectName)
        {
            long instanceHandle = ((XRTIObjectInstanceHandle)theObject).Identifier;
            long classHandle    = ((XRTIObjectClassHandle)theObjectClass).Identifier;

            object proxy = rti.objectManager.CreateProxyObject(objectName, instanceHandle, classHandle);

            if (proxy != null)
            {
                RegisterObjectInstance(proxy);
            }
            else
            {
                throw new RTIinternalError("Type not found: " + objectName + ".");
            }
            if (OnNewObject != null)
            {
                if (log.IsInfoEnabled)
                {
                    log.Info("Discovered a new object: " + proxy);
                }
                OnNewObject(proxy);
            }
        }
Beispiel #18
0
 public virtual void StopRegistrationForObjectClass(IObjectClassHandle theClass)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Beispiel #19
0
 public DiscoverObjectInstanceCallback(IFederateAmbassador federate, ILogicalTime time, long federateHandle, long interactionIndex, IObjectInstanceHandle theObjectParam, IObjectClassHandle theObjectClassParam, string objectNameParam)
     : base(federate, time, federateHandle, interactionIndex)
 {
     this.theObject = theObjectParam;
     this.theObjectClass = theObjectClassParam;
     this.objectName = objectNameParam;
 }
Beispiel #20
0
 public DiscoverObjectInstanceCallback(IFederateAmbassador federate, IObjectInstanceHandle theObjectParam, IObjectClassHandle theObjectClassParam, string objectNameParam)
     : base(federate)
 {
     this.theObject = theObjectParam;
     this.theObjectClass = theObjectClassParam;
     this.objectName = objectNameParam;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="objClass">the object class description
 /// </param>
 /// <param name="pHandle">the handle of the object class
 /// </param>
 /// <param name="pParentDescriptors">the descriptors of the object class's parents
 /// </param>
 public ObjectClassDescriptor(Sxta.Rti1516.Reflection.HLAObjectClass objClass, IObjectClassHandle pHandle, List <ObjectClassDescriptor> pParentDescriptors)
 {
     objectDescription = objClass;
     handle            = pHandle;
     parentDescriptors = pParentDescriptors;
 }
Beispiel #22
0
 public virtual void StopRegistrationForObjectClass(IObjectClassHandle theClass)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Beispiel #23
0
 public virtual void DiscoverObjectInstance(IObjectInstanceHandle theObject, IObjectClassHandle theObjectClass, string objectName)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Beispiel #24
0
 /// <summary> Returns the descriptor for the object class with the given handle.
 /// 
 /// </summary>
 /// <param name="handle">the handle of the object class
 /// </param>
 /// <returns> the object class descriptor, or <code>null</code> if no such
 /// descriptor exists
 /// </returns>
 public virtual ObjectClassDescriptor GetObjectClassDescriptor(IObjectClassHandle handle)
 {
     return objectClassHandleDescriptorMap[handle];
 }
Beispiel #25
0
 /// <summary> 
 /// Checks whether the specified object class handle is a bootstrap
 /// handle.
 /// </summary>
 /// <param name="och">the object class handle to check
 /// </param>
 /// <returns> <code>true</code> if the handle is a bootstrap handle,
 /// <code>false</code> otherwise
 /// </returns>
 public virtual bool IsBootstrapHandle(IObjectClassHandle och)
 {
     return ((XRTIObjectClassHandle)och).Identifier < handleCounter;
 }
Beispiel #26
0
 public virtual void DiscoverObjectInstance(IObjectInstanceHandle theObject, IObjectClassHandle theObjectClass, string objectName)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 /// <summary> 
 /// Constructor.
 /// </summary>
 /// <param name="objClass">the object class description
 /// </param>
 /// <param name="pHandle">the handle of the object class
 /// </param>
 /// <param name="pParentDescriptors">the descriptors of the object class's parents
 /// </param>
 public ObjectClassDescriptor(Sxta.Rti1516.Reflection.HLAObjectClass objClass, IObjectClassHandle pHandle, List<ObjectClassDescriptor> pParentDescriptors)
 {
     objectDescription = objClass;
     handle = pHandle;
     parentDescriptors = pParentDescriptors;
 }