Chromium Code Reviews| Index: device/bluetooth/device.cc |
| diff --git a/device/bluetooth/device.cc b/device/bluetooth/device.cc |
| index 1fce856606e50c1fd357443faa14a444266f3451..fdcdaa5a81e9125eb9ce27caf4c84dcf52c69c1f 100644 |
| --- a/device/bluetooth/device.cc |
| +++ b/device/bluetooth/device.cc |
| @@ -95,6 +95,23 @@ void Device::GetServices(const GetServicesCallback& callback) { |
| base::Bind(&Device::GetServicesImpl, base::Unretained(this), callback)); |
| } |
| +void Device::GetCharacteristics(const std::string& service_id, |
| + const GetCharacteristicsCallback& callback) { |
| + device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); |
| + DCHECK(device); |
| + |
| + if (device->IsGattServicesDiscoveryComplete()) { |
| + GetCharacteristicsImpl(service_id, callback); |
| + return; |
| + } |
| + |
| + // pending_services_requests_ is owned by Device, so base::Unretained is |
| + // safe. |
| + pending_services_requests_.push_back( |
| + base::Bind(&Device::GetCharacteristicsImpl, base::Unretained(this), |
| + service_id, callback)); |
| +} |
| + |
| Device::Device(scoped_refptr<device::BluetoothAdapter> adapter, |
| std::unique_ptr<device::BluetoothGattConnection> connection) |
| : adapter_(std::move(adapter)), connection_(std::move(connection)) { |
| @@ -126,6 +143,32 @@ mojom::ServiceInfoPtr Device::ConstructServiceInfoStruct( |
| return service_info; |
| } |
| +void Device::GetCharacteristicsImpl( |
| + const std::string& service_id, |
| + const GetCharacteristicsCallback& callback) { |
| + device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); |
| + DCHECK(device); |
| + device::BluetoothRemoteGattService* service = |
| + device->GetGattService(service_id); |
| + DCHECK(service); |
| + |
| + std::vector<mojom::CharacteristicInfoPtr> characteristics; |
| + |
| + for (const device::BluetoothRemoteGattCharacteristic* characteristic : |
| + service->GetCharacteristics()) { |
|
scheib
2017/01/13 05:24:40
for (const auto* characteristic : service->GetChar
mbrunson
2017/01/13 21:21:13
Done.
|
| + mojom::CharacteristicInfoPtr characteristic_info = |
| + mojom::CharacteristicInfo::New(); |
| + |
| + characteristic_info->id = characteristic->GetIdentifier(); |
| + characteristic_info->uuid = characteristic->GetUUID(); |
| + characteristic_info->properties = characteristic->GetProperties(); |
| + |
| + characteristics.push_back(std::move(characteristic_info)); |
| + } |
| + |
| + callback.Run(std::move(characteristics)); |
| +} |
| + |
| const std::string& Device::GetAddress() { |
| return connection_->GetDeviceAddress(); |
| } |