Bug 1220121: Convert IPDL of Bluetooth GATT API to |BluetoothAddress|, r=joliu

This commit is contained in:
Thomas Zimmermann 2015-11-12 11:23:36 +01:00
parent 9ec12aea49
commit 10e5c8cb29
10 changed files with 119 additions and 122 deletions

View File

@ -363,7 +363,7 @@ BluetoothServiceBluedroid::StopLeScanInternal(
void void
BluetoothServiceBluedroid::ConnectGattClientInternal( BluetoothServiceBluedroid::ConnectGattClientInternal(
const nsAString& aAppUuid, const nsAString& aDeviceAddress, const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -376,18 +376,12 @@ BluetoothServiceBluedroid::ConnectGattClientInternal(
BluetoothUuid appUuid; BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid); StringToUuid(aAppUuid, appUuid);
BluetoothAddress deviceAddress; gatt->Connect(appUuid, aDeviceAddress, aRunnable);
if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
gatt->Connect(appUuid, deviceAddress, aRunnable);
} }
void void
BluetoothServiceBluedroid::DisconnectGattClientInternal( BluetoothServiceBluedroid::DisconnectGattClientInternal(
const nsAString& aAppUuid, const nsAString& aDeviceAddress, const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -400,13 +394,7 @@ BluetoothServiceBluedroid::DisconnectGattClientInternal(
BluetoothUuid appUuid; BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid); StringToUuid(aAppUuid, appUuid);
BluetoothAddress deviceAddress; gatt->Disconnect(appUuid, aDeviceAddress, aRunnable);
if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
gatt->Disconnect(appUuid, deviceAddress, aRunnable);
} }
void void
@ -478,7 +466,7 @@ BluetoothServiceBluedroid::UnregisterGattClientInternal(
void void
BluetoothServiceBluedroid::GattClientReadRemoteRssiInternal( BluetoothServiceBluedroid::GattClientReadRemoteRssiInternal(
int aClientIf, const nsAString& aDeviceAddress, int aClientIf, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -488,13 +476,7 @@ BluetoothServiceBluedroid::GattClientReadRemoteRssiInternal(
BluetoothGattManager* gatt = BluetoothGattManager::Get(); BluetoothGattManager* gatt = BluetoothGattManager::Get();
ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable); ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
BluetoothAddress deviceAddress; gatt->ReadRemoteRssi(aClientIf, aDeviceAddress, aRunnable);
if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
gatt->ReadRemoteRssi(aClientIf, deviceAddress, aRunnable);
} }
void void
@ -589,7 +571,7 @@ BluetoothServiceBluedroid::GattClientWriteDescriptorValueInternal(
// GATT Server // GATT Server
void void
BluetoothServiceBluedroid::GattServerConnectPeripheralInternal( BluetoothServiceBluedroid::GattServerConnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAddress, const nsAString& aAppUuid, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -602,18 +584,12 @@ BluetoothServiceBluedroid::GattServerConnectPeripheralInternal(
BluetoothUuid appUuid; BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid); StringToUuid(aAppUuid, appUuid);
BluetoothAddress address; gatt->ConnectPeripheral(appUuid, aAddress, aRunnable);
if (NS_FAILED(StringToAddress(aAddress, address))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
gatt->ConnectPeripheral(appUuid, address, aRunnable);
} }
void void
BluetoothServiceBluedroid::GattServerDisconnectPeripheralInternal( BluetoothServiceBluedroid::GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAddress, const nsAString& aAppUuid, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -626,13 +602,7 @@ BluetoothServiceBluedroid::GattServerDisconnectPeripheralInternal(
BluetoothUuid appUuid; BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid); StringToUuid(aAppUuid, appUuid);
BluetoothAddress address; gatt->DisconnectPeripheral(appUuid, aAddress, aRunnable);
if (NS_FAILED(StringToAddress(aAddress, address))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
gatt->DisconnectPeripheral(appUuid, address, aRunnable);
} }
void void
@ -806,7 +776,7 @@ BluetoothServiceBluedroid::GattServerStopServiceInternal(
void void
BluetoothServiceBluedroid::GattServerSendResponseInternal( BluetoothServiceBluedroid::GattServerSendResponseInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
uint16_t aStatus, uint16_t aStatus,
int32_t aRequestId, int32_t aRequestId,
const BluetoothGattResponse& aRsp, const BluetoothGattResponse& aRsp,
@ -822,20 +792,14 @@ BluetoothServiceBluedroid::GattServerSendResponseInternal(
BluetoothUuid appUuid; BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid); StringToUuid(aAppUuid, appUuid);
BluetoothAddress address;
if (NS_FAILED(StringToAddress(aAddress, address))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
gatt->ServerSendResponse( gatt->ServerSendResponse(
appUuid, address, aStatus, aRequestId, aRsp, aRunnable); appUuid, aAddress, aStatus, aRequestId, aRsp, aRunnable);
} }
void void
BluetoothServiceBluedroid::GattServerSendIndicationInternal( BluetoothServiceBluedroid::GattServerSendIndicationInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle, const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm, bool aConfirm,
const nsTArray<uint8_t>& aValue, const nsTArray<uint8_t>& aValue,
@ -851,14 +815,8 @@ BluetoothServiceBluedroid::GattServerSendIndicationInternal(
BluetoothUuid appUuid; BluetoothUuid appUuid;
StringToUuid(aAppUuid, appUuid); StringToUuid(aAppUuid, appUuid);
BluetoothAddress address;
if (NS_FAILED(StringToAddress(aAddress, address))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
gatt->ServerSendIndication(appUuid, gatt->ServerSendIndication(appUuid,
address, aAddress,
aCharacteristicHandle, aCharacteristicHandle,
aConfirm, aConfirm,
aValue, aValue,

View File

@ -283,12 +283,12 @@ public:
virtual void virtual void
ConnectGattClientInternal(const nsAString& aAppUuid, ConnectGattClientInternal(const nsAString& aAppUuid,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
DisconnectGattClientInternal(const nsAString& aAppUuid, DisconnectGattClientInternal(const nsAString& aAppUuid,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -315,7 +315,7 @@ public:
virtual void virtual void
GattClientReadRemoteRssiInternal( GattClientReadRemoteRssiInternal(
int aClientIf, const nsAString& aDeviceAddress, int aClientIf, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -354,13 +354,13 @@ public:
virtual void virtual void
GattServerConnectPeripheralInternal( GattServerConnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
GattServerDisconnectPeripheralInternal( GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -420,7 +420,7 @@ public:
virtual void virtual void
GattServerSendResponseInternal( GattServerSendResponseInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
uint16_t aStatus, uint16_t aStatus,
int32_t aRequestId, int32_t aRequestId,
const BluetoothGattResponse& aRsp, const BluetoothGattResponse& aRsp,
@ -429,7 +429,7 @@ public:
virtual void virtual void
GattServerSendIndicationInternal( GattServerSendIndicationInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle, const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm, bool aConfirm,
const nsTArray<uint8_t>& aValue, const nsTArray<uint8_t>& aValue,

View File

@ -4309,14 +4309,14 @@ BluetoothDBusService::StopLeScanInternal(
void void
BluetoothDBusService::ConnectGattClientInternal( BluetoothDBusService::ConnectGattClientInternal(
const nsAString& aAppUuid, const nsAString& aDeviceAddress, const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
} }
void void
BluetoothDBusService::DisconnectGattClientInternal( BluetoothDBusService::DisconnectGattClientInternal(
const nsAString& aAppUuid, const nsAString& aDeviceAddress, const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
} }
@ -4349,7 +4349,7 @@ BluetoothDBusService::UnregisterGattClientInternal(
void void
BluetoothDBusService::GattClientReadRemoteRssiInternal( BluetoothDBusService::GattClientReadRemoteRssiInternal(
int aClientIf, const nsAString& aDeviceAddress, int aClientIf, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
} }
@ -4521,14 +4521,14 @@ BluetoothDBusService::ReplyToMapMessageUpdate(long aMasId, bool aStatus,
void void
BluetoothDBusService::GattServerConnectPeripheralInternal( BluetoothDBusService::GattServerConnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAddress, const nsAString& aAppUuid, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
} }
void void
BluetoothDBusService::GattServerDisconnectPeripheralInternal( BluetoothDBusService::GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAddress, const nsAString& aAppUuid, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
} }
@ -4606,7 +4606,7 @@ BluetoothDBusService::GattServerStopServiceInternal(
void void
BluetoothDBusService::GattServerSendIndicationInternal( BluetoothDBusService::GattServerSendIndicationInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle, const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm, bool aConfirm,
const nsTArray<uint8_t>& aValue, const nsTArray<uint8_t>& aValue,
@ -4617,7 +4617,7 @@ BluetoothDBusService::GattServerSendIndicationInternal(
void void
BluetoothDBusService::GattServerSendResponseInternal( BluetoothDBusService::GattServerSendResponseInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
uint16_t aStatus, uint16_t aStatus,
int32_t aRequestId, int32_t aRequestId,
const BluetoothGattResponse& aRsp, const BluetoothGattResponse& aRsp,

View File

@ -294,12 +294,12 @@ public:
virtual void virtual void
ConnectGattClientInternal(const nsAString& aAppUuid, ConnectGattClientInternal(const nsAString& aAppUuid,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
DisconnectGattClientInternal(const nsAString& aAppUuid, DisconnectGattClientInternal(const nsAString& aAppUuid,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -326,7 +326,7 @@ public:
virtual void virtual void
GattClientReadRemoteRssiInternal( GattClientReadRemoteRssiInternal(
int aClientIf, const nsAString& aDeviceAddress, int aClientIf, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -365,13 +365,13 @@ public:
virtual void virtual void
GattServerConnectPeripheralInternal( GattServerConnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
GattServerDisconnectPeripheralInternal( GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -431,7 +431,7 @@ public:
virtual void virtual void
GattServerSendResponseInternal( GattServerSendResponseInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
uint16_t aStatus, uint16_t aStatus,
int32_t aRequestId, int32_t aRequestId,
const BluetoothGattResponse& aRsp, const BluetoothGattResponse& aRsp,
@ -440,7 +440,7 @@ public:
virtual void virtual void
GattServerSendIndicationInternal( GattServerSendIndicationInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle, const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm, bool aConfirm,
const nsTArray<uint8_t>& aValue, const nsTArray<uint8_t>& aValue,

View File

@ -442,7 +442,7 @@ public:
*/ */
virtual void virtual void
ConnectGattClientInternal(const nsAString& aAppUuid, ConnectGattClientInternal(const nsAString& aAppUuid,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
/** /**
@ -451,7 +451,7 @@ public:
*/ */
virtual void virtual void
DisconnectGattClientInternal(const nsAString& aAppUuid, DisconnectGattClientInternal(const nsAString& aAppUuid,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
/** /**
@ -494,7 +494,7 @@ public:
*/ */
virtual void virtual void
GattClientReadRemoteRssiInternal(int aClientIf, GattClientReadRemoteRssiInternal(int aClientIf,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
/** /**
@ -549,13 +549,13 @@ public:
virtual void virtual void
GattServerConnectPeripheralInternal( GattServerConnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
virtual void virtual void
GattServerDisconnectPeripheralInternal( GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
/** /**
@ -618,7 +618,7 @@ public:
virtual void virtual void
GattServerSendResponseInternal( GattServerSendResponseInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
uint16_t aStatus, uint16_t aStatus,
int32_t aRequestId, int32_t aRequestId,
const BluetoothGattResponse& aRsp, const BluetoothGattResponse& aRsp,
@ -627,7 +627,7 @@ public:
virtual void virtual void
GattServerSendIndicationInternal( GattServerSendIndicationInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle, const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm, bool aConfirm,
const nsTArray<uint8_t>& aValue, const nsTArray<uint8_t>& aValue,

View File

@ -112,6 +112,12 @@ BluetoothGatt::Connect(ErrorResult& aRv)
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
BluetoothAddress deviceAddr;
BT_ENSURE_TRUE_REJECT(
NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
promise,
NS_ERROR_DOM_OPERATION_ERR);
if (mAppUuid.IsEmpty()) { if (mAppUuid.IsEmpty()) {
nsresult rv = GenerateUuid(mAppUuid); nsresult rv = GenerateUuid(mAppUuid);
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv) && !mAppUuid.IsEmpty(), BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv) && !mAppUuid.IsEmpty(),
@ -122,7 +128,7 @@ BluetoothGatt::Connect(ErrorResult& aRv)
UpdateConnectionState(BluetoothConnectionState::Connecting); UpdateConnectionState(BluetoothConnectionState::Connecting);
bs->ConnectGattClientInternal( bs->ConnectGattClientInternal(
mAppUuid, mDeviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise)); mAppUuid, deviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget(); return promise.forget();
} }
@ -147,9 +153,15 @@ BluetoothGatt::Disconnect(ErrorResult& aRv)
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
BluetoothAddress deviceAddr;
BT_ENSURE_TRUE_REJECT(
NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
promise,
NS_ERROR_DOM_OPERATION_ERR);
UpdateConnectionState(BluetoothConnectionState::Disconnecting); UpdateConnectionState(BluetoothConnectionState::Disconnecting);
bs->DisconnectGattClientInternal( bs->DisconnectGattClientInternal(
mAppUuid, mDeviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise)); mAppUuid, deviceAddr, new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget(); return promise.forget();
} }
@ -196,8 +208,14 @@ BluetoothGatt::ReadRemoteRssi(ErrorResult& aRv)
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
BluetoothAddress deviceAddr;
BT_ENSURE_TRUE_REJECT(
NS_SUCCEEDED(StringToAddress(mDeviceAddr, deviceAddr)),
promise,
NS_ERROR_DOM_OPERATION_ERR);
bs->GattClientReadRemoteRssiInternal( bs->GattClientReadRemoteRssiInternal(
mClientIf, mDeviceAddr, new ReadRemoteRssiTask(promise)); mClientIf, deviceAddr, new ReadRemoteRssiTask(promise));
return promise.forget(); return promise.forget();
} }

View File

@ -319,12 +319,18 @@ BluetoothGattServer::Connect(const nsAString& aAddress, ErrorResult& aRv)
RefPtr<Promise> promise = Promise::Create(global, aRv); RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr); NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
BluetoothAddress address;
BT_ENSURE_TRUE_REJECT(
NS_SUCCEEDED(StringToAddress(aAddress, address)),
promise,
NS_ERROR_INVALID_ARG);
BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
bs->GattServerConnectPeripheralInternal( bs->GattServerConnectPeripheralInternal(
mAppUuid, aAddress, new BluetoothVoidReplyRunnable(nullptr, promise)); mAppUuid, address, new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget(); return promise.forget();
} }
@ -341,12 +347,18 @@ BluetoothGattServer::Disconnect(const nsAString& aAddress, ErrorResult& aRv)
RefPtr<Promise> promise = Promise::Create(global, aRv); RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr); NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
BluetoothAddress address;
BT_ENSURE_TRUE_REJECT(
NS_SUCCEEDED(StringToAddress(aAddress, address)),
promise,
NS_ERROR_INVALID_ARG);
BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
bs->GattServerDisconnectPeripheralInternal( bs->GattServerDisconnectPeripheralInternal(
mAppUuid, aAddress, new BluetoothVoidReplyRunnable(nullptr, promise)); mAppUuid, address, new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget(); return promise.forget();
} }
@ -798,6 +810,12 @@ BluetoothGattServer::NotifyCharacteristicChanged(
BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
BluetoothAddress address;
BT_ENSURE_TRUE_REJECT(
NS_SUCCEEDED(StringToAddress(aAddress, address)),
promise,
NS_ERROR_INVALID_ARG);
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
@ -808,7 +826,7 @@ BluetoothGattServer::NotifyCharacteristicChanged(
NS_ERROR_NOT_AVAILABLE); NS_ERROR_NOT_AVAILABLE);
bs->GattServerSendIndicationInternal( bs->GattServerSendIndicationInternal(
mAppUuid, aAddress, aCharacteristic.GetCharacteristicHandle(), aConfirm, mAppUuid, address, aCharacteristic.GetCharacteristicHandle(), aConfirm,
aCharacteristic.GetValue(), aCharacteristic.GetValue(),
new BluetoothVoidReplyRunnable(nullptr, promise)); new BluetoothVoidReplyRunnable(nullptr, promise));
@ -830,6 +848,12 @@ BluetoothGattServer::SendResponse(const nsAString& aAddress,
RefPtr<Promise> promise = Promise::Create(global, aRv); RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr); NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
BluetoothAddress address;
BT_ENSURE_TRUE_REJECT(
NS_SUCCEEDED(StringToAddress(aAddress, address)),
promise,
NS_ERROR_INVALID_ARG);
BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(mValid, promise, NS_ERROR_NOT_AVAILABLE);
RequestData* requestData; RequestData* requestData;
@ -862,7 +886,7 @@ BluetoothGattServer::SendResponse(const nsAString& aAddress,
bs->GattServerSendResponseInternal( bs->GattServerSendResponseInternal(
mAppUuid, mAppUuid,
aAddress, address,
aStatus, aStatus,
aRequestId, aRequestId,
response, response,

View File

@ -550,20 +550,20 @@ BluetoothServiceChildProcess::SendPlayStatus(int64_t aDuration,
void void
BluetoothServiceChildProcess::ConnectGattClientInternal( BluetoothServiceChildProcess::ConnectGattClientInternal(
const nsAString& aAppUuid, const nsAString& aDeviceAddress, const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
SendRequest(aRunnable, ConnectGattClientRequest(nsString(aAppUuid), SendRequest(aRunnable, ConnectGattClientRequest(nsString(aAppUuid),
nsString(aDeviceAddress))); aDeviceAddress));
} }
void void
BluetoothServiceChildProcess::DisconnectGattClientInternal( BluetoothServiceChildProcess::DisconnectGattClientInternal(
const nsAString& aAppUuid, const nsAString& aDeviceAddress, const nsAString& aAppUuid, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
SendRequest(aRunnable, SendRequest(aRunnable,
DisconnectGattClientRequest(nsString(aAppUuid), nsString(aDeviceAddress))); DisconnectGattClientRequest(nsString(aAppUuid), aDeviceAddress));
} }
void void
@ -601,12 +601,11 @@ BluetoothServiceChildProcess::UnregisterGattClientInternal(
void void
BluetoothServiceChildProcess::GattClientReadRemoteRssiInternal( BluetoothServiceChildProcess::GattClientReadRemoteRssiInternal(
int aClientIf, const nsAString& aDeviceAddress, int aClientIf, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
SendRequest(aRunnable, SendRequest(aRunnable,
GattClientReadRemoteRssiRequest(aClientIf, GattClientReadRemoteRssiRequest(aClientIf, aDeviceAddress));
nsString(aDeviceAddress)));
} }
void void
@ -674,23 +673,21 @@ BluetoothServiceChildProcess::GattClientWriteDescriptorValueInternal(
void void
BluetoothServiceChildProcess::GattServerConnectPeripheralInternal( BluetoothServiceChildProcess::GattServerConnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
SendRequest(aRunnable, SendRequest(aRunnable,
GattServerConnectPeripheralRequest(nsString(aAppUuid), GattServerConnectPeripheralRequest(nsString(aAppUuid), aAddress));
nsString(aAddress)));
} }
void void
BluetoothServiceChildProcess::GattServerDisconnectPeripheralInternal( BluetoothServiceChildProcess::GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
SendRequest(aRunnable, SendRequest(aRunnable,
GattServerDisconnectPeripheralRequest(nsString(aAppUuid), GattServerDisconnectPeripheralRequest(nsString(aAppUuid), aAddress));
nsString(aAddress)));
} }
void void
@ -791,7 +788,7 @@ BluetoothServiceChildProcess::GattServerStopServiceInternal(
void void
BluetoothServiceChildProcess::GattServerSendResponseInternal( BluetoothServiceChildProcess::GattServerSendResponseInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
uint16_t aStatus, uint16_t aStatus,
int32_t aRequestId, int32_t aRequestId,
const BluetoothGattResponse& aRsp, const BluetoothGattResponse& aRsp,
@ -799,13 +796,13 @@ BluetoothServiceChildProcess::GattServerSendResponseInternal(
{ {
SendRequest(aRunnable, SendRequest(aRunnable,
GattServerSendResponseRequest( GattServerSendResponseRequest(
nsString(aAppUuid), nsString(aAddress), aStatus, aRequestId, aRsp)); nsString(aAppUuid), aAddress, aStatus, aRequestId, aRsp));
} }
void void
BluetoothServiceChildProcess::GattServerSendIndicationInternal( BluetoothServiceChildProcess::GattServerSendIndicationInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle, const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm, bool aConfirm,
const nsTArray<uint8_t>& aValue, const nsTArray<uint8_t>& aValue,
@ -813,7 +810,7 @@ BluetoothServiceChildProcess::GattServerSendIndicationInternal(
{ {
SendRequest(aRunnable, SendRequest(aRunnable,
GattServerSendIndicationRequest(nsString(aAppUuid), GattServerSendIndicationRequest(nsString(aAppUuid),
nsString(aAddress), aAddress,
aCharacteristicHandle, aCharacteristicHandle,
aConfirm, aConfirm,
aValue)); aValue));

View File

@ -285,12 +285,12 @@ public:
virtual void virtual void
ConnectGattClientInternal(const nsAString& aAppUuid, ConnectGattClientInternal(const nsAString& aAppUuid,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
DisconnectGattClientInternal(const nsAString& aAppUuid, DisconnectGattClientInternal(const nsAString& aAppUuid,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -317,7 +317,7 @@ public:
virtual void virtual void
GattClientReadRemoteRssiInternal(int aClientIf, GattClientReadRemoteRssiInternal(int aClientIf,
const nsAString& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -356,13 +356,13 @@ public:
virtual void virtual void
GattServerConnectPeripheralInternal( GattServerConnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
GattServerDisconnectPeripheralInternal( GattServerDisconnectPeripheralInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -422,7 +422,7 @@ public:
virtual void virtual void
GattServerSendResponseInternal( GattServerSendResponseInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
uint16_t aStatus, uint16_t aStatus,
int32_t aRequestId, int32_t aRequestId,
const BluetoothGattResponse& aRsp, const BluetoothGattResponse& aRsp,
@ -431,7 +431,7 @@ public:
virtual void virtual void
GattServerSendIndicationInternal( GattServerSendIndicationInternal(
const nsAString& aAppUuid, const nsAString& aAppUuid,
const nsAString& aAddress, const BluetoothAddress& aAddress,
const BluetoothAttributeHandle& aCharacteristicHandle, const BluetoothAttributeHandle& aCharacteristicHandle,
bool aConfirm, bool aConfirm,
const nsTArray<uint8_t>& aValue, const nsTArray<uint8_t>& aValue,

View File

@ -276,13 +276,13 @@ struct SendPlayStatusRequest
struct ConnectGattClientRequest struct ConnectGattClientRequest
{ {
nsString appUuid; nsString appUuid;
nsString deviceAddress; BluetoothAddress deviceAddress;
}; };
struct DisconnectGattClientRequest struct DisconnectGattClientRequest
{ {
nsString appUuid; nsString appUuid;
nsString deviceAddress; BluetoothAddress deviceAddress;
}; };
struct DiscoverGattServicesRequest struct DiscoverGattServicesRequest
@ -312,7 +312,7 @@ struct UnregisterGattClientRequest
struct GattClientReadRemoteRssiRequest struct GattClientReadRemoteRssiRequest
{ {
int clientIf; int clientIf;
nsString deviceAddress; BluetoothAddress deviceAddress;
}; };
struct GattClientReadCharacteristicValueRequest struct GattClientReadCharacteristicValueRequest
@ -351,13 +351,13 @@ struct GattClientWriteDescriptorValueRequest
struct GattServerConnectPeripheralRequest struct GattServerConnectPeripheralRequest
{ {
nsString appUuid; nsString appUuid;
nsString address; BluetoothAddress address;
}; };
struct GattServerDisconnectPeripheralRequest struct GattServerDisconnectPeripheralRequest
{ {
nsString appUuid; nsString appUuid;
nsString address; BluetoothAddress address;
}; };
struct UnregisterGattServerRequest struct UnregisterGattServerRequest
@ -418,7 +418,7 @@ struct GattServerStopServiceRequest
struct GattServerSendResponseRequest struct GattServerSendResponseRequest
{ {
nsString appUuid; nsString appUuid;
nsString address; BluetoothAddress address;
uint16_t status; uint16_t status;
int32_t requestId; int32_t requestId;
BluetoothGattResponse response; BluetoothGattResponse response;
@ -427,7 +427,7 @@ struct GattServerSendResponseRequest
struct GattServerSendIndicationRequest struct GattServerSendIndicationRequest
{ {
nsString appUuid; nsString appUuid;
nsString address; BluetoothAddress address;
BluetoothAttributeHandle characteristicHandle; BluetoothAttributeHandle characteristicHandle;
bool confirm; bool confirm;
uint8_t[] value; uint8_t[] value;