Bug 1038645: Asynchronous Bluetooth Handsfree response methods (under bluetooth2/), r=btian

This commit is contained in:
Thomas Zimmermann 2014-07-22 13:53:29 +02:00
parent 3e3e02dad1
commit e6da23b9d8
3 changed files with 140 additions and 64 deletions

View File

@ -751,47 +751,69 @@ BluetoothHandsfreeInterface::DeviceStatusNotification(
/* Responses */
bt_status_t
BluetoothHandsfreeInterface::CopsResponse(const char* aCops)
void
BluetoothHandsfreeInterface::CopsResponse(
const char* aCops, BluetoothHandsfreeResultHandler* aRes)
{
return mInterface->cops_response(aCops);
bt_status_t status = mInterface->cops_response(aCops);
if (aRes) {
DispatchBluetoothHandsfreeResult(
aRes, &BluetoothHandsfreeResultHandler::CopsResponse, status);
}
}
bt_status_t
BluetoothHandsfreeInterface::CindResponse(int aSvc, int aNumActive,
int aNumHeld,
bthf_call_state_t aCallSetupState,
int aSignal, int aRoam, int aBattChg)
void
BluetoothHandsfreeInterface::CindResponse(
int aSvc, int aNumActive, int aNumHeld, bthf_call_state_t aCallSetupState,
int aSignal, int aRoam, int aBattChg, BluetoothHandsfreeResultHandler* aRes)
{
return mInterface->cind_response(aSvc, aNumActive, aNumHeld,
aCallSetupState, aSignal, aRoam,
aBattChg);
bt_status_t status = mInterface->cind_response(aSvc, aNumActive, aNumHeld,
aCallSetupState, aSignal,
aRoam, aBattChg);
if (aRes) {
DispatchBluetoothHandsfreeResult(
aRes, &BluetoothHandsfreeResultHandler::CindResponse, status);
}
}
bt_status_t
BluetoothHandsfreeInterface::FormattedAtResponse(const char* aRsp)
void
BluetoothHandsfreeInterface::FormattedAtResponse(
const char* aRsp, BluetoothHandsfreeResultHandler* aRes)
{
return mInterface->formatted_at_response(aRsp);
bt_status_t status = mInterface->formatted_at_response(aRsp);
if (aRes) {
DispatchBluetoothHandsfreeResult(
aRes, &BluetoothHandsfreeResultHandler::FormattedAtResponse, status);
}
}
bt_status_t
void
BluetoothHandsfreeInterface::AtResponse(bthf_at_response_t aResponseCode,
int aErrorCode)
int aErrorCode,
BluetoothHandsfreeResultHandler* aRes)
{
return mInterface->at_response(aResponseCode, aErrorCode);
bt_status_t status = mInterface->at_response(aResponseCode, aErrorCode);
if (aRes) {
DispatchBluetoothHandsfreeResult(
aRes, &BluetoothHandsfreeResultHandler::AtResponse, status);
}
}
bt_status_t
BluetoothHandsfreeInterface::ClccResponse(int aIndex,
bthf_call_direction_t aDir,
bthf_call_state_t aState,
bthf_call_mode_t aMode,
bthf_call_mpty_type_t aMpty,
const char* aNumber,
bthf_call_addrtype_t aType)
void
BluetoothHandsfreeInterface::ClccResponse(
int aIndex, bthf_call_direction_t aDir, bthf_call_state_t aState,
bthf_call_mode_t aMode, bthf_call_mpty_type_t aMpty, const char* aNumber,
bthf_call_addrtype_t aType, BluetoothHandsfreeResultHandler* aRes)
{
return mInterface->clcc_response(aIndex, aDir, aState, aMode, aMpty,
aNumber, aType);
bt_status_t status = mInterface->clcc_response(aIndex, aDir, aState, aMode,
aMpty, aNumber, aType);
if (aRes) {
DispatchBluetoothHandsfreeResult(
aRes, &BluetoothHandsfreeResultHandler::ClccResponse, status);
}
}
/* Phone State */

View File

@ -146,16 +146,21 @@ public:
/* Responses */
bt_status_t CopsResponse(const char* aCops);
bt_status_t CindResponse(int aSvc, int aNumActive, int aNumHeld,
bthf_call_state_t aCallSetupState, int aSignal,
int aRoam, int aBattChg);
bt_status_t FormattedAtResponse(const char* aRsp);
bt_status_t AtResponse(bthf_at_response_t aResponseCode, int aErrorCode);
bt_status_t ClccResponse(int aIndex, bthf_call_direction_t aDir,
bthf_call_state_t aState, bthf_call_mode_t aMode,
bthf_call_mpty_type_t aMpty, const char* aNumber,
bthf_call_addrtype_t aType);
void CopsResponse(const char* aCops,
BluetoothHandsfreeResultHandler* aRes);
void CindResponse(int aSvc, int aNumActive, int aNumHeld,
bthf_call_state_t aCallSetupState, int aSignal,
int aRoam, int aBattChg,
BluetoothHandsfreeResultHandler* aRes);
void FormattedAtResponse(const char* aRsp,
BluetoothHandsfreeResultHandler* aRes);
void AtResponse(bthf_at_response_t aResponseCode, int aErrorCode,
BluetoothHandsfreeResultHandler* aRes);
void ClccResponse(int aIndex, bthf_call_direction_t aDir,
bthf_call_state_t aState, bthf_call_mode_t aMode,
bthf_call_mpty_type_t aMpty, const char* aNumber,
bthf_call_addrtype_t aType,
BluetoothHandsfreeResultHandler* aRes);
/* Phone State */

View File

@ -803,6 +803,17 @@ BluetoothHfpManager::ProcessAtCnum()
SendResponse(BTHF_AT_RESPONSE_OK);
}
class CindResponseResultHandler MOZ_FINAL
: public BluetoothHandsfreeResultHandler
{
public:
void OnError(bt_status_t aStatus) MOZ_OVERRIDE
{
BT_WARNING("BluetoothHandsfreeInterface::CindResponse failed: %d",
(int)aStatus);
}
};
void
BluetoothHfpManager::ProcessAtCind()
{
@ -810,25 +821,32 @@ BluetoothHfpManager::ProcessAtCind()
int numActive = GetNumberOfCalls(nsITelephonyService::CALL_STATE_CONNECTED);
int numHeld = GetNumberOfCalls(nsITelephonyService::CALL_STATE_HELD);
bthf_call_state_t callState = ConvertToBthfCallState(GetCallSetupState());
bt_status_t status = sBluetoothHfpInterface->CindResponse(
mService,
numActive,
numHeld,
ConvertToBthfCallState(GetCallSetupState()),
mSignal,
mRoam,
mBattChg);
NS_ENSURE_TRUE_VOID(status == BT_STATUS_SUCCESS);
sBluetoothHfpInterface->CindResponse(mService, numActive, numHeld,
callState, mSignal, mRoam, mBattChg,
new CindResponseResultHandler());
}
class CopsResponseResultHandler MOZ_FINAL
: public BluetoothHandsfreeResultHandler
{
public:
void OnError(bt_status_t aStatus) MOZ_OVERRIDE
{
BT_WARNING("BluetoothHandsfreeInterface::CopsResponse failed: %d",
(int)aStatus);
}
};
void
BluetoothHfpManager::ProcessAtCops()
{
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
sBluetoothHfpInterface->CopsResponse(
NS_ConvertUTF16toUTF8(mOperatorName).get()));
sBluetoothHfpInterface->CopsResponse(
NS_ConvertUTF16toUTF8(mOperatorName).get(),
new CopsResponseResultHandler());
}
void
@ -850,14 +868,26 @@ BluetoothHfpManager::ProcessAtClcc()
SendResponse(BTHF_AT_RESPONSE_OK);
}
class AtResponseResultHandler MOZ_FINAL
: public BluetoothHandsfreeResultHandler
{
public:
void OnError(bt_status_t aStatus) MOZ_OVERRIDE
{
BT_WARNING("BluetoothHandsfreeInterface::AtResponse failed: %d",
(int)aStatus);
}
};
void
BluetoothHfpManager::ProcessUnknownAt(char *aAtString)
{
BT_LOGR("[%s]", aAtString);
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
sBluetoothHfpInterface->AtResponse(BTHF_AT_RESPONSE_ERROR, 0));
sBluetoothHfpInterface->AtResponse(BTHF_AT_RESPONSE_ERROR, 0,
new AtResponseResultHandler());
}
void
@ -1115,6 +1145,17 @@ BluetoothHfpManager::HandleShutdown()
sBluetoothHfpManager = nullptr;
}
class ClccResponseResultHandler MOZ_FINAL
: public BluetoothHandsfreeResultHandler
{
public:
void OnError(bt_status_t aStatus) MOZ_OVERRIDE
{
BT_WARNING("BluetoothHandsfreeInterface::ClccResponse failed: %d",
(int)aStatus);
}
};
void
BluetoothHfpManager::SendCLCC(Call& aCall, int aIndex)
{
@ -1134,31 +1175,39 @@ BluetoothHfpManager::SendCLCC(Call& aCall, int aIndex)
callState = BTHF_CALL_STATE_WAITING;
}
bt_status_t status = sBluetoothHfpInterface->ClccResponse(
aIndex,
aCall.mDirection,
callState,
BTHF_CALL_TYPE_VOICE,
BTHF_CALL_MPTY_TYPE_SINGLE,
NS_ConvertUTF16toUTF8(aCall.mNumber).get(),
aCall.mType);
NS_ENSURE_TRUE_VOID(status == BT_STATUS_SUCCESS);
sBluetoothHfpInterface->ClccResponse(
aIndex, aCall.mDirection, callState, BTHF_CALL_TYPE_VOICE,
BTHF_CALL_MPTY_TYPE_SINGLE, NS_ConvertUTF16toUTF8(aCall.mNumber).get(),
aCall.mType, new ClccResponseResultHandler());
}
class FormattedAtResponseResultHandler MOZ_FINAL
: public BluetoothHandsfreeResultHandler
{
public:
void OnError(bt_status_t aStatus) MOZ_OVERRIDE
{
BT_WARNING("BluetoothHandsfreeInterface::FormattedAtResponse failed: %d",
(int)aStatus);
}
};
void
BluetoothHfpManager::SendLine(const char* aMessage)
{
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
sBluetoothHfpInterface->FormattedAtResponse(aMessage));
sBluetoothHfpInterface->FormattedAtResponse(
aMessage, new FormattedAtResponseResultHandler());
}
void
BluetoothHfpManager::SendResponse(bthf_at_response_t aResponseCode)
{
NS_ENSURE_TRUE_VOID(sBluetoothHfpInterface);
NS_ENSURE_TRUE_VOID(BT_STATUS_SUCCESS ==
sBluetoothHfpInterface->AtResponse(aResponseCode, 0));
sBluetoothHfpInterface->AtResponse(
aResponseCode, 0, new AtResponseResultHandler());
}
void