Beispiel #1
0
        /// <summary>
        /// Adds a characteristic to this service.
        /// </summary>
        /// <param name="characteristic">The characteristic to be added.</param>
        /// <returns>true on success, false otherwise.</returns>
        /// <exception cref="InvalidOperationException">Thrown when the add GATT characteristic procedure fails.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void AddCharacteristic(BluetoothGattCharacteristic characteristic)
        {
            if (GetGattClient() != null)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
            }

            if (characteristic.GetService() != null)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
            }

            _impl.AddCharacteristic(characteristic);
            characteristic.SetParent(this);
        }
        internal BluetoothGattCharacteristic GetCharacteristic(BluetoothGattService service, string uuid)
        {
            BluetoothGattAttributeHandle attributeHandle;
            int err = Interop.Bluetooth.BtGattServiceGetCharacteristic(_handle, uuid, out attributeHandle);

            if (err.IsFailed())
            {
                GattUtil.Error(err, string.Format("Failed to get Characteristic with UUID ({0})", uuid));
                return(null);
            }

            BluetoothGattCharacteristic Characteristic = BluetoothGattCharacteristicImpl.CreateBluetoothGattGattCharacteristic(attributeHandle, uuid);

            Characteristic.SetParent(service);
            return(Characteristic);
        }
        internal IEnumerable <BluetoothGattCharacteristic> GetCharacteristics(BluetoothGattService service)
        {
            List <BluetoothGattCharacteristic> attribututeList = new List <BluetoothGattCharacteristic>();

            Interop.Bluetooth.BtGattForeachCallback cb = (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(), cb, IntPtr.Zero);

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

            return(attribututeList);
        }