From c9a3c00a12a69105f765e8a6860c56dfb8a72e7b Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 19 Nov 2015 11:21:03 +0100 Subject: [PATCH] Bug 1223806: Add |BluetoothDaemonCoreInterface|, r=btian --- .../BluetoothDaemonCoreInterface.cpp | 290 ++++++++++++++++++ .../bluedroid/BluetoothDaemonCoreInterface.h | 97 ++++++ 2 files changed, 387 insertions(+) diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.cpp b/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.cpp index cf6655f936c5..cd397d3c97bc 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.cpp +++ b/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.cpp @@ -1063,4 +1063,294 @@ BluetoothDaemonCoreModule::HandleNtf( (this->*(HandleNtf[index]))(aHeader, aPDU); } +// +// Core interface +// + +BluetoothDaemonCoreInterface::BluetoothDaemonCoreInterface( + BluetoothDaemonCoreModule* aModule) + : mModule(aModule) +{ } + +BluetoothDaemonCoreInterface::~BluetoothDaemonCoreInterface() +{ } + +void +BluetoothDaemonCoreInterface::SetNotificationHandler( + BluetoothCoreNotificationHandler* aNotificationHandler) +{ + MOZ_ASSERT(mModule); + + mModule->SetNotificationHandler(aNotificationHandler); +} + +/* Enable / Disable */ + +void +BluetoothDaemonCoreInterface::Enable(BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->EnableCmd(aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::Disable(BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->DisableCmd(aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* Adapter Properties */ + +void +BluetoothDaemonCoreInterface::GetAdapterProperties( + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->GetAdapterPropertiesCmd(aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::GetAdapterProperty( + BluetoothPropertyType aType, BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->GetAdapterPropertyCmd(aType, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::SetAdapterProperty( + const BluetoothProperty& aProperty, BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->SetAdapterPropertyCmd(aProperty, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* Remote Device Properties */ + +void +BluetoothDaemonCoreInterface::GetRemoteDeviceProperties( + const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->GetRemoteDevicePropertiesCmd(aRemoteAddr, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::GetRemoteDeviceProperty( + const BluetoothAddress& aRemoteAddr, BluetoothPropertyType aType, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->GetRemoteDevicePropertyCmd(aRemoteAddr, aType, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::SetRemoteDeviceProperty( + const BluetoothAddress& aRemoteAddr, const BluetoothProperty& aProperty, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->SetRemoteDevicePropertyCmd(aRemoteAddr, + aProperty, + aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* Remote Services */ + +void +BluetoothDaemonCoreInterface::GetRemoteServiceRecord( + const BluetoothAddress& aRemoteAddr, const BluetoothUuid& aUuid, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->GetRemoteServiceRecordCmd(aRemoteAddr, aUuid, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::GetRemoteServices( + const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->GetRemoteServicesCmd(aRemoteAddr, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* Discovery */ + +void +BluetoothDaemonCoreInterface::StartDiscovery(BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->StartDiscoveryCmd(aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::CancelDiscovery(BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->CancelDiscoveryCmd(aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* Bonds */ + +void +BluetoothDaemonCoreInterface::CreateBond(const BluetoothAddress& aBdAddr, + BluetoothTransport aTransport, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->CreateBondCmd(aBdAddr, aTransport, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::RemoveBond(const BluetoothAddress& aBdAddr, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->RemoveBondCmd(aBdAddr, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::CancelBond( + const BluetoothAddress& aBdAddr, BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->CancelBondCmd(aBdAddr, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* Connection */ + +void +BluetoothDaemonCoreInterface::GetConnectionState( + const BluetoothAddress& aBdAddr, BluetoothCoreResultHandler* aRes) +{ + // NO-OP: no corresponding interface of current BlueZ +} + +/* Authentication */ + +void +BluetoothDaemonCoreInterface::PinReply(const BluetoothAddress& aBdAddr, + bool aAccept, + const BluetoothPinCode& aPinCode, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->PinReplyCmd(aBdAddr, aAccept, aPinCode, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::SspReply(const BluetoothAddress& aBdAddr, + BluetoothSspVariant aVariant, + bool aAccept, uint32_t aPasskey, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->SspReplyCmd(aBdAddr, aVariant, aAccept, aPasskey, + aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* DUT Mode */ + +void +BluetoothDaemonCoreInterface::DutModeConfigure( + bool aEnable, BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->DutModeConfigureCmd(aEnable, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +void +BluetoothDaemonCoreInterface::DutModeSend(uint16_t aOpcode, + uint8_t* aBuf, + uint8_t aLen, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->DutModeSendCmd(aOpcode, aBuf, aLen, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* LE Mode */ + +void +BluetoothDaemonCoreInterface::LeTestMode(uint16_t aOpcode, + uint8_t* aBuf, + uint8_t aLen, + BluetoothCoreResultHandler* aRes) +{ + nsresult rv = mModule->LeTestModeCmd(aOpcode, aBuf, aLen, aRes); + if (NS_FAILED(rv)) { + DispatchError(aRes, rv); + } +} + +/* Energy Information */ + +void +BluetoothDaemonCoreInterface::ReadEnergyInfo(BluetoothCoreResultHandler* aRes) +{ + // NO-OP: no corresponding interface of current BlueZ +} + +void +BluetoothDaemonCoreInterface::DispatchError(BluetoothCoreResultHandler* aRes, + BluetoothStatus aStatus) +{ + DaemonResultRunnable1< + BluetoothCoreResultHandler, void, + BluetoothStatus, BluetoothStatus>::Dispatch( + aRes, &BluetoothCoreResultHandler::OnError, + ConstantInitOp1(aStatus)); +} + +void +BluetoothDaemonCoreInterface::DispatchError(BluetoothCoreResultHandler* 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/BluetoothDaemonCoreInterface.h b/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.h index 8ab340027da5..0d6f03d47efe 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.h +++ b/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.h @@ -340,6 +340,103 @@ private: static BluetoothCoreNotificationHandler* sNotificationHandler; }; +class BluetoothDaemonCoreInterface final + : public BluetoothCoreInterface +{ +public: + BluetoothDaemonCoreInterface(BluetoothDaemonCoreModule* aModule); + ~BluetoothDaemonCoreInterface(); + + void SetNotificationHandler( + BluetoothCoreNotificationHandler* aNotificationHandler) override; + + /* Enable / Disable */ + + void Enable(BluetoothCoreResultHandler* aRes) override; + void Disable(BluetoothCoreResultHandler* aRes) override; + + /* Adapter Properties */ + + void GetAdapterProperties(BluetoothCoreResultHandler* aRes) override; + void GetAdapterProperty(BluetoothPropertyType aType, + BluetoothCoreResultHandler* aRes) override; + void SetAdapterProperty(const BluetoothProperty& aProperty, + BluetoothCoreResultHandler* aRes) override; + + /* Remote Device Properties */ + + void GetRemoteDeviceProperties(const BluetoothAddress& aRemoteAddr, + BluetoothCoreResultHandler* aRes) override; + void GetRemoteDeviceProperty(const BluetoothAddress& aRemoteAddr, + BluetoothPropertyType aType, + BluetoothCoreResultHandler* aRes) override; + void SetRemoteDeviceProperty(const BluetoothAddress& aRemoteAddr, + const BluetoothProperty& aProperty, + BluetoothCoreResultHandler* aRes) override; + + /* Remote Services */ + + void GetRemoteServiceRecord(const BluetoothAddress& aRemoteAddr, + const BluetoothUuid& aUuid, + BluetoothCoreResultHandler* aRes) override; + void GetRemoteServices(const BluetoothAddress& aRemoteAddr, + BluetoothCoreResultHandler* aRes) override; + + /* Discovery */ + + void StartDiscovery(BluetoothCoreResultHandler* aRes) override; + void CancelDiscovery(BluetoothCoreResultHandler* aRes) override; + + /* Bonds */ + + void CreateBond(const BluetoothAddress& aBdAddr, + BluetoothTransport aTransport, + BluetoothCoreResultHandler* aRes) override; + void RemoveBond(const BluetoothAddress& aBdAddr, + BluetoothCoreResultHandler* aRes) override; + void CancelBond(const BluetoothAddress& aBdAddr, + BluetoothCoreResultHandler* aRes) override; + + /* Connection */ + + void GetConnectionState(const BluetoothAddress& aBdAddr, + BluetoothCoreResultHandler* aRes) override; + + /* Authentication */ + + void PinReply(const BluetoothAddress& aBdAddr, bool aAccept, + const BluetoothPinCode& aPinCode, + BluetoothCoreResultHandler* aRes) override; + + void SspReply(const BluetoothAddress& aBdAddr, + BluetoothSspVariant aVariant, + bool aAccept, uint32_t aPasskey, + BluetoothCoreResultHandler* aRes) override; + + /* DUT Mode */ + + void DutModeConfigure(bool aEnable, BluetoothCoreResultHandler* aRes); + void DutModeSend(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen, + BluetoothCoreResultHandler* aRes) override; + + /* LE Mode */ + + void LeTestMode(uint16_t aOpcode, uint8_t* aBuf, uint8_t aLen, + BluetoothCoreResultHandler* aRes) override; + + /* Energy Information */ + + void ReadEnergyInfo(BluetoothCoreResultHandler* aRes) override; + +private: + void DispatchError(BluetoothCoreResultHandler* aRes, + BluetoothStatus aStatus); + void DispatchError(BluetoothCoreResultHandler* aRes, + nsresult aRv); + + BluetoothDaemonCoreModule* mModule; +}; + END_BLUETOOTH_NAMESPACE #endif // mozilla_dom_bluetooth_bluedroid_BluetoothDaemonCoreInterface_h