Bug 1195685 - Transform macro |BT_APPEND_NAMED_VALUE| into function, r=shuang

This commit is contained in:
Ben Tian 2015-09-09 10:59:36 +08:00
parent e1b0c7e2ed
commit 95b08b1104
13 changed files with 170 additions and 173 deletions

View File

@ -631,7 +631,7 @@ BluetoothA2dpManager::ConnectionStateNotification(
AvStatusToSinkString(aState, a2dpState);
InfallibleTArray<BluetoothNamedValue> props;
BT_APPEND_NAMED_VALUE(props, "State", a2dpState);
AppendNamedValue(props, "State", a2dpState);
HandleSinkPropertyChanged(BluetoothSignal(NS_LITERAL_STRING("AudioSink"),
nsString(aBdAddr), props));
@ -656,7 +656,7 @@ BluetoothA2dpManager::AudioStateNotification(BluetoothA2dpAudioState aState,
}
InfallibleTArray<BluetoothNamedValue> props;
BT_APPEND_NAMED_VALUE(props, "State", a2dpState);
AppendNamedValue(props, "State", a2dpState);
HandleSinkPropertyChanged(BluetoothSignal(NS_LITERAL_STRING("AudioSink"),
nsString(aBdAddr), props));

View File

@ -1757,10 +1757,10 @@ private:
InfallibleTArray<BluetoothNamedValue> properties;
BT_APPEND_NAMED_VALUE(properties, "Address", mBdAddr);
BT_APPEND_NAMED_VALUE(properties, "Rssi", mRssi);
BT_APPEND_NAMED_VALUE(properties, "GattAdv", mAdvData);
BT_APPEND_NAMED_VALUE(properties, "Type", static_cast<uint32_t>(type));
AppendNamedValue(properties, "Address", mBdAddr);
AppendNamedValue(properties, "Rssi", mRssi);
AppendNamedValue(properties, "GattAdv", mAdvData);
AppendNamedValue(properties, "Type", static_cast<uint32_t>(type));
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
@ -1990,8 +1990,8 @@ BluetoothGattManager::GetCharacteristicNotification(
// Notify BluetoothGatt to make BluetoothGattService create characteristics
// then proceed
nsTArray<BluetoothNamedValue> values;
BT_APPEND_NAMED_VALUE(values, "serviceId", aServiceId);
BT_APPEND_NAMED_VALUE(values, "characteristics", client->mCharacteristics);
AppendNamedValue(values, "serviceId", aServiceId);
AppendNamedValue(values, "characteristics", client->mCharacteristics);
bs->DistributeSignal(NS_LITERAL_STRING("CharacteristicsDiscovered"),
client->mAppUuid,
@ -2036,9 +2036,9 @@ BluetoothGattManager::GetDescriptorNotification(
// Notify BluetoothGatt to make BluetoothGattCharacteristic create
// descriptors then proceed
nsTArray<BluetoothNamedValue> values;
BT_APPEND_NAMED_VALUE(values, "serviceId", aServiceId);
BT_APPEND_NAMED_VALUE(values, "characteristicId", aCharId);
BT_APPEND_NAMED_VALUE(values, "descriptors", client->mDescriptors);
AppendNamedValue(values, "serviceId", aServiceId);
AppendNamedValue(values, "characteristicId", aCharId);
AppendNamedValue(values, "descriptors", client->mDescriptors);
bs->DistributeSignal(NS_LITERAL_STRING("DescriptorsDiscovered"),
client->mAppUuid,
@ -2082,9 +2082,8 @@ BluetoothGattManager::GetIncludedServiceNotification(
// Notify BluetoothGatt to make BluetoothGattService create included
// services
nsTArray<BluetoothNamedValue> values;
BT_APPEND_NAMED_VALUE(values, "serviceId", aServiceId);
BT_APPEND_NAMED_VALUE(values, "includedServices",
client->mIncludedServices);
AppendNamedValue(values, "serviceId", aServiceId);
AppendNamedValue(values, "includedServices", client->mIncludedServices);
bs->DistributeSignal(NS_LITERAL_STRING("IncludedServicesDiscovered"),
client->mAppUuid,
@ -2491,8 +2490,8 @@ BluetoothGattManager::ConnectionNotification(int aConnId,
// Notify BluetoothGattServer that connection status changed
InfallibleTArray<BluetoothNamedValue> props;
BT_APPEND_NAMED_VALUE(props, "Connected", aConnected);
BT_APPEND_NAMED_VALUE(props, "Address", nsString(aBdAddr));
AppendNamedValue(props, "Connected", aConnected);
AppendNamedValue(props, "Address", nsString(aBdAddr));
bs->DistributeSignal(
NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID),
server->mAppUuid,

View File

@ -1419,12 +1419,12 @@ BluetoothOppManager::FileTransferComplete()
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-transfer-complete");
InfallibleTArray<BluetoothNamedValue> parameters;
BT_APPEND_NAMED_VALUE(parameters, "address", mDeviceAddress);
BT_APPEND_NAMED_VALUE(parameters, "success", mSuccessFlag);
BT_APPEND_NAMED_VALUE(parameters, "received", mIsServer);
BT_APPEND_NAMED_VALUE(parameters, "fileName", mFileName);
BT_APPEND_NAMED_VALUE(parameters, "fileLength", mSentFileLength);
BT_APPEND_NAMED_VALUE(parameters, "contentType", mContentType);
AppendNamedValue(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "success", mSuccessFlag);
AppendNamedValue(parameters, "received", mIsServer);
AppendNamedValue(parameters, "fileName", mFileName);
AppendNamedValue(parameters, "fileLength", mSentFileLength);
AppendNamedValue(parameters, "contentType", mContentType);
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
@ -1437,11 +1437,11 @@ BluetoothOppManager::StartFileTransfer()
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-transfer-start");
InfallibleTArray<BluetoothNamedValue> parameters;
BT_APPEND_NAMED_VALUE(parameters, "address", mDeviceAddress);
BT_APPEND_NAMED_VALUE(parameters, "received", mIsServer);
BT_APPEND_NAMED_VALUE(parameters, "fileName", mFileName);
BT_APPEND_NAMED_VALUE(parameters, "fileLength", mFileLength);
BT_APPEND_NAMED_VALUE(parameters, "contentType", mContentType);
AppendNamedValue(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "received", mIsServer);
AppendNamedValue(parameters, "fileName", mFileName);
AppendNamedValue(parameters, "fileLength", mFileLength);
AppendNamedValue(parameters, "contentType", mContentType);
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
@ -1454,10 +1454,10 @@ BluetoothOppManager::UpdateProgress()
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-update-progress");
InfallibleTArray<BluetoothNamedValue> parameters;
BT_APPEND_NAMED_VALUE(parameters, "address", mDeviceAddress);
BT_APPEND_NAMED_VALUE(parameters, "received", mIsServer);
BT_APPEND_NAMED_VALUE(parameters, "processedLength", mSentFileLength);
BT_APPEND_NAMED_VALUE(parameters, "fileLength", mFileLength);
AppendNamedValue(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "received", mIsServer);
AppendNamedValue(parameters, "processedLength", mSentFileLength);
AppendNamedValue(parameters, "fileLength", mFileLength);
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}
@ -1468,10 +1468,10 @@ BluetoothOppManager::ReceivingFileConfirmation()
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-receiving-file-confirmation");
InfallibleTArray<BluetoothNamedValue> parameters;
BT_APPEND_NAMED_VALUE(parameters, "address", mDeviceAddress);
BT_APPEND_NAMED_VALUE(parameters, "fileName", mFileName);
BT_APPEND_NAMED_VALUE(parameters, "fileLength", mFileLength);
BT_APPEND_NAMED_VALUE(parameters, "contentType", mContentType);
AppendNamedValue(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "fileName", mFileName);
AppendNamedValue(parameters, "fileLength", mFileLength);
AppendNamedValue(parameters, "contentType", mContentType);
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}

View File

@ -9,6 +9,7 @@
#include "BluetoothService.h"
#include "BluetoothSocket.h"
#include "BluetoothUtils.h"
#include "BluetoothUuid.h"
#include "ObexBase.h"
@ -429,24 +430,17 @@ BluetoothPbapManager::PullPhonebook(const ObexHeaderSet& aHeader)
nsString name;
aHeader.GetName(name);
BT_APPEND_NAMED_VALUE(data, "name", name);
AppendNamedValue(data, "name", name);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::Format);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::PropertySelector);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::MaxListCount);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::ListStartOffset);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::vCardSelector);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::Format);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::PropertySelector);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::MaxListCount);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::ListStartOffset);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::vCardSelector);
#ifdef MOZ_B2G_BT_API_V1
bs->DistributeSignal(
BluetoothSignal(NS_LITERAL_STRING(PULL_PHONEBOOK_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data));
#else
bs->DistributeSignal(NS_LITERAL_STRING(PULL_PHONEBOOK_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data);
#endif
bs->DistributeSignal(NS_LITERAL_STRING(PULL_PHONEBOOK_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data);
return ObexResponseCode::Success;
}
@ -465,25 +459,18 @@ BluetoothPbapManager::PullvCardListing(const ObexHeaderSet& aHeader)
nsString name;
aHeader.GetName(name);
BT_APPEND_NAMED_VALUE(data, "name", name);
AppendNamedValue(data, "name", name);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::Order);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::SearchValue);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::SearchProperty);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::MaxListCount);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::ListStartOffset);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::vCardSelector);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::Order);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::SearchValue);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::SearchProperty);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::MaxListCount);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::ListStartOffset);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::vCardSelector);
#ifdef MOZ_B2G_BT_API_V1
bs->DistributeSignal(
BluetoothSignal(NS_LITERAL_STRING(PULL_VCARD_LISTING_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data));
#else
bs->DistributeSignal(NS_LITERAL_STRING(PULL_VCARD_LISTING_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data);
#endif
bs->DistributeSignal(NS_LITERAL_STRING(PULL_VCARD_LISTING_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data);
return ObexResponseCode::Success;
}
@ -502,27 +489,20 @@ BluetoothPbapManager::PullvCardEntry(const ObexHeaderSet& aHeader)
nsString name;
aHeader.GetName(name);
BT_APPEND_NAMED_VALUE(data, "name", name);
AppendNamedValue(data, "name", name);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::Format);
AppendBtNamedValueByTagId(aHeader, data, AppParameterTag::PropertySelector);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::Format);
AppendNamedValueByTagId(aHeader, data, AppParameterTag::PropertySelector);
#ifdef MOZ_B2G_BT_API_V1
bs->DistributeSignal(
BluetoothSignal(NS_LITERAL_STRING(PULL_VCARD_ENTRY_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data));
#else
bs->DistributeSignal(NS_LITERAL_STRING(PULL_VCARD_ENTRY_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data);
#endif
bs->DistributeSignal(NS_LITERAL_STRING(PULL_VCARD_ENTRY_REQ_ID),
NS_LITERAL_STRING(KEY_ADAPTER),
data);
return ObexResponseCode::Success;
}
void
BluetoothPbapManager::AppendBtNamedValueByTagId(
BluetoothPbapManager::AppendNamedValueByTagId(
const ObexHeaderSet& aHeader,
InfallibleTArray<BluetoothNamedValue>& aValues,
const AppParameterTag aTagId)
@ -535,16 +515,18 @@ BluetoothPbapManager::AppendBtNamedValueByTagId(
switch (aTagId) {
case AppParameterTag::Order: {
using namespace mozilla::dom::vCardOrderTypeValues;
uint32_t order = buf[0] < ArrayLength(strings) ? (uint32_t) buf[0]
: 0; // default: indexed
BT_APPEND_NAMED_VALUE(aValues, "order", order);
uint32_t order =
buf[0] < ArrayLength(strings) ? static_cast<uint32_t>(buf[0])
: 0; // default: indexed
AppendNamedValue(aValues, "order", order);
break;
}
case AppParameterTag::SearchProperty: {
using namespace mozilla::dom::vCardSearchKeyTypeValues;
uint32_t searchKey = buf[0] < ArrayLength(strings) ? (uint32_t) buf[0]
: 0; // default: name
BT_APPEND_NAMED_VALUE(aValues, "searchKey", searchKey);
uint32_t searchKey =
buf[0] < ArrayLength(strings) ? static_cast<uint32_t>(buf[0])
: 0; // default: name
AppendNamedValue(aValues, "searchKey", searchKey);
break;
}
case AppParameterTag::SearchValue: {
@ -555,7 +537,7 @@ BluetoothPbapManager::AppendBtNamedValueByTagId(
// 'MDN:Internal_strings'.
nsCString text((char *) buf);
BT_APPEND_NAMED_VALUE(aValues, "searchText", text);
AppendNamedValue(aValues, "searchText", text);
break;
}
case AppParameterTag::MaxListCount: {
@ -569,7 +551,8 @@ BluetoothPbapManager::AppendBtNamedValueByTagId(
// present in the request with a value of 0, else it is excluded.
mPhonebookSizeRequired = !maxListCount;
BT_APPEND_NAMED_VALUE(aValues, "maxListCount", (uint32_t) maxListCount);
AppendNamedValue(aValues, "maxListCount",
static_cast<uint32_t>(maxListCount));
break;
}
case AppParameterTag::ListStartOffset: {
@ -578,19 +561,19 @@ BluetoothPbapManager::AppendBtNamedValueByTagId(
// convert big endian to little endian
listStartOffset = (listStartOffset >> 8) | (listStartOffset << 8);
BT_APPEND_NAMED_VALUE(aValues, "listStartOffset",
(uint32_t) listStartOffset);
AppendNamedValue(aValues, "listStartOffset",
static_cast<uint32_t>(listStartOffset));
break;
}
case AppParameterTag::PropertySelector: {
InfallibleTArray<uint32_t> props = PackPropertiesMask(buf, 64);
BT_APPEND_NAMED_VALUE(aValues, "propSelector", props);
AppendNamedValue(aValues, "propSelector", props);
break;
}
case AppParameterTag::Format: {
bool usevCard3 = buf[0];
BT_APPEND_NAMED_VALUE(aValues, "format", usevCard3);
AppendNamedValue(aValues, "format", usevCard3);
break;
}
case AppParameterTag::vCardSelector: {
@ -600,11 +583,9 @@ BluetoothPbapManager::AppendBtNamedValueByTagId(
AppParameterTag::vCardSelectorOperator, buf, 64);
if (hasVCardSelectorOperator && buf[0]) {
BT_APPEND_NAMED_VALUE(aValues, "vCardSelector_AND",
BluetoothValue(props));
AppendNamedValue(aValues, "vCardSelector_AND", BluetoothValue(props));
} else {
BT_APPEND_NAMED_VALUE(aValues, "vCardSelector_OR",
BluetoothValue(props));
AppendNamedValue(aValues, "vCardSelector_OR", BluetoothValue(props));
}
break;
}

View File

@ -149,7 +149,7 @@ private:
uint8_t PullPhonebook(const ObexHeaderSet& aHeader);
uint8_t PullvCardListing(const ObexHeaderSet& aHeader);
uint8_t PullvCardEntry(const ObexHeaderSet& aHeader);
void AppendBtNamedValueByTagId(
void AppendNamedValueByTagId(
const ObexHeaderSet& aHeader,
InfallibleTArray<BluetoothNamedValue>& aValues,
const AppParameterTag aTagId);

View File

@ -619,27 +619,21 @@ BluetoothServiceBluedroid::GetAdaptersInternal(
* | {"Adapter", BluetoothValue = BluetoothNamedValue[]}
* ...
*/
BluetoothValue adaptersProperties = InfallibleTArray<BluetoothNamedValue>();
InfallibleTArray<BluetoothNamedValue> adaptersProperties;
uint32_t numAdapters = 1; // Bluedroid supports single adapter only
for (uint32_t i = 0; i < numAdapters; i++) {
BluetoothValue properties = InfallibleTArray<BluetoothNamedValue>();
InfallibleTArray<BluetoothNamedValue> properties;
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"State", mEnabled);
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"Address", mBdAddress);
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"Name", mBdName);
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"Discoverable", mDiscoverable);
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"Discovering", mDiscovering);
BT_APPEND_NAMED_VALUE(properties.get_ArrayOfBluetoothNamedValue(),
"PairedDevices", mBondedAddresses);
AppendNamedValue(properties, "State", mEnabled);
AppendNamedValue(properties, "Address", mBdAddress);
AppendNamedValue(properties, "Name", mBdName);
AppendNamedValue(properties, "Discoverable", mDiscoverable);
AppendNamedValue(properties, "Discovering", mDiscovering);
AppendNamedValue(properties, "PairedDevices", mBondedAddresses);
BT_APPEND_NAMED_VALUE(adaptersProperties.get_ArrayOfBluetoothNamedValue(),
"Adapter", properties);
AppendNamedValue(adaptersProperties, "Adapter",
BluetoothValue(properties));
}
DispatchReplySuccess(aRunnable, adaptersProperties);
@ -1461,15 +1455,15 @@ BluetoothServiceBluedroid::AdapterStateChangedNotification(bool aState)
mBdName.Truncate();
InfallibleTArray<BluetoothNamedValue> props;
BT_APPEND_NAMED_VALUE(props, "Name", mBdName);
BT_APPEND_NAMED_VALUE(props, "Address", mBdAddress);
AppendNamedValue(props, "Name", mBdName);
AppendNamedValue(props, "Address", mBdAddress);
if (mDiscoverable) {
mDiscoverable = false;
BT_APPEND_NAMED_VALUE(props, "Discoverable", false);
AppendNamedValue(props, "Discoverable", false);
}
if (mDiscovering) {
mDiscovering = false;
BT_APPEND_NAMED_VALUE(props, "Discovering", false);
AppendNamedValue(props, "Discovering", false);
}
bs->DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
@ -1562,11 +1556,11 @@ BluetoothServiceBluedroid::AdapterPropertiesNotification(
if (p.mType == PROPERTY_BDADDR) {
mBdAddress = p.mString;
BT_APPEND_NAMED_VALUE(propertiesArray, "Address", mBdAddress);
AppendNamedValue(propertiesArray, "Address", mBdAddress);
} else if (p.mType == PROPERTY_BDNAME) {
mBdName = p.mString;
BT_APPEND_NAMED_VALUE(propertiesArray, "Name", mBdName);
AppendNamedValue(propertiesArray, "Name", mBdName);
} else if (p.mType == PROPERTY_ADAPTER_SCAN_MODE) {
@ -1575,7 +1569,7 @@ BluetoothServiceBluedroid::AdapterPropertiesNotification(
// properties to bluetooth backend once Bluetooth is enabled.
if (IsEnabled()) {
mDiscoverable = (p.mScanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE);
BT_APPEND_NAMED_VALUE(propertiesArray, "Discoverable", mDiscoverable);
AppendNamedValue(propertiesArray, "Discoverable", mDiscoverable);
}
} else if (p.mType == PROPERTY_ADAPTER_BONDED_DEVICES) {
// We have to cache addresses of bonded devices. Unlike BlueZ,
@ -1588,8 +1582,7 @@ BluetoothServiceBluedroid::AdapterPropertiesNotification(
mBondedAddresses.Clear();
mBondedAddresses.AppendElements(p.mStringArray);
BT_APPEND_NAMED_VALUE(propertiesArray, "PairedDevices",
mBondedAddresses);
AppendNamedValue(propertiesArray, "PairedDevices", mBondedAddresses);
} else if (p.mType == PROPERTY_UNKNOWN) {
/* Bug 1065999: working around unknown properties */
} else {
@ -1630,21 +1623,21 @@ BluetoothServiceBluedroid::RemoteDevicePropertiesNotification(
InfallibleTArray<BluetoothNamedValue> propertiesArray;
nsString bdAddr(aBdAddr);
BT_APPEND_NAMED_VALUE(propertiesArray, "Address", bdAddr);
AppendNamedValue(propertiesArray, "Address", bdAddr);
for (int i = 0; i < aNumProperties; ++i) {
const BluetoothProperty& p = aProperties[i];
if (p.mType == PROPERTY_BDNAME) {
BT_APPEND_NAMED_VALUE(propertiesArray, "Name", p.mString);
AppendNamedValue(propertiesArray, "Name", p.mString);
// Update <address, name> mapping
mDeviceNameMap.Remove(bdAddr);
mDeviceNameMap.Put(bdAddr, p.mString);
} else if (p.mType == PROPERTY_CLASS_OF_DEVICE) {
uint32_t cod = p.mUint32;
BT_APPEND_NAMED_VALUE(propertiesArray, "Cod", cod);
AppendNamedValue(propertiesArray, "Cod", cod);
} else if (p.mType == PROPERTY_UUIDS) {
nsTArray<nsString> uuids;
@ -1658,11 +1651,11 @@ BluetoothServiceBluedroid::RemoteDevicePropertiesNotification(
uuids.InsertElementSorted(uuid);
}
}
BT_APPEND_NAMED_VALUE(propertiesArray, "UUIDs", uuids);
AppendNamedValue(propertiesArray, "UUIDs", uuids);
} else if (p.mType == PROPERTY_TYPE_OF_DEVICE) {
BT_APPEND_NAMED_VALUE(propertiesArray, "Type",
static_cast<uint32_t>(p.mTypeOfDevice));
AppendNamedValue(propertiesArray, "Type",
static_cast<uint32_t>(p.mTypeOfDevice));
} else if (p.mType == PROPERTY_UNKNOWN) {
/* Bug 1065999: working around unknown properties */
@ -1732,13 +1725,13 @@ BluetoothServiceBluedroid::DeviceFoundNotification(
const BluetoothProperty& p = aProperties[i];
if (p.mType == PROPERTY_BDADDR) {
BT_APPEND_NAMED_VALUE(propertiesArray, "Address", p.mString);
AppendNamedValue(propertiesArray, "Address", p.mString);
bdAddr = p.mString;
} else if (p.mType == PROPERTY_BDNAME) {
BT_APPEND_NAMED_VALUE(propertiesArray, "Name", p.mString);
AppendNamedValue(propertiesArray, "Name", p.mString);
bdName = p.mString;
} else if (p.mType == PROPERTY_CLASS_OF_DEVICE) {
BT_APPEND_NAMED_VALUE(propertiesArray, "Cod", p.mUint32);
AppendNamedValue(propertiesArray, "Cod", p.mUint32);
} else if (p.mType == PROPERTY_UUIDS) {
nsTArray<nsString> uuids;
@ -1752,11 +1745,11 @@ BluetoothServiceBluedroid::DeviceFoundNotification(
uuids.InsertElementSorted(uuid);
}
}
BT_APPEND_NAMED_VALUE(propertiesArray, "UUIDs", uuids);
AppendNamedValue(propertiesArray, "UUIDs", uuids);
} else if (p.mType == PROPERTY_TYPE_OF_DEVICE) {
BT_APPEND_NAMED_VALUE(propertiesArray, "Type",
static_cast<uint32_t>(p.mTypeOfDevice));
AppendNamedValue(propertiesArray, "Type",
static_cast<uint32_t>(p.mTypeOfDevice));
} else if (p.mType == PROPERTY_UNKNOWN) {
/* Bug 1065999: working around unknown properties */
@ -1783,7 +1776,7 @@ BluetoothServiceBluedroid::DiscoveryStateChangedNotification(bool aState)
// Fire PropertyChanged of Discovering
InfallibleTArray<BluetoothNamedValue> propertiesArray;
BT_APPEND_NAMED_VALUE(propertiesArray, "Discovering", mDiscovering);
AppendNamedValue(propertiesArray, "Discovering", mDiscovering);
DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
NS_LITERAL_STRING(KEY_ADAPTER),
@ -1815,11 +1808,11 @@ BluetoothServiceBluedroid::PinRequestNotification(
mDeviceNameMap.Put(bdAddr, bdName);
}
BT_APPEND_NAMED_VALUE(propertiesArray, "address", bdAddr);
BT_APPEND_NAMED_VALUE(propertiesArray, "name", bdName);
BT_APPEND_NAMED_VALUE(propertiesArray, "passkey", EmptyString());
BT_APPEND_NAMED_VALUE(propertiesArray, "type",
NS_LITERAL_STRING(PAIRING_REQ_TYPE_ENTERPINCODE));
AppendNamedValue(propertiesArray, "address", bdAddr);
AppendNamedValue(propertiesArray, "name", bdName);
AppendNamedValue(propertiesArray, "passkey", EmptyString());
AppendNamedValue(propertiesArray, "type",
NS_LITERAL_STRING(PAIRING_REQ_TYPE_ENTERPINCODE));
DistributeSignal(NS_LITERAL_STRING("PairingRequest"),
NS_LITERAL_STRING(KEY_PAIRING_LISTENER),
@ -1873,10 +1866,10 @@ BluetoothServiceBluedroid::SspRequestNotification(
return;
}
BT_APPEND_NAMED_VALUE(propertiesArray, "address", bdAddr);
BT_APPEND_NAMED_VALUE(propertiesArray, "name", bdName);
BT_APPEND_NAMED_VALUE(propertiesArray, "passkey", passkey);
BT_APPEND_NAMED_VALUE(propertiesArray, "type", pairingType);
AppendNamedValue(propertiesArray, "address", bdAddr);
AppendNamedValue(propertiesArray, "name", bdName);
AppendNamedValue(propertiesArray, "passkey", passkey);
AppendNamedValue(propertiesArray, "type", pairingType);
DistributeSignal(NS_LITERAL_STRING("PairingRequest"),
NS_LITERAL_STRING(KEY_PAIRING_LISTENER),
@ -1938,17 +1931,17 @@ BluetoothServiceBluedroid::BondStateChangedNotification(
// valid, according to Bluetooth Core Spec. v3.0 - Sec. 6.22:
// "a valid Bluetooth name is a UTF-8 encoding string which is up to 248
// bytes in length."
BT_APPEND_NAMED_VALUE(propertiesArray, "Name", remotebdName);
AppendNamedValue(propertiesArray, "Name", remotebdName);
}
// Notify device of attribute changed
BT_APPEND_NAMED_VALUE(propertiesArray, "Paired", bonded);
AppendNamedValue(propertiesArray, "Paired", bonded);
DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
remoteBdAddr,
BluetoothValue(propertiesArray));
// Notify adapter of device paired/unpaired
BT_INSERT_NAMED_VALUE(propertiesArray, 0, "Address", remoteBdAddr);
InsertNamedValue(propertiesArray, 0, "Address", remoteBdAddr);
DistributeSignal(bonded ? NS_LITERAL_STRING(DEVICE_PAIRED_ID)
: NS_LITERAL_STRING(DEVICE_UNPAIRED_ID),
NS_LITERAL_STRING(KEY_ADAPTER),

View File

@ -609,7 +609,7 @@ BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
NS_NAMED_LITERAL_STRING(type, "bluetooth-dialer-command");
InfallibleTArray<BluetoothNamedValue> parameters;
BT_APPEND_NAMED_VALUE(parameters, "command", nsString(aCommand));
AppendNamedValue(parameters, "command", nsString(aCommand));
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}

View File

@ -58,22 +58,6 @@ extern bool gBluetoothDebugFlag;
#define BT_WARNING(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)
#endif
/**
* Wrap literal name and value into a BluetoothNamedValue
* and append it to the array.
*/
#define BT_APPEND_NAMED_VALUE(array, name, value) \
array.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING(name), \
BluetoothValue(value)))
/**
* Wrap literal name and value into a BluetoothNamedValue
* and insert it to the array.
*/
#define BT_INSERT_NAMED_VALUE(array, index, name, value) \
array.InsertElementAt(index, BluetoothNamedValue(NS_LITERAL_STRING(name), \
BluetoothValue(value)))
/**
* Convert an enum value to string and append it to a fallible array.
*/

View File

@ -244,8 +244,8 @@ BluetoothHidManager::NotifyStatusChanged()
NS_NAMED_LITERAL_STRING(type, BLUETOOTH_HID_STATUS_CHANGED_ID);
InfallibleTArray<BluetoothNamedValue> parameters;
BT_APPEND_NAMED_VALUE(parameters, "connected", mConnected);
BT_APPEND_NAMED_VALUE(parameters, "address", mDeviceAddress);
AppendNamedValue(parameters, "connected", mConnected);
AppendNamedValue(parameters, "address", mDeviceAddress);
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}

View File

@ -664,7 +664,7 @@ BluetoothService::FireAdapterStateChanged(bool aEnable)
MOZ_ASSERT(NS_IsMainThread());
InfallibleTArray<BluetoothNamedValue> props;
BT_APPEND_NAMED_VALUE(props, "State", aEnable);
AppendNamedValue(props, "State", aEnable);
DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
NS_LITERAL_STRING(KEY_ADAPTER),

View File

@ -312,8 +312,8 @@ DispatchStatusChangedEvent(const nsAString& aType,
MOZ_ASSERT(NS_IsMainThread());
InfallibleTArray<BluetoothNamedValue> data;
BT_APPEND_NAMED_VALUE(data, "address", nsString(aAddress));
BT_APPEND_NAMED_VALUE(data, "status", aStatus);
AppendNamedValue(data, "address", nsString(aAddress));
AppendNamedValue(data, "status", aStatus);
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
@ -321,4 +321,25 @@ DispatchStatusChangedEvent(const nsAString& aType,
bs->DistributeSignal(aType, NS_LITERAL_STRING(KEY_ADAPTER), data);
}
void
AppendNamedValue(InfallibleTArray<BluetoothNamedValue>& aArray,
const char* aName, const BluetoothValue& aValue)
{
nsString name;
name.AssignASCII(aName);
aArray.AppendElement(BluetoothNamedValue(name, aValue));
}
void
InsertNamedValue(InfallibleTArray<BluetoothNamedValue>& aArray,
uint8_t aIndex, const char* aName,
const BluetoothValue& aValue)
{
nsString name;
name.AssignASCII(aName);
aArray.InsertElementAt(aIndex, BluetoothNamedValue(name, aValue));
}
END_BLUETOOTH_NAMESPACE

View File

@ -157,6 +157,25 @@ DispatchStatusChangedEvent(const nsAString& aType,
const nsAString& aDeviceAddress,
bool aStatus);
//
// BluetoothNamedValue manipulation
//
/**
* Wrap literal name and value into a BluetoothNamedValue and
* append it to the array.
*/
void AppendNamedValue(InfallibleTArray<BluetoothNamedValue>& aArray,
const char* aName, const BluetoothValue& aValue);
/**
* Wrap literal name and value into a BluetoothNamedValue and
* insert it to the array.
*/
void InsertNamedValue(InfallibleTArray<BluetoothNamedValue>& aArray,
uint8_t aIndex, const char* aName,
const BluetoothValue& aValue);
END_BLUETOOTH_NAMESPACE
#endif // mozilla_dom_bluetooth_BluetoothUtils_h

View File

@ -449,8 +449,8 @@ BluetoothAdapter::SetPropertyByValue(const BluetoothNamedValue& aValue)
}
InfallibleTArray<BluetoothNamedValue> props;
BT_APPEND_NAMED_VALUE(props, "Address", pairedDeviceAddresses[i]);
BT_APPEND_NAMED_VALUE(props, "Paired", true);
AppendNamedValue(props, "Address", pairedDeviceAddresses[i]);
AppendNamedValue(props, "Paired", true);
// Create paired device and append to adapter's device array
mDevices.AppendElement(