//---- public new void CreateServiceRecord(ServiceRecord record) { if (record == null) { throw new ArgumentNullException("record"); } if (_hSR.HasValue) { throw new InvalidOperationException("One at a time please."); } // ServiceElement svcIdListElement; var newList = new List <ServiceAttribute>(Math.Max(record.Count - 1, 0)); foreach (var cur in record) { if (cur.Id == UniversalAttributeId.ServiceClassIdList) { svcIdListElement = cur.Value; } else { newList.Add(cur); } } var newRecord = new ServiceRecord(newList); Debug.Assert(!newRecord.Contains(UniversalAttributeId.ServiceClassIdList), "DOES!! contain SvcIdList"); // Add the list of UUIDs var el = record.GetAttributeById(UniversalAttributeId.ServiceClassIdList).Value; var classList = el.GetValueAsElementList(); var svcIdListList = new Structs.SDP_UUID_Entry_Bytes[classList.Count]; for (int i = 0; i < svcIdListList.Length; ++i) { svcIdListList[i] = Structs.SDP_UUID_Entry_Bytes.Create(classList[i]); } Debug.Assert(svcIdListList.Length != 0, "Docs: 'the number of UUID Entries'...'CANNOT be zero'."); // int hSR = _fcty.Api.SDP_Create_Service_Record(_fcty.StackId, checked ((uint)svcIdListList.Length), svcIdListList); var ret = (BluetopiaError)hSR; BluetopiaUtils.CheckAndThrowZeroIsIllegal(ret, "SDP_Create_Service_Record"); _hSR = unchecked ((uint)hSR); // int count = base.CreateServiceRecord(newRecord, s_dummy); }
internal IAsyncResult BeginQuery(BluetoothAddress device, Guid svcClass, bool rfcommOnly, AsyncCallback asyncCallback, object state) { int id0 = Interlocked.Increment(ref _callbackCount); var id = unchecked ((uint)id0); var ar = new AsyncResultGsr(asyncCallback, state, id); // Attribute range/etc Structs.SDP_Attribute_ID_List_Entry[] attrIdListArr; var attrIdAll = Structs.SDP_Attribute_ID_List_Entry.CreateRange(0, 0xFFFF); var attrIdSvcList = Structs.SDP_Attribute_ID_List_Entry.CreateItem( UniversalAttributeId.ServiceClassIdList); var attrIdProto = Structs.SDP_Attribute_ID_List_Entry.CreateItem( UniversalAttributeId.ProtocolDescriptorList); if (rfcommOnly) { attrIdListArr = new[] { attrIdSvcList, attrIdProto }; } else { attrIdListArr = new[] { attrIdAll }; } // UUID var uuidArg = new Structs.SDP_UUID_Entry(svcClass); Structs.SDP_UUID_Entry[] uuidArr = new[] { uuidArg }; AsyncResultGsr old; old = MyInterlockedCompareExchange <AsyncResultGsr>(ref _ar, ar, null); if (old != null) { throw new NotImplementedException("One at a time please."); } bool trySuccess = false; try { // Call _fcty.CancelAllQueryNames(); int hRequest = _fcty.Api.SDP_Service_Search_Attribute_Request(_fcty.StackId, BluetopiaUtils.BluetoothAddressAsInteger(device), (uint)uuidArr.Length, uuidArr, (uint)attrIdListArr.Length, attrIdListArr, _callback, id); var ret = (BluetopiaError)hRequest; int i; for (i = 0; i < 5 && ret == BluetopiaError.ATTEMPTING_CONNECTION_TO_DEVICE; ++i) { // See BluetopiaRfcommStream.DoOpenClient... Assuming here a // previous baseband connection was closing right when as we // wanted to connect, so retry. if (i > 0) { Thread.Sleep(100); // Try right away, then after 100ms sleeps } hRequest = _fcty.Api.SDP_Service_Search_Attribute_Request(_fcty.StackId, BluetopiaUtils.BluetoothAddressAsInteger(device), (uint)uuidArr.Length, uuidArr, (uint)attrIdListArr.Length, attrIdListArr, _callback, id); ret = (BluetopiaError)hRequest; } if (i > 0) { Debug.WriteLine("Auto-retry " + i + " after ATTEMPTING_CONNECTION_TO_DEVICE for SDP_Service_Search_Attribute_Request"); } BluetopiaUtils.CheckAndThrowZeroIsIllegal(ret, "SDP_Service_Search_Attribute_Request"); trySuccess = true; return(ar); } finally { if (!trySuccess) { // If we got here it must be our value in the variable! var replaced = MyInterlockedExchange(ref _ar, null); Debug.Assert(replaced != null); Debug.Assert(replaced == ar); } } }
internal BluetopiaFactory(IBluetopiaApi api, IBluetopiaSecurity optionalSecurityInstance) { if (api == null) { throw new ArgumentNullException("api"); } _api = api; // _inquiryHandler = new BluetopiaInquiry(this); _inquiryEventCallback = _inquiryHandler.HandleInquiryEvent; _HandleNameLookup = HandleNameLookup; // //int handle = _api.BSC_Initialize((byte[])InitData.Clone(), 0); Utils.MiscUtils.Trace_WriteLine( "Calling BSC_Initialize with:" + InitData2.ToString()); int handle = _api.BSC_Initialize(ref InitData2, 0); //TEST--CheckStructBytes(ref InitData2, (byte[])InitData.Clone()); var ret = (BluetopiaError)handle; if (!BluetopiaUtils.IsSuccessZeroIsIllegal(ret)) { KillBtExplorerExe(); // Since one app at a time! // _Quickly_ try to init, as BTExplorer.exe restarts automatically! handle = _api.BSC_Initialize(ref InitData2, 0); ret = (BluetopiaError)handle; } if (!BluetopiaUtils.IsSuccessZeroIsIllegal(ret)) { Utils.MiscUtils.Trace_WriteLine("Stonestreet One Bluetopia failed to init: " + BluetopiaUtils.ErrorToString(ret)); } BluetopiaUtils.CheckAndThrowZeroIsIllegal(ret, "BSC_Initialize"); _stackId = checked ((uint)handle); // if (optionalSecurityInstance != null) { _sec = optionalSecurityInstance; } else { _sec = new BluetopiaSecurity(this); } _sec.InitStack(); // // var packetDebug = false; var eap = BluetoothFactoryConfig.GetEntryAssemblyPath(); if (eap != null) // null if we're under unit-test or... { var dir = Path.GetDirectoryName(eap); var filename = Path.Combine(dir, "DoPacketDebug.txt"); if (File.Exists(filename)) { packetDebug = true; } } if (packetDebug) { _pdebug = new BluetopiaPacketDebug(this); } // InitApiVersion(); }