Пример #1
0
        ///<summary>
        /// Writes this HLAattributeHandleValuePair 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="IOException"> if an error occurs</exception>
        public override void Serialize(HlaEncodingWriter writer, object obj)
        {
            HLAattributeHandleValuePair attributeHandleValue = (HLAattributeHandleValuePair)obj;

            writer.WriteHLAinteger64BE(attributeHandleValue.AttributeHandle);
            serializerManager.GetSerializer(attributeHandleValue.AttributeHandle).Serialize(writer, attributeHandleValue.AttributeValue);
        }
Пример #2
0
        ///<summary>
        /// Reads and returns a HLAattributeHandleValuePair from the specified stream.
        ///</summary>
        ///<param name="reader"> the input stream to read from</param>
        ///<returns> the decoded value</returns>
        ///<exception cref="IOException"> if an error occurs</exception>
        public override object Deserialize(HlaEncodingReader reader, ref object msg)
        {
            if (msg.Equals(BaseInteractionMessage.NullBaseInteractionMessage))
            {
                msg = new HLAattributeHandleValuePair();
            }
            HLAattributeHandleValuePair decodedValue = msg as HLAattributeHandleValuePair;

            decodedValue.AttributeHandle = reader.ReadHLAinteger64BE();
            object tmp = BaseInteractionMessage.NullBaseInteractionMessage;

            decodedValue.AttributeValue = serializerManager.GetSerializer(decodedValue.AttributeHandle).Deserialize(reader, ref tmp);
            return(decodedValue);
        }
        ///<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);
        }
 ///<summary> Copy constructor. </summary>
 ///<param name="other"> the other HLAattributeHandleValuePair to copy</param>
 public HLAattributeHandleValuePair(HLAattributeHandleValuePair other)
 {
     this.attributeHandle = other.attributeHandle;
     this.attributeValue = other.attributeValue;
 }
 ///<summary>
 /// Reads and returns a HLAattributeHandleValuePair from the specified stream.
 ///</summary>
 ///<param name="reader"> the input stream to read from</param>
 ///<returns> the decoded value</returns>
 ///<exception cref="IOException"> if an error occurs</exception>
 public override object Deserialize(HlaEncodingReader reader, ref object msg)
 {
     if (msg.Equals(BaseInteractionMessage.NullBaseInteractionMessage))
     {
         msg = new HLAattributeHandleValuePair();
     }
     HLAattributeHandleValuePair decodedValue = msg as HLAattributeHandleValuePair;
     decodedValue.AttributeHandle = reader.ReadHLAinteger64BE();
     object tmp = BaseInteractionMessage.NullBaseInteractionMessage;
     decodedValue.AttributeValue = serializerManager.GetSerializer(decodedValue.AttributeHandle).Deserialize(reader, ref tmp);
     return decodedValue;
 }
        protected void SendInfoAboutObjects(IList<HLAobjectRoot> objects, HLAsubscribeObjectClassAttributesMessage msg)
        {
            foreach (HLAobjectRoot obj in objects)
            {
                // if it is a local object and its class handle is equal to the object class handle sent
                if (obj.HLAprivilegeToDeleteObject && obj.ClassHandle.Equals(msg.HLAobjectClass))
                {
                    parent.RegisterObjectInstance(obj);

                    IList<HLAattributeHandleValuePair> propertyValuePair = new List<HLAattributeHandleValuePair>();

                    // TODO ANGEL: Esto es incorrecto y esta mal. Puede haber propiedades que no sean remotas
                    foreach (IAttributeHandle attribute in msg.HLAattributeList)
                    {
                        AttributeDescriptor ad = parent.descriptorManager.GetAttributeDescriptor(attribute);
                        if (ad == null)
                        {
                            throw new InvalidAttributeHandle(attribute.ToString());
                        }
                        else
                        {
                            PropertyInfo pi = obj.GetType().BaseType.GetProperty(ad.Name);

                            if (!ad.Name.Equals("HLAprivilegeToDeleteObject") && pi != null)
                            {
                                object value = pi.GetValue(obj, null);

                                if (value != null)
                                {
                                    propertyValuePair.Add(new HLAattributeHandleValuePair(((XRTIAttributeHandle)ad.Handle).Identifier, value));
                                }
                            }
                        }
                    }

                    HLAattributeHandleValuePair[] propertyValuePairArray = new HLAattributeHandleValuePair[propertyValuePair.Count];
                    propertyValuePair.CopyTo(propertyValuePairArray, 0);

                    // TODO ANGEL: Que pasa con el userTag
                    parent.UpdateAttributeValues(obj.InstanceHandle, propertyValuePairArray, null);
                }
            }
        }
Пример #7
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;
        }
Пример #8
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;
        }
Пример #9
0
 public override void ReflectAttributeValuesExt(IObjectInstanceHandle theObject, HLAattributeHandleValuePair[] theAttributes, byte[] userSuppliedTag, OrderType sentOrdering, TransportationType theTransport)
 {
     // TODO ANGEL: LOCK DUDOSO
     //lock (this)
     //{
     if (objectInstanceHandleProxyMap.ContainsKey(theObject))
     {
         object instance = objectInstanceHandleProxyMap[theObject];
         rti.objectManager.UpdateAttributeValuesProxyObject(instance, theAttributes);
     }
     else
     {
         if (log.IsErrorEnabled)
             log.Error("Object " + theObject + " not found. Attributes to reflect: " + theAttributes);
     }
     //}
 }
        private void AddCallbackUpdateAttributeValues(HLAattributeHandleValuePair[] handleValuePairList, long objectInstanceHandle, byte[] userSuppliedTag, long federateHandle, long interactionIndex, ILogicalTime time)
        {
            if (parent.State != null)
            {
                Lrc.ReflectAttributeValuesExtCallback callback =
                    new Lrc.ReflectAttributeValuesExtCallback(this.parent.FederateAmbassador,
                        time, federateHandle, interactionIndex, new XRTIObjectInstanceHandle(objectInstanceHandle),
                            handleValuePairList, userSuppliedTag);

                parent.lrc.AddCallback(callback);
            }
        }
Пример #11
0
 public ReflectAttributeValuesExtCallback(IFederateAmbassador federate, ILogicalTime time, long federateHandle, long interactionIndex, IObjectInstanceHandle theObjectParam, HLAattributeHandleValuePair[] theAttributesParam, byte[] userSuppliedTagParam)
     : base(federate, time, federateHandle, interactionIndex)
 {
     this.theObject = theObjectParam;
     this.theAttributes = theAttributesParam;
     this.userSuppliedTag = userSuppliedTagParam;
 }
Пример #12
0
 public ReflectAttributeValuesExtCallback(IFederateAmbassador federate, IObjectInstanceHandle theObjectParam, HLAattributeHandleValuePair[] theAttributesParam, byte[] userSuppliedTagParam)
     : base(federate)
 {
     this.theObject = theObjectParam;
     this.theAttributes = theAttributesParam;
     this.userSuppliedTag = userSuppliedTagParam;
 }
Пример #13
0
 // TODO ANGEL: Se añade un método de actualización específico para las propiedades de los objetos.
 //             Es debido a que usaban un IAttributeHandleValueMap que imponía una serie de problemas: implicaba la conversión de los values de object a byte[]
 public virtual void ReflectAttributeValuesExt(IObjectInstanceHandle theObject, HLAattributeHandleValuePair[] theAttributes, byte[] userSuppliedTag, OrderType sentOrdering, TransportationType theTransport)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Пример #14
0
 ///<summary> Copy constructor. </summary>
 ///<param name="other"> the other HLAattributeHandleValuePair to copy</param>
 public HLAattributeHandleValuePair(HLAattributeHandleValuePair other)
 {
     this.attributeHandle = other.attributeHandle;
     this.attributeValue  = other.attributeValue;
 }
Пример #15
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();
                            }
                            */
                        }
                    }
                }
            }
        }
Пример #16
0
        public object UpdateAttributeValuesProxyObject(object instance, HLAattributeHandleValuePair[] methodNameValueMap)
        {
            if (instance is HLAobjectRoot)
            {
                HLAobjectRoot obj = instance as HLAobjectRoot;
                ObjectClassDescriptor ocd = descriptorManager.GetObjectClassDescriptor(obj.ClassHandle);
                foreach (HLAattributeHandleValuePair entry in methodNameValueMap)
                {
                    if (log.IsDebugEnabled)
                        log.Debug("The method " + entry.AttributeHandle + " from object " + obj.InstanceHandle +
                            " has been called; new value:" + entry.AttributeValue + "; parameter type = " + entry.AttributeValue.GetType());

                    string attrName = ocd.GetAttributeDescriptor(new XRTIAttributeHandle(entry.AttributeHandle)).Name;
                    HLAAttributeAttribute attr = obj.AttrTable[attrName];
                    attr.propInfo.GetSetMethod().Invoke(obj, new object[] { entry.AttributeValue });
                    //obj.GetType().BaseType.GetProperty(attrName).GetSetMethod().Invoke(obj, new object[] { entry.AttributeValue });
                }
            }

            return instance;
        }