Bug 1132229: Handle I/O errors in Bluetooth's daemon backend, r=shuang

This patch adds error handling to all interface methods of Bluedroid's
daemon backend. If an error occures while sending a command to the daemon,
the methods dispatch an error.
This commit is contained in:
Thomas Zimmermann 2015-02-26 09:52:45 +01:00
parent 9a28747b22
commit a47be502a6
13 changed files with 368 additions and 68 deletions

View File

@ -0,0 +1,28 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "BluetoothInterfaceHelpers.h"
BEGIN_BLUETOOTH_NAMESPACE
//
// Conversion
//
nsresult
Convert(nsresult aIn, BluetoothStatus& aOut)
{
if (NS_SUCCEEDED(aIn)) {
aOut = STATUS_SUCCESS;
} else if (aIn == NS_ERROR_OUT_OF_MEMORY) {
aOut = STATUS_NOMEM;
} else {
aOut = STATUS_FAIL;
}
return NS_OK;
}
END_BLUETOOTH_NAMESPACE

View File

@ -12,6 +12,13 @@
BEGIN_BLUETOOTH_NAMESPACE
//
// Conversion
//
nsresult
Convert(nsresult aIn, BluetoothStatus& aOut);
//
// Result handling
//

View File

@ -395,7 +395,7 @@ BluetoothDaemonA2dpInterface::Init(
nsresult rv = mModule->RegisterModule(BluetoothDaemonA2dpModule::SERVICE_ID,
0x00, BluetoothDaemonA2dpModule::MAX_NUM_CLIENTS, res);
if (NS_FAILED(rv) && aRes) {
DispatchError(aRes, STATUS_FAIL);
DispatchError(aRes, rv);
}
}
@ -443,8 +443,12 @@ void
BluetoothDaemonA2dpInterface::Cleanup(
BluetoothA2dpResultHandler* aRes)
{
mModule->UnregisterModule(BluetoothDaemonA2dpModule::SERVICE_ID,
new CleanupResultHandler(mModule, aRes));
nsresult rv = mModule->UnregisterModule(
BluetoothDaemonA2dpModule::SERVICE_ID,
new CleanupResultHandler(mModule, aRes));
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Connect / Disconnect */
@ -455,7 +459,10 @@ BluetoothDaemonA2dpInterface::Connect(
{
MOZ_ASSERT(mModule);
mModule->ConnectCmd(aBdAddr, aRes);
nsresult rv = mModule->ConnectCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -464,7 +471,10 @@ BluetoothDaemonA2dpInterface::Disconnect(
{
MOZ_ASSERT(mModule);
mModule->DisconnectCmd(aBdAddr, aRes);
nsresult rv = mModule->DisconnectCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -477,4 +487,16 @@ BluetoothDaemonA2dpInterface::DispatchError(
ConstantInitOp1<BluetoothStatus>(aStatus));
}
void
BluetoothDaemonA2dpInterface::DispatchError(
BluetoothA2dpResultHandler* aRes, nsresult aRv)
{
BluetoothStatus status;
if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
status = STATUS_FAIL;
}
DispatchError(aRes, status);
}
END_BLUETOOTH_NAMESPACE

View File

@ -155,6 +155,7 @@ public:
private:
void DispatchError(BluetoothA2dpResultHandler* aRes,
BluetoothStatus aStatus);
void DispatchError(BluetoothA2dpResultHandler* aRes, nsresult aRv);
BluetoothDaemonA2dpModule* mModule;
};

View File

@ -893,7 +893,7 @@ BluetoothDaemonAvrcpInterface::Init(
BluetoothDaemonAvrcpModule::MAX_NUM_CLIENTS, 0x00, res);
if (NS_FAILED(rv) && aRes) {
DispatchError(aRes, STATUS_FAIL);
DispatchError(aRes, rv);
}
}
@ -943,8 +943,12 @@ BluetoothDaemonAvrcpInterface::Cleanup(
{
MOZ_ASSERT(mModule);
mModule->UnregisterModule(BluetoothDaemonAvrcpModule::SERVICE_ID,
new CleanupResultHandler(mModule, aRes));
nsresult rv = mModule->UnregisterModule(
BluetoothDaemonAvrcpModule::SERVICE_ID,
new CleanupResultHandler(mModule, aRes));
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -954,7 +958,11 @@ BluetoothDaemonAvrcpInterface::GetPlayStatusRsp(
{
MOZ_ASSERT(mModule);
mModule->GetPlayStatusRspCmd(aPlayStatus, aSongLen, aSongPos, aRes);
nsresult rv = mModule->GetPlayStatusRspCmd(aPlayStatus, aSongLen,
aSongPos, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -964,7 +972,10 @@ BluetoothDaemonAvrcpInterface::ListPlayerAppAttrRsp(
{
MOZ_ASSERT(mModule);
mModule->ListPlayerAppAttrRspCmd(aNumAttr, aPAttrs, aRes);
nsresult rv = mModule->ListPlayerAppAttrRspCmd(aNumAttr, aPAttrs, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -973,7 +984,10 @@ BluetoothDaemonAvrcpInterface::ListPlayerAppValueRsp(
{
MOZ_ASSERT(mModule);
mModule->ListPlayerAppValueRspCmd(aNumVal, aPVals, aRes);
nsresult rv = mModule->ListPlayerAppValueRspCmd(aNumVal, aPVals, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -983,7 +997,11 @@ BluetoothDaemonAvrcpInterface::GetPlayerAppValueRsp(
{
MOZ_ASSERT(mModule);
mModule->GetPlayerAppValueRspCmd(aNumAttrs, aIds, aValues, aRes);
nsresult rv = mModule->GetPlayerAppValueRspCmd(aNumAttrs, aIds,
aValues, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -993,7 +1011,11 @@ BluetoothDaemonAvrcpInterface::GetPlayerAppAttrTextRsp(
{
MOZ_ASSERT(mModule);
mModule->GetPlayerAppAttrTextRspCmd(aNumAttr, aIds, aTexts, aRes);
nsresult rv = mModule->GetPlayerAppAttrTextRspCmd(aNumAttr, aIds,
aTexts, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1003,7 +1025,11 @@ BluetoothDaemonAvrcpInterface::GetPlayerAppValueTextRsp(
{
MOZ_ASSERT(mModule);
mModule->GetPlayerAppValueTextRspCmd(aNumVal, aIds, aTexts, aRes);
nsresult rv = mModule->GetPlayerAppValueTextRspCmd(aNumVal, aIds,
aTexts, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1013,7 +1039,10 @@ BluetoothDaemonAvrcpInterface::GetElementAttrRsp(
{
MOZ_ASSERT(mModule);
mModule->GetElementAttrRspCmd(aNumAttr, aAttr, aRes);
nsresult rv = mModule->GetElementAttrRspCmd(aNumAttr, aAttr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1022,7 +1051,10 @@ BluetoothDaemonAvrcpInterface::SetPlayerAppValueRsp(
{
MOZ_ASSERT(mModule);
mModule->SetPlayerAppValueRspCmd(aRspStatus, aRes);
nsresult rv = mModule->SetPlayerAppValueRspCmd(aRspStatus, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1034,7 +1066,11 @@ BluetoothDaemonAvrcpInterface::RegisterNotificationRsp(
{
MOZ_ASSERT(mModule);
mModule->RegisterNotificationRspCmd(aEvent, aType, aParam, aRes);
nsresult rv = mModule->RegisterNotificationRspCmd(aEvent, aType,
aParam, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1043,7 +1079,10 @@ BluetoothDaemonAvrcpInterface::SetVolume(
{
MOZ_ASSERT(mModule);
mModule->SetVolumeCmd(aVolume, aRes);
nsresult rv = mModule->SetVolumeCmd(aVolume, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1056,4 +1095,16 @@ BluetoothDaemonAvrcpInterface::DispatchError(
ConstantInitOp1<BluetoothStatus>(aStatus));
}
void
BluetoothDaemonAvrcpInterface::DispatchError(
BluetoothAvrcpResultHandler* aRes, nsresult aRv)
{
BluetoothStatus status;
if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
status = STATUS_FAIL;
}
DispatchError(aRes, status);
}
END_BLUETOOTH_NAMESPACE

View File

@ -346,6 +346,7 @@ public:
private:
void DispatchError(BluetoothAvrcpResultHandler* aRes,
BluetoothStatus aStatus);
void DispatchError(BluetoothAvrcpResultHandler* aRes, nsresult aRv);
BluetoothDaemonAvrcpModule* mModule;
};

View File

@ -1512,7 +1512,7 @@ BluetoothDaemonHandsfreeInterface::Init(
aMaxNumClients, res);
if (NS_FAILED(rv) && aRes) {
DispatchError(aRes, STATUS_FAIL);
DispatchError(aRes, rv);
}
}
@ -1532,6 +1532,7 @@ public:
{
MOZ_ASSERT(NS_IsMainThread());
BT_LOGR("%s:%d", __func__, __LINE__);
if (mRes) {
mRes->OnError(aStatus);
}
@ -1541,6 +1542,7 @@ public:
{
MOZ_ASSERT(NS_IsMainThread());
BT_LOGR("%s:%d", __func__, __LINE__);
// Clear notification handler _after_ module has been
// unregistered. While unregistering the module, we might
// still receive notifications.
@ -1560,8 +1562,14 @@ void
BluetoothDaemonHandsfreeInterface::Cleanup(
BluetoothHandsfreeResultHandler* aRes)
{
mModule->UnregisterModule(BluetoothDaemonHandsfreeModule::SERVICE_ID,
new CleanupResultHandler(mModule, aRes));
BT_LOGR("%s:%d", __func__, __LINE__);
nsresult rv = mModule->UnregisterModule(
BluetoothDaemonHandsfreeModule::SERVICE_ID,
new CleanupResultHandler(mModule, aRes));
BT_LOGR("%s:%d", __func__, __LINE__);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Connect / Disconnect */
@ -1572,7 +1580,10 @@ BluetoothDaemonHandsfreeInterface::Connect(
{
MOZ_ASSERT(mModule);
mModule->ConnectCmd(aBdAddr, aRes);
nsresult rv = mModule->ConnectCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1581,7 +1592,10 @@ BluetoothDaemonHandsfreeInterface::Disconnect(
{
MOZ_ASSERT(mModule);
mModule->DisconnectCmd(aBdAddr, aRes);
nsresult rv = mModule->DisconnectCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1590,7 +1604,10 @@ BluetoothDaemonHandsfreeInterface::ConnectAudio(
{
MOZ_ASSERT(mModule);
mModule->ConnectAudioCmd(aBdAddr, aRes);
nsresult rv = mModule->ConnectAudioCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1599,7 +1616,10 @@ BluetoothDaemonHandsfreeInterface::DisconnectAudio(
{
MOZ_ASSERT(mModule);
mModule->DisconnectAudioCmd(aBdAddr, aRes);
nsresult rv = mModule->DisconnectAudioCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Voice Recognition */
@ -1610,7 +1630,10 @@ BluetoothDaemonHandsfreeInterface::StartVoiceRecognition(
{
MOZ_ASSERT(mModule);
mModule->StartVoiceRecognitionCmd(aBdAddr, aRes);
nsresult rv = mModule->StartVoiceRecognitionCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1619,7 +1642,10 @@ BluetoothDaemonHandsfreeInterface::StopVoiceRecognition(
{
MOZ_ASSERT(mModule);
mModule->StopVoiceRecognitionCmd(aBdAddr, aRes);
nsresult rv = mModule->StopVoiceRecognitionCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Volume */
@ -1631,7 +1657,10 @@ BluetoothDaemonHandsfreeInterface::VolumeControl(
{
MOZ_ASSERT(mModule);
mModule->VolumeControlCmd(aType, aVolume, aBdAddr, aRes);
nsresult rv = mModule->VolumeControlCmd(aType, aVolume, aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Device status */
@ -1644,8 +1673,12 @@ BluetoothDaemonHandsfreeInterface::DeviceStatusNotification(
{
MOZ_ASSERT(mModule);
mModule->DeviceStatusNotificationCmd(aNtkState, aSvcType, aSignal,
aBattChg, aRes);
nsresult rv = mModule->DeviceStatusNotificationCmd(aNtkState, aSvcType,
aSignal, aBattChg,
aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Responses */
@ -1657,7 +1690,10 @@ BluetoothDaemonHandsfreeInterface::CopsResponse(
{
MOZ_ASSERT(mModule);
mModule->CopsResponseCmd(aCops, aBdAddr, aRes);
nsresult rv = mModule->CopsResponseCmd(aCops, aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1669,8 +1705,12 @@ BluetoothDaemonHandsfreeInterface::CindResponse(
{
MOZ_ASSERT(mModule);
mModule->CindResponseCmd(aSvc, aNumActive, aNumHeld, aCallSetupState,
aSignal, aRoam, aBattChg, aBdAddr, aRes);
nsresult rv = mModule->CindResponseCmd(aSvc, aNumActive, aNumHeld,
aCallSetupState, aSignal,
aRoam, aBattChg, aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1680,7 +1720,10 @@ BluetoothDaemonHandsfreeInterface::FormattedAtResponse(
{
MOZ_ASSERT(mModule);
mModule->FormattedAtResponseCmd(aRsp, aBdAddr, aRes);
nsresult rv = mModule->FormattedAtResponseCmd(aRsp, aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1690,7 +1733,11 @@ BluetoothDaemonHandsfreeInterface::AtResponse(
{
MOZ_ASSERT(mModule);
mModule->AtResponseCmd(aResponseCode, aErrorCode, aBdAddr, aRes);
nsresult rv = mModule->AtResponseCmd(aResponseCode, aErrorCode,
aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1706,8 +1753,11 @@ BluetoothDaemonHandsfreeInterface::ClccResponse(
{
MOZ_ASSERT(mModule);
mModule->ClccResponseCmd(aIndex, aDir, aState, aMode, aMpty, aNumber,
aType, aBdAddr, aRes);
nsresult rv = mModule->ClccResponseCmd(aIndex, aDir, aState, aMode, aMpty,
aNumber, aType, aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Phone State */
@ -1722,8 +1772,12 @@ BluetoothDaemonHandsfreeInterface::PhoneStateChange(
{
MOZ_ASSERT(mModule);
mModule->PhoneStateChangeCmd(aNumActive, aNumHeld, aCallSetupState, aNumber,
aType, aRes);
nsresult rv = mModule->PhoneStateChangeCmd(aNumActive, aNumHeld,
aCallSetupState, aNumber,
aType, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Wide Band Speech */
@ -1735,7 +1789,10 @@ BluetoothDaemonHandsfreeInterface::ConfigureWbs(
{
MOZ_ASSERT(mModule);
mModule->ConfigureWbsCmd(aBdAddr, aConfig, aRes);
nsresult rv = mModule->ConfigureWbsCmd(aBdAddr, aConfig, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -1748,4 +1805,16 @@ BluetoothDaemonHandsfreeInterface::DispatchError(
ConstantInitOp1<BluetoothStatus>(aStatus));
}
void
BluetoothDaemonHandsfreeInterface::DispatchError(
BluetoothHandsfreeResultHandler* aRes, nsresult aRv)
{
BluetoothStatus status;
if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
status = STATUS_FAIL;
}
DispatchError(aRes, status);
}
END_BLUETOOTH_NAMESPACE

View File

@ -472,6 +472,7 @@ public:
private:
void DispatchError(BluetoothHandsfreeResultHandler* aRes,
BluetoothStatus aStatus);
void DispatchError(BluetoothHandsfreeResultHandler* aRes, nsresult aRv);
BluetoothDaemonHandsfreeModule* mModule;
};

View File

@ -2194,19 +2194,31 @@ BluetoothDaemonInterface::Cleanup(BluetoothResultHandler* aRes)
mResultHandlerQ.AppendElement(aRes);
// Cleanup, step 1: Unregister Socket module
mProtocol->UnregisterModuleCmd(0x02, new CleanupResultHandler(this));
nsresult rv = mProtocol->UnregisterModuleCmd(
0x02, new CleanupResultHandler(this));
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonInterface::Enable(BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>(mProtocol)->EnableCmd(aRes);
nsresult rv =
static_cast<BluetoothDaemonCoreModule*>(mProtocol)->EnableCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonInterface::Disable(BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>(mProtocol)->DisableCmd(aRes);
nsresult rv =
static_cast<BluetoothDaemonCoreModule*>(mProtocol)->DisableCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Adapter Properties */
@ -2214,24 +2226,33 @@ BluetoothDaemonInterface::Disable(BluetoothResultHandler* aRes)
void
BluetoothDaemonInterface::GetAdapterProperties(BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->GetAdapterPropertiesCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonInterface::GetAdapterProperty(const nsAString& aName,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->GetAdapterPropertyCmd(aName, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonInterface::SetAdapterProperty(
const BluetoothNamedValue& aProperty, BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->SetAdapterPropertyCmd(aProperty, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Remote Device Properties */
@ -2240,8 +2261,11 @@ void
BluetoothDaemonInterface::GetRemoteDeviceProperties(
const nsAString& aRemoteAddr, BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->GetRemoteDevicePropertiesCmd(aRemoteAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -2249,8 +2273,11 @@ BluetoothDaemonInterface::GetRemoteDeviceProperty(
const nsAString& aRemoteAddr, const nsAString& aName,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->GetRemoteDevicePropertyCmd(aRemoteAddr, aName, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -2258,8 +2285,11 @@ BluetoothDaemonInterface::SetRemoteDeviceProperty(
const nsAString& aRemoteAddr, const BluetoothNamedValue& aProperty,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->SetRemoteDevicePropertyCmd(aRemoteAddr, aProperty, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Remote Services */
@ -2269,16 +2299,22 @@ BluetoothDaemonInterface::GetRemoteServiceRecord(const nsAString& aRemoteAddr,
const uint8_t aUuid[16],
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>(
mProtocol)->GetRemoteServiceRecordCmd(aRemoteAddr, aUuid, aRes);
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->GetRemoteServiceRecordCmd(aRemoteAddr, aUuid, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonInterface::GetRemoteServices(const nsAString& aRemoteAddr,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>(
mProtocol)->GetRemoteServicesCmd(aRemoteAddr, aRes);
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->GetRemoteServicesCmd(aRemoteAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Discovery */
@ -2286,14 +2322,21 @@ BluetoothDaemonInterface::GetRemoteServices(const nsAString& aRemoteAddr,
void
BluetoothDaemonInterface::StartDiscovery(BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>(mProtocol)->StartDiscoveryCmd(aRes);
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->StartDiscoveryCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonInterface::CancelDiscovery(BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->CancelDiscoveryCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Bonds */
@ -2303,24 +2346,33 @@ BluetoothDaemonInterface::CreateBond(const nsAString& aBdAddr,
BluetoothTransport aTransport,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->CreateBondCmd(aBdAddr, aTransport, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonInterface::RemoveBond(const nsAString& aBdAddr,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->RemoveBondCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonInterface::CancelBond(const nsAString& aBdAddr,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->CancelBondCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Connection */
@ -2339,8 +2391,11 @@ BluetoothDaemonInterface::PinReply(const nsAString& aBdAddr, bool aAccept,
const nsAString& aPinCode,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->PinReplyCmd(aBdAddr, aAccept, aPinCode, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -2349,8 +2404,11 @@ BluetoothDaemonInterface::SspReply(const nsAString& aBdAddr,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->SspReplyCmd(aBdAddr, aVariant, aAccept, aPasskey, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* DUT Mode */
@ -2359,8 +2417,11 @@ void
BluetoothDaemonInterface::DutModeConfigure(bool aEnable,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->DutModeConfigureCmd(aEnable, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -2368,8 +2429,11 @@ BluetoothDaemonInterface::DutModeSend(uint16_t aOpcode, uint8_t* aBuf,
uint8_t aLen,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->DutModeSendCmd(aOpcode, aBuf, aLen, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* LE Mode */
@ -2379,8 +2443,11 @@ BluetoothDaemonInterface::LeTestMode(uint16_t aOpcode, uint8_t* aBuf,
uint8_t aLen,
BluetoothResultHandler* aRes)
{
static_cast<BluetoothDaemonCoreModule*>
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->LeTestModeCmd(aOpcode, aBuf, aLen, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Energy Information */
@ -2401,6 +2468,18 @@ BluetoothDaemonInterface::DispatchError(BluetoothResultHandler* aRes,
ConstantInitOp1<BluetoothStatus>(aStatus));
}
void
BluetoothDaemonInterface::DispatchError(BluetoothResultHandler* aRes,
nsresult aRv)
{
BluetoothStatus status;
if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
status = STATUS_FAIL;
}
DispatchError(aRes, status);
}
// Profile Interfaces
//

View File

@ -135,6 +135,7 @@ protected:
private:
void DispatchError(BluetoothResultHandler* aRes, BluetoothStatus aStatus);
void DispatchError(BluetoothResultHandler* aRes, nsresult aRv);
nsCString mListenSocketName;
nsRefPtr<BluetoothDaemonListenSocket> mListenSocket;

View File

@ -315,8 +315,11 @@ BluetoothDaemonSocketInterface::Listen(BluetoothSocketType aType,
{
MOZ_ASSERT(mModule);
mModule->ListenCmd(aType, aServiceName, aServiceUuid, aChannel,
aEncrypt, aAuth, aRes);
nsresult rv = mModule->ListenCmd(aType, aServiceName, aServiceUuid,
aChannel, aEncrypt, aAuth, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -329,7 +332,11 @@ BluetoothDaemonSocketInterface::Connect(const nsAString& aBdAddr,
{
MOZ_ASSERT(mModule);
mModule->ConnectCmd(aBdAddr, aType, aUuid, aChannel, aEncrypt, aAuth, aRes);
nsresult rv = mModule->ConnectCmd(aBdAddr, aType, aUuid, aChannel,
aEncrypt, aAuth, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -338,7 +345,10 @@ BluetoothDaemonSocketInterface::Accept(int aFd,
{
MOZ_ASSERT(mModule);
mModule->AcceptCmd(aFd, aRes);
nsresult rv = mModule->AcceptCmd(aFd, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
@ -346,7 +356,32 @@ BluetoothDaemonSocketInterface::Close(BluetoothSocketResultHandler* aRes)
{
MOZ_ASSERT(mModule);
mModule->CloseCmd(aRes);
nsresult rv = mModule->CloseCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonSocketInterface::DispatchError(
BluetoothSocketResultHandler* aRes, BluetoothStatus aStatus)
{
BluetoothResultRunnable1<BluetoothSocketResultHandler, void,
BluetoothStatus, BluetoothStatus>::Dispatch(
aRes, &BluetoothSocketResultHandler::OnError,
ConstantInitOp1<BluetoothStatus>(aStatus));
}
void
BluetoothDaemonSocketInterface::DispatchError(
BluetoothSocketResultHandler* aRes, nsresult aRv)
{
BluetoothStatus status;
if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
status = STATUS_FAIL;
}
DispatchError(aRes, status);
}
END_BLUETOOTH_NAMESPACE

View File

@ -113,6 +113,10 @@ public:
void Close(BluetoothSocketResultHandler* aRes);
private:
void DispatchError(BluetoothSocketResultHandler* aRes,
BluetoothStatus aStatus);
void DispatchError(BluetoothSocketResultHandler* aRes, nsresult aRv);
BluetoothDaemonSocketModule* mModule;
};

View File

@ -10,6 +10,7 @@ if CONFIG['MOZ_B2G_BT']:
'BluetoothDevice.cpp',
'BluetoothHidManager.cpp',
'BluetoothInterface.cpp',
'BluetoothInterfaceHelpers.cpp',
'BluetoothManager.cpp',
'BluetoothProfileController.cpp',
'BluetoothPropertyContainer.cpp',