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

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2595373003: Bluetooth: mac: Working on macOS descriptor implementation. (Closed)
Patch Set: Fixes 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
Index: device/bluetooth/bluetooth_low_energy_device_mac.mm
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
index 00da119194d0554126386e33db737b400f0d4f04..6570a5068c972e52ddf4356fd533cb90f90f3fed 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -242,22 +242,7 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics(
GetBluetoothRemoteGattService(cb_service);
DCHECK(gatt_service);
gatt_service->DidDiscoverCharacteristics();
-
- // Notify when all services have been discovered.
- bool discovery_complete =
- std::find_if_not(
- gatt_services_.begin(), gatt_services_.end(),
- [](GattServiceMap::value_type& pair) {
- BluetoothRemoteGattService* gatt_service = pair.second.get();
- return static_cast<BluetoothRemoteGattServiceMac*>(gatt_service)
- ->IsDiscoveryComplete();
- }) == gatt_services_.end();
- if (discovery_complete) {
- device_uuids_.ReplaceServiceUUIDs(gatt_services_);
- SetGattServicesDiscoveryComplete(true);
- adapter_->NotifyGattServicesDiscovered(this);
- adapter_->NotifyDeviceChanged(this);
- }
+ SendNotificationIfDiscoveryComplete();
}
void BluetoothLowEnergyDeviceMac::DidModifyServices(
@@ -309,6 +294,29 @@ void BluetoothLowEnergyDeviceMac::DidUpdateNotificationState(
gatt_service->DidUpdateNotificationState(characteristic, error);
}
+void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors(
+ CBCharacteristic* cb_characteristic,
+ NSError* error) {
+ if (error) {
+ // TODO(http://crbug.com/609320): Need to pass the error.
+ // TODO(http://crbug.com/609844): Decide what to do if discover failed
+ VLOG(1) << "Can't discover descriptors: "
+ << error.localizedDescription.UTF8String << " (" << error.domain
+ << ": " << error.code << ")";
+ return;
+ }
+ VLOG(1) << "DidDiscoverDescriptors.";
+ if (!IsGattConnected()) {
+ // Don't discover descriptors if the device disconnected.
+ return;
+ }
+ BluetoothRemoteGattServiceMac* gatt_service =
+ GetBluetoothRemoteGattService(cb_characteristic.service);
+ DCHECK(gatt_service);
+ gatt_service->DidDiscoverDescriptors(cb_characteristic);
+ SendNotificationIfDiscoveryComplete();
+}
+
// static
std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(
CBPeripheral* peripheral) {
@@ -329,6 +337,24 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(
return BluetoothDevice::CanonicalizeAddress(hash);
}
+void BluetoothLowEnergyDeviceMac::SendNotificationIfDiscoveryComplete() {
+ // Notify when all services have been discovered.
+ bool discovery_complete =
+ std::find_if_not(
+ gatt_services_.begin(), gatt_services_.end(),
+ [](GattServiceMap::value_type& pair) {
+ BluetoothRemoteGattService* gatt_service = pair.second.get();
+ return static_cast<BluetoothRemoteGattServiceMac*>(gatt_service)
+ ->IsDiscoveryComplete();
+ }) == gatt_services_.end();
+ if (discovery_complete) {
+ device_uuids_.ReplaceServiceUUIDs(gatt_services_);
+ SetGattServicesDiscoveryComplete(true);
+ adapter_->NotifyGattServicesDiscovered(this);
+ adapter_->NotifyDeviceChanged(this);
+ }
+}
+
device::BluetoothAdapterMac* BluetoothLowEnergyDeviceMac::GetMacAdapter() {
return static_cast<BluetoothAdapterMac*>(this->adapter_);
}
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_device_mac.h ('k') | device/bluetooth/bluetooth_low_energy_peripheral_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698