зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1033961: Asynchronous discovery methods in Bluedroid (under bluetooth2/), r=btian
This commit is contained in:
Родитель
83272ecf5c
Коммит
4f71ca5e0c
|
@ -685,16 +685,28 @@ BluetoothInterface::GetRemoteServices(bt_bdaddr_t* aRemoteAddr,
|
|||
|
||||
/* Discovery */
|
||||
|
||||
int
|
||||
BluetoothInterface::StartDiscovery()
|
||||
void
|
||||
BluetoothInterface::StartDiscovery(BluetoothResultHandler* aRes)
|
||||
{
|
||||
return mInterface->start_discovery();
|
||||
int status = mInterface->start_discovery();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothResult(aRes,
|
||||
&BluetoothResultHandler::StartDiscovery,
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
BluetoothInterface::CancelDiscovery()
|
||||
void
|
||||
BluetoothInterface::CancelDiscovery(BluetoothResultHandler* aRes)
|
||||
{
|
||||
return mInterface->cancel_discovery();
|
||||
int status = mInterface->cancel_discovery();
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothResult(aRes,
|
||||
&BluetoothResultHandler::CancelDiscovery,
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Bonds */
|
||||
|
|
|
@ -266,8 +266,8 @@ public:
|
|||
|
||||
/* Discovery */
|
||||
|
||||
int StartDiscovery();
|
||||
int CancelDiscovery();
|
||||
void StartDiscovery(BluetoothResultHandler* aRes);
|
||||
void CancelDiscovery(BluetoothResultHandler* aRes);
|
||||
|
||||
/* Bonds */
|
||||
|
||||
|
|
|
@ -1187,6 +1187,24 @@ BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal(
|
|||
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
|
||||
BluetoothServiceBluedroid::StartDiscoveryInternal(
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
|
@ -1195,17 +1213,30 @@ BluetoothServiceBluedroid::StartDiscoveryInternal(
|
|||
|
||||
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);
|
||||
sBtInterface->StartDiscovery(new StartDiscoveryResultHandler(aRunnable));
|
||||
|
||||
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
|
||||
BluetoothServiceBluedroid::StopDiscoveryInternal(
|
||||
BluetoothReplyRunnable* aRunnable)
|
||||
|
@ -1214,13 +1245,8 @@ BluetoothServiceBluedroid::StopDiscoveryInternal(
|
|||
|
||||
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);
|
||||
sBtInterface->CancelDiscovery(new CancelDiscoveryResultHandler(aRunnable));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче