Index: device/bluetooth/device.cc |
diff --git a/device/bluetooth/device.cc b/device/bluetooth/device.cc |
index ca1e6149dbf2370efbbb3caea1dd7d202d18fb56..cb261980c151856dde070b902490ef88bd4155e9 100644 |
--- a/device/bluetooth/device.cc |
+++ b/device/bluetooth/device.cc |
@@ -112,6 +112,42 @@ void Device::GetCharacteristics(const std::string& service_id, |
service_id, callback)); |
} |
+void Device::GetDescriptors(const std::string& service_id, |
+ const std::string& characteristic_id, |
+ const GetDescriptorsCallback& callback) { |
+ device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); |
+ if (device == nullptr) { |
Dan Beam
2017/01/24 06:07:29
is this preferable to just if (!device) { ?
mbrunson
2017/01/24 21:29:46
I've seen it both ways, but the other files here u
|
+ callback.Run(base::nullopt); |
+ return; |
+ } |
+ |
+ device::BluetoothRemoteGattService* service = |
+ device->GetGattService(service_id); |
+ if (service == nullptr) { |
+ callback.Run(base::nullopt); |
+ return; |
+ } |
+ |
+ device::BluetoothRemoteGattCharacteristic* characteristic = |
+ service->GetCharacteristic(characteristic_id); |
+ if (characteristic == nullptr) { |
+ callback.Run(base::nullopt); |
+ return; |
+ } |
+ |
+ std::vector<mojom::DescriptorInfoPtr> descriptors; |
+ |
+ for (const auto* descriptor : characteristic->GetDescriptors()) { |
+ mojom::DescriptorInfoPtr descriptor_info = mojom::DescriptorInfo::New(); |
+ |
+ descriptor_info->id = descriptor->GetIdentifier(); |
+ descriptor_info->uuid = descriptor->GetUUID(); |
+ descriptors.push_back(std::move(descriptor_info)); |
+ } |
+ |
+ callback.Run(std::move(descriptors)); |
+} |
+ |
Device::Device(scoped_refptr<device::BluetoothAdapter> adapter, |
std::unique_ptr<device::BluetoothGattConnection> connection) |
: adapter_(std::move(adapter)), connection_(std::move(connection)) { |