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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -609,7 +609,7 @@ BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
NS_NAMED_LITERAL_STRING(type, "bluetooth-dialer-command"); NS_NAMED_LITERAL_STRING(type, "bluetooth-dialer-command");
InfallibleTArray<BluetoothNamedValue> parameters; InfallibleTArray<BluetoothNamedValue> parameters;
BT_APPEND_NAMED_VALUE(parameters, "command", nsString(aCommand)); AppendNamedValue(parameters, "command", nsString(aCommand));
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters); 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__) #define BT_WARNING(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)
#endif #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. * 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); NS_NAMED_LITERAL_STRING(type, BLUETOOTH_HID_STATUS_CHANGED_ID);
InfallibleTArray<BluetoothNamedValue> parameters; InfallibleTArray<BluetoothNamedValue> parameters;
BT_APPEND_NAMED_VALUE(parameters, "connected", mConnected); AppendNamedValue(parameters, "connected", mConnected);
BT_APPEND_NAMED_VALUE(parameters, "address", mDeviceAddress); AppendNamedValue(parameters, "address", mDeviceAddress);
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters); BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
} }

View File

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

View File

@ -312,8 +312,8 @@ DispatchStatusChangedEvent(const nsAString& aType,
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
InfallibleTArray<BluetoothNamedValue> data; InfallibleTArray<BluetoothNamedValue> data;
BT_APPEND_NAMED_VALUE(data, "address", nsString(aAddress)); AppendNamedValue(data, "address", nsString(aAddress));
BT_APPEND_NAMED_VALUE(data, "status", aStatus); AppendNamedValue(data, "status", aStatus);
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs); NS_ENSURE_TRUE_VOID(bs);
@ -321,4 +321,25 @@ DispatchStatusChangedEvent(const nsAString& aType,
bs->DistributeSignal(aType, NS_LITERAL_STRING(KEY_ADAPTER), data); 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 END_BLUETOOTH_NAMESPACE

View File

@ -157,6 +157,25 @@ DispatchStatusChangedEvent(const nsAString& aType,
const nsAString& aDeviceAddress, const nsAString& aDeviceAddress,
bool aStatus); 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 END_BLUETOOTH_NAMESPACE
#endif // mozilla_dom_bluetooth_BluetoothUtils_h #endif // mozilla_dom_bluetooth_BluetoothUtils_h

View File

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