BluetopiaError IBluetopiaApi.SDP_Add_Attribute(uint BluetoothStackID, uint Service_Record_Handle, ushort Attribute_ID, ref Structs.SDP_Data_Element__Struct SDP_Data_Element) { #if DEBUG //NativeMethods.My2_SDP_Add_Attribute(BluetoothStackID, Service_Record_Handle, // Attribute_ID, ref SDP_Data_Element); #endif return(BluetopiaError.OK); }
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."); } } } }
internal static extern BluetopiaError My2_SDP_Add_Attribute(uint BluetoothStackID, UInt32 Service_Record_Handle, ushort Attribute_ID, [In] ref Structs.SDP_Data_Element__Struct SDP_Data_Element);