void BluetoothGatt::Notify(const BluetoothSignal& aData) { BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get()); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("ClientRegistered")) { MOZ_ASSERT(v.type() == BluetoothValue::Tuint32_t); mClientIf = v.get_uint32_t(); } else if (aData.name().EqualsLiteral("ClientUnregistered")) { mClientIf = 0; } else if (aData.name().EqualsLiteral(GATT_CONNECTION_STATE_CHANGED_ID)) { MOZ_ASSERT(v.type() == BluetoothValue::Tbool); BluetoothConnectionState state = v.get_bool() ? BluetoothConnectionState::Connected : BluetoothConnectionState::Disconnected; UpdateConnectionState(state); } else if (aData.name().EqualsLiteral("ServicesDiscovered")) { HandleServicesDiscovered(v); } else if (aData.name().EqualsLiteral("DiscoverCompleted")) { MOZ_ASSERT(v.type() == BluetoothValue::Tbool); bool isDiscoverSuccess = v.get_bool(); if (!isDiscoverSuccess) { // Clean all discovered attributes if failed mServices.Clear(); BluetoothGattBinding::ClearCachedServicesValue(this); } mDiscoveringServices = false; } else { BT_WARNING("Not handling GATT signal: %s", NS_ConvertUTF16toUTF8(aData.name()).get()); } }
bool BluetoothAdapter::IsAdapterAttributeChanged(BluetoothAdapterAttribute aType, const BluetoothValue& aValue) { switch(aType) { case BluetoothAdapterAttribute::State: MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool); return aValue.get_bool() ? mState != BluetoothAdapterState::Enabled : mState != BluetoothAdapterState::Disabled; case BluetoothAdapterAttribute::Name: MOZ_ASSERT(aValue.type() == BluetoothValue::TnsString); return !mName.Equals(aValue.get_nsString()); case BluetoothAdapterAttribute::Address: MOZ_ASSERT(aValue.type() == BluetoothValue::TnsString); return !mAddress.Equals(aValue.get_nsString()); case BluetoothAdapterAttribute::Discoverable: MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool); return mDiscoverable != aValue.get_bool(); case BluetoothAdapterAttribute::Discovering: MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool); return mDiscovering != aValue.get_bool(); default: BT_WARNING("Type %d is not handled", uint32_t(aType)); return false; } }
void BluetoothAdapter::Notify(const BluetoothSignal& aData) { InfallibleTArray<BluetoothNamedValue> arr; BT_LOGD("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get()); BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("DeviceFound")) { nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value()); BluetoothDeviceEventInit init; init.mBubbles = false; init.mCancelable = false; init.mDevice = device; nsRefPtr<BluetoothDeviceEvent> event = BluetoothDeviceEvent::Constructor(this, NS_LITERAL_STRING("devicefound"), init); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral("PropertyChanged")) { MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) { SetPropertyByValue(arr[i]); } } else if (aData.name().EqualsLiteral(DISCOVERY_STATE_CHANGED_ID)) { MOZ_ASSERT(v.type() == BluetoothValue::Tbool); BluetoothDiscoveryStateChangedEventInit init; init.mDiscovering = v.get_bool(); nsRefPtr<BluetoothDiscoveryStateChangedEvent> event = BluetoothDiscoveryStateChangedEvent::Constructor( this, NS_LITERAL_STRING(DISCOVERY_STATE_CHANGED_ID), init); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral(PAIRED_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(HFP_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(SCO_STATUS_CHANGED_ID) || aData.name().EqualsLiteral(A2DP_STATUS_CHANGED_ID)) { MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue(); MOZ_ASSERT(arr.Length() == 2 && arr[0].value().type() == BluetoothValue::TnsString && arr[1].value().type() == BluetoothValue::Tbool); nsString address = arr[0].value().get_nsString(); bool status = arr[1].value().get_bool(); BluetoothStatusChangedEventInit init; init.mBubbles = false; init.mCancelable = false; init.mAddress = address; init.mStatus = status; nsRefPtr<BluetoothStatusChangedEvent> event = BluetoothStatusChangedEvent::Constructor(this, aData.name(), init); DispatchTrustedEvent(event); } else if (aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) { nsCOMPtr<nsIDOMEvent> event; nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr); NS_ENSURE_SUCCESS_VOID(rv); rv = event->InitEvent(aData.name(), false, false); NS_ENSURE_SUCCESS_VOID(rv); DispatchTrustedEvent(event); } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling adapter signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); BT_WARNING(warningMsg.get()); #endif } }