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

Unified Diff: device/bluetooth/device.cc

Issue 2622393002: bluetooth: Add characteristic list to DeviceDetailsPage in internals page. (Closed)
Patch Set: Simplifications 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/device_unittest.cc » ('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 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();
}
« no previous file with comments | « device/bluetooth/device.h ('k') | device/bluetooth/device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698