diff --git a/dom/bluetooth/bluedroid/BluetoothGattManager.cpp b/dom/bluetooth/bluedroid/BluetoothGattManager.cpp index 88feb8a51cf6..1a4183ec2983 100644 --- a/dom/bluetooth/bluedroid/BluetoothGattManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothGattManager.cpp @@ -947,9 +947,6 @@ public: (int)aStatus); MOZ_ASSERT(mClient->mReadRemoteRssiRunnable); - BluetoothService* bs = BluetoothService::Get(); - NS_ENSURE_TRUE_VOID(bs); - // Reject the read remote rssi request DispatchReplyError(mClient->mReadRemoteRssiRunnable, NS_LITERAL_STRING("ReadRemoteRssi failed")); @@ -1484,9 +1481,6 @@ public: BT_WARNING("BluetoothGattServerInterface::RegisterServer failed: %d", (int)aStatus); - BluetoothService* bs = BluetoothService::Get(); - NS_ENSURE_TRUE_VOID(bs); - // Reject the connect request if (mServer->mConnectPeripheralRunnable) { DispatchReplyError(mServer->mConnectPeripheralRunnable, @@ -1528,9 +1522,6 @@ public: (int)aStatus); MOZ_ASSERT(mServer->mConnectPeripheralRunnable); - BluetoothService* bs = BluetoothService::Get(); - NS_ENSURE_TRUE_VOID(bs); - DispatchReplyError(mServer->mConnectPeripheralRunnable, NS_LITERAL_STRING("ConnectPeripheral failed")); mServer->mConnectPeripheralRunnable = nullptr; @@ -1623,9 +1614,6 @@ public: (int)aStatus); MOZ_ASSERT(mServer->mDisconnectPeripheralRunnable); - BluetoothService* bs = BluetoothService::Get(); - NS_ENSURE_TRUE_VOID(bs); - // Reject the disconnect request DispatchReplyError(mServer->mDisconnectPeripheralRunnable, NS_LITERAL_STRING("DisconnectPeripheral failed")); @@ -2939,9 +2927,6 @@ BluetoothGattManager::ReadRemoteRssiNotification(int aClientIf, { MOZ_ASSERT(NS_IsMainThread()); - BluetoothService* bs = BluetoothService::Get(); - NS_ENSURE_TRUE_VOID(bs); - size_t index = sClients->IndexOf(aClientIf, 0 /* Start */, InterfaceIdComparator()); NS_ENSURE_TRUE_VOID(index != sClients->NoIndex); diff --git a/dom/bluetooth/common/webapi/BluetoothGattServer.cpp b/dom/bluetooth/common/webapi/BluetoothGattServer.cpp index 9cee27240f24..99709719d193 100644 --- a/dom/bluetooth/common/webapi/BluetoothGattServer.cpp +++ b/dom/bluetooth/common/webapi/BluetoothGattServer.cpp @@ -66,6 +66,39 @@ BluetoothGattServer::~BluetoothGattServer() Invalidate(); } +void BluetoothGattServer::HandleServerRegistered(const BluetoothValue& aValue) +{ + MOZ_ASSERT(aValue.type() == BluetoothValue::Tuint32_t); + mServerIf = aValue.get_uint32_t(); +} + +void BluetoothGattServer::HandleServerUnregistered(const BluetoothValue& aValue) +{ + mServerIf = 0; +} + +void BluetoothGattServer::HandleConnectionStateChanged( + const BluetoothValue& aValue) +{ + MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue); + const InfallibleTArray& arr = + aValue.get_ArrayOfBluetoothNamedValue(); + + MOZ_ASSERT(arr.Length() == 2 && + arr[0].value().type() == BluetoothValue::Tbool && + arr[1].value().type() == BluetoothValue::TnsString); + + BluetoothStatusChangedEventInit init; + init.mStatus = arr[0].value().get_bool(); + init.mAddress = arr[1].value().get_nsString(); + + nsRefPtr event = + BluetoothStatusChangedEvent::Constructor( + this, NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID), init); + + DispatchTrustedEvent(event); +} + void BluetoothGattServer::HandleServiceHandleUpdated(const BluetoothValue& aValue) { @@ -151,28 +184,11 @@ BluetoothGattServer::Notify(const BluetoothSignal& aData) BluetoothValue v = aData.value(); if (aData.name().EqualsLiteral("ServerRegistered")) { - MOZ_ASSERT(v.type() == BluetoothValue::Tuint32_t); - mServerIf = v.get_uint32_t(); + HandleServerRegistered(v); } else if (aData.name().EqualsLiteral("ServerUnregistered")) { - mServerIf = 0; + HandleServerUnregistered(v); } else if (aData.name().EqualsLiteral(GATT_CONNECTION_STATE_CHANGED_ID)) { - MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue); - const InfallibleTArray& arr = - v.get_ArrayOfBluetoothNamedValue(); - - MOZ_ASSERT(arr.Length() == 2 && - arr[0].value().type() == BluetoothValue::Tbool && - arr[1].value().type() == BluetoothValue::TnsString); - - BluetoothStatusChangedEventInit init; - init.mStatus = arr[0].value().get_bool(); - init.mAddress = arr[1].value().get_nsString(); - - nsRefPtr event = - BluetoothStatusChangedEvent::Constructor( - this, NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID), init); - - DispatchTrustedEvent(event); + HandleConnectionStateChanged(v); } else if (aData.name().EqualsLiteral("ServiceHandleUpdated")) { HandleServiceHandleUpdated(v); } else if (aData.name().EqualsLiteral("CharacteristicHandleUpdated")) { diff --git a/dom/bluetooth/common/webapi/BluetoothGattServer.h b/dom/bluetooth/common/webapi/BluetoothGattServer.h index 229c36aee3af..7918efd8285a 100644 --- a/dom/bluetooth/common/webapi/BluetoothGattServer.h +++ b/dom/bluetooth/common/webapi/BluetoothGattServer.h @@ -102,6 +102,9 @@ private: friend class AddServiceTask; friend class RemoveServiceTask; + void HandleServerRegistered(const BluetoothValue& aValue); + void HandleServerUnregistered(const BluetoothValue& aValue); + void HandleConnectionStateChanged(const BluetoothValue& aValue); void HandleServiceHandleUpdated(const BluetoothValue& aValue); void HandleCharacteristicHandleUpdated(const BluetoothValue& aValue); void HandleDescriptorHandleUpdated(const BluetoothValue& aValue); diff --git a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h index bc7c4640b417..d7feafba1c6e 100644 --- a/dom/bluetooth/ipc/BluetoothServiceChildProcess.h +++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.h @@ -287,7 +287,7 @@ public: const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharacteristicId, const BluetoothGattId& aDescriptorId, - BluetoothReplyRunnable* aRunnable); + BluetoothReplyRunnable* aRunnable) override; virtual void GattClientWriteDescriptorValueInternal( @@ -296,19 +296,19 @@ public: const BluetoothGattId& aCharacteristicId, const BluetoothGattId& aDescriptorId, const nsTArray& aValue, - BluetoothReplyRunnable* aRunnable); + BluetoothReplyRunnable* aRunnable) override; virtual void GattServerConnectPeripheralInternal( const nsAString& aAppUuid, const nsAString& aAddress, - BluetoothReplyRunnable* aRunnable); + BluetoothReplyRunnable* aRunnable) override; virtual void GattServerDisconnectPeripheralInternal( const nsAString& aAppUuid, const nsAString& aAddress, - BluetoothReplyRunnable* aRunnable); + BluetoothReplyRunnable* aRunnable) override; virtual void UnregisterGattServerInternal(int aServerIf,