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

This commit is contained in:
Thomas Zimmermann 2014-07-09 09:38:20 +02:00
parent 317b0ad1b1
commit 8ac530a6b1
3 changed files with 65 additions and 22 deletions

View File

@ -573,22 +573,42 @@ BluetoothInterface::Disable(BluetoothResultHandler* aRes)
/* Adapter Properties */
int
BluetoothInterface::GetAdapterProperties()
void
BluetoothInterface::GetAdapterProperties(BluetoothResultHandler* aRes)
{
return mInterface->get_adapter_properties();
int status = mInterface->get_adapter_properties();
if (aRes) {
DispatchBluetoothResult(aRes,
&BluetoothResultHandler::GetAdapterProperties,
status);
}
}
int
BluetoothInterface::GetAdapterProperty(bt_property_type_t aType)
void
BluetoothInterface::GetAdapterProperty(bt_property_type_t aType,
BluetoothResultHandler* aRes)
{
return mInterface->get_adapter_property(aType);
int status = mInterface->get_adapter_property(aType);
if (aRes) {
DispatchBluetoothResult(aRes,
&BluetoothResultHandler::GetAdapterProperty,
status);
}
}
int
BluetoothInterface::SetAdapterProperty(const bt_property_t* aProperty)
void
BluetoothInterface::SetAdapterProperty(const bt_property_t* aProperty,
BluetoothResultHandler* aRes)
{
return mInterface->set_adapter_property(aProperty);
int status = mInterface->set_adapter_property(aProperty);
if (aRes) {
DispatchBluetoothResult(aRes,
&BluetoothResultHandler::SetAdapterProperty,
status);
}
}
/* Remote Device Properties */

View File

@ -239,9 +239,11 @@ public:
/* Adapter Properties */
int GetAdapterProperties();
int GetAdapterProperty(bt_property_type_t aType);
int SetAdapterProperty(const bt_property_t* aProperty);
void GetAdapterProperties(BluetoothResultHandler* aRes);
void GetAdapterProperty(bt_property_type_t aType,
BluetoothResultHandler* aRes);
void SetAdapterProperty(const bt_property_t* aProperty,
BluetoothResultHandler* aRes);
/* Remote Device Properties */

View File

@ -105,6 +105,16 @@ private:
class SetupAfterEnabledTask MOZ_FINAL : public nsRunnable
{
public:
class SetAdapterPropertyResultHandler MOZ_FINAL
: public BluetoothResultHandler
{
public:
void OnError(int aStatus) MOZ_OVERRIDE
{
BT_LOGR("Fail to set: BT_SCAN_MODE_CONNECTABLE");
}
};
NS_IMETHOD
Run()
{
@ -126,11 +136,8 @@ public:
prop.len = sizeof(mode);
NS_ENSURE_TRUE(sBtInterface, NS_ERROR_FAILURE);
int ret = sBtInterface->SetAdapterProperty(&prop);
if (ret != BT_STATUS_SUCCESS) {
BT_LOGR("Fail to set: BT_SCAN_MODE_CONNECTABLE");
}
sBtInterface->SetAdapterProperty(&prop,
new SetAdapterPropertyResultHandler());
// Trigger BluetoothOppManager to listen
BluetoothOppManager* opp = BluetoothOppManager::Get();
@ -1193,6 +1200,23 @@ BluetoothServiceBluedroid::StopDiscoveryInternal(
return NS_OK;
}
class SetAdapterPropertyResultHandler MOZ_FINAL : public BluetoothResultHandler
{
public:
SetAdapterPropertyResultHandler(BluetoothReplyRunnable* aRunnable)
: mRunnable(aRunnable)
{ }
void OnError(int aStatus) MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
sSetPropertyRunnableArray.RemoveElement(mRunnable);
ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("SetProperty"));
}
private:
BluetoothReplyRunnable* mRunnable;
};
nsresult
BluetoothServiceBluedroid::SetProperty(BluetoothObjectType aType,
const BluetoothNamedValue& aValue,
@ -1247,11 +1271,8 @@ BluetoothServiceBluedroid::SetProperty(BluetoothObjectType aType,
sSetPropertyRunnableArray.AppendElement(aRunnable);
int ret = sBtInterface->SetAdapterProperty(&prop);
if (ret != BT_STATUS_SUCCESS) {
ReplyStatusError(aRunnable, ret, NS_LITERAL_STRING(ERR_SET_PROPERTY));
sSetPropertyRunnableArray.RemoveElement(aRunnable);
}
sBtInterface->SetAdapterProperty(&prop,
new SetAdapterPropertyResultHandler(aRunnable));
return NS_OK;
}