Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(865)

Unified Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2101283003: arc: bluetooth: Implement Gatt server request to read/write (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gs2
Patch Set: Remove unneeded Callback struct Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d9a373b1388e17da362347d78e7328d4325ab956..a8899dd6cef8ec0f9f9c873d637ed577e16a0bc1 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 |
@@ -94,7 +95,7 @@ arc::mojom::BluetoothGattDBElementPtr CreateGattDBElement(
template <class RemoteGattAttribute>
RemoteGattAttribute* FindGattAttributeFromUuid(
const std::vector<RemoteGattAttribute*> gatt_attrs,
- const device::BluetoothUUID uuid) {
+ const BluetoothUUID uuid) {
auto it = std::find_if(
gatt_attrs.begin(), gatt_attrs.end(),
[uuid](RemoteGattAttribute* attr) { return attr->GetUUID() == uuid; });
@@ -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,59 @@ 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) {
+ 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()->RequestGattRead(
+ mojom::BluetoothAddress::From(device->GetAddress()),
+ gatt_handle_[gatt_obj->GetIdentifier()], offset, false /*is_long */,
Luis Héctor Chávez 2016/07/20 23:09:31 nit: /* is_long */
puthik_chromium 2016/07/21 00:05:10 Done.
+ base::Bind(&OnGattServerRead, success_callback, error_callback));
+}
+
+template <class LocalGattAttribute>
+void ArcBluetoothBridge::OnGattAttributeWriteRequest(
+ const BluetoothDevice* device,
+ const LocalGattAttribute* gatt_obj,
+ const std::vector<uint8_t>& value,
+ int offset,
+ const base::Closure& success_callback,
+ const ErrorCallback& error_callback) {
+ 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<BluetoothLocalGattCharacteristic>(
+ device, characteristic, offset, callback, error_callback);
+}
void ArcBluetoothBridge::OnCharacteristicWriteRequest(
const BluetoothDevice* device,
@@ -387,14 +458,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<BluetoothLocalGattCharacteristic>(
+ 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<BluetoothLocalGattDescriptor>(
+ device, descriptor, offset, callback, error_callback);
+}
void ArcBluetoothBridge::OnDescriptorWriteRequest(
const BluetoothDevice* device,
@@ -402,7 +479,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<BluetoothLocalGattDescriptor>(
+ device, descriptor, value, offset, callback, error_callback);
+}
void ArcBluetoothBridge::OnNotificationsStart(
const BluetoothDevice* device,
@@ -1065,6 +1145,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;
}
@@ -1163,9 +1244,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);
}
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698