mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1209469: Replace |BluetoothNamedValue| with |BluetoothProperty| in Bluetooth backend, r=brsun
This commit is contained in:
parent
ecb15936dd
commit
dafc28435a
@ -128,7 +128,7 @@ BluetoothDaemonCoreModule::GetAdapterPropertyCmd(BluetoothPropertyType aType,
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonCoreModule::SetAdapterPropertyCmd(
|
||||
const BluetoothNamedValue& aProperty, BluetoothResultHandler* aRes)
|
||||
const BluetoothProperty& aProperty, BluetoothResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -197,7 +197,7 @@ BluetoothDaemonCoreModule::GetRemoteDevicePropertyCmd(
|
||||
nsresult
|
||||
BluetoothDaemonCoreModule::SetRemoteDevicePropertyCmd(
|
||||
const BluetoothAddress& aRemoteAddr,
|
||||
const BluetoothNamedValue& aProperty,
|
||||
const BluetoothProperty& aProperty,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
nsresult GetAdapterPropertyCmd(BluetoothPropertyType aType,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
nsresult SetAdapterPropertyCmd(const BluetoothNamedValue& aProperty,
|
||||
nsresult SetAdapterPropertyCmd(const BluetoothProperty& aProperty,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
nsresult GetRemoteDevicePropertiesCmd(const BluetoothAddress& aRemoteAddr,
|
||||
@ -93,7 +93,7 @@ public:
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
nsresult SetRemoteDevicePropertyCmd(const BluetoothAddress& aRemoteAddr,
|
||||
const BluetoothNamedValue& aProperty,
|
||||
const BluetoothProperty& aProperty,
|
||||
BluetoothResultHandler* aRes);
|
||||
|
||||
nsresult GetRemoteServiceRecordCmd(const BluetoothAddress& aRemoteAddr,
|
||||
|
@ -513,24 +513,6 @@ Convert(int32_t aIn, BluetoothGattStatus& aOut)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(const nsAString& aIn, BluetoothPropertyType& aOut)
|
||||
{
|
||||
if (aIn.EqualsLiteral("Name")) {
|
||||
aOut = PROPERTY_BDNAME;
|
||||
} else if (aIn.EqualsLiteral("Discoverable")) {
|
||||
aOut = PROPERTY_ADAPTER_SCAN_MODE;
|
||||
} else if (aIn.EqualsLiteral("DiscoverableTimeout")) {
|
||||
aOut = PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
|
||||
} else if (MOZ_HAL_IPC_CONVERT_WARN_IF(
|
||||
false, nsAString, BluetoothPropertyType)) {
|
||||
BT_LOGR("Invalid property name: %s", NS_ConvertUTF16toUTF8(aIn).get());
|
||||
aOut = static_cast<BluetoothPropertyType>(0); // silences compiler warning
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Convert(nsresult aIn, BluetoothStatus& aOut)
|
||||
{
|
||||
@ -1219,37 +1201,42 @@ PackPDU(const BluetoothHandsfreeWbsConfig& aIn, DaemonSocketPDU& aPDU)
|
||||
}
|
||||
|
||||
nsresult
|
||||
PackPDU(const BluetoothNamedValue& aIn, DaemonSocketPDU& aPDU)
|
||||
PackPDU(const BluetoothProperty& aIn, DaemonSocketPDU& aPDU)
|
||||
{
|
||||
nsresult rv = PackPDU(
|
||||
PackConversion<nsString, BluetoothPropertyType>(aIn.name()), aPDU);
|
||||
nsresult rv = PackPDU(aIn.mType, aPDU);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (aIn.value().type() == BluetoothValue::Tuint32_t) {
|
||||
// Set discoverable timeout
|
||||
rv = PackPDU(static_cast<uint16_t>(sizeof(uint32_t)),
|
||||
aIn.value().get_uint32_t(), aPDU);
|
||||
} else if (aIn.value().type() == BluetoothValue::TnsString) {
|
||||
// Set name
|
||||
const nsCString value =
|
||||
NS_ConvertUTF16toUTF8(aIn.value().get_nsString());
|
||||
switch (aIn.mType) {
|
||||
case PROPERTY_BDNAME:
|
||||
/* fall through */
|
||||
case PROPERTY_REMOTE_FRIENDLY_NAME: {
|
||||
NS_ConvertUTF16toUTF8 stringUTF8(aIn.mString);
|
||||
|
||||
rv = PackPDU(PackConversion<size_t, uint16_t>(value.Length()),
|
||||
PackArray<uint8_t>(
|
||||
reinterpret_cast<const uint8_t*>(value.get()),
|
||||
value.Length()),
|
||||
aPDU);
|
||||
} else if (aIn.value().type() == BluetoothValue::Tbool) {
|
||||
// Set scan mode
|
||||
bool value = aIn.value().get_bool();
|
||||
|
||||
rv = PackPDU(static_cast<uint16_t>(sizeof(int32_t)),
|
||||
PackConversion<bool, BluetoothScanMode>(value), aPDU);
|
||||
} else if (MOZ_HAL_IPC_PACK_WARN_IF(true, BluetoothNamedValue)) {
|
||||
BT_LOGR("Invalid property value type");
|
||||
rv = NS_ERROR_ILLEGAL_VALUE;
|
||||
rv = PackPDU(PackConversion<size_t, uint16_t>(stringUTF8.Length()),
|
||||
PackArray<uint8_t>(
|
||||
reinterpret_cast<const uint8_t*>(stringUTF8.get()),
|
||||
stringUTF8.Length()),
|
||||
aPDU);
|
||||
}
|
||||
break;
|
||||
case PROPERTY_CLASS_OF_DEVICE:
|
||||
/* fall through */
|
||||
case PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
|
||||
rv = PackPDU(PackConversion<size_t, uint16_t>(sizeof(aIn.mUint32)),
|
||||
aIn.mUint32,
|
||||
aPDU);
|
||||
break;
|
||||
case PROPERTY_ADAPTER_SCAN_MODE:
|
||||
/* |mScanMode| is sent as signed int of 4 bytes */
|
||||
rv = PackPDU(PackConversion<size_t, uint16_t>(sizeof(int32_t)),
|
||||
aIn.mScanMode,
|
||||
aPDU);
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("Invalid property for packing");
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -182,9 +182,6 @@ Convert(int32_t aIn, BluetoothAttributeHandle& aOut);
|
||||
nsresult
|
||||
Convert(int32_t aIn, BluetoothGattStatus& aOut);
|
||||
|
||||
nsresult
|
||||
Convert(const nsAString& aIn, BluetoothPropertyType& aOut);
|
||||
|
||||
nsresult
|
||||
Convert(const BluetoothAttributeHandle& aIn, int32_t& aOut);
|
||||
|
||||
@ -327,7 +324,7 @@ nsresult
|
||||
PackPDU(const BluetoothHandsfreeWbsConfig& aIn, DaemonSocketPDU& aPDU);
|
||||
|
||||
nsresult
|
||||
PackPDU(const BluetoothNamedValue& aIn, DaemonSocketPDU& aPDU);
|
||||
PackPDU(const BluetoothProperty& aIn, DaemonSocketPDU& aPDU);
|
||||
|
||||
nsresult
|
||||
PackPDU(const BluetoothPinCode& aIn, DaemonSocketPDU& aPDU);
|
||||
|
@ -654,7 +654,7 @@ BluetoothDaemonInterface::GetAdapterProperty(BluetoothPropertyType aType,
|
||||
|
||||
void
|
||||
BluetoothDaemonInterface::SetAdapterProperty(
|
||||
const BluetoothNamedValue& aProperty, BluetoothResultHandler* aRes)
|
||||
const BluetoothProperty& aProperty, BluetoothResultHandler* aRes)
|
||||
{
|
||||
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
|
||||
(mProtocol)->SetAdapterPropertyCmd(aProperty, aRes);
|
||||
@ -690,7 +690,7 @@ BluetoothDaemonInterface::GetRemoteDeviceProperty(
|
||||
|
||||
void
|
||||
BluetoothDaemonInterface::SetRemoteDeviceProperty(
|
||||
const BluetoothAddress& aRemoteAddr, const BluetoothNamedValue& aProperty,
|
||||
const BluetoothAddress& aRemoteAddr, const BluetoothProperty& aProperty,
|
||||
BluetoothResultHandler* aRes)
|
||||
{
|
||||
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
void GetAdapterProperties(BluetoothResultHandler* aRes) override;
|
||||
void GetAdapterProperty(BluetoothPropertyType aType,
|
||||
BluetoothResultHandler* aRes) override;
|
||||
void SetAdapterProperty(const BluetoothNamedValue& aProperty,
|
||||
void SetAdapterProperty(const BluetoothProperty& aProperty,
|
||||
BluetoothResultHandler* aRes) override;
|
||||
|
||||
/* Remote Device Properties */
|
||||
@ -68,7 +68,7 @@ public:
|
||||
BluetoothPropertyType aType,
|
||||
BluetoothResultHandler* aRes) override;
|
||||
void SetRemoteDeviceProperty(const BluetoothAddress& aRemoteAddr,
|
||||
const BluetoothNamedValue& aProperty,
|
||||
const BluetoothProperty& aProperty,
|
||||
BluetoothResultHandler* aRes) override;
|
||||
|
||||
/* Remote Services */
|
||||
|
@ -1046,8 +1046,16 @@ BluetoothServiceBluedroid::SetProperty(BluetoothObjectType aType,
|
||||
|
||||
ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
|
||||
|
||||
BluetoothProperty property;
|
||||
nsresult rv = NamedValueToProperty(aValue, property);
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
|
||||
return rv;
|
||||
}
|
||||
|
||||
mSetAdapterPropertyRunnables.AppendElement(aRunnable);
|
||||
sBtInterface->SetAdapterProperty(aValue,
|
||||
sBtInterface->SetAdapterProperty(
|
||||
property,
|
||||
new DispatchReplyErrorResultHandler(mSetAdapterPropertyRunnables,
|
||||
aRunnable));
|
||||
|
||||
@ -1947,7 +1955,7 @@ BluetoothServiceBluedroid::AdapterStateChangedNotification(bool aState)
|
||||
// be connectable and non-discoverable.
|
||||
NS_ENSURE_TRUE_VOID(sBtInterface);
|
||||
sBtInterface->SetAdapterProperty(
|
||||
BluetoothNamedValue(NS_ConvertUTF8toUTF16("Discoverable"), false),
|
||||
BluetoothProperty(PROPERTY_ADAPTER_SCAN_MODE, SCAN_MODE_CONNECTABLE),
|
||||
new SetAdapterPropertyDiscoverableResultHandler());
|
||||
|
||||
// Trigger OPP & PBAP managers to listen
|
||||
|
@ -560,6 +560,68 @@ struct BluetoothProperty {
|
||||
|
||||
/* PROPERTY_REMOTE_VERSION_INFO */
|
||||
BluetoothRemoteInfo mRemoteInfo;
|
||||
|
||||
BluetoothProperty()
|
||||
: mType(PROPERTY_UNKNOWN)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType,
|
||||
const BluetoothAddress& aBdAddress)
|
||||
: mType(aType)
|
||||
, mBdAddress(aBdAddress)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType,
|
||||
const nsAString& aString)
|
||||
: mType(aType)
|
||||
, mString(aString)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType,
|
||||
const nsTArray<BluetoothUuid>& aUuidArray)
|
||||
: mType(aType)
|
||||
, mUuidArray(aUuidArray)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType,
|
||||
const nsTArray<BluetoothAddress>& aBdAddressArray)
|
||||
: mType(aType)
|
||||
, mBdAddressArray(aBdAddressArray)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType, uint32_t aUint32)
|
||||
: mType(aType)
|
||||
, mUint32(aUint32)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType, int32_t aInt32)
|
||||
: mType(aType)
|
||||
, mInt32(aInt32)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType,
|
||||
BluetoothTypeOfDevice aTypeOfDevice)
|
||||
: mType(aType)
|
||||
, mTypeOfDevice(aTypeOfDevice)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType,
|
||||
const BluetoothServiceRecord& aServiceRecord)
|
||||
: mType(aType)
|
||||
, mServiceRecord(aServiceRecord)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType,
|
||||
BluetoothScanMode aScanMode)
|
||||
: mType(aType)
|
||||
, mScanMode(aScanMode)
|
||||
{ }
|
||||
|
||||
explicit BluetoothProperty(BluetoothPropertyType aType,
|
||||
const BluetoothRemoteInfo& aRemoteInfo)
|
||||
: mType(aType)
|
||||
, mRemoteInfo(aRemoteInfo)
|
||||
{ }
|
||||
};
|
||||
|
||||
enum BluetoothSocketType {
|
||||
|
@ -1040,7 +1040,7 @@ public:
|
||||
virtual void GetAdapterProperties(BluetoothResultHandler* aRes) = 0;
|
||||
virtual void GetAdapterProperty(BluetoothPropertyType,
|
||||
BluetoothResultHandler* aRes) = 0;
|
||||
virtual void SetAdapterProperty(const BluetoothNamedValue& aProperty,
|
||||
virtual void SetAdapterProperty(const BluetoothProperty& aProperty,
|
||||
BluetoothResultHandler* aRes) = 0;
|
||||
|
||||
/* Remote Device Properties */
|
||||
@ -1051,7 +1051,7 @@ public:
|
||||
BluetoothPropertyType aType,
|
||||
BluetoothResultHandler* aRes) = 0;
|
||||
virtual void SetRemoteDeviceProperty(const BluetoothAddress& aRemoteAddr,
|
||||
const BluetoothNamedValue& aProperty,
|
||||
const BluetoothProperty& aProperty,
|
||||
BluetoothResultHandler* aRes) = 0;
|
||||
|
||||
/* Remote Services */
|
||||
|
@ -99,6 +99,55 @@ StringToPropertyType(const nsAString& aString, BluetoothPropertyType& aType)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NamedValueToProperty(const BluetoothNamedValue& aValue,
|
||||
BluetoothProperty& aProperty)
|
||||
{
|
||||
nsresult rv = StringToPropertyType(aValue.name(), aProperty.mType);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
switch (aProperty.mType) {
|
||||
case PROPERTY_BDNAME:
|
||||
if (aValue.value().type() != BluetoothValue::TnsString) {
|
||||
BT_LOGR("Bluetooth property value is not a string");
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
// Set name
|
||||
aProperty.mString = aValue.value().get_nsString();
|
||||
break;
|
||||
|
||||
case PROPERTY_ADAPTER_SCAN_MODE:
|
||||
if (aValue.value().type() != BluetoothValue::Tbool) {
|
||||
BT_LOGR("Bluetooth property value is not a boolean");
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
// Set scan mode
|
||||
if (aValue.value().get_bool()) {
|
||||
aProperty.mScanMode = SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
} else {
|
||||
aProperty.mScanMode = SCAN_MODE_CONNECTABLE;
|
||||
}
|
||||
break;
|
||||
|
||||
case PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
|
||||
if (aValue.value().type() != BluetoothValue::Tuint32_t) {
|
||||
BT_LOGR("Bluetooth property value is not an unsigned integer");
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
// Set discoverable timeout
|
||||
aProperty.mUint32 = aValue.value().get_uint32_t();
|
||||
break;
|
||||
|
||||
default:
|
||||
BT_LOGR("Invalid property value type");
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
RemoteNameToString(const BluetoothRemoteName& aRemoteName, nsAString& aString)
|
||||
{
|
||||
|
@ -47,6 +47,14 @@ StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode);
|
||||
nsresult
|
||||
StringToPropertyType(const nsAString& aString, BluetoothPropertyType& aType);
|
||||
|
||||
//
|
||||
// Property conversion
|
||||
//
|
||||
|
||||
nsresult
|
||||
NamedValueToProperty(const BluetoothNamedValue& aIn,
|
||||
BluetoothProperty& aProperty);
|
||||
|
||||
//
|
||||
// Remote name/string conversion
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user