Commit 547833ae authored by Qiyu Hu's avatar Qiyu Hu Committed by Commit Bot

arc: bluetooth: Add a type to specify read/write request to characteristic or descriptor

This is necessary as request_read/write_cb in android have become
request_read/write_characteristic/descriptor_cb

BUG: b:73743210
TEST: ./out/Default/unit_tests --gtest_filter="ArcBluetoothBridgeTest.*"
      Also push this to my device, working fine

Change-Id: Ib850fceae979c29746affd5591cbac7264de77d2
Reviewed-on: https://chromium-review.googlesource.com/998797Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarGreg Kerr <kerrnel@chromium.org>
Commit-Queue: Qiyu Hu <qiyuh@google.com>
Cr-Commit-Position: refs/heads/master@{#548801}
parent 05f707ae
......@@ -692,6 +692,7 @@ void ArcBluetoothBridge::OnGattAttributeReadRequest(
const BluetoothDevice* device,
const LocalGattAttribute* attribute,
int offset,
mojom::BluetoothGattDBAttributeType attribute_type,
const ValueCallback& success_callback,
const ErrorCallback& error_callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
......@@ -707,6 +708,7 @@ void ArcBluetoothBridge::OnGattAttributeReadRequest(
bluetooth_instance->RequestGattRead(
mojom::BluetoothAddress::From(device->GetAddress()),
gatt_handle_[attribute->GetIdentifier()], offset, false /* is_long */,
attribute_type,
base::BindOnce(&OnGattServerRead, success_callback, error_callback));
}
......@@ -716,6 +718,7 @@ void ArcBluetoothBridge::OnGattAttributeWriteRequest(
const LocalGattAttribute* attribute,
const std::vector<uint8_t>& value,
int offset,
mojom::BluetoothGattDBAttributeType attribute_type,
const base::Closure& success_callback,
const ErrorCallback& error_callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
......@@ -730,7 +733,7 @@ void ArcBluetoothBridge::OnGattAttributeWriteRequest(
bluetooth_instance->RequestGattWrite(
mojom::BluetoothAddress::From(device->GetAddress()),
gatt_handle_[attribute->GetIdentifier()], offset, value,
gatt_handle_[attribute->GetIdentifier()], offset, value, attribute_type,
base::BindOnce(&OnGattServerWrite, success_callback, error_callback));
}
......@@ -740,8 +743,10 @@ void ArcBluetoothBridge::OnCharacteristicReadRequest(
int offset,
const ValueCallback& callback,
const ErrorCallback& error_callback) {
OnGattAttributeReadRequest(device, characteristic, offset, callback,
error_callback);
OnGattAttributeReadRequest(
device, characteristic, offset,
mojom::BluetoothGattDBAttributeType::BTGATT_DB_CHARACTERISTIC, callback,
error_callback);
}
void ArcBluetoothBridge::OnCharacteristicWriteRequest(
......@@ -751,8 +756,10 @@ void ArcBluetoothBridge::OnCharacteristicWriteRequest(
int offset,
const base::Closure& callback,
const ErrorCallback& error_callback) {
OnGattAttributeWriteRequest(device, characteristic, value, offset, callback,
error_callback);
OnGattAttributeWriteRequest(
device, characteristic, value, offset,
mojom::BluetoothGattDBAttributeType::BTGATT_DB_CHARACTERISTIC, callback,
error_callback);
}
void ArcBluetoothBridge::OnDescriptorReadRequest(
......@@ -761,8 +768,10 @@ void ArcBluetoothBridge::OnDescriptorReadRequest(
int offset,
const ValueCallback& callback,
const ErrorCallback& error_callback) {
OnGattAttributeReadRequest(device, descriptor, offset, callback,
error_callback);
OnGattAttributeReadRequest(
device, descriptor, offset,
mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, callback,
error_callback);
}
void ArcBluetoothBridge::OnDescriptorWriteRequest(
......@@ -772,8 +781,10 @@ void ArcBluetoothBridge::OnDescriptorWriteRequest(
int offset,
const base::Closure& callback,
const ErrorCallback& error_callback) {
OnGattAttributeWriteRequest(device, descriptor, value, offset, callback,
error_callback);
OnGattAttributeWriteRequest(
device, descriptor, value, offset,
mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, callback,
error_callback);
}
void ArcBluetoothBridge::OnNotificationsStart(
......
......@@ -433,20 +433,24 @@ class ArcBluetoothBridge
// Common code for OnCharacteristicReadRequest and OnDescriptorReadRequest
template <class LocalGattAttribute>
void OnGattAttributeReadRequest(const device::BluetoothDevice* device,
const LocalGattAttribute* attribute,
int offset,
const ValueCallback& success_callback,
const ErrorCallback& error_callback);
void OnGattAttributeReadRequest(
const device::BluetoothDevice* device,
const LocalGattAttribute* attribute,
int offset,
mojom::BluetoothGattDBAttributeType attribute_type,
const ValueCallback& success_callback,
const ErrorCallback& error_callback);
// Common code for OnCharacteristicWriteRequest and OnDescriptorWriteRequest
template <class LocalGattAttribute>
void OnGattAttributeWriteRequest(const device::BluetoothDevice* device,
const LocalGattAttribute* attribute,
const std::vector<uint8_t>& value,
int offset,
const base::Closure& success_callback,
const ErrorCallback& error_callback);
void OnGattAttributeWriteRequest(
const device::BluetoothDevice* device,
const LocalGattAttribute* attribute,
const std::vector<uint8_t>& value,
int offset,
mojom::BluetoothGattDBAttributeType attribute_type,
const base::Closure& success_callback,
const ErrorCallback& error_callback);
void OnSetDiscoverable(bool discoverable, bool success, uint32_t timeout);
void SetDiscoverable(bool discoverable, uint32_t timeout);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Next MinVersion: 9
// Next MinVersion: 10
module arc.mojom;
......@@ -451,15 +451,19 @@ interface BluetoothInstance {
array<uint8> value);
// Bluetooth Gatt Server functions
[MinVersion=3] RequestGattRead@14(BluetoothAddress address,
int32 attribute_handle,
int32 offset,
bool is_long)
[MinVersion=3] RequestGattRead@14(
BluetoothAddress address,
int32 attribute_handle,
int32 offset,
bool is_long,
[MinVersion=9] BluetoothGattDBAttributeType attribute_type)
=> (BluetoothGattStatus status, array<uint8> value);
[MinVersion=3] RequestGattWrite@15(BluetoothAddress address,
int32 attribute_handle,
int32 offset,
array<uint8> value)
[MinVersion=3] RequestGattWrite@15(
BluetoothAddress address,
int32 attribute_handle,
int32 offset,
array<uint8> value,
[MinVersion=9] BluetoothGattDBAttributeType attribute_type)
=> (BluetoothGattStatus status);
// Bluetooth SDP function
......
......@@ -108,17 +108,20 @@ void FakeBluetoothInstance::OnGattNotify(
bool is_notify,
const std::vector<uint8_t>& value) {}
void FakeBluetoothInstance::RequestGattRead(mojom::BluetoothAddressPtr address,
int32_t attribute_handle,
int32_t offset,
bool is_long,
RequestGattReadCallback callback) {}
void FakeBluetoothInstance::RequestGattRead(
mojom::BluetoothAddressPtr address,
int32_t attribute_handle,
int32_t offset,
bool is_long,
mojom::BluetoothGattDBAttributeType attribute_type,
RequestGattReadCallback callback) {}
void FakeBluetoothInstance::RequestGattWrite(
mojom::BluetoothAddressPtr address,
int32_t attribute_handle,
int32_t offset,
const std::vector<uint8_t>& value,
mojom::BluetoothGattDBAttributeType attribute_type,
RequestGattWriteCallback callback) {}
void FakeBluetoothInstance::OnGetSdpRecords(
......
......@@ -116,12 +116,14 @@ class FakeBluetoothInstance : public mojom::BluetoothInstance {
int32_t attribute_handle,
int32_t offset,
bool is_long,
mojom::BluetoothGattDBAttributeType attribute_type,
RequestGattReadCallback callback) override;
void RequestGattWrite(mojom::BluetoothAddressPtr address,
int32_t attribute_handle,
int32_t offset,
const std::vector<uint8_t>& value,
mojom::BluetoothGattDBAttributeType attribute_type,
RequestGattWriteCallback callback) override;
void OnGetSdpRecords(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment