зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1029386: Asynchronous Bluedroid adapter methods, r=shuang
This commit is contained in:
Родитель
4a8768ea72
Коммит
e0760329b5
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -103,6 +103,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()
|
||||
{
|
||||
|
@ -123,11 +133,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());
|
||||
|
||||
// Try to fire event 'AdapterAdded' to fit the original behaviour when
|
||||
// we used BlueZ as backend.
|
||||
|
@ -1141,6 +1148,22 @@ 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());
|
||||
ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("SetProperty"));
|
||||
}
|
||||
private:
|
||||
BluetoothReplyRunnable* mRunnable;
|
||||
};
|
||||
|
||||
nsresult
|
||||
BluetoothServiceBluedroid::SetProperty(BluetoothObjectType aType,
|
||||
const BluetoothNamedValue& aValue,
|
||||
|
@ -1189,10 +1212,8 @@ BluetoothServiceBluedroid::SetProperty(BluetoothObjectType aType,
|
|||
|
||||
sSetPropertyRunnableArray.AppendElement(aRunnable);
|
||||
|
||||
int ret = sBtInterface->SetAdapterProperty(&prop);
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
ReplyStatusError(aRunnable, ret, NS_LITERAL_STRING("SetProperty"));
|
||||
}
|
||||
sBtInterface->SetAdapterProperty(&prop,
|
||||
new SetAdapterPropertyResultHandler(aRunnable));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче