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

    const InfallibleTArray<BluetoothNamedValue>& values =
        aValue.get_ArrayOfBluetoothNamedValue();
    MOZ_ASSERT(values.Length() == 2); // ServiceId, IncludedServices
    MOZ_ASSERT(values[0].name().EqualsLiteral("serviceId"));
    MOZ_ASSERT(values[0].value().type() ==
               BluetoothValue::TBluetoothGattServiceId);
    MOZ_ASSERT(values[1].name().EqualsLiteral("includedServices"));
    MOZ_ASSERT(values[1].value().type() ==
               BluetoothValue::TArrayOfBluetoothGattServiceId);

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

    RefPtr<BluetoothGattService> service = mServices.ElementAt(index);
    service->AssignIncludedServices(
        values[1].value().get_ArrayOfBluetoothGattServiceId());
}