Beispiel #1
0
void
BluetoothGatt::HandleDescriptorsDiscovered(const BluetoothValue& aValue)
{
    MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);

    const InfallibleTArray<BluetoothNamedValue>& values =
        aValue.get_ArrayOfBluetoothNamedValue();
    MOZ_ASSERT(values.Length() == 3); // ServiceId, CharacteristicId, Descriptors
    MOZ_ASSERT(values[0].name().EqualsLiteral("serviceId"));
    MOZ_ASSERT(values[0].value().type() ==
               BluetoothValue::TBluetoothGattServiceId);
    MOZ_ASSERT(values[1].name().EqualsLiteral("characteristicId"));
    MOZ_ASSERT(values[1].value().type() == BluetoothValue::TBluetoothGattId);
    MOZ_ASSERT(values[2].name().EqualsLiteral("descriptors"));
    MOZ_ASSERT(values[2].value().type() ==
               BluetoothValue::TArrayOfBluetoothGattId);

    size_t index = mServices.IndexOf(
                       values[0].value().get_BluetoothGattServiceId());
    NS_ENSURE_TRUE_VOID(index != mServices.NoIndex);

    RefPtr<BluetoothGattService> service = mServices.ElementAt(index);
    service->AssignDescriptors(values[1].value().get_BluetoothGattId(),
                               values[2].value().get_ArrayOfBluetoothGattId());
}
void
BluetoothGattService::AssignDescriptors(
  const BluetoothGattId& aCharacteristicId,
  const nsTArray<BluetoothGattId>& aDescriptorIds)
{
  size_t index = mCharacteristics.IndexOf(aCharacteristicId);
  NS_ENSURE_TRUE_VOID(index != mCharacteristics.NoIndex);

  RefPtr<BluetoothGattCharacteristic> characteristic =
    mCharacteristics.ElementAt(index);
  characteristic->AssignDescriptors(aDescriptorIds);
}