Beispiel #1
0
        internal static BluetopiaDeviceInfo CreateFromInquiry(
            Structs.GAP_Inquiry_Entry_Event_Data data, BluetopiaFactory factory)
        {
            var bdi = new BluetopiaDeviceInfo(factory,
                                              BluetopiaUtils.ToBluetoothAddress(data.BD_ADDR));

            bdi._cod = BluetopiaUtils.ToClassOfDevice(data.Class_of_Device);
            bdi._blockFindNameForNow = true;
            bdi._clockOffsetEtc      = new ClockOffsetEtc(data);
            return(bdi);
        }
Beispiel #2
0
        internal BluetopiaError QueryName(BluetopiaDeviceInfo device,
                                          bool mayUseCached, bool mayQueryName)
        {
            const int CancelBlockingTimeSeconds = 2;

            lock (_lockDevices) {
                if (mayUseCached)
                {
                    BluetopiaDeviceInfo prev;
                    var got = _knownDevices.TryGetValue(device.DeviceAddress, out prev);
                    if (prev != null && prev.HasDeviceName)
                    {
                        device.SetName(prev.DeviceName);
                        return(BluetopiaError.OK);
                    }
                }
                //
                if (!mayQueryName)
                {
                    return(BluetopiaError.OK);
                }
                var since = DateTime.UtcNow - _lastCancelAllQueryNames;
                if (since.TotalSeconds < CancelBlockingTimeSeconds)
                {
                    Debug.WriteLine("QueryName blocked");
                    return(BluetopiaError.OK);
                }
                else     //DEBUG
                {
                }
                List <BluetopiaDeviceInfo> instList;
                var exists = _nameQueryList.TryGetValue(device.DeviceAddress, out instList);
                if (instList == null)
                {
                    Debug.Assert(!exists, "Null Value!?!");
                    instList = new List <BluetopiaDeviceInfo>();
                    _nameQueryList.Add(device.DeviceAddress, instList);
                }
                if (instList.Contains(device))
                {
                    // Already querying...
                    return(BluetopiaError.OK);
                }
                instList.Add(device);
            }//lock
            var ret = _api.GAP_Query_Remote_Device_Name(this.StackId,
                                                        BluetopiaUtils.BluetoothAddressAsInteger(device.DeviceAddress),
                                                        _HandleNameLookup, 0);

            BluetopiaUtils.WriteLineIfError(ret, "GAP_Query_Remote_Device_Name");
            return(ret);
        }
Beispiel #3
0
        private void AddNamedKnownDevice(BluetoothAddress addr, string name)
        {
            var bdiNew = BluetopiaDeviceInfo.CreateFromGivenAddress(addr, this);

            bdiNew.SetRemembered();
            bdiNew.SetName(name);
            lock (_lockDevices) {
                BluetopiaDeviceInfo prev;
                var got = _knownDevices.TryGetValue(addr, out prev);
                if (prev != null)
                {
                    prev.SetName(name);
                }
                else
                {
                    _knownDevices.Add(bdiNew.DeviceAddress, bdiNew);
                }
            }//lock
        }
Beispiel #4
0
            //----
            protected override IBluetoothDeviceInfo CreateDeviceInfo(Structs.GAP_Inquiry_Entry_Event_Data item)
            {
                BluetopiaDeviceInfo bdi = BluetopiaDeviceInfo.CreateFromInquiry(item, _fcty);

                return(bdi);
            }
Beispiel #5
0
 protected override IBluetoothDeviceInfo GetBluetoothDeviceInfo(BluetoothAddress address)
 {
     return(BluetopiaDeviceInfo.CreateFromGivenAddress(address, this));
 }