Chromium Code Reviews| Index: components/arc/bluetooth/arc_bluetooth_bridge.cc |
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| index 17ddb50b4d881a08d5691f3bcc6f2cbdec0405be..7c9e7a8d7afccd0c6e645ea81e3bd5d3b3346bc1 100644 |
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| @@ -50,6 +50,7 @@ using device::BluetoothUUID; |
| namespace { |
| constexpr int32_t kMinBtleVersion = 1; |
| constexpr int32_t kMinBtleNotifyVersion = 2; |
| +constexpr int32_t kMinGattServerVersion = 3; |
| constexpr uint32_t kGattReadPermission = |
| BluetoothGattCharacteristic::Permission::PERMISSION_READ | |
| BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | |
| @@ -137,6 +138,29 @@ void OnGattReadError(const GattReadCallback& callback, |
| callback.Run(std::move(gattValue)); |
| } |
| +// Callback function for mojom::BluetoothInstance::RequestGattRead |
| +void OnGattServerRead( |
| + const BluetoothLocalGattService::Delegate::ValueCallback& success_callback, |
| + const BluetoothLocalGattService::Delegate::ErrorCallback& error_callback, |
| + arc::mojom::BluetoothGattStatus status, |
| + mojo::Array<uint8_t> value) { |
| + if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) |
| + success_callback.Run(value.To<std::vector<uint8_t>>()); |
| + else |
| + error_callback.Run(); |
| +} |
| + |
| +// Callback function for mojom::BluetoothInstance::RequestGattWrite |
| +void OnGattServerWrite( |
| + const base::Closure& success_callback, |
| + const BluetoothLocalGattService::Delegate::ErrorCallback& error_callback, |
| + arc::mojom::BluetoothGattStatus status) { |
| + if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) |
| + success_callback.Run(); |
| + else |
| + error_callback.Run(); |
| +} |
| + |
| } // namespace |
| namespace arc { |
| @@ -374,12 +398,61 @@ void ArcBluetoothBridge::GattDescriptorValueChanged( |
| // Placeholder for GATT client functionality |
| } |
| +template <class LocalGattAttribute> |
| +void ArcBluetoothBridge::OnGattAttributeReadRequest( |
| + const BluetoothDevice* device, |
| + const LocalGattAttribute* gatt_obj, |
| + int offset, |
| + const ValueCallback& success_callback, |
| + const ErrorCallback& error_callback) { |
| + DCHECK(CalledOnValidThread()); |
| + if (!HasBluetoothInstance() || |
| + !CheckBluetoothInstanceVersion(kMinGattServerVersion) || offset < 0) { |
|
palmer
2016/07/22 01:46:10
Is there an upper bound for offset? Or, if sanity
puthik_chromium
2016/07/22 02:12:33
The upper bound is the size of the Gatt Attribute
palmer
2016/07/22 21:49:11
I'm not sure I'm looking at the right thing, but t
puthik_chromium
2016/07/22 22:41:05
Done. Found it in the spec.
|
| + error_callback.Run(); |
| + return; |
| + } |
| + |
| + DCHECK(gatt_handle_.find(gatt_obj->GetIdentifier()) != gatt_handle_.end()); |
|
palmer
2016/07/22 01:46:10
This could only happen by programmer error? I ask
puthik_chromium
2016/07/22 02:12:33
The caller of these function is On{Characteristic,
palmer
2016/07/22 21:49:11
Great, thanks.
|
| + |
| + arc_bridge_service()->bluetooth()->instance()->RequestGattRead( |
| + mojom::BluetoothAddress::From(device->GetAddress()), |
| + gatt_handle_[gatt_obj->GetIdentifier()], offset, false /* is_long */, |
| + base::Bind(&OnGattServerRead, success_callback, error_callback)); |
| +} |
| + |
| +template <class LocalGattAttribute> |
| +void ArcBluetoothBridge::OnGattAttributeWriteRequest( |
|
palmer
2016/07/22 01:46:10
Same questions as above for this function.
puthik_chromium
2016/07/22 02:12:33
Same answer as above
|
| + const BluetoothDevice* device, |
| + const LocalGattAttribute* gatt_obj, |
| + const std::vector<uint8_t>& value, |
| + int offset, |
| + const base::Closure& success_callback, |
| + const ErrorCallback& error_callback) { |
| + DCHECK(CalledOnValidThread()); |
| + if (!HasBluetoothInstance() || |
| + !CheckBluetoothInstanceVersion(kMinGattServerVersion) || offset < 0) { |
| + error_callback.Run(); |
| + return; |
| + } |
| + |
| + DCHECK(gatt_handle_.find(gatt_obj->GetIdentifier()) != gatt_handle_.end()); |
| + |
| + arc_bridge_service()->bluetooth()->instance()->RequestGattWrite( |
| + mojom::BluetoothAddress::From(device->GetAddress()), |
| + gatt_handle_[gatt_obj->GetIdentifier()], offset, |
| + mojo::Array<uint8_t>::From(value), |
| + base::Bind(&OnGattServerWrite, success_callback, error_callback)); |
| +} |
| + |
| void ArcBluetoothBridge::OnCharacteristicReadRequest( |
| const BluetoothDevice* device, |
| const BluetoothLocalGattCharacteristic* characteristic, |
| int offset, |
| const ValueCallback& callback, |
| - const ErrorCallback& error_callback) {} |
| + const ErrorCallback& error_callback) { |
| + OnGattAttributeReadRequest(device, characteristic, offset, callback, |
| + error_callback); |
| +} |
| void ArcBluetoothBridge::OnCharacteristicWriteRequest( |
| const BluetoothDevice* device, |
| @@ -387,14 +460,20 @@ void ArcBluetoothBridge::OnCharacteristicWriteRequest( |
| const std::vector<uint8_t>& value, |
| int offset, |
| const base::Closure& callback, |
| - const ErrorCallback& error_callback) {} |
| + const ErrorCallback& error_callback) { |
| + OnGattAttributeWriteRequest(device, characteristic, value, offset, callback, |
| + error_callback); |
| +} |
| void ArcBluetoothBridge::OnDescriptorReadRequest( |
| const BluetoothDevice* device, |
| const BluetoothLocalGattDescriptor* descriptor, |
| int offset, |
| const ValueCallback& callback, |
| - const ErrorCallback& error_callback) {} |
| + const ErrorCallback& error_callback) { |
| + OnGattAttributeReadRequest(device, descriptor, offset, callback, |
| + error_callback); |
| +} |
| void ArcBluetoothBridge::OnDescriptorWriteRequest( |
| const BluetoothDevice* device, |
| @@ -402,7 +481,10 @@ void ArcBluetoothBridge::OnDescriptorWriteRequest( |
| const std::vector<uint8_t>& value, |
| int offset, |
| const base::Closure& callback, |
| - const ErrorCallback& error_callback) {} |
| + const ErrorCallback& error_callback) { |
| + OnGattAttributeWriteRequest(device, descriptor, value, offset, callback, |
| + error_callback); |
| +} |
| void ArcBluetoothBridge::OnNotificationsStart( |
| const BluetoothDevice* device, |
| @@ -1071,6 +1153,7 @@ int32_t ArcBluetoothBridge::CreateGattAttributeHandle( |
| int32_t handle = next_gatt_server_attribute_handle(); |
| const std::string& identifier = gatt_attr->GetIdentifier(); |
| gatt_identifier_[handle] = identifier; |
| + gatt_handle_[identifier] = handle; |
| return handle; |
| } |
| @@ -1171,9 +1254,9 @@ void ArcBluetoothBridge::DeleteService(int32_t service_handle, |
| BluetoothLocalGattService* service = |
| bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]); |
| DCHECK(service); |
| - |
| - service->Delete(); |
| gatt_identifier_.erase(service_handle); |
| + gatt_handle_.erase(service->GetIdentifier()); |
| + service->Delete(); |
| OnGattOperationDone(callback); |
| } |