diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h index 6b3181bdceea..268fe53ac455 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h +++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h @@ -97,12 +97,6 @@ struct BluetoothAvrcpEventParamPair { const BluetoothAvrcpNotificationParam& mParam; }; -struct BluetoothConfigurationParameter { - uint8_t mType; - uint16_t mLength; - nsAutoArrayPtr mValue; -}; - // // Conversion // diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp index 04575a1174d1..4efa8fd9aa0f 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp +++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp @@ -889,9 +889,21 @@ BluetoothDaemonInterface::DispatchError(BluetoothResultHandler* aRes, DispatchError(aRes, status); } -// Profile Interfaces +// Service Interfaces // +BluetoothSetupInterface* +BluetoothDaemonInterface::GetBluetoothSetupInterface() +{ + if (mSetupInterface) { + return mSetupInterface; + } + + mSetupInterface = new BluetoothDaemonSetupInterface(mProtocol); + + return mSetupInterface; +} + BluetoothSocketInterface* BluetoothDaemonInterface::GetBluetoothSocketInterface() { diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h index 2aef2f50ef5d..9b908417fcb9 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h +++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.h @@ -27,6 +27,7 @@ class BluetoothDaemonAvrcpInterface; class BluetoothDaemonGattInterface; class BluetoothDaemonHandsfreeInterface; class BluetoothDaemonProtocol; +class BluetoothDaemonSetupInterface; class BluetoothDaemonSocketInterface; class BluetoothDaemonInterface final @@ -125,8 +126,9 @@ public: void ReadEnergyInfo(BluetoothResultHandler* aRes) override; - /* Profile Interfaces */ + /* Service Interfaces */ + BluetoothSetupInterface* GetBluetoothSetupInterface() override; BluetoothSocketInterface* GetBluetoothSocketInterface() override; BluetoothHandsfreeInterface* GetBluetoothHandsfreeInterface() override; BluetoothA2dpInterface* GetBluetoothA2dpInterface() override; @@ -162,6 +164,7 @@ private: nsTArray > mResultHandlerQ; + nsAutoPtr mSetupInterface; nsAutoPtr mSocketInterface; nsAutoPtr mHandsfreeInterface; nsAutoPtr mA2dpInterface; diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.cpp b/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.cpp index c3e2196c1087..8640ca303644 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.cpp +++ b/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.cpp @@ -9,6 +9,8 @@ BEGIN_BLUETOOTH_NAMESPACE +using namespace mozilla::ipc; + // // Setup module // @@ -167,4 +169,77 @@ BluetoothDaemonSetupModule::ConfigurationRsp( UnpackPDUInitOp(aPDU)); } +// +// Setup interface +// + +BluetoothDaemonSetupInterface::BluetoothDaemonSetupInterface( + BluetoothDaemonSetupModule* aModule) + : mModule(aModule) +{ } + +BluetoothDaemonSetupInterface::~BluetoothDaemonSetupInterface() +{ } + +void +BluetoothDaemonSetupInterface::RegisterModule( + uint8_t aId, uint8_t aMode, uint32_t aMaxNumClients, + BluetoothSetupResultHandler* aRes) +{ + MOZ_ASSERT(mModule); + + nsresult rv = mModule->RegisterModuleCmd(aId, aMode, aMaxNumClients, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonSetupInterface::UnregisterModule( + uint8_t aId, + BluetoothSetupResultHandler* aRes) +{ + MOZ_ASSERT(mModule); + + nsresult rv = mModule->UnregisterModuleCmd(aId, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonSetupInterface::Configuration( + const BluetoothConfigurationParameter* aParam, uint8_t aLen, + BluetoothSetupResultHandler* aRes) +{ + MOZ_ASSERT(mModule); + + nsresult rv = mModule->ConfigurationCmd(aParam, aLen, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonSetupInterface::DispatchError( + BluetoothSetupResultHandler* aRes, BluetoothStatus aStatus) +{ + DaemonResultRunnable1::Dispatch( + aRes, &BluetoothSetupResultHandler::OnError, + ConstantInitOp1(aStatus)); +} + +void +BluetoothDaemonSetupInterface::DispatchError( + BluetoothSetupResultHandler* aRes, nsresult aRv) +{ + BluetoothStatus status; + + if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) { + status = STATUS_FAIL; + } + DispatchError(aRes, status); +} + END_BLUETOOTH_NAMESPACE diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.h b/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.h index b6264892b1a7..ccd62c634ec4 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.h +++ b/dom/bluetooth/bluedroid/BluetoothDaemonSetupInterface.h @@ -86,6 +86,32 @@ private: BluetoothSetupResultHandler* aRes); }; +class BluetoothDaemonSetupInterface final + : public BluetoothSetupInterface +{ +public: + BluetoothDaemonSetupInterface(BluetoothDaemonSetupModule* aModule); + ~BluetoothDaemonSetupInterface(); + + void RegisterModule(uint8_t aId, uint8_t aMode, + uint32_t aMaxNumClients, + BluetoothSetupResultHandler* aRes) override; + + void UnregisterModule(uint8_t aId, + BluetoothSetupResultHandler* aRes) override; + + void Configuration(const BluetoothConfigurationParameter* aParam, + uint8_t aLen, + BluetoothSetupResultHandler* aRes) override; + +private: + void DispatchError(BluetoothSetupResultHandler* aRes, + BluetoothStatus aStatus); + void DispatchError(BluetoothSetupResultHandler* aRes, nsresult aRv); + + BluetoothDaemonSetupModule* mModule; +}; + END_BLUETOOTH_NAMESPACE #endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonSetupInterface_h diff --git a/dom/bluetooth/common/BluetoothCommon.h b/dom/bluetooth/common/BluetoothCommon.h index 714eb8977f65..f93b4c80d157 100644 --- a/dom/bluetooth/common/BluetoothCommon.h +++ b/dom/bluetooth/common/BluetoothCommon.h @@ -9,6 +9,7 @@ #include "mozilla/Compiler.h" #include "mozilla/Observer.h" +#include "nsAutoPtr.h" #include "nsPrintfCString.h" #include "nsString.h" #include "nsTArray.h" @@ -480,6 +481,12 @@ struct BluetoothAddress { }; +struct BluetoothConfigurationParameter { + uint8_t mType; + uint16_t mLength; + nsAutoArrayPtr mValue; +}; + struct BluetoothUuid { uint8_t mUuid[16]; diff --git a/dom/bluetooth/common/BluetoothInterface.cpp b/dom/bluetooth/common/BluetoothInterface.cpp index 6b0180b36dc3..a76b95e71c81 100644 --- a/dom/bluetooth/common/BluetoothInterface.cpp +++ b/dom/bluetooth/common/BluetoothInterface.cpp @@ -39,6 +39,12 @@ void BluetoothSetupResultHandler::Configuration() { } +// Interface +// + +BluetoothSetupInterface::~BluetoothSetupInterface() +{ } + // // Socket Interface // diff --git a/dom/bluetooth/common/BluetoothInterface.h b/dom/bluetooth/common/BluetoothInterface.h index 6a81cd682561..a6206d6e9dca 100644 --- a/dom/bluetooth/common/BluetoothInterface.h +++ b/dom/bluetooth/common/BluetoothInterface.h @@ -30,6 +30,25 @@ protected: virtual ~BluetoothSetupResultHandler() { } }; +class BluetoothSetupInterface +{ +public: + virtual void RegisterModule(uint8_t aId, + uint8_t aMode, + uint32_t aMaxNumClients, + BluetoothSetupResultHandler* aRes) = 0; + + virtual void UnregisterModule(uint8_t aId, + BluetoothSetupResultHandler* aRes) = 0; + + virtual void Configuration(const BluetoothConfigurationParameter* aParam, + uint8_t aLen, + BluetoothSetupResultHandler* aRes) = 0; + +protected: + virtual ~BluetoothSetupInterface(); +}; + // // Socket Interface // @@ -1111,6 +1130,7 @@ public: /* Profile Interfaces */ + virtual BluetoothSetupInterface* GetBluetoothSetupInterface() = 0; virtual BluetoothSocketInterface* GetBluetoothSocketInterface() = 0; virtual BluetoothHandsfreeInterface* GetBluetoothHandsfreeInterface() = 0; virtual BluetoothA2dpInterface* GetBluetoothA2dpInterface() = 0;