Bug 995061 - Patch 1/2: [bluedroid] define and apply macro to append named value in profile managers, r=echou

This commit is contained in:
Ben Tian 2014-04-11 11:52:44 +08:00
parent 2150cc6fa7
commit 0baecb5eac
6 changed files with 56 additions and 128 deletions

View File

@ -57,6 +57,25 @@ 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), value))
/**
* Ensure success of system message broadcast with void return.
*/
#define BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters) \
do { \
if (!BroadcastSystemMessage(type, parameters)) { \
BT_WARNING("Failed to broadcast [%s]", \
NS_ConvertUTF16toUTF8(type).get()); \
return; \
} \
} while(0)
#define BEGIN_BLUETOOTH_NAMESPACE \
namespace mozilla { namespace dom { namespace bluetooth {
#define END_BLUETOOTH_NAMESPACE \

View File

@ -241,18 +241,10 @@ BluetoothHidManager::NotifyStatusChanged()
NS_NAMED_LITERAL_STRING(type, BLUETOOTH_HID_STATUS_CHANGED_ID);
InfallibleTArray<BluetoothNamedValue> parameters;
BluetoothValue v = mConnected;
parameters.AppendElement(
BluetoothNamedValue(NS_LITERAL_STRING("connected"), v));
BT_APPEND_NAMED_VALUE(parameters, "connected", mConnected);
BT_APPEND_NAMED_VALUE(parameters, "address", mDeviceAddress);
v = mDeviceAddress;
parameters.AppendElement(
BluetoothNamedValue(NS_LITERAL_STRING("address"), v));
if (!BroadcastSystemMessage(type, parameters)) {
BT_WARNING("Failed to broadcast system message to settings");
return;
}
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}
void

View File

@ -266,8 +266,7 @@ A2dpConnectionStateCallback(btav_connection_state_t aState,
AvStatusToSinkString(aState, a2dpState);
InfallibleTArray<BluetoothNamedValue> props;
props.AppendElement(
BluetoothNamedValue(NS_LITERAL_STRING("State"), a2dpState));
BT_APPEND_NAMED_VALUE(props, "State", a2dpState);
BluetoothSignal signal(NS_LITERAL_STRING("AudioSink"),
remoteDeviceBdAddress, props);
@ -296,8 +295,7 @@ A2dpAudioStateCallback(btav_audio_state_t aState,
}
InfallibleTArray<BluetoothNamedValue> props;
props.AppendElement(
BluetoothNamedValue(NS_LITERAL_STRING("State"), a2dpState));
BT_APPEND_NAMED_VALUE(props, "State", a2dpState);
BluetoothSignal signal(NS_LITERAL_STRING("AudioSink"),
remoteDeviceBdAddress, props);

View File

@ -1265,39 +1265,17 @@ BluetoothOppManager::FileTransferComplete()
return;
}
nsString type, name;
BluetoothValue v;
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-transfer-complete");
InfallibleTArray<BluetoothNamedValue> parameters;
type.AssignLiteral("bluetooth-opp-transfer-complete");
name.AssignLiteral("address");
v = mDeviceAddress;
parameters.AppendElement(BluetoothNamedValue(name, v));
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);
name.AssignLiteral("success");
v = mSuccessFlag;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("received");
v = mIsServer;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("fileName");
v = mFileName;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("fileLength");
v = mSentFileLength;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("contentType");
v = mContentType;
parameters.AppendElement(BluetoothNamedValue(name, v));
if (!BroadcastSystemMessage(type, parameters)) {
BT_WARNING("Failed to broadcast [bluetooth-opp-transfer-complete]");
return;
}
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
mSendTransferCompleteFlag = true;
}
@ -1305,35 +1283,16 @@ BluetoothOppManager::FileTransferComplete()
void
BluetoothOppManager::StartFileTransfer()
{
nsString type, name;
BluetoothValue v;
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-transfer-start");
InfallibleTArray<BluetoothNamedValue> parameters;
type.AssignLiteral("bluetooth-opp-transfer-start");
name.AssignLiteral("address");
v = mDeviceAddress;
parameters.AppendElement(BluetoothNamedValue(name, v));
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);
name.AssignLiteral("received");
v = mIsServer;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("fileName");
v = mFileName;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("fileLength");
v = mFileLength;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("contentType");
v = mContentType;
parameters.AppendElement(BluetoothNamedValue(name, v));
if (!BroadcastSystemMessage(type, parameters)) {
BT_WARNING("Failed to broadcast [bluetooth-opp-transfer-start]");
return;
}
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
mSendTransferCompleteFlag = false;
}
@ -1341,61 +1300,29 @@ BluetoothOppManager::StartFileTransfer()
void
BluetoothOppManager::UpdateProgress()
{
nsString type, name;
BluetoothValue v;
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-update-progress");
InfallibleTArray<BluetoothNamedValue> parameters;
type.AssignLiteral("bluetooth-opp-update-progress");
name.AssignLiteral("address");
v = mDeviceAddress;
parameters.AppendElement(BluetoothNamedValue(name, v));
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);
name.AssignLiteral("received");
v = mIsServer;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("processedLength");
v = mSentFileLength;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("fileLength");
v = mFileLength;
parameters.AppendElement(BluetoothNamedValue(name, v));
if (!BroadcastSystemMessage(type, parameters)) {
BT_WARNING("Failed to broadcast [bluetooth-opp-update-progress]");
return;
}
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}
void
BluetoothOppManager::ReceivingFileConfirmation()
{
nsString type, name;
BluetoothValue v;
NS_NAMED_LITERAL_STRING(type, "bluetooth-opp-receiving-file-confirmation");
InfallibleTArray<BluetoothNamedValue> parameters;
type.AssignLiteral("bluetooth-opp-receiving-file-confirmation");
name.AssignLiteral("address");
v = mDeviceAddress;
parameters.AppendElement(BluetoothNamedValue(name, v));
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);
name.AssignLiteral("fileName");
v = mFileName;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("fileLength");
v = mFileLength;
parameters.AppendElement(BluetoothNamedValue(name, v));
name.AssignLiteral("contentType");
v = mContentType;
parameters.AppendElement(BluetoothNamedValue(name, v));
if (!BroadcastSystemMessage(type, parameters)) {
BT_WARNING("Failed to send [bluetooth-opp-receiving-file-confirmation]");
return;
}
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}
void

View File

@ -176,10 +176,8 @@ DispatchStatusChangedEvent(const nsAString& aType,
MOZ_ASSERT(NS_IsMainThread());
InfallibleTArray<BluetoothNamedValue> data;
data.AppendElement(
BluetoothNamedValue(NS_LITERAL_STRING("address"), nsString(aAddress)));
data.AppendElement(
BluetoothNamedValue(NS_LITERAL_STRING("status"), aStatus));
BT_APPEND_NAMED_VALUE(data, "address", nsString(aAddress));
BT_APPEND_NAMED_VALUE(data, "status", aStatus);
BluetoothSignal signal(nsString(aType), NS_LITERAL_STRING(KEY_ADAPTER), data);

View File

@ -811,18 +811,12 @@ BluetoothHfpManager::NotifyConnectionStateChanged(const nsAString& aType)
void
BluetoothHfpManager::NotifyDialer(const nsAString& aCommand)
{
BluetoothValue v;
NS_NAMED_LITERAL_STRING(type, "bluetooth-dialer-command");
InfallibleTArray<BluetoothNamedValue> parameters;
NS_NAMED_LITERAL_STRING(type, "bluetooth-dialer-command");
NS_NAMED_LITERAL_STRING(name, "command");
BT_APPEND_NAMED_VALUE(parameters, "command", nsString(aCommand));
v = nsString(aCommand);
parameters.AppendElement(BluetoothNamedValue(name, v));
if (!BroadcastSystemMessage(type, parameters)) {
BT_WARNING("Failed to broadcast system message to dialer");
}
BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters);
}
void