Bug 1029390: Asynchronous A2DP connect/disconnect, r=shuang

This commit is contained in:
Thomas Zimmermann 2014-07-23 07:56:23 +02:00
parent 08bd1b58db
commit f3ed04c2d8
4 changed files with 70 additions and 20 deletions

View File

@ -771,6 +771,29 @@ BluetoothA2dpManager::HandleShutdown()
sBluetoothA2dpManager = nullptr;
}
void
BluetoothA2dpManager::OnConnectError()
{
MOZ_ASSERT(NS_IsMainThread());
mController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
mController = nullptr;
mDeviceAddress.Truncate();
}
class ConnectResultHandler MOZ_FINAL : public BluetoothA2dpResultHandler
{
public:
void OnError(bt_status_t aStatus) MOZ_OVERRIDE
{
BT_LOGR("BluetoothA2dpInterface::Connect failed: %d", (int)aStatus);
NS_ENSURE_TRUE_VOID(sBluetoothA2dpManager);
sBluetoothA2dpManager->OnConnectError();
}
};
void
BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
BluetoothProfileController* aController)
@ -802,14 +825,29 @@ BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
bt_bdaddr_t remoteAddress;
StringToBdAddressType(aDeviceAddress, &remoteAddress);
bt_status_t result = sBtA2dpInterface->Connect(&remoteAddress);
if (BT_STATUS_SUCCESS != result) {
BT_LOGR("Failed to connect: %x", result);
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
return;
}
sBtA2dpInterface->Connect(&remoteAddress, new ConnectResultHandler());
}
void
BluetoothA2dpManager::OnDisconnectError()
{
MOZ_ASSERT(NS_IsMainThread());
mController->NotifyCompletion(NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
}
class DisconnectResultHandler MOZ_FINAL : public BluetoothA2dpResultHandler
{
public:
void OnError(bt_status_t aStatus) MOZ_OVERRIDE
{
BT_LOGR("BluetoothA2dpInterface::Disconnect failed: %d", (int)aStatus);
NS_ENSURE_TRUE_VOID(sBluetoothA2dpManager);
sBluetoothA2dpManager->OnDisconnectError();
}
};
void
BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
{
@ -844,12 +882,7 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
bt_bdaddr_t remoteAddress;
StringToBdAddressType(mDeviceAddress, &remoteAddress);
bt_status_t result = sBtA2dpInterface->Disconnect(&remoteAddress);
if (BT_STATUS_SUCCESS != result) {
BT_LOGR("Failed to disconnect: %x", result);
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
return;
}
sBtA2dpInterface->Disconnect(&remoteAddress, new DisconnectResultHandler());
}
void

View File

@ -34,6 +34,9 @@ public:
static void DeinitA2dpInterface(BluetoothProfileResultHandler* aRes);
virtual ~BluetoothA2dpManager();
void OnConnectError();
void OnDisconnectError();
// A2DP-specific functions
void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);

View File

@ -911,16 +911,28 @@ BluetoothA2dpInterface::Cleanup(BluetoothA2dpResultHandler* aRes)
}
}
bt_status_t
BluetoothA2dpInterface::Connect(bt_bdaddr_t *aBdAddr)
void
BluetoothA2dpInterface::Connect(bt_bdaddr_t *aBdAddr,
BluetoothA2dpResultHandler* aRes)
{
return mInterface->connect(aBdAddr);
bt_status_t status = mInterface->connect(aBdAddr);
if (aRes) {
DispatchBluetoothA2dpResult(aRes, &BluetoothA2dpResultHandler::Connect,
status);
}
}
bt_status_t
BluetoothA2dpInterface::Disconnect(bt_bdaddr_t *aBdAddr)
void
BluetoothA2dpInterface::Disconnect(bt_bdaddr_t *aBdAddr,
BluetoothA2dpResultHandler* aRes)
{
return mInterface->disconnect(aBdAddr);
bt_status_t status = mInterface->disconnect(aBdAddr);
if (aRes) {
DispatchBluetoothA2dpResult(aRes, &BluetoothA2dpResultHandler::Disconnect,
status);
}
}
//

View File

@ -208,8 +208,10 @@ public:
BluetoothA2dpResultHandler* aRes);
void Cleanup(BluetoothA2dpResultHandler* aRes);
bt_status_t Connect(bt_bdaddr_t *aBdAddr);
bt_status_t Disconnect(bt_bdaddr_t *aBdAddr);
void Connect(bt_bdaddr_t *aBdAddr,
BluetoothA2dpResultHandler* aRes);
void Disconnect(bt_bdaddr_t *aBdAddr,
BluetoothA2dpResultHandler* aRes);
protected:
BluetoothA2dpInterface(const btav_interface_t* aInterface);