mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
Bug 1029386: Asynchronous Bluedroid device-property methods, r=shuang
This commit is contained in:
parent
e0760329b5
commit
c408b4d665
@ -613,24 +613,45 @@ BluetoothInterface::SetAdapterProperty(const bt_property_t* aProperty,
|
||||
|
||||
/* Remote Device Properties */
|
||||
|
||||
int
|
||||
BluetoothInterface::GetRemoteDeviceProperties(bt_bdaddr_t *aRemoteAddr)
|
||||
void
|
||||
BluetoothInterface::GetRemoteDeviceProperties(bt_bdaddr_t *aRemoteAddr,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
return mInterface->get_remote_device_properties(aRemoteAddr);
|
||||
int status = mInterface->get_remote_device_properties(aRemoteAddr);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothResult(aRes,
|
||||
&BluetoothResultHandler::GetRemoteDeviceProperties,
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
BluetoothInterface::GetRemoteDeviceProperty(bt_bdaddr_t* aRemoteAddr,
|
||||
bt_property_type_t aType)
|
||||
bt_property_type_t aType,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
return mInterface->get_remote_device_property(aRemoteAddr, aType);
|
||||
int status = mInterface->get_remote_device_property(aRemoteAddr, aType);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothResult(aRes,
|
||||
&BluetoothResultHandler::GetRemoteDeviceProperty,
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
BluetoothInterface::SetRemoteDeviceProperty(bt_bdaddr_t* aRemoteAddr,
|
||||
const bt_property_t* aProperty)
|
||||
const bt_property_t* aProperty,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
return mInterface->set_remote_device_property(aRemoteAddr, aProperty);
|
||||
int status = mInterface->set_remote_device_property(aRemoteAddr, aProperty);
|
||||
|
||||
if (aRes) {
|
||||
DispatchBluetoothResult(aRes,
|
||||
&BluetoothResultHandler::SetRemoteDeviceProperty,
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
/* Remote Services */
|
||||
|
@ -247,11 +247,14 @@ public:
|
||||
|
||||
/* Remote Device Properties */
|
||||
|
||||
int GetRemoteDeviceProperties(bt_bdaddr_t *aRemoteAddr);
|
||||
int GetRemoteDeviceProperty(bt_bdaddr_t* aRemoteAddr,
|
||||
bt_property_type_t aType);
|
||||
int SetRemoteDeviceProperty(bt_bdaddr_t* aRemoteAddr,
|
||||
const bt_property_t* aProperty);
|
||||
void GetRemoteDeviceProperties(bt_bdaddr_t *aRemoteAddr,
|
||||
BluetoothResultHandler* aRes);
|
||||
void GetRemoteDeviceProperty(bt_bdaddr_t* aRemoteAddr,
|
||||
bt_property_type_t aType,
|
||||
BluetoothResultHandler* aRes);
|
||||
void SetRemoteDeviceProperty(bt_bdaddr_t* aRemoteAddr,
|
||||
const bt_property_t* aProperty,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
/* Remote Services */
|
||||
|
||||
|
@ -59,6 +59,7 @@ static InfallibleTArray<nsString> sAdapterBondedAddressArray;
|
||||
// Static variables below should only be used on *main thread*
|
||||
static BluetoothInterface* sBtInterface;
|
||||
static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
|
||||
static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
|
||||
static nsTArray<int> sRequestedDeviceCountArray;
|
||||
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
|
||||
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetDeviceRunnableArray;
|
||||
@ -456,8 +457,6 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
|
||||
|
||||
// Use address as the index
|
||||
sRemoteDevicesPack.AppendElement(
|
||||
BluetoothNamedValue(mRemoteDeviceBdAddress, mProps));
|
||||
@ -1026,6 +1025,38 @@ BluetoothServiceBluedroid::GetDefaultAdapterPathInternal(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class GetRemoteDevicePropertiesResultHandler MOZ_FINAL
|
||||
: public BluetoothResultHandler
|
||||
{
|
||||
public:
|
||||
GetRemoteDevicePropertiesResultHandler(const nsAString& aDeviceAddress)
|
||||
: mDeviceAddress(aDeviceAddress)
|
||||
{ }
|
||||
|
||||
void OnError(int aStatus) MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
BT_WARNING("GetRemoteDeviceProperties(%s) failed: %d",
|
||||
mDeviceAddress.get(), aStatus);
|
||||
|
||||
/* dispatch result after final pending operation */
|
||||
if (--sRequestedDeviceCountArray[0] == 0) {
|
||||
if (!sGetDeviceRunnableArray.IsEmpty()) {
|
||||
DispatchBluetoothReply(sGetDeviceRunnableArray[0],
|
||||
sRemoteDevicesPack, EmptyString());
|
||||
sGetDeviceRunnableArray.RemoveElementAt(0);
|
||||
}
|
||||
|
||||
sRequestedDeviceCountArray.RemoveElementAt(0);
|
||||
sRemoteDevicesPack.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
nsString mDeviceAddress;
|
||||
};
|
||||
|
||||
nsresult
|
||||
BluetoothServiceBluedroid::GetConnectedDevicePropertiesInternal(
|
||||
uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable)
|
||||
@ -1057,22 +1088,18 @@ BluetoothServiceBluedroid::GetConnectedDevicePropertiesInternal(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
sRequestedDeviceCountArray.AppendElement(requestedDeviceCount);
|
||||
sGetDeviceRunnableArray.AppendElement(aRunnable);
|
||||
|
||||
for (int i = 0; i < requestedDeviceCount; i++) {
|
||||
// Retrieve all properties of devices
|
||||
bt_bdaddr_t addressType;
|
||||
StringToBdAddressType(deviceAddresses[i], &addressType);
|
||||
|
||||
int ret = sBtInterface->GetRemoteDeviceProperties(&addressType);
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
DispatchBluetoothReply(aRunnable, BluetoothValue(true),
|
||||
NS_LITERAL_STRING("GetConnectedDeviceFailed"));
|
||||
return NS_OK;
|
||||
}
|
||||
sBtInterface->GetRemoteDeviceProperties(&addressType,
|
||||
new GetRemoteDevicePropertiesResultHandler(deviceAddresses[i]));
|
||||
}
|
||||
|
||||
sRequestedDeviceCountArray.AppendElement(requestedDeviceCount);
|
||||
sGetDeviceRunnableArray.AppendElement(aRunnable);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1091,20 +1118,17 @@ BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
sRequestedDeviceCountArray.AppendElement(requestedDeviceCount);
|
||||
sGetDeviceRunnableArray.AppendElement(aRunnable);
|
||||
|
||||
for (int i = 0; i < requestedDeviceCount; i++) {
|
||||
// Retrieve all properties of devices
|
||||
bt_bdaddr_t addressType;
|
||||
StringToBdAddressType(aDeviceAddress[i], &addressType);
|
||||
int ret = sBtInterface->GetRemoteDeviceProperties(&addressType);
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
DispatchBluetoothReply(aRunnable, BluetoothValue(true),
|
||||
NS_LITERAL_STRING("GetPairedDeviceFailed"));
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
sRequestedDeviceCountArray.AppendElement(requestedDeviceCount);
|
||||
sGetDeviceRunnableArray.AppendElement(aRunnable);
|
||||
sBtInterface->GetRemoteDeviceProperties(&addressType,
|
||||
new GetRemoteDevicePropertiesResultHandler(aDeviceAddress[i]));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user