public RosMessageConstantDescriptor(int index, RosType rosType, string rosIdentifier, object value)
        {
            Index         = index;
            RosType       = rosType ?? throw new ArgumentNullException(nameof(rosType));
            RosIdentifier = rosIdentifier ?? throw new ArgumentNullException(nameof(rosIdentifier));
            Value         = value ?? throw new ArgumentNullException(nameof(value));

            if (!rosType.IsBuiltIn || rosType.IsArray)
            {
                throw new ArgumentOutOfRangeException(nameof(rosType), $"ROS type {rosType} is no supported constant type");
            }
        }
Esempio n. 2
0
        private static RosType GetRosFieldType(string rosType, string fallbackPackage)
        {
            var rosFieldType = RosType.Parse(rosType);

            // Add package definition for intra package type refs
            if (!rosFieldType.IsFullQualified)
            {
                rosFieldType = rosFieldType.ToFullQualifiedType(fallbackPackage);
            }

            return(rosFieldType);
        }
 private static RosType GetOrSetCacheItem(string type, RosType rosType)
 {
     lock (RosTypeCache)
     {
         if (RosTypeCache.TryGetValue(type, out var cachedType))
         {
             return(cachedType);
         }
         else
         {
             RosTypeCache.Add(type, rosType);
             return(rosType);
         }
     }
 }
Esempio n. 4
0
        public static Type GetSerializationType(RosType rosType)
        {
            if (RosTypeMappings.TryGetValue(rosType.TypeName, out var type))
            {
                Debug.Assert(type != null, nameof(type) + " != null");
                return(type);
            }

            // Type was not found. Maybe it was not a built in ros type
            if (!rosType.IsBuiltIn)
            {
                throw new InvalidOperationException($"ROS type {rosType} is not a built in ROS type.");
            }

            throw new InvalidOperationException($"ROS type {rosType} is not supported.");
        }
Esempio n. 5
0
        public RosMessageDescriptor(RosType rosType, IEnumerable <RosMessageFieldDescriptor> fields,
                                    IEnumerable <RosMessageConstantDescriptor> constants)
        {
            RosType = rosType ?? throw new ArgumentNullException(nameof(rosType));

            if (fields == null)
            {
                fields = Enumerable.Empty <RosMessageFieldDescriptor>();
            }

            if (constants == null)
            {
                constants = Enumerable.Empty <RosMessageConstantDescriptor>();
            }

            Fields = fields
                     .OrderBy(f => f.Index)
                     .ToList();

            Constants = constants
                        .OrderBy(c => c.Index)
                        .ToList();
        }
 protected bool Equals(RosType other)
 {
     return(PackageName == other.PackageName && TypeName == other.TypeName && IsBuiltIn == other.IsBuiltIn && IsArray == other.IsArray && ArraySize == other.ArraySize);
 }
Esempio n. 7
0
 protected RosMessageFieldDescriptor(int index, RosType rosType, string rosIdentifier)
 {
     Index         = index;
     RosType       = rosType ?? throw new ArgumentNullException(nameof(rosType));
     RosIdentifier = rosIdentifier ?? throw new ArgumentNullException(nameof(rosIdentifier));
 }
Esempio n. 8
0
 public void SetRosType(RosType rosType)
 {
     _rosType = rosType ?? throw new ArgumentNullException(nameof(rosType));
 }
 public DescriptorBasedRosServiceInfo(RosType type, DescriptorBasedMessageTypeInfo request, DescriptorBasedMessageTypeInfo response)
 {
     RosType = type ?? throw new ArgumentNullException(nameof(type));
     _request = request ?? throw new ArgumentNullException(nameof(request));
     _response = response ?? throw new ArgumentNullException(nameof(response));
 }
Esempio n. 10
0
 public PropertyRosMessageFieldDescriptor(int index, RosType rosType, string rosIdentifier,
                                          PropertyInfo mappedProperty) : base(index, rosType, rosIdentifier)
 {
     MappedProperty = mappedProperty ?? throw new ArgumentNullException(nameof(mappedProperty));
 }
Esempio n. 11
0
        public static RosMessageDescriptor Create(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var messageTypeAttribute = type.GetCustomAttributes(false)
                                       .OfType <RosMessageBaseAttribute>()
                                       .FirstOrDefault();

            if (messageTypeAttribute == null)
            {
                throw new NotSupportedException();
            }

            var descriptorBuilder = new RosMessageDescriptorBuilder();

            var rosType = RosType.Parse(messageTypeAttribute.MessageType);

            descriptorBuilder.SetRosType(rosType);

            // Get Fields from properties
            foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var rosFieldAttribute = GetRosMessageFieldAttribute(property);

                if (rosFieldAttribute == null)
                {
                    continue;
                }

                var rosFieldType  = GetRosFieldType(rosFieldAttribute.RosType, rosType.PackageName);
                var rosIdentifier = rosFieldAttribute.RosIdentifier ?? property.Name;

                var fieldDescriptor = new PropertyRosMessageFieldDescriptor(rosFieldAttribute.Index, rosFieldType,
                                                                            rosIdentifier, property);

                descriptorBuilder.Add(fieldDescriptor);
            }

            // Get Fields from fields
            foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public))
            {
                var rosFieldAttribute = GetRosMessageFieldAttribute(field);

                if (rosFieldAttribute == null)
                {
                    continue;
                }

                var rosFieldType  = GetRosFieldType(rosFieldAttribute.RosType, rosType.PackageName);
                var rosIdentifier = rosFieldAttribute.RosIdentifier ?? field.Name;

                var fieldDescriptor = new FieldRosMessageFieldDescriptor(rosFieldAttribute.Index, rosFieldType,
                                                                         rosIdentifier, field);

                descriptorBuilder.Add(fieldDescriptor);
            }

            // Get Constants
            foreach (var constant in GetConstants(type))
            {
                var rosConstantAttribute = constant.GetCustomAttributes(false)
                                           .OfType <RosMessageFieldAttribute>()
                                           .FirstOrDefault();

                if (rosConstantAttribute == null)
                {
                    continue;
                }

                var rosConstantType    = RosType.Parse(rosConstantAttribute.RosType);
                var constantValue      = constant.GetValue(null);
                var constantDescriptor = new RosMessageConstantDescriptor(rosConstantAttribute.Index, rosConstantType,
                                                                          rosConstantAttribute.RosIdentifier, constantValue);

                descriptorBuilder.Add(constantDescriptor);
            }


            return(descriptorBuilder.Build());
        }
 public FieldRosMessageFieldDescriptor(int index, RosType rosType, string rosIdentifier,
                                       FieldInfo mappedField) : base(index, rosType, rosIdentifier)
 {
     MappedField = mappedField ?? throw new ArgumentNullException(nameof(mappedField));
 }
 public override string ToString()
 {
     return(RosType.ToString());
 }