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

Unified Diff: device/bluetooth/device.cc

Issue 2649473002: bluetooth: Add control for reading/writing of descriptor values to internals page. (Closed)
Patch Set: Merge upstream Created 3 years, 11 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 | « device/bluetooth/device.h ('k') | device/bluetooth/public/interfaces/device.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/device.cc
diff --git a/device/bluetooth/device.cc b/device/bluetooth/device.cc
index 873d277849efa3b4b2f2b46db4e9506960b89479..acba3d246cbdc4c8dea3b201fe274d4fd3a720cd 100644
--- a/device/bluetooth/device.cc
+++ b/device/bluetooth/device.cc
@@ -213,12 +213,90 @@ void Device::GetDescriptors(const std::string& service_id,
descriptor_info->id = descriptor->GetIdentifier();
descriptor_info->uuid = descriptor->GetUUID();
+ descriptor_info->last_known_value = descriptor->GetValue();
+
descriptors.push_back(std::move(descriptor_info));
}
callback.Run(std::move(descriptors));
}
+void Device::ReadValueForDescriptor(
+ const std::string& service_id,
+ const std::string& characteristic_id,
+ const std::string& descriptor_id,
+ const ReadValueForDescriptorCallback& callback) {
+ device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
+ DCHECK(device);
+
+ device::BluetoothRemoteGattService* service =
+ device->GetGattService(service_id);
+ if (!service) {
+ callback.Run(mojom::GattResult::SERVICE_NOT_FOUND,
+ base::nullopt /* value */);
+ return;
+ }
+
+ device::BluetoothRemoteGattCharacteristic* characteristic =
+ service->GetCharacteristic(characteristic_id);
+ if (!characteristic) {
+ callback.Run(mojom::GattResult::CHARACTERISTIC_NOT_FOUND,
+ base::nullopt /* value */);
+ return;
+ }
+
+ device::BluetoothRemoteGattDescriptor* descriptor =
+ characteristic->GetDescriptor(descriptor_id);
+ if (!descriptor) {
+ callback.Run(mojom::GattResult::DESCRIPTOR_NOT_FOUND,
+ base::nullopt /* value */);
+ return;
+ }
+
+ descriptor->ReadRemoteDescriptor(
+ base::Bind(&Device::OnReadRemoteDescriptor,
+ weak_ptr_factory_.GetWeakPtr(), callback),
+ base::Bind(&Device::OnReadRemoteDescriptorError,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+}
+
+void Device::WriteValueForDescriptor(
+ const std::string& service_id,
+ const std::string& characteristic_id,
+ const std::string& descriptor_id,
+ const std::vector<uint8_t>& value,
+ const WriteValueForDescriptorCallback& callback) {
+ device::BluetoothDevice* device = adapter_->GetDevice(GetAddress());
+ DCHECK(device);
+
+ device::BluetoothRemoteGattService* service =
+ device->GetGattService(service_id);
+ if (!service) {
+ callback.Run(mojom::GattResult::SERVICE_NOT_FOUND);
+ return;
+ }
+
+ device::BluetoothRemoteGattCharacteristic* characteristic =
+ service->GetCharacteristic(characteristic_id);
+ if (!characteristic) {
+ callback.Run(mojom::GattResult::CHARACTERISTIC_NOT_FOUND);
+ return;
+ }
+
+ device::BluetoothRemoteGattDescriptor* descriptor =
+ characteristic->GetDescriptor(descriptor_id);
+ if (!descriptor) {
+ callback.Run(mojom::GattResult::DESCRIPTOR_NOT_FOUND);
+ return;
+ }
+
+ descriptor->WriteRemoteDescriptor(
+ value, base::Bind(&Device::OnWriteRemoteDescriptor,
+ weak_ptr_factory_.GetWeakPtr(), callback),
+ base::Bind(&Device::OnWriteRemoteDescriptorError,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+}
+
Device::Device(scoped_refptr<device::BluetoothAdapter> adapter,
std::unique_ptr<device::BluetoothGattConnection> connection)
: adapter_(std::move(adapter)),
@@ -276,6 +354,30 @@ void Device::OnWriteRemoteCharacteristicError(
callback.Run(mojo::ConvertTo<mojom::GattResult>(error_code));
}
+void Device::OnReadRemoteDescriptor(
+ const ReadValueForDescriptorCallback& callback,
+ const std::vector<uint8_t>& value) {
+ callback.Run(mojom::GattResult::SUCCESS, std::move(value));
+}
+
+void Device::OnReadRemoteDescriptorError(
+ const ReadValueForDescriptorCallback& callback,
+ device::BluetoothGattService::GattErrorCode error_code) {
+ callback.Run(mojo::ConvertTo<mojom::GattResult>(error_code),
+ base::nullopt /* value */);
+}
+
+void Device::OnWriteRemoteDescriptor(
+ const WriteValueForDescriptorCallback& callback) {
+ callback.Run(mojom::GattResult::SUCCESS);
+}
+
+void Device::OnWriteRemoteDescriptorError(
+ const WriteValueForDescriptorCallback& callback,
+ device::BluetoothGattService::GattErrorCode error_code) {
+ callback.Run(mojo::ConvertTo<mojom::GattResult>(error_code));
+}
+
const std::string& Device::GetAddress() {
return connection_->GetDeviceAddress();
}
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/public/interfaces/device.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698