Bug 1126720: Handle all used type in PDU explicitly (under bluetooth2/), r=btian

This patch is based on bug 1129846.
This commit is contained in:
Thomas Zimmermann 2015-02-05 15:35:57 +08:00
Родитель 97d6c157e9
Коммит db3ff31476
2 изменённых файлов: 81 добавлений и 0 удалений

Просмотреть файл

@ -659,6 +659,22 @@ Convert(BluetoothAvrcpNotification aIn, uint8_t& aOut)
return NS_OK;
}
nsresult
Convert(BluetoothAvrcpPlayerAttribute aIn, uint8_t& aOut)
{
static const uint8_t sValue[] = {
CONVERT(AVRCP_PLAYER_ATTRIBUTE_EQUALIZER, 0x01),
CONVERT(AVRCP_PLAYER_ATTRIBUTE_REPEAT, 0x02),
CONVERT(AVRCP_PLAYER_ATTRIBUTE_SHUFFLE, 0x03),
CONVERT(AVRCP_PLAYER_ATTRIBUTE_SCAN, 0x04)
};
if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sValue))) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sValue[aIn];
return NS_OK;
}
nsresult
Convert(BluetoothAvrcpRemoteFeature aIn, unsigned long& aOut)
{
@ -671,6 +687,23 @@ Convert(BluetoothAvrcpRemoteFeature aIn, unsigned long& aOut)
return NS_OK;
}
nsresult
Convert(BluetoothAvrcpStatus aIn, uint8_t& aOut)
{
static const uint8_t sValue[] = {
CONVERT(AVRCP_STATUS_BAD_COMMAND, 0x00),
CONVERT(AVRCP_STATUS_BAD_PARAMETER, 0x01),
CONVERT(AVRCP_STATUS_NOT_FOUND, 0x02),
CONVERT(AVRCP_STATUS_INTERNAL_ERROR, 0x03),
CONVERT(AVRCP_STATUS_SUCCESS, 0x04)
};
if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sValue))) {
return NS_ERROR_ILLEGAL_VALUE;
}
aOut = sValue[aIn];
return NS_OK;
}
nsresult
Convert(BluetoothHandsfreeAtResponse aIn, uint8_t& aOut)
{
@ -1092,6 +1125,19 @@ PackPDU(BluetoothAvrcpNotification aIn, BluetoothDaemonPDU& aPDU)
PackConversion<BluetoothAvrcpNotification, uint8_t>(aIn), aPDU);
}
nsresult
PackPDU(BluetoothAvrcpPlayerAttribute aIn, BluetoothDaemonPDU& aPDU)
{
return PackPDU(
PackConversion<BluetoothAvrcpPlayerAttribute, uint8_t>(aIn), aPDU);
}
nsresult
PackPDU(BluetoothAvrcpStatus aIn, BluetoothDaemonPDU& aPDU)
{
return PackPDU(PackConversion<BluetoothAvrcpStatus, uint8_t>(aIn), aPDU);
}
nsresult
PackPDU(const BluetoothConfigurationParameter& aIn, BluetoothDaemonPDU& aPDU)
{

Просмотреть файл

@ -233,9 +233,15 @@ Convert(BluetoothAvrcpEvent aIn, uint8_t& aOut);
nsresult
Convert(BluetoothAvrcpNotification aIn, uint8_t& aOut);
nsresult
Convert(BluetoothAvrcpPlayerAttribute aIn, uint8_t& aOut);
nsresult
Convert(BluetoothAvrcpRemoteFeature aIn, unsigned long& aOut);
nsresult
Convert(BluetoothAvrcpStatus aIn, uint8_t& aOut);
nsresult
Convert(BluetoothHandsfreeAtResponse aIn, uint8_t& aOut);
@ -285,6 +291,11 @@ Convert(ControlPlayStatus aIn, uint8_t& aOut);
// Packing
//
// introduce link errors on non-handled data types
template <typename T>
nsresult
PackPDU(T aIn, BluetoothDaemonPDU& aPDU);
nsresult
PackPDU(bool aIn, BluetoothDaemonPDU& aPDU);
@ -335,6 +346,12 @@ PackPDU(const BluetoothAvrcpEventParamPair& aIn, BluetoothDaemonPDU& aPDU);
nsresult
PackPDU(BluetoothAvrcpNotification aIn, BluetoothDaemonPDU& aPDU);
nsresult
PackPDU(BluetoothAvrcpPlayerAttribute aIn, BluetoothDaemonPDU& aPDU);
nsresult
PackPDU(BluetoothAvrcpStatus aIn, BluetoothDaemonPDU& aPDU);
nsresult
PackPDU(const BluetoothConfigurationParameter& aIn, BluetoothDaemonPDU& aPDU);
@ -593,6 +610,11 @@ PackPDU(const T1& aIn1, const T2& aIn2, const T3& aIn3,
// Unpacking
//
// introduce link errors on non-handled data types
template <typename T>
nsresult
UnpackPDU(BluetoothDaemonPDU& aPDU, T& aOut);
inline nsresult
UnpackPDU(BluetoothDaemonPDU& aPDU, int8_t& aOut)
{
@ -804,6 +826,19 @@ UnpackPDU(BluetoothDaemonPDU& aPDU, const UnpackArray<T>& aOut)
return NS_OK;
}
template<typename T>
inline nsresult
UnpackPDU(BluetoothDaemonPDU& aPDU, UnpackArray<T>& aOut)
{
for (size_t i = 0; i < aOut.mLength; ++i) {
nsresult rv = UnpackPDU(aPDU, aOut.mData[i]);
if (NS_FAILED(rv)) {
return rv;
}
}
return NS_OK;
}
template<>
inline nsresult
UnpackPDU<uint8_t>(BluetoothDaemonPDU& aPDU, const UnpackArray<uint8_t>& aOut)