protected override BluetopiaError AddAttribute(Structs.SDP_Data_Element__Class eNotNative) { uint?hSR; ServiceAttributeId attrId; base.GetRecordAttrInfo(out hSR, out attrId); #pragma warning disable 618 // Obsolete var ret = _fcty.Api.SDP_Add_Attribute(_fcty.StackId, hSR.Value, unchecked ((ushort)attrId), eNotNative); #pragma warning restore 618 // Obsolete return(ret); }
//---- #region Hold Element state private void SetCurElement(Structs.SDP_Data_Element__Class e) { if (_seqAltStack.Count != 0) { Debug.Assert(_element == null, "(overwrite???!)"); _seqAltStack.Peek().SeqAltChildren.Add(e); } else { Debug.Assert(_element == null, "overwrite!!!"); this._element = e; } }
protected virtual BluetopiaError AddAttribute(Structs.SDP_Data_Element__Class eNotNative) { Structs.SDP_Data_Element__Struct e; var toFree = new List <IntPtr>(); try { ConvertToNativeStructs(eNotNative, out e, toFree); var ret = _fcty.Api.SDP_Add_Attribute(_fcty.StackId, _hSR.Value, unchecked ((ushort)this._attrId), ref e); return(ret); } finally { foreach (var p in toFree) { Marshal.FreeHGlobal(p); } } }
//---- protected sealed override void WriteAttribute(ServiceAttribute attr, byte[] buffer, ref int offset) { bool doneKnown = WriteWellKnownAttribute(attr); if (doneKnown) { return; } // base.WriteAttribute(attr, buffer, ref offset); // var e = _element; var ret = AddAttribute(e); BluetopiaUtils.CheckAndThrow(ret, "SDP_Add_Attribute"); _element = null; }
BluetopiaError IBluetopiaApi.SDP_Add_Attribute(uint BluetoothStackID, uint Service_Record_Handle, ushort Attribute_ID, Structs.SDP_Data_Element__Class SDP_Data_Element) { throw new NotSupportedException(); }
private void ConvertToNativeStructs(Structs.SDP_Data_Element__Class eNotNative, out Structs.SDP_Data_Element__Struct e, List <IntPtr> toFree) { var eEa = eNotNative as Structs.SDP_Data_Element__Class_ElementArray; if (eEa != null) { Debug.Assert(eEa.SDP_Data_Element_Length == eEa.elementArray.Length); var newEa = new Structs.SDP_Data_Element__Struct[eEa.SDP_Data_Element_Length]; for (int i = 0; i < newEa.Length; ++i) { ConvertToNativeStructs(eEa.elementArray[i], out newEa[i], toFree); } var p = CopyArrayToHGlobal(newEa, toFree); byte[] addrArr = PointerAsBytes(p); e = new Structs.SDP_Data_Element__Struct(eEa.SDP_Data_Element_Type, eEa.SDP_Data_Element_Length, addrArr); } else { var eIba = eNotNative as Structs.SDP_Data_Element__Class_InlineByteArray; if (eIba != null) { e = new Structs.SDP_Data_Element__Struct(eIba.SDP_Data_Element_Type, eNotNative.SDP_Data_Element_Length, eIba._elementValue); Debug.Assert(eNotNative.SDP_Data_Element_Type == e.SDP_Data_Element_Type); Debug.Assert(eNotNative.SDP_Data_Element_Length == e.SDP_Data_Element_Length); Debug.Assert(eIba._elementValue.Length == e._content.Length); if (eIba._elementValue.Length != 0) { Debug.Assert(eIba._elementValue[0] == e._content[0]); Debug.Assert(eIba._elementValue[eIba._elementValue.Length - 1] == e._content[e._content.Length - 1]); } } else { var eNiBA = eNotNative as Structs.SDP_Data_Element__Class_NonInlineByteArray; if (eNiBA != null) { int len = checked ((int)eNiBA.SDP_Data_Element_Length); var p = Marshal.AllocHGlobal(len); Debug.Assert(eNiBA._elementValue.Length == eNiBA.SDP_Data_Element_Length); Marshal.Copy(eNiBA._elementValue, 0, p, len); byte[] addrArr = PointerAsBytes(p); e = new Structs.SDP_Data_Element__Struct(eNiBA.SDP_Data_Element_Type, eNiBA.SDP_Data_Element_Length, addrArr); Debug.Assert(eNotNative.SDP_Data_Element_Type == e.SDP_Data_Element_Type); Debug.Assert(eNotNative.SDP_Data_Element_Length == e.SDP_Data_Element_Length); Debug.Assert(eNiBA._elementValue.Length == e.SDP_Data_Element_Length); if (eNiBA._elementValue.Length != 0) { Debug.Assert(eNiBA._elementValue[0] == Marshal.ReadByte(p, 0)); Debug.Assert(eNiBA._elementValue[eNiBA._elementValue.Length - 1] == Marshal.ReadByte(p, checked ((int)e.SDP_Data_Element_Length) - 1)); } } else { throw new InvalidOperationException("Unknown type."); } } } }
public SdpServiceExpectedCall(UInt16 attrId, Structs.SDP_Data_Element__Class element) { this.attrId = attrId; this.element = element; }