Bug 977146: Push ToggleBtAck into implementations of {Start|Stop}Internal, r=echou

The methods {Start|Stop}Internal for BlueZ and Bluedroid now send
ToggleBtAck to signal completeness of the operation.

The current patch allows for further cleanups in the BlueZ code. It
does not change the semantics or code flow.
This commit is contained in:
Thomas Zimmermann 2014-03-03 13:07:17 +01:00
parent 714a2b2204
commit f3401e1c87
3 changed files with 55 additions and 5 deletions

View File

@ -206,6 +206,10 @@ public:
*/
if (!mIsStartup && mEnabled == sBluetoothService->IsEnabledInternal()) {
BT_WARNING("Bluetooth has already been enabled/disabled before.");
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(mEnabled);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
} else {
// Switch on/off bluetooth
if (mEnabled) {
@ -221,11 +225,6 @@ public:
}
}
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(mEnabled);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_OK;
}

View File

@ -741,9 +741,18 @@ BluetoothServiceBluedroid::StartInternal()
nsresult ret = StartStopGonkBluetooth(true);
if (NS_FAILED(ret)) {
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(false);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
BT_LOGR("Error");
}
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(true);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return ret;
}
@ -754,9 +763,18 @@ BluetoothServiceBluedroid::StopInternal()
nsresult ret = StartStopGonkBluetooth(false);
if (NS_FAILED(ret)) {
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(true);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
BT_LOGR("Error");
}
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(false);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return ret;
}

View File

@ -1889,12 +1889,20 @@ BluetoothDBusService::StartInternal()
if (sDBusConnection) {
// This should actually not happen.
BT_WARNING("Bluetooth is already running");
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(true);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_OK;
}
#ifdef MOZ_WIDGET_GONK
if (!sBluedroid.Enable()) {
BT_WARNING("Bluetooth not available.");
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(false);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_ERROR_FAILURE;
}
#endif
@ -1903,6 +1911,10 @@ BluetoothDBusService::StartInternal()
nsresult rv = connection->EstablishDBusConnection();
if (NS_FAILED(rv)) {
BT_WARNING("Failed to establish connection to BlueZ daemon");
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(false);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_ERROR_FAILURE;
}
@ -1926,6 +1938,10 @@ BluetoothDBusService::StartInternal()
if (!dbus_connection_add_filter(connection->GetConnection(),
EventFilter, nullptr, nullptr)) {
BT_WARNING("Cannot create DBus Event Filter for DBus Thread!");
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(false);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_ERROR_FAILURE;
}
@ -1938,6 +1954,11 @@ BluetoothDBusService::StartInternal()
Task* task = new StartDBusConnectionTask(connection, sAdapterPath.IsEmpty());
DispatchToDBusThread(task);
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(true);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_OK;
}
@ -1985,6 +2006,10 @@ BluetoothDBusService::StopInternal()
}
if (!sDBusConnection) {
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(false);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_OK;
}
@ -2032,10 +2057,18 @@ BluetoothDBusService::StopInternal()
#ifdef MOZ_WIDGET_GONK
MOZ_ASSERT(sBluedroid.IsEnabled());
if (!sBluedroid.Disable()) {
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(true);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_ERROR_FAILURE;
}
#endif
nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(false);
if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
BT_WARNING("Failed to dispatch to main thread!");
}
return NS_OK;
}