Bug 1033961: Split Bluedroid start/stop code (under bluetooth2/), r=btian

This patch prepares refactoring of the Bluedroid start and stop
code towards an asynchronous design.
This commit is contained in:
Thomas Zimmermann 2014-07-09 09:37:53 +02:00
parent b8bec5f581
commit 749115a0d9

View File

@ -831,7 +831,7 @@ EnableInternal()
}
static nsresult
StartStopGonkBluetooth(bool aShouldEnable)
StartGonkBluetooth()
{
MOZ_ASSERT(NS_IsMainThread());
@ -840,17 +840,43 @@ StartStopGonkBluetooth(bool aShouldEnable)
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
if (bs->IsEnabled() == aShouldEnable) {
if (bs->IsEnabled()) {
// Keep current enable status
nsRefPtr<nsRunnable> runnable =
new BluetoothService::ToggleBtAck(aShouldEnable);
new BluetoothService::ToggleBtAck(true);
if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_OK;
}
int ret = aShouldEnable ? EnableInternal() : sBtInterface->Disable();
int ret = EnableInternal();
NS_ENSURE_TRUE(ret == BT_STATUS_SUCCESS, NS_ERROR_FAILURE);
return NS_OK;
}
static nsresult
StopGonkBluetooth()
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_TRUE(sBtInterface, NS_ERROR_FAILURE);
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
if (!bs->IsEnabled()) {
// Keep current enable status
nsRefPtr<nsRunnable> runnable =
new BluetoothService::ToggleBtAck(false);
if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_OK;
}
int ret = sBtInterface->Disable();
NS_ENSURE_TRUE(ret == BT_STATUS_SUCCESS, NS_ERROR_FAILURE);
return NS_OK;
@ -910,7 +936,7 @@ BluetoothServiceBluedroid::StartInternal(BluetoothReplyRunnable* aRunnable)
sChangeAdapterStateRunnableArray.AppendElement(aRunnable);
}
nsresult ret = StartStopGonkBluetooth(true);
nsresult ret = StartGonkBluetooth();
if (NS_FAILED(ret)) {
nsRefPtr<nsRunnable> runnable =
new BluetoothService::ToggleBtAck(false);
@ -942,7 +968,7 @@ BluetoothServiceBluedroid::StopInternal(BluetoothReplyRunnable* aRunnable)
sChangeAdapterStateRunnableArray.AppendElement(aRunnable);
}
nsresult ret = StartStopGonkBluetooth(false);
nsresult ret = StopGonkBluetooth();
if (NS_FAILED(ret)) {
nsRefPtr<nsRunnable> runnable =
new BluetoothService::ToggleBtAck(true);