Index: device/bluetooth/device.cc |
diff --git a/device/bluetooth/device.cc b/device/bluetooth/device.cc |
index 1fce856606e50c1fd357443faa14a444266f3451..ca1e6149dbf2370efbbb3caea1dd7d202d18fb56 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,31 @@ 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 auto* characteristic : service->GetCharacteristics()) { |
+ 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(); |
} |