예제 #1
0
 public ExpectedServiceElement(ElementType elementType, ElementTypeDescriptor etd, Object value)
 {
     if (!ServiceRecordParser.TypeMatchesEtd(etd, elementType))
     {
         throw new ArgumentException(String.Format(
                                         "Test setup; ElementType does not match TypeDescriptor ({0}/{1}).",
                                         elementType, etd));
     }
     this.ElementType = elementType;
     this.Etd         = etd;
     //
     if (value != null)   // Can't check types when the value is null.
     {
         if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative)
         {
             if (typeof(ExpectedServiceElement[]) != value.GetType())
             {
                 throw new ArgumentException("DataElementSequence and DataElementAlternative need an array of ExpectedAttributeValue.");
             }
             this.Children = (ExpectedServiceElement[])value;
         }
         else
         {
             if (typeof(ExpectedServiceElement[]) == value.GetType())
             {
                 throw new ArgumentException("DataElementSequence and DataElementAlternative must be used for an array of ExpectedAttributeValue.");
             }
             this.Value = value;
         }
     }
 }
        //----
        protected override int MakeVariableLengthHeader(byte[] buf, int offset,
                                                        ElementTypeDescriptor etd, out HeaderWriteState headerState)
        {
            bool seqOrAltToStore = false;

            if (!this.aboveBase)
            {
                Debug.Assert(etd == ElementTypeDescriptor.ElementSequence,
                             "Outer element is a SEQ!  Or are we called elsewhere!?");
                this.aboveBase = true;
            }
            else if (this.isInSeqOrAlt)
            {
                // Child of a SEQ/ALT, will be written from byte buffer.
            }
            else if (etd == ElementTypeDescriptor.ElementSequence ||
                     etd == ElementTypeDescriptor.ElementAlternative)
            {
                seqOrAltToStore = true;
            }
            //
            int ret = base.MakeVariableLengthHeader(buf, offset, etd, out headerState);

            //
            if (seqOrAltToStore)
            {
                this.isInSeqOrAlt = true; // Ignore individual elements
                headerState.widcommNeedsStoring = true;
            }
            return(ret);
        }
예제 #3
0
        //--------------------------------------------------------------

        /// <summary>
        /// Obsolete, use <see cref="M:InTheHand.Net.Bluetooth.ServiceElement.#ctor(InTheHand.Net.Bluetooth.ElementType,System.Object)"/> instead.
        /// Initializes a new instance of the <see cref="T:InTheHand.Net.Bluetooth.ServiceElement"/> class.
        /// </summary>
        internal ServiceElement(ElementTypeDescriptor etd, ElementType type, Object value)
        {
            ServiceRecordParser.VerifyTypeMatchesEtd(etd, type);
            m_type = type;
            m_etd  = etd;
            SetValue(value);
        }
예제 #4
0
 protected virtual int MakeVariableLengthHeader(byte[] buf, int offset, ElementTypeDescriptor elementTypeDescriptor, out HeaderWriteState headerState)
 {
     HackFxCopHintNonStaticMethod();
     // We only support one-byte length fields (currently?).
     headerState = new HeaderWriteState(elementTypeDescriptor, buf, offset, SizeIndex.AdditionalUInt8, 2);
     return(headerState.HeaderLength);
 }
예제 #5
0
        private static byte CreateHeaderByte(ElementTypeDescriptor etd, SizeIndex sizeIndex)
        {
            System.Diagnostics.Debug.Assert((int)etd < 32);
            byte headerByte = (byte)((int)etd << ServiceRecordParser.ElementTypeDescriptorOffset);

            System.Diagnostics.Debug.Assert((int)sizeIndex < 8);
            headerByte |= (byte)sizeIndex;
            return(headerByte);
        }
예제 #6
0
        private int WriteHeaderFixedLength(ElementTypeDescriptor elementTypeDescriptor, int contentLength,
                                           byte[] buf, int offset,
                                           out int totalLength)
        {
            SizeIndex sizeIndex = FixedLengthToSizeIndex(contentLength);
            int       len       = WriteHeaderFixedLength_(elementTypeDescriptor, contentLength, sizeIndex, buf, offset, out totalLength);

            return(len);
        }
예제 #7
0
 internal HeaderWriteState(ElementTypeDescriptor elementTypeDescriptor, byte[] buf, int offset, SizeIndex sizeIndex, int headerLength)
 {
     this.Etd          = elementTypeDescriptor;
     this.HeaderOffset = offset;
     this.SizeIndex    = sizeIndex;
     this.HeaderLength = headerLength;
     //
     VerifyWriteSpaceRemaining(HeaderLength, buf, offset);
     ServiceRecordParser.VerifyAllowedSizeIndex(Etd, SizeIndex, false);
 }
예제 #8
0
 public static IAttributeBuilder CreateBuilder(this ElementTypeDescriptor descriptor,
                                               Attribute[] attributes,
                                               PropertyDescriptorCollection propertyDescriptors,
                                               Func <ModelElement, bool> appliedToElement)
 {
     return(appliedToElement(descriptor.ModelElement)
                ? (IAttributeBuilder)
            new AttributeBuilderImplementation(descriptor, attributes, propertyDescriptors,
                                               descriptor.ModelElement)
                : new AttributeBuilderNop(propertyDescriptors, descriptor.ModelElement));
 }
        public DomainEnumPropertyDescriptor(ElementTypeDescriptor owner, ModelElement modelElement, DomainPropertyInfo domainProperty, DomainEnumeration domainEnum, Attribute[] attributes)
            : base(owner, modelElement, domainProperty, attributes)
        {
            this.domainEnum = domainEnum;

            System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
            foreach(EnumerationLiteral enumerationLiteral in this.domainEnum.Literals)
                list.Add(enumerationLiteral.Name);
            
            enumFields = list.AsReadOnly();
        }
        public DomainEnumPropertyDescriptor(ElementTypeDescriptor owner, ModelElement modelElement, DomainPropertyInfo domainProperty, DomainEnumeration domainEnum, Attribute[] attributes)
            : base(owner, modelElement, domainProperty, attributes)
        {
            this.domainEnum = domainEnum;

            System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>();
            foreach (EnumerationLiteral enumerationLiteral in this.domainEnum.Literals)
            {
                list.Add(enumerationLiteral.Name);
            }

            enumFields = list.AsReadOnly();
        }
예제 #11
0
        //--------------------------------------------------------------

        /// <summary>
        /// Create an instance of <see cref="T:InTheHand.Net.Bluetooth.ServiceElement"/>
        /// but internally converting the numeric value to the required type.
        /// </summary>
        /// -
        /// <remarks>
        /// <para>As noted in the constructor documentation
        /// (<see cref="M:InTheHand.Net.Bluetooth.ServiceElement.#ctor(InTheHand.Net.Bluetooth.ElementType,System.Object)"/>)
        /// the type of the value supplied <strong>must</strong> exactly match the element's natural type,
        /// the contructor will return an error if that is not the case. This method
        /// will instead attempt to convert the value to the required type.  It uses
        /// the <see cref="T:System.IConvertible"/> interface to do the conversion, for
        /// instance if the element type is <c>Uint16</c> then it will cast the input value
        /// to <see cref="T:System.IConvertible"/> and call
        /// <see cref="M:System.IConvertible.ToUInt16(System.IFormatProvider)"/> on it.
        /// If the value is not convertible to the element type then an
        /// <see cref="T:System.ArgumentOutOfRangeException"/> will be thrown see below.
        /// </para>
        /// <para>For instance, passing in an C# <c>int</c> / Visual Basic <c>Integer</c>
        /// to the constructor will fail for element types <see cref="F:InTheHand.Net.Bluetooth.ElementType.UInt8"/>
        /// etc, however by using this method it will succeed if the value is in the
        /// correct range.
        /// For example
        /// <code lang="C#">
        /// int i = 10;
        /// int j = -1;
        ///
        /// // Error, Int32 not suitable for element type UInt8.
        /// ServiceElement e0 = new ServiceElement(ElementType.UInt8, i);
        ///
        /// // Success, Byte value 10 stored.
        /// ServiceElement e1 = ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, i);
        ///
        /// // Error, -1 not in range of type Byte.
        /// ServiceElement e2 = ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, j);
        /// </code>
        /// The last example failing with:
        /// <code lang="none">
        /// System.ArgumentOutOfRangeException: Value '-1'  of type 'System.Int32' not valid for element type UInt16.
        ///  ---> System.OverflowException: Value was either too large or too small for a UInt16.
        ///    at System.Convert.ToUInt16(Int32 value)
        ///    at System.Int32.System.IConvertible.ToUInt16(IFormatProvider provider)
        ///    at InTheHand.Net.Bluetooth.ServiceElement.ConvertNumericalValue(ElementType elementType, Object value)
        ///    --- End of inner exception stack trace ---
        ///    at InTheHand.Net.Bluetooth.ServiceElement.ConvertNumericalValue(ElementType elementType, Object value)
        ///    at InTheHand.Net.Bluetooth.ServiceElement.CreateNumericalServiceElement(ElementType elementType, Object value)
        ///    at MiscFeatureTestCs.Main(String[] args)
        /// </code>
        /// </para>
        /// </remarks>
        /// -
        /// <param name="elementType">The type of the element as an ElementType.
        /// Should be one of the <c>UnsignedInteger</c>/<c>TwosComplementInteger</c> types.
        /// </param>
        /// <param name="value">The value for the new element,
        /// should be a numerical type.
        /// </param>
        /// -
        /// <returns>The new element.
        /// </returns>
        /// -
        /// <exception cref="T:System.ArgumentException">
        /// The <paramref name="elementType"/> is not a numerical type.
        /// </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// The value wasn&#x2019;t convertible to the required type, e.g. if -1 is
        /// passed for element type UInt8, as shown above.
        /// </exception>
        public static ServiceElement CreateNumericalServiceElement(ElementType elementType, object value)
        {
            ElementTypeDescriptor etd = GetEtdForType(elementType);

            if (!(etd == ElementTypeDescriptor.UnsignedInteger ||
                  etd == ElementTypeDescriptor.TwosComplementInteger))
            {
                throw new ArgumentException(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                          ErrorMsgFmtCreateNumericalGivenNonNumber,
                                                          etd /*, (int)etd, elementType, (int)elementType*/));
            }
            object valueConverted = ConvertNumericalValue(elementType, value);

            return(new ServiceElement(elementType, valueConverted));
        }
예제 #12
0
        private int WriteHeaderFixedLength_(ElementTypeDescriptor elementTypeDescriptor, int contentLength, SizeIndex sizeIndex,
                                            byte[] buf, int offset,
                                            out int totalLength)
        {
            System.Diagnostics.Debug.Assert(
                sizeIndex == SizeIndex.LengthOneByteOrNil ||
                sizeIndex == SizeIndex.LengthTwoBytes ||
                sizeIndex == SizeIndex.LengthFourBytes ||
                sizeIndex == SizeIndex.LengthEightBytes ||
                sizeIndex == SizeIndex.LengthSixteenBytes);
            ServiceRecordParser.VerifyAllowedSizeIndex(elementTypeDescriptor, sizeIndex, false);
            HeaderWriteState headerState = new HeaderWriteState(elementTypeDescriptor, buf, offset, sizeIndex, 1);

            CompleteHeaderWrite(headerState, buf, offset + contentLength + headerState.HeaderLength, out totalLength);
            return(headerState.HeaderLength);
        }
예제 #13
0
        /// <summary>
        /// Add a custom attribute of simple type.
        /// </summary>
        /// -
        /// <remarks>
        /// <para>If the <paramref name="elementType"/> is a numerical type
        /// then this is equivalent to using
        /// <see cref="M:InTheHand.Net.Bluetooth.ServiceElement.CreateNumericalServiceElement(InTheHand.Net.Bluetooth.ElementType,System.Object)"/>
        /// otherwise the value is used directly in creating the
        /// <see cref="T:InTheHand.Net.Bluetooth.ServiceElement"/>.
        /// </para>
        /// </remarks>
        /// -
        /// <param name="id">The Attribute Id as a <see cref="T:InTheHand.Net.Bluetooth.ServiceAttributeId"/>.</param>
        /// <param name="elementType">The type of the element as an <see cref="T:InTheHand.Net.Bluetooth.ElementType"/>.</param>
        /// <param name="value">The value for the new element.</param>
        public void AddCustomAttribute(ServiceAttributeId id, ElementType elementType, object value)
        {
            ServiceElement        e;
            ElementTypeDescriptor etd = ServiceRecordParser.GetEtdForType(elementType);

            if ((etd == ElementTypeDescriptor.UnsignedInteger ||
                 etd == ElementTypeDescriptor.TwosComplementInteger))
            {
                e = ServiceElement.CreateNumericalServiceElement(elementType, value);
            }
            else
            {
                e = new ServiceElement(elementType, value);
            }
            this.AddCustomAttribute(new ServiceAttribute(id, e));
        }
        //--------

        private static SdpService.DESC_TYPE ToDESC_TYPE(ElementTypeDescriptor elementTypeDescriptor)
        {
            // This is actually a one-to-one exact match, so no need for this map
            // but leave, as it allows us to block Nil for instance.
            SdpService.DESC_TYPE dt;
            switch (elementTypeDescriptor)
            {
            case ElementTypeDescriptor.UnsignedInteger:
                dt = SdpService.DESC_TYPE.UINT;
                break;

            case ElementTypeDescriptor.TwosComplementInteger:
                dt = SdpService.DESC_TYPE.TWO_COMP_INT;
                break;

            case ElementTypeDescriptor.Uuid:
                dt = SdpService.DESC_TYPE.UUID;
                break;

            case ElementTypeDescriptor.TextString:
                dt = SdpService.DESC_TYPE.TEXT_STR;
                break;

            case ElementTypeDescriptor.Boolean:
                dt = SdpService.DESC_TYPE.BOOLEAN;
                break;

            case ElementTypeDescriptor.ElementSequence:
                dt = SdpService.DESC_TYPE.DATA_ELE_SEQ;
                break;

            case ElementTypeDescriptor.ElementAlternative:
                dt = SdpService.DESC_TYPE.DATA_ELE_ALT;
                break;

            case ElementTypeDescriptor.Url:
                dt = SdpService.DESC_TYPE.URL;
                break;

            //
            case ElementTypeDescriptor.Unknown:
            case ElementTypeDescriptor.Nil:
            default:
                throw new ArgumentException("ToDESC_TYPE(" + elementTypeDescriptor + ")");
            }
            return(dt);
        }
예제 #15
0
            public AttributeBuilderImplementation(ElementTypeDescriptor descriptor, Attribute[] attributes,
                                                  PropertyDescriptorCollection propertyDescriptors, ModelElement appliedTo)
            {
                this.Element         = appliedTo;
                this.descriptor      = descriptor;
                this.outerAttributes = attributes;

                this.propertyDescriptors = propertyDescriptors;// descriptor.GetProperties(attributes);
                //this.modelElement = descriptor.ModelElement;

                if (this.Element != null)
                {
                    List <PropertyDescriptor> elementPropertyDescriptors =
                        propertyDescriptors.OfType <ElementPropertyDescriptor>().Cast <PropertyDescriptor>().ToList();
                    processingPropertyDescriptors.Add(ProcessPropertyType.Element, elementPropertyDescriptors);

                    List <PropertyDescriptor> rolePlayerPropertyDescriptors =
                        propertyDescriptors.OfType <RolePlayerPropertyDescriptor>().Cast <PropertyDescriptor>().ToList();
                    processingPropertyDescriptors.Add(ProcessPropertyType.RolePlayer, rolePlayerPropertyDescriptors);
                }
            }
예제 #16
0
        private void DoTest(ElementTypeDescriptor expectedEtd, SizeIndex expectedSizeIndex, byte headerByte)
        {
            ServiceRecordParser parser = new ServiceRecordParser();
            //
            // Test the (original) individual methods.
            ElementTypeDescriptor resultEtd = ServiceRecordParser.GetElementTypeDescriptor(headerByte);

            Assert.AreEqual(expectedEtd, resultEtd);
            //
            SizeIndex resultSI = ServiceRecordParser.GetSizeIndex(headerByte);

            Assert.AreEqual(expectedSizeIndex, resultSI);
            //
            // Test the single method (which calls each of the individual methods).
            ElementTypeDescriptor resultEtd2;
            SizeIndex             resultSI2;

            ServiceRecordParser.SplitHeaderByte(headerByte, out resultEtd2, out resultSI2);
            Assert.AreEqual(expectedEtd, resultEtd2);
            Assert.AreEqual(expectedSizeIndex, resultSI2);
        }
예제 #17
0
 private int WriteHeaderFixedLength(ElementTypeDescriptor elementTypeDescriptor, int contentLength,
     byte[] buf, int offset,
     out int totalLength)
 {
     SizeIndex sizeIndex = FixedLengthToSizeIndex(contentLength);
     int len = WriteHeaderFixedLength_(elementTypeDescriptor, contentLength, sizeIndex, buf, offset, out totalLength);
     return len;
 }
예제 #18
0
        internal void SetValue(object value)
        {
            ElementTypeDescriptor etd  = m_etd;
            ElementType           type = m_type;

            //
            if (value == null)
            {
                if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative)
                {
                    throw new ArgumentNullException("value", "Type DataElementSequence and DataElementAlternative need an list of AttributeValue.");
                }
                else if (etd == ElementTypeDescriptor.Nil)
                {
                }
                else if (etd == ElementTypeDescriptor.Unknown)
                {
                }
                else
                {
                    throw new ArgumentNullException("value", "Null not valid for type: '" + type + "'.");
                }
            }
            else
            {
                IList <ServiceElement> asElementList = value as IList <ServiceElement>;
                if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative)
                {
                    if (asElementList == null)
                    {
                        throw new ArgumentException("Type ElementSequence and ElementAlternative need an list of ServiceElement.");
                    }
                }
                else
                {
                    if (asElementList != null)
                    {
                        throw new ArgumentException("Type ElementSequence and ElementAlternative must be used for an list of ServiceElement.");
                    }
                }
                //--------
                bool validTypeForType;
                if (type == ElementType.Nil)
                {
                    validTypeForType = value == null;
                }
                else if (etd == ElementTypeDescriptor.UnsignedInteger || etd == ElementTypeDescriptor.TwosComplementInteger)
                {
                    switch (type)
                    {
                    case ElementType.UInt8:
                        validTypeForType = value is byte;
                        break;

                    case ElementType.Int8:
                        validTypeForType = value is sbyte;
                        break;

                    case ElementType.UInt16:
                        validTypeForType = value is ushort;
                        break;

                    case ElementType.Int16:
                        validTypeForType = value is short;
                        break;

                    case ElementType.UInt32:
                        validTypeForType = value is uint;
                        break;

                    case ElementType.Int32:
                        validTypeForType = value is int;
                        break;

                    case ElementType.UInt64:
                        validTypeForType = value is ulong;
                        break;

                    case ElementType.Int64:
                        validTypeForType = value is long;
                        break;

                    case ElementType.UInt128:
                    case ElementType.Int128:
                        const int NumBytesIn128bits = 16;
                        if (value is byte[] arr && arr.Length == NumBytesIn128bits)
                        {
                            validTypeForType = true;
                        }
                        else
                        {     // HACK UNTESTED
                            validTypeForType = false;
                            throw new ArgumentException(
                                      "Element type '" + type + "' needs a length 16 byte array.");
                        }
                        break;
예제 #19
0
 private int MakeVariableLengthHeader(byte[] buf, int offset, ElementTypeDescriptor elementTypeDescriptor, out HeaderWriteState headerState)
 {
     HackFxCopHintNonStaticMethod();
     // We only support one-byte length fields (currently?).
     headerState = new HeaderWriteState(elementTypeDescriptor, buf, offset, SizeIndex.AdditionalUInt8, 2);
     return headerState.HeaderLength;
 }
예제 #20
0
        private static void Map(StackConsts.SDP_Data_Element_Type sdpDataElementType,
                                out ElementTypeDescriptor etd, out SizeIndex sizeIndex)
        {
            const SizeIndex NotUsed = SizeIndex.LengthOneByteOrNil;

            switch (sdpDataElementType)
            {
            // Signed/Unsigned Integer
            case StackConsts.SDP_Data_Element_Type.UnsignedInteger1Byte:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            case StackConsts.SDP_Data_Element_Type.SignedInteger1Byte:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            case StackConsts.SDP_Data_Element_Type.UnsignedInteger2Bytes:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthTwoBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.SignedInteger2Bytes:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthTwoBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.UnsignedInteger4Bytes:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthFourBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.SignedInteger4Bytes:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthFourBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.UnsignedInteger8Bytes:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthEightBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.SignedInteger8Bytes:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthEightBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.UnsignedInteger16Bytes:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthSixteenBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.SignedInteger16Bytes:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthSixteenBytes;
                break;

            // Strings
            case StackConsts.SDP_Data_Element_Type.TextString:
                etd       = ElementTypeDescriptor.TextString;
                sizeIndex = NotUsed;
                break;

            case StackConsts.SDP_Data_Element_Type.URL:
                etd       = ElementTypeDescriptor.Url;
                sizeIndex = NotUsed;
                break;

            // UUID
            case StackConsts.SDP_Data_Element_Type.UUID_16:
                etd       = ElementTypeDescriptor.Uuid;
                sizeIndex = SizeIndex.LengthTwoBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.UUID_32:
                etd       = ElementTypeDescriptor.Uuid;
                sizeIndex = SizeIndex.LengthTwoBytes;
                break;

            case StackConsts.SDP_Data_Element_Type.UUID_128:
                etd       = ElementTypeDescriptor.Uuid;
                sizeIndex = SizeIndex.LengthFourBytes;
                break;

            // Seq/Alt
            case StackConsts.SDP_Data_Element_Type.Sequence:
                etd       = ElementTypeDescriptor.ElementSequence;
                sizeIndex = NotUsed;
                break;

            case StackConsts.SDP_Data_Element_Type.Alternative:
                etd       = ElementTypeDescriptor.ElementAlternative;
                sizeIndex = NotUsed;
                break;

            // Nil/Boolean/etc.
            case StackConsts.SDP_Data_Element_Type.Boolean:
                etd       = ElementTypeDescriptor.Boolean;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            case StackConsts.SDP_Data_Element_Type.NIL:
                etd       = ElementTypeDescriptor.Nil;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            case StackConsts.SDP_Data_Element_Type.NULL:
                Debug.Fail("SDP_Data_Element_Type.deNULL");
                etd       = ElementTypeDescriptor.Unknown;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            //
            default:
                Debug.Fail("Unexpected SDP_Data_Element_Type: 0x" + ((int)sdpDataElementType).ToString("X"));
                etd       = ElementTypeDescriptor.Unknown;
                sizeIndex = SizeIndex.AdditionalUInt32;
                break;
            }
        }
예제 #21
0
 private int WriteHeaderFixedLength_(ElementTypeDescriptor elementTypeDescriptor, int contentLength, SizeIndex sizeIndex,
     byte[] buf, int offset,
     out int totalLength)
 {
     System.Diagnostics.Debug.Assert(
         sizeIndex == SizeIndex.LengthOneByteOrNil
         || sizeIndex == SizeIndex.LengthTwoBytes
         || sizeIndex == SizeIndex.LengthFourBytes
         || sizeIndex == SizeIndex.LengthEightBytes
         || sizeIndex == SizeIndex.LengthSixteenBytes);
     ServiceRecordParser.VerifyAllowedSizeIndex(elementTypeDescriptor, sizeIndex, false);
     HeaderWriteState headerState = new HeaderWriteState(elementTypeDescriptor, buf, offset, sizeIndex, 1);
     CompleteHeaderWrite(headerState, buf, offset + contentLength + headerState.HeaderLength, out totalLength);
     return headerState.HeaderLength;
 }
예제 #22
0
        internal void SetValue(Object value)
        {
            ElementTypeDescriptor etd  = m_etd;
            ElementType           type = m_type;

            //
            if (value == null)
            {
                if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative)
                {
                    throw new ArgumentNullException("value", "Type DataElementSequence and DataElementAlternative need an list of AttributeValue.");
                }
                else if (etd == ElementTypeDescriptor.Nil)
                {
                }
                else if (etd == ElementTypeDescriptor.Unknown)
                {
                }
                else
                {
                    throw new ArgumentNullException("value", "Null not valid for type: '" + type + "'.");
                }
            }
            else
            {
                // Check iff type=seq/alt then value is IList<ServiceElement>
#if V1
#if DEBUG
                //Type t1 = value.GetType();
                //string st1 = t1.Name;
                //Type t2 = null;
                //string st2 = null;
                //string j = null;
                //try {
                //    Array a = (Array)value;
                //    object item = a.GetValue(0);
                //    t2 = value.GetType();
                //    st2 = t2.Name;
                //} catch (Exception) {
                //    j = string.Empty;
                //}
                //Console.WriteLine("" + st1 + " / " + st2 + " " + j);
#endif
                IList asElementList;
                // Parser passes in an ArrayList
                asElementList = value as ArrayList;
                if (asElementList == null)
                {
                    // .ctor(ElementType type, params ServiceElement[] childElements)
                    asElementList = value as ServiceElement[];
                }
                if (asElementList != null)
                {
                    // Ensure that the above casting won't pick up the byte[] for TextString etc.
                    System.Diagnostics.Debug.Assert(!(value is byte[]));
                    foreach (object item in asElementList)
                    {
                        //System.Diagnostics.Debug.Assert(item is ServiceElement);
                        if (!(item is ServiceElement))
                        {
                            throw new ArgumentException(ErrorMsgListContainsNotElement);
                        }
                    }
                }
#else
                IList <ServiceElement> asElementList = value as IList <ServiceElement>;
#endif
                if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative)
                {
                    if (asElementList == null)
                    {
                        throw new ArgumentException("Type ElementSequence and ElementAlternative need an list of ServiceElement.");
                    }
                }
                else
                {
                    if (asElementList != null)
                    {
                        throw new ArgumentException("Type ElementSequence and ElementAlternative must be used for an list of ServiceElement.");
                    }
                }
                //--------
                bool validTypeForType;
                if (type == ElementType.Nil)
                {
                    validTypeForType = value == null;
                }
                else if (etd == ElementTypeDescriptor.UnsignedInteger || etd == ElementTypeDescriptor.TwosComplementInteger)
                {
                    switch (type)
                    {
                    case ElementType.UInt8:
                        validTypeForType = value is Byte;
                        break;

                    case ElementType.Int8:
                        validTypeForType = value is SByte;
                        break;

                    case ElementType.UInt16:
                        validTypeForType = value is UInt16;
                        break;

                    case ElementType.Int16:
                        validTypeForType = value is Int16;
                        break;

                    case ElementType.UInt32:
                        validTypeForType = value is UInt32;
                        break;

                    case ElementType.Int32:
                        validTypeForType = value is Int32;
                        break;

                    case ElementType.UInt64:
                        validTypeForType = value is UInt64;
                        break;

                    case ElementType.Int64:
                        validTypeForType = value is Int64;
                        break;

                    case ElementType.UInt128:
                    case ElementType.Int128:
                        const int NumBytesIn128bits = 16;
                        byte[]    arr = value as byte[];
                        if (arr != null && arr.Length == NumBytesIn128bits)
                        {
                            validTypeForType = true;
                        }
                        else         // HACK UNTESTED
                        {
                            validTypeForType = false;
                            throw new ArgumentException(
                                      "Element type '" + type + "' needs a length 16 byte array.");
                        }
                        break;

                    default:
                        System.Diagnostics.Debug.Fail("Unexpected numerical type");
                        validTypeForType = false;
                        break;
                    }//switch
                }
                else if (type == ElementType.Uuid16)
                {
                    validTypeForType = value is UInt16;
                    validTypeForType = value is UInt16;
                }
                else if (type == ElementType.Uuid32)
                {
                    validTypeForType
                        = value is UInt16 ||
                          value is Int16 ||
                          value is UInt32 ||
                          value is Int32
                        ;
                }
                else if (type == ElementType.Uuid128)
                {
                    validTypeForType = value is Guid;
                }
                else if (type == ElementType.TextString)
                {
                    validTypeForType = value is byte[] || value is String;
                }
                else if (type == ElementType.Boolean)
                {
                    validTypeForType = value is Boolean;
                }
                else if (type == ElementType.ElementSequence || type == ElementType.ElementAlternative)
                {
                    validTypeForType = asElementList != null;
                }
                else
                {
                    // if (type == ElementType.Url)
                    System.Diagnostics.Debug.Assert(type == ElementType.Url);
                    validTypeForType = value is byte[] || value is Uri || value is string;
                }
                if (!validTypeForType)
                {
                    throw new ArgumentException("CLR type '" + value.GetType().Name + "' not valid type for element type '" + type + "'.");
                }
            }
            m_rawValue = value;
        }
예제 #23
0
 internal HeaderWriteState(ElementTypeDescriptor elementTypeDescriptor, byte[] buf, int offset, SizeIndex sizeIndex, int headerLength)
 {
     this.Etd = elementTypeDescriptor;
     this.HeaderOffset = offset;
     this.SizeIndex = sizeIndex;
     this.HeaderLength = headerLength;
     //
     VerifyWriteSpaceRemaining(HeaderLength, buf, offset);
     ServiceRecordParser.VerifyAllowedSizeIndex(Etd, SizeIndex, false);
 }
 /// <summary>
 /// Create a new <see cref="AutomatedElementFilterPropertyDescriptor"/>
 /// </summary>
 public AutomatedElementFilterPropertyDescriptor(ElementTypeDescriptor owner, ModelElement modelElement, DomainPropertyInfo domainProperty, Attribute[] attributes)
     : base(owner, modelElement, domainProperty, attributes)
 {
 }
 public MatchDataTypePropertyDescriptor(ElementTypeDescriptor owner, ModelElement modelElement, DomainPropertyInfo domainProperty, Attribute[] attributes)
     : base(owner, modelElement, domainProperty, attributes)
 {
 }
예제 #26
0
        internal void SetValue(Object value)
        {
            ElementTypeDescriptor etd  = m_etd;
            ElementType           type = m_type;

            //
            if (value == null)
            {
                if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative)
                {
                    throw new ArgumentNullException("value", "Type DataElementSequence and DataElementAlternative need an list of AttributeValue.");
                }
                else if (etd == ElementTypeDescriptor.Nil)
                {
                }
                else if (etd == ElementTypeDescriptor.Unknown)
                {
                }
                else
                {
                    throw new ArgumentNullException("value", "Null not valid for type: '" + type + "'.");
                }
            }
            else
            {
                // Check iff type=seq/alt then value is IList<ServiceElement>

                IList <ServiceElement> asElementList = value as IList <ServiceElement>;

                if (etd == ElementTypeDescriptor.ElementSequence || etd == ElementTypeDescriptor.ElementAlternative)
                {
                    if (asElementList == null)
                    {
                        throw new ArgumentException("Type ElementSequence and ElementAlternative need an list of ServiceElement.");
                    }
                }
                else
                {
                    if (asElementList != null)
                    {
                        throw new ArgumentException("Type ElementSequence and ElementAlternative must be used for an list of ServiceElement.");
                    }
                }
                //--------
                bool validTypeForType;
                if (type == ElementType.Nil)
                {
                    validTypeForType = value == null;
                }
                else if (etd == ElementTypeDescriptor.UnsignedInteger || etd == ElementTypeDescriptor.TwosComplementInteger)
                {
                    switch (type)
                    {
                    case ElementType.UInt8:
                        validTypeForType = value is Byte;
                        break;

                    case ElementType.Int8:
                        validTypeForType = value is SByte;
                        break;

                    case ElementType.UInt16:
                        validTypeForType = value is UInt16;
                        break;

                    case ElementType.Int16:
                        validTypeForType = value is Int16;
                        break;

                    case ElementType.UInt32:
                        validTypeForType = value is UInt32;
                        break;

                    case ElementType.Int32:
                        validTypeForType = value is Int32;
                        break;

                    case ElementType.UInt64:
                        validTypeForType = value is UInt64;
                        break;

                    case ElementType.Int64:
                        validTypeForType = value is Int64;
                        break;

                    case ElementType.UInt128:
                    case ElementType.Int128:
                        const int NumBytesIn128bits = 16;
                        byte[]    arr = value as byte[];
                        if (arr != null && arr.Length == NumBytesIn128bits)
                        {
                            validTypeForType = true;
                        }
                        else         // HACK UNTESTED
                        {
                            validTypeForType = false;
                            throw new ArgumentException(
                                      "Element type '" + type + "' needs a length 16 byte array.");
                        }
                        break;

                    default:
                        System.Diagnostics.Debug.Fail("Unexpected numerical type");
                        validTypeForType = false;
                        break;
                    }//switch
                }
                else if (type == ElementType.Uuid16)
                {
                    validTypeForType = value is UInt16;
                    validTypeForType = value is UInt16;
                }
                else if (type == ElementType.Uuid32)
                {
                    validTypeForType
                        = value is UInt16 ||
                          value is Int16 ||
                          value is UInt32 ||
                          value is Int32
                        ;
                }
                else if (type == ElementType.Uuid128)
                {
                    validTypeForType = value is Guid;
                }
                else if (type == ElementType.TextString)
                {
                    validTypeForType = value is byte[] || value is String;
                }
                else if (type == ElementType.Boolean)
                {
                    validTypeForType = value is Boolean;
                }
                else if (type == ElementType.ElementSequence || type == ElementType.ElementAlternative)
                {
                    validTypeForType = asElementList != null;
                }
                else
                {
                    // if (type == ElementType.Url)
                    System.Diagnostics.Debug.Assert(type == ElementType.Url);
                    validTypeForType = value is byte[] || value is Uri || value is string;
                }
                if (!validTypeForType)
                {
                    throw new ArgumentException("CLR type '" + value.GetType().Name + "' not valid type for element type '" + type + "'.");
                }
            }
            m_rawValue = value;
        }
		/// <summary>
		/// Create a new <see cref="AutomatedElementFilterPropertyDescriptor"/>
		/// </summary>
		public AutomatedElementFilterPropertyDescriptor(ElementTypeDescriptor owner, ModelElement modelElement, DomainPropertyInfo domainProperty, Attribute[] attributes)
			: base(owner, modelElement, domainProperty, attributes)
		{
		}
예제 #28
0
 public ExpectedServiceAttribute(UInt16 id, ElementType elementType, ElementTypeDescriptor etd, Object value)
     : base(elementType, etd, value)
 {
     this.Id = id;
 }
예제 #29
0
        private static void Map(StackConsts.SdpType_uint8_t sdpDataElementType,
                                out ElementTypeDescriptor etd, out SizeIndex sizeIndex)
        {
            const SizeIndex NotUsed = SizeIndex.LengthOneByteOrNil;

            switch (sdpDataElementType)
            {
            // Signed/Unsigned Integer
            case StackConsts.SdpType_uint8_t.UINT8:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            case StackConsts.SdpType_uint8_t.INT8:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            case StackConsts.SdpType_uint8_t.UINT16:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthTwoBytes;
                break;

            case StackConsts.SdpType_uint8_t.INT16:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthTwoBytes;
                break;

            case StackConsts.SdpType_uint8_t.UINT32:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthFourBytes;
                break;

            case StackConsts.SdpType_uint8_t.INT32:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthFourBytes;
                break;

            case StackConsts.SdpType_uint8_t.UINT64:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthEightBytes;
                break;

            case StackConsts.SdpType_uint8_t.INT64:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthEightBytes;
                break;

            case StackConsts.SdpType_uint8_t.UINT128:
                etd       = ElementTypeDescriptor.UnsignedInteger;
                sizeIndex = SizeIndex.LengthSixteenBytes;
                break;

            case StackConsts.SdpType_uint8_t.INT128:
                etd       = ElementTypeDescriptor.TwosComplementInteger;
                sizeIndex = SizeIndex.LengthSixteenBytes;
                break;

            // Strings
            case StackConsts.SdpType_uint8_t.TEXT_STR_UNSPEC:
            case StackConsts.SdpType_uint8_t.TEXT_STR8:
            case StackConsts.SdpType_uint8_t.TEXT_STR16:
            case StackConsts.SdpType_uint8_t.TEXT_STR32:
                etd       = ElementTypeDescriptor.TextString;
                sizeIndex = NotUsed;
                break;

            case StackConsts.SdpType_uint8_t.URL_STR_UNSPEC:
            case StackConsts.SdpType_uint8_t.URL_STR8:
            case StackConsts.SdpType_uint8_t.URL_STR16:
            case StackConsts.SdpType_uint8_t.URL_STR32:
                etd       = ElementTypeDescriptor.Url;
                sizeIndex = NotUsed;
                break;

            // UUID
            case StackConsts.SdpType_uint8_t.UUID16:
                etd       = ElementTypeDescriptor.Uuid;
                sizeIndex = SizeIndex.LengthTwoBytes;
                break;

            case StackConsts.SdpType_uint8_t.UUID32:
                etd       = ElementTypeDescriptor.Uuid;
                sizeIndex = SizeIndex.LengthFourBytes;
                break;

            case StackConsts.SdpType_uint8_t.UUID128:
                etd       = ElementTypeDescriptor.Uuid;
                sizeIndex = SizeIndex.LengthSixteenBytes;
                break;

            case StackConsts.SdpType_uint8_t.UUID_UNSPEC:
                throw new NotSupportedException("UUID_UNSPEC");

            // Seq/Alt
            case StackConsts.SdpType_uint8_t.SEQ_UNSPEC:
            case StackConsts.SdpType_uint8_t.SEQ8:
            case StackConsts.SdpType_uint8_t.SEQ16:
            case StackConsts.SdpType_uint8_t.SEQ32:
                etd       = ElementTypeDescriptor.ElementSequence;
                sizeIndex = NotUsed;
                break;

            case StackConsts.SdpType_uint8_t.ALT_UNSPEC:
            case StackConsts.SdpType_uint8_t.ALT8:
            case StackConsts.SdpType_uint8_t.ALT16:
            case StackConsts.SdpType_uint8_t.ALT32:
                etd       = ElementTypeDescriptor.ElementAlternative;
                sizeIndex = NotUsed;
                break;

            // Nil/Boolean/etc.
            case StackConsts.SdpType_uint8_t.BOOL:
                etd       = ElementTypeDescriptor.Boolean;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            case StackConsts.SdpType_uint8_t.DATA_NIL:
                etd       = ElementTypeDescriptor.Nil;
                sizeIndex = SizeIndex.LengthOneByteOrNil;
                break;

            //
            default:
                Debug.Fail("Unexpected SdpType_uint8_t: 0x" + ((int)sdpDataElementType).ToString("X"));
                etd       = ElementTypeDescriptor.Unknown;
                sizeIndex = SizeIndex.AdditionalUInt32;
                break;
            }
        }
예제 #30
0
 private static byte CreateHeaderByte(ElementTypeDescriptor etd, SizeIndex sizeIndex)
 {
     System.Diagnostics.Debug.Assert((int)etd < 32);
     byte headerByte = (byte)((int)etd << ServiceRecordParser.ElementTypeDescriptorOffset);
     System.Diagnostics.Debug.Assert((int)sizeIndex < 8);
     headerByte |= (byte)sizeIndex;
     return headerByte;
 }
 public NameGeneratorPropertyDescriptor(ElementTypeDescriptor owner, ModelElement modelElement, DomainPropertyInfo domainProperty, Attribute[] attributes)
     : base(owner, modelElement, domainProperty, attributes)
 {
 }
예제 #32
0
        //--------------------------------------------------------------

        /// <summary>
        /// Obsolete, use <see cref="M:InTheHand.Net.Bluetooth.ServiceElement.#ctor(InTheHand.Net.Bluetooth.ElementType,System.Object)"/> instead.
        /// Initializes a new instance of the <see cref="T:InTheHand.Net.Bluetooth.ServiceElement"/> class.
        /// </summary>
        internal ServiceElement(ElementTypeDescriptor etd, ElementType type, Object value)
        {
            ServiceRecordParser.VerifyTypeMatchesEtd(etd, type);
            m_type = type;
            m_etd = etd;
            SetValue(value);
        }