From e4f30d0b9a66525b404d8b24373c9c35f3b12947 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 22 Jul 2014 13:53:27 +0200 Subject: [PATCH] Bug 1038645: Add result-handler class for Bluetooth Handsfree profile (under bluetooth2/), r=btian --- .../bluedroid/BluetoothInterface.cpp | 31 ++++++++++++++++ dom/bluetooth2/bluedroid/BluetoothInterface.h | 35 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/dom/bluetooth2/bluedroid/BluetoothInterface.cpp b/dom/bluetooth2/bluedroid/BluetoothInterface.cpp index cd5d01ee46a..5fd4e73742a 100644 --- a/dom/bluetooth2/bluedroid/BluetoothInterface.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothInterface.cpp @@ -576,6 +576,37 @@ struct interface_traits } }; +typedef + BluetoothInterfaceRunnable0 + BluetoothHandsfreeResultRunnable; + +typedef + BluetoothInterfaceRunnable1 + BluetoothHandsfreeErrorRunnable; + +static nsresult +DispatchBluetoothHandsfreeResult( + BluetoothHandsfreeResultHandler* aRes, + void (BluetoothHandsfreeResultHandler::*aMethod)(), + bt_status_t aStatus) +{ + MOZ_ASSERT(aRes); + + nsRunnable* runnable; + + if (aStatus == BT_STATUS_SUCCESS) { + runnable = new BluetoothHandsfreeResultRunnable(aRes, aMethod); + } else { + runnable = new BluetoothHandsfreeErrorRunnable(aRes, + &BluetoothHandsfreeResultHandler::OnError, aStatus); + } + nsresult rv = NS_DispatchToMainThread(runnable); + if (NS_FAILED(rv)) { + BT_WARNING("NS_DispatchToMainThread failed: %X", rv); + } + return rv; +} + BluetoothHandsfreeInterface::BluetoothHandsfreeInterface( const bthf_interface_t* aInterface) : mInterface(aInterface) diff --git a/dom/bluetooth2/bluedroid/BluetoothInterface.h b/dom/bluetooth2/bluedroid/BluetoothInterface.h index 24d1946df94..c67170ed1ba 100644 --- a/dom/bluetooth2/bluedroid/BluetoothInterface.h +++ b/dom/bluetooth2/bluedroid/BluetoothInterface.h @@ -72,6 +72,41 @@ private: // Handsfree Interface // +class BluetoothHandsfreeResultHandler +{ +public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothHandsfreeResultHandler) + + virtual ~BluetoothHandsfreeResultHandler() { } + + virtual void OnError(bt_status_t aStatus) + { + BT_WARNING("Received error code %d", (int)aStatus); + } + + virtual void Init() { } + virtual void Cleanup() { } + + virtual void Connect() { } + virtual void Disconnect() { } + virtual void ConnectAudio() { } + virtual void DisconnectAudio() { } + + virtual void StartVoiceRecognition() { } + virtual void StopVoiceRecognition() { } + + virtual void VolumeControl() { } + + virtual void DeviceStatusNotification() { } + + virtual void CopsResponse() { } + virtual void CindResponse() { } + virtual void FormattedAtResponse() { } + virtual void AtResponse() { } + virtual void ClccResponse() { } + virtual void PhoneStateChange() { } +}; + class BluetoothHandsfreeInterface { public: