Bug 1033961: Asynchronous discovery methods in Bluedroid (under bluetooth2/), r=btian

This commit is contained in:
Thomas Zimmermann 2014-07-09 09:39:04 +02:00
Родитель 83272ecf5c
Коммит 4f71ca5e0c
3 изменённых файлов: 59 добавлений и 21 удалений

Просмотреть файл

@ -685,16 +685,28 @@ BluetoothInterface::GetRemoteServices(bt_bdaddr_t* aRemoteAddr,
/* Discovery */ /* Discovery */
int void
BluetoothInterface::StartDiscovery() BluetoothInterface::StartDiscovery(BluetoothResultHandler* aRes)
{ {
return mInterface->start_discovery(); int status = mInterface->start_discovery();
if (aRes) {
DispatchBluetoothResult(aRes,
&BluetoothResultHandler::StartDiscovery,
status);
}
} }
int void
BluetoothInterface::CancelDiscovery() BluetoothInterface::CancelDiscovery(BluetoothResultHandler* aRes)
{ {
return mInterface->cancel_discovery(); int status = mInterface->cancel_discovery();
if (aRes) {
DispatchBluetoothResult(aRes,
&BluetoothResultHandler::CancelDiscovery,
status);
}
} }
/* Bonds */ /* Bonds */

Просмотреть файл

@ -266,8 +266,8 @@ public:
/* Discovery */ /* Discovery */
int StartDiscovery(); void StartDiscovery(BluetoothResultHandler* aRes);
int CancelDiscovery(); void CancelDiscovery(BluetoothResultHandler* aRes);
/* Bonds */ /* Bonds */

Просмотреть файл

@ -1187,6 +1187,24 @@ BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal(
return NS_OK; return NS_OK;
} }
class StartDiscoveryResultHandler MOZ_FINAL : public BluetoothResultHandler
{
public:
StartDiscoveryResultHandler(BluetoothReplyRunnable* aRunnable)
: mRunnable(aRunnable)
{ }
void OnError(int aStatus) MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
sChangeDiscoveryRunnableArray.RemoveElement(mRunnable);
ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("StartDiscovery"));
}
private:
BluetoothReplyRunnable* mRunnable;
};
nsresult nsresult
BluetoothServiceBluedroid::StartDiscoveryInternal( BluetoothServiceBluedroid::StartDiscoveryInternal(
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
@ -1195,17 +1213,30 @@ BluetoothServiceBluedroid::StartDiscoveryInternal(
ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK); ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
int ret = sBtInterface->StartDiscovery();
if (ret != BT_STATUS_SUCCESS) {
ReplyStatusError(aRunnable, ret, NS_LITERAL_STRING("StartDiscovery"));
return NS_OK;
}
sChangeDiscoveryRunnableArray.AppendElement(aRunnable); sChangeDiscoveryRunnableArray.AppendElement(aRunnable);
sBtInterface->StartDiscovery(new StartDiscoveryResultHandler(aRunnable));
return NS_OK; return NS_OK;
} }
class CancelDiscoveryResultHandler MOZ_FINAL : public BluetoothResultHandler
{
public:
CancelDiscoveryResultHandler(BluetoothReplyRunnable* aRunnable)
: mRunnable(aRunnable)
{ }
void OnError(int aStatus) MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
sChangeDiscoveryRunnableArray.RemoveElement(mRunnable);
ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("StopDiscovery"));
}
private:
BluetoothReplyRunnable* mRunnable;
};
nsresult nsresult
BluetoothServiceBluedroid::StopDiscoveryInternal( BluetoothServiceBluedroid::StopDiscoveryInternal(
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
@ -1214,13 +1245,8 @@ BluetoothServiceBluedroid::StopDiscoveryInternal(
ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK); ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
int ret = sBtInterface->CancelDiscovery();
if (ret != BT_STATUS_SUCCESS) {
ReplyStatusError(aRunnable, ret, NS_LITERAL_STRING("StopDiscovery"));
return NS_OK;
}
sChangeDiscoveryRunnableArray.AppendElement(aRunnable); sChangeDiscoveryRunnableArray.AppendElement(aRunnable);
sBtInterface->CancelDiscovery(new CancelDiscoveryResultHandler(aRunnable));
return NS_OK; return NS_OK;
} }