From f3401e1c87ea458d73dab57bf58f8edfd8a89aa3 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Mon, 3 Mar 2014 13:07:17 +0100 Subject: [PATCH] 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. --- dom/bluetooth/BluetoothService.cpp | 9 +++-- .../bluedroid/BluetoothServiceBluedroid.cpp | 18 ++++++++++ dom/bluetooth/bluez/BluetoothDBusService.cpp | 33 +++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/dom/bluetooth/BluetoothService.cpp b/dom/bluetooth/BluetoothService.cpp index 7db4e2659d6..b29d505f09a 100644 --- a/dom/bluetooth/BluetoothService.cpp +++ b/dom/bluetooth/BluetoothService.cpp @@ -206,6 +206,10 @@ public: */ if (!mIsStartup && mEnabled == sBluetoothService->IsEnabledInternal()) { BT_WARNING("Bluetooth has already been enabled/disabled before."); + nsCOMPtr 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 ackTask = new BluetoothService::ToggleBtAck(mEnabled); - if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { - BT_WARNING("Failed to dispatch to main thread!"); - } - return NS_OK; } diff --git a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp index 560f165c3c0..780dee06ad2 100644 --- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp +++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp @@ -741,9 +741,18 @@ BluetoothServiceBluedroid::StartInternal() nsresult ret = StartStopGonkBluetooth(true); if (NS_FAILED(ret)) { + nsCOMPtr ackTask = new BluetoothService::ToggleBtAck(false); + if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { + BT_WARNING("Failed to dispatch to main thread!"); + } BT_LOGR("Error"); } + nsCOMPtr 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 ackTask = new BluetoothService::ToggleBtAck(true); + if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { + BT_WARNING("Failed to dispatch to main thread!"); + } BT_LOGR("Error"); } + nsCOMPtr ackTask = new BluetoothService::ToggleBtAck(false); + if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { + BT_WARNING("Failed to dispatch to main thread!"); + } + return ret; } diff --git a/dom/bluetooth/bluez/BluetoothDBusService.cpp b/dom/bluetooth/bluez/BluetoothDBusService.cpp index c5872a3b3f3..f8a21885e9c 100644 --- a/dom/bluetooth/bluez/BluetoothDBusService.cpp +++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp @@ -1889,12 +1889,20 @@ BluetoothDBusService::StartInternal() if (sDBusConnection) { // This should actually not happen. BT_WARNING("Bluetooth is already running"); + nsCOMPtr 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 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 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 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 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 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 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 ackTask = new BluetoothService::ToggleBtAck(false); + if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { + BT_WARNING("Failed to dispatch to main thread!"); + } return NS_OK; }