Esempio n. 1
0
        internal Task <bool> ReadValueAsyncTask(BluetoothGattAttributeHandle handle)
        {
            TaskCompletionSource <bool> task = new TaskCompletionSource <bool>();
            int requestId = 0;

            lock (this)
            {
                requestId = _requestId++;
                _readValueTaskSource[requestId] = task;
            }

            int err = Interop.Bluetooth.BtGattClientReadValue(handle, _readValueCallback, (IntPtr)requestId);

            if (err.IsFailed())
            {
                GattUtil.Error(err, "Failed to read value from remote device");
                task.SetResult(false);
                _readValueTaskSource.Remove(requestId);
                BluetoothErrorFactory.ThrowBluetoothException(err);
            }
            return(task.Task);
        }
Esempio n. 2
0
        internal IEnumerable <BluetoothGattService> GetServices(BluetoothGattClient client)
        {
            List <BluetoothGattService> attribututeList = new List <BluetoothGattService>();

            _serviceForeachCallback = (total, index, attributeHandle, userData) =>
            {
                BluetoothGattAttributeHandle handle  = new BluetoothGattAttributeHandle(attributeHandle, false);
                BluetoothGattService         service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, "");
                if (service != null)
                {
                    service.SetParent(client);
                    attribututeList.Add(service);
                }
                return(true);
            };

            int err = Interop.Bluetooth.BtGattClientForeachServices(_handle, _serviceForeachCallback, IntPtr.Zero);

            GattUtil.Error(err, "Failed to get all services");

            return(attribututeList);
        }
Esempio n. 3
0
        internal IEnumerable <BluetoothGattDescriptor> GetDescriptors(BluetoothGattCharacteristic characteristic)
        {
            List <BluetoothGattDescriptor> attribututeList = new List <BluetoothGattDescriptor>();

            _descriptorForeachCallback = (total, index, attributeHandle, userData) =>
            {
                BluetoothGattAttributeHandle handle     = new BluetoothGattAttributeHandle(attributeHandle, false);
                BluetoothGattDescriptor      descriptor = BluetoothGattDescriptorImpl.CreateBluetoothGattDescriptor(handle, "");
                if (descriptor != null)
                {
                    descriptor.SetParent(characteristic);
                    attribututeList.Add(descriptor);
                }
                return(true);
            };

            int err = Interop.Bluetooth.BtGattCharacteristicForeachDescriptors(characteristic.GetHandle(), _descriptorForeachCallback, IntPtr.Zero);

            GattUtil.Error(err, "Failed to get all descriptor");

            return(attribututeList);
        }
Esempio n. 4
0
        internal IEnumerable <BluetoothGattCharacteristic> GetCharacteristics(BluetoothGattService service)
        {
            List <BluetoothGattCharacteristic> attribututeList = new List <BluetoothGattCharacteristic>();

            _characteristicForeachCallback = (total, index, attributeHandle, userData) =>
            {
                BluetoothGattAttributeHandle handle         = new BluetoothGattAttributeHandle(attributeHandle, false);
                BluetoothGattCharacteristic  Characteristic = BluetoothGattCharacteristicImpl.CreateBluetoothGattGattCharacteristic(handle, "");
                if (Characteristic != null)
                {
                    Characteristic.SetParent(service);
                    attribututeList.Add(Characteristic);
                }
                return(true);
            };

            int err = Interop.Bluetooth.BtGattServiceForeachCharacteristics(service.GetHandle(), _characteristicForeachCallback, IntPtr.Zero);

            GattUtil.Error(err, "Failed to get all Characteristic");

            return(attribututeList);
        }
Esempio n. 5
0
 internal BluetoothGattDescriptorImpl(BluetoothGattAttributeHandle handle)
 {
     _handle = handle;
 }
Esempio n. 6
0
        internal static BluetoothGattCharacteristic CreateBluetoothGattGattCharacteristic(BluetoothGattAttributeHandle handle, string uuid)
        {
            int permission;
            int err = Interop.Bluetooth.BtGattCharacteristicGetPermissions(handle, out permission);

            GattUtil.ThrowForError(err, "Failed to get permissions");

            if (uuid == "")
            {
                err = Interop.Bluetooth.BtGattGetUuid(handle, out uuid);
                GattUtil.ThrowForError(err, "Failed to get UUID");
            }

            BluetoothGattCharacteristicImpl impl = new BluetoothGattCharacteristicImpl(handle);

            return(new BluetoothGattCharacteristic(impl, uuid, (BluetoothGattPermission)permission));
        }
Esempio n. 7
0
 internal BluetoothGattCharacteristicImpl(BluetoothGattAttributeHandle handle)
 {
     _handle = handle;
 }
Esempio n. 8
0
 internal BluetoothGattServiceImpl(BluetoothGattAttributeHandle handle)
 {
     _handle = handle;
 }