diff --git a/dom/bluetooth/BluetoothA2dpManager.h b/dom/bluetooth/BluetoothA2dpManager.h index 14435b93bac..70d88f34557 100644 --- a/dom/bluetooth/BluetoothA2dpManager.h +++ b/dom/bluetooth/BluetoothA2dpManager.h @@ -18,6 +18,11 @@ class BluetoothA2dpManager : public BluetoothProfileManagerBase public: NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER + BT_DECL_PROFILE_MGR_BASE + virtual void GetName(nsACString& aName) + { + aName.AssignLiteral("A2DP"); + } enum SinkState { SINK_UNKNOWN, @@ -32,24 +37,6 @@ public: void ResetA2dp(); void ResetAvrcp(); - // The following functions are inherited from BluetoothProfileManagerBase - virtual void OnGetServiceChannel(const nsAString& aDeviceAddress, - const nsAString& aServiceUuid, - int aChannel) MOZ_OVERRIDE; - virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE; - virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE; - virtual bool IsConnected() MOZ_OVERRIDE; - virtual void Connect(const nsAString& aDeviceAddress, - BluetoothProfileController* aController) MOZ_OVERRIDE; - virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE; - virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE; - virtual void OnDisconnect(const nsAString& aErrorStr) MOZ_OVERRIDE; - - virtual void GetName(nsACString& aName) - { - aName.AssignLiteral("A2DP"); - } - // A2DP-specific functions void HandleSinkPropertyChanged(const BluetoothSignal& aSignal); diff --git a/dom/bluetooth/BluetoothHfpManager.h b/dom/bluetooth/BluetoothHfpManager.h index b62eb8dc2ff..e81dd90b50c 100644 --- a/dom/bluetooth/BluetoothHfpManager.h +++ b/dom/bluetooth/BluetoothHfpManager.h @@ -80,6 +80,11 @@ class BluetoothHfpManager : public BluetoothSocketObserver public: NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER + BT_DECL_PROFILE_MGR_BASE + virtual void GetName(nsACString& aName) + { + aName.AssignLiteral("HFP/HSP"); + } static BluetoothHfpManager* Get(); ~BluetoothHfpManager(); @@ -92,27 +97,11 @@ public: virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE; virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE; - // The following functions are inherited from BluetoothProfileManagerBase - virtual void OnGetServiceChannel(const nsAString& aDeviceAddress, - const nsAString& aServiceUuid, - int aChannel) MOZ_OVERRIDE; - virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE; - virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE; - virtual void Connect(const nsAString& aDeviceAddress, - BluetoothProfileController* aController) MOZ_OVERRIDE; - virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE; - virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE; - virtual void OnDisconnect(const nsAString& AErrorStr) MOZ_OVERRIDE; - - virtual void GetName(nsACString& aName) - { - aName.AssignLiteral("HFP/HSP"); - } - bool Listen(); bool ConnectSco(BluetoothReplyRunnable* aRunnable = nullptr); bool DisconnectSco(); bool ListenSco(); + bool IsScoConnected(); #ifdef MOZ_B2G_RIL /** @@ -123,12 +112,7 @@ public: const bool aIsOutgoing, bool aSend); void HandleIccInfoChanged(); void HandleVoiceConnectionChanged(); -#endif - bool IsConnected(); - bool IsScoConnected(); - -#ifdef MOZ_B2G_RIL // CDMA-specific functions void UpdateSecondNumber(const nsAString& aNumber); void AnswerWaitingCall(); diff --git a/dom/bluetooth/BluetoothHidManager.h b/dom/bluetooth/BluetoothHidManager.h index 85e774279a7..41fccf56359 100644 --- a/dom/bluetooth/BluetoothHidManager.h +++ b/dom/bluetooth/BluetoothHidManager.h @@ -18,29 +18,15 @@ class BluetoothHidManager : public BluetoothProfileManagerBase public: NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER - - static BluetoothHidManager* Get(); - ~BluetoothHidManager(); - - // The following functions are inherited from BluetoothProfileManagerBase - virtual void OnGetServiceChannel(const nsAString& aDeviceAddress, - const nsAString& aServiceUuid, - int aChannel) MOZ_OVERRIDE; - virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE; - virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE; - virtual bool IsConnected() MOZ_OVERRIDE; - virtual void Connect(const nsAString& aDeviceAddress, - BluetoothProfileController* aController) MOZ_OVERRIDE; - virtual void Disconnect(BluetoothProfileController* aController) - MOZ_OVERRIDE; - virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE; - virtual void OnDisconnect(const nsAString& aErrorStr) MOZ_OVERRIDE; - + BT_DECL_PROFILE_MGR_BASE virtual void GetName(nsACString& aName) { aName.AssignLiteral("HID"); } + static BluetoothHidManager* Get(); + ~BluetoothHidManager(); + // HID-specific functions void HandleInputPropertyChanged(const BluetoothSignal& aSignal); diff --git a/dom/bluetooth/BluetoothOppManager.h b/dom/bluetooth/BluetoothOppManager.h index 4fba2205811..536ad88bdb8 100644 --- a/dom/bluetooth/BluetoothOppManager.h +++ b/dom/bluetooth/BluetoothOppManager.h @@ -31,6 +31,11 @@ class BluetoothOppManager : public BluetoothSocketObserver public: NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER + BT_DECL_PROFILE_MGR_BASE + virtual void GetName(nsACString& aName) + { + aName.AssignLiteral("OPP"); + } /* * Channel of reserved services are fixed values, please check @@ -69,25 +74,6 @@ public: virtual void OnSocketConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE; virtual void OnSocketDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE; - // The following functions are inherited from BluetoothProfileManagerBase - virtual void OnGetServiceChannel(const nsAString& aDeviceAddress, - const nsAString& aServiceUuid, - int aChannel) MOZ_OVERRIDE; - virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE; - virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE; - virtual bool IsConnected() MOZ_OVERRIDE; - - virtual void GetName(nsACString& aName) - { - aName.AssignLiteral("OPP"); - } - - virtual void Connect(const nsAString& aDeviceAddress, - BluetoothProfileController* aController) MOZ_OVERRIDE; - virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE; - virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE; - virtual void OnDisconnect(const nsAString& aErrorStr) MOZ_OVERRIDE; - private: BluetoothOppManager(); bool Init(); diff --git a/dom/bluetooth/BluetoothProfileManagerBase.h b/dom/bluetooth/BluetoothProfileManagerBase.h index 013eb41da8d..af2adc0211b 100644 --- a/dom/bluetooth/BluetoothProfileManagerBase.h +++ b/dom/bluetooth/BluetoothProfileManagerBase.h @@ -70,6 +70,20 @@ public: virtual void GetName(nsACString& aName) = 0; }; +#define BT_DECL_PROFILE_MGR_BASE \ +public: \ + virtual void OnGetServiceChannel(const nsAString& aDeviceAddress, \ + const nsAString& aServiceUuid, \ + int aChannel) MOZ_OVERRIDE; \ + virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE; \ + virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE; \ + virtual bool IsConnected() MOZ_OVERRIDE; \ + virtual void Connect(const nsAString& aDeviceAddress, \ + BluetoothProfileController* aController) MOZ_OVERRIDE; \ + virtual void Disconnect(BluetoothProfileController* aController) MOZ_OVERRIDE; \ + virtual void OnConnect(const nsAString& aErrorStr) MOZ_OVERRIDE; \ + virtual void OnDisconnect(const nsAString& AErrorStr) MOZ_OVERRIDE; \ + END_BLUETOOTH_NAMESPACE #endif //#ifndef mozilla_dom_bluetooth_bluetoothprofilemanagerbase_h__ diff --git a/dom/bluetooth/BluetoothServiceBluedroid.cpp b/dom/bluetooth/BluetoothServiceBluedroid.cpp index 6c36e16bdb1..2f8c2b89bf0 100644 --- a/dom/bluetooth/BluetoothServiceBluedroid.cpp +++ b/dom/bluetooth/BluetoothServiceBluedroid.cpp @@ -21,6 +21,7 @@ #include #include +#include "BluetoothProfileController.h" #include "BluetoothReplyRunnable.h" #include "BluetoothUtils.h" #include "BluetoothUuid.h" @@ -70,6 +71,7 @@ static nsString sAdapterBdName; static uint32_t sAdapterDiscoverableTimeout; static InfallibleTArray sAdapterBondedAddressArray; static InfallibleTArray sRemoteDevicesPack; +static nsTArray > sControllerArray; static nsTArray > sBondingRunnableArray; static nsTArray > sChangeDiscoveryRunnableArray; static nsTArray > sGetPairedDeviceRunnableArray; @@ -1079,13 +1081,55 @@ BluetoothServiceBluedroid::PrepareAdapterInternal() return NS_OK; } +static void +NextBluetoothProfileController() +{ + sControllerArray[0] = nullptr; + sControllerArray.RemoveElementAt(0); + + if (!sControllerArray.IsEmpty()) { + sControllerArray[0]->Start(); + } +} + +static void +ConnectDisconnect(bool aConnect, const nsAString& aDeviceAddress, + BluetoothReplyRunnable* aRunnable, + uint16_t aServiceUuid, uint32_t aCod = 0) +{ + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(aRunnable); + + BluetoothProfileController* controller = + new BluetoothProfileController(aConnect, aDeviceAddress, aRunnable, + NextBluetoothProfileController, + aServiceUuid, aCod); + sControllerArray.AppendElement(controller); + + /** + * If the request is the first element of the quene, start from here. Note + * that other request is pushed into the quene and is popped out after the + * first one is completed. See NextBluetoothProfileController() for details. + */ + if (sControllerArray.Length() == 1) { + sControllerArray[0]->Start(); + } +} + void BluetoothServiceBluedroid::Connect(const nsAString& aDeviceAddress, uint32_t aCod, uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable) { + // TODO: Remove this error reply once Connect() is done in profile managers + if (aRunnable) { + DispatchBluetoothReply(aRunnable, BluetoothValue(), + NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); + return; + } + ConnectDisconnect(true, aDeviceAddress, aRunnable, aServiceUuid, aCod); } bool @@ -1099,7 +1143,14 @@ BluetoothServiceBluedroid::Disconnect( const nsAString& aDeviceAddress, uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable) { + // TODO: Remove this error reply once Disconnect() is done in profile managers + if (aRunnable) { + DispatchBluetoothReply(aRunnable, BluetoothValue(), + NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); + return; + } + ConnectDisconnect(false, aDeviceAddress, aRunnable, aServiceUuid); } void