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 6fa8927657b9b53b79404a03d6a621a03db24542..4693e3ffac17e8949d9f27a736801dbc300c2a0c 100644 |
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm |
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm |
@@ -176,11 +176,13 @@ void BluetoothLowEnergyDeviceMac::ConnectToServiceInsecurely( |
void BluetoothLowEnergyDeviceMac::CreateGattConnectionImpl() { |
if (!IsGattConnected()) { |
+ VLOG(1) << *this << ": CreateGattConnection."; |
GetMacAdapter()->CreateGattConnection(this); |
} |
} |
void BluetoothLowEnergyDeviceMac::DisconnectGatt() { |
+ VLOG(1) << *this << ": Disconnect."; |
GetMacAdapter()->DisconnectGatt(this); |
} |
@@ -189,7 +191,7 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) { |
if (discovery_pending_count_ < 0) { |
// This should never happens, just in case it happens with a device, |
// discovery_pending_count_ is set back to 0. |
- VLOG(1) << GetName()->c_str() |
+ VLOG(1) << *this |
<< ": BluetoothLowEnergyDeviceMac::discovery_pending_count_ " |
<< discovery_pending_count_; |
discovery_pending_count_ = 0; |
@@ -199,18 +201,19 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) { |
// TODO(http://crbug.com/609320): Need to pass the error. |
// TODO(http://crbug.com/609844): Decide what to do if discover failed |
// a device services. |
- VLOG(1) << "Can't discover primary services: " |
+ VLOG(1) << *this << ": Can't discover primary services: " |
<< error.localizedDescription.UTF8String << " (" << error.domain |
- << ": " << error.code << ")"; |
+ << ": " << error.code << ")."; |
return; |
} |
- VLOG(1) << "DidDiscoverPrimaryServices, pending count: " |
- << discovery_pending_count_; |
if (!IsGattConnected()) { |
// Don't create services if the device disconnected. |
+ VLOG(1) << *this << ": DidDiscoverPrimaryServices, gatt not connected."; |
return; |
} |
+ VLOG(1) << *this << ": DidDiscoverPrimaryServices, pending count: " |
+ << discovery_pending_count_; |
for (CBService* cb_service in GetPeripheral().services) { |
BluetoothRemoteGattServiceMac* gatt_service = |
@@ -221,7 +224,10 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) { |
auto result_iter = gatt_services_.insert(std::make_pair( |
gatt_service->GetIdentifier(), base::WrapUnique(gatt_service))); |
DCHECK(result_iter.second); |
+ VLOG(1) << *gatt_service << ": New service."; |
adapter_->NotifyGattServiceAdded(gatt_service); |
+ } else { |
+ VLOG(1) << *gatt_service << ": Known service."; |
} |
} |
if (discovery_pending_count_ == 0) { |
@@ -241,14 +247,14 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics( |
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 characteristics: " |
+ VLOG(1) << *this << ": Can't discover characteristics: " |
<< error.localizedDescription.UTF8String << " (" << error.domain |
- << ": " << error.code << ")"; |
+ << ": " << error.code << ")."; |
return; |
} |
- VLOG(1) << "DidDiscoverCharacteristics."; |
if (!IsGattConnected()) { |
+ VLOG(1) << *this << ": DidDiscoverCharacteristics, gatt disconnected."; |
// Don't create characteristics if the device disconnected. |
return; |
} |
@@ -262,7 +268,9 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics( |
void BluetoothLowEnergyDeviceMac::DidModifyServices( |
NSArray* invalidatedServices) { |
- VLOG(1) << "DidModifyServices: "; |
+ VLOG(1) << *this << ": DidModifyServices: " |
+ << " invalidated services " |
+ << base::SysNSStringToUTF8([invalidatedServices description]); |
for (CBService* cb_service in invalidatedServices) { |
BluetoothRemoteGattServiceMac* gatt_service = |
GetBluetoothRemoteGattService(cb_service); |
@@ -282,7 +290,6 @@ void BluetoothLowEnergyDeviceMac::DidModifyServices( |
void BluetoothLowEnergyDeviceMac::DidUpdateValue( |
CBCharacteristic* characteristic, |
NSError* error) { |
- VLOG(1) << "DidUpdateValue."; |
BluetoothRemoteGattServiceMac* gatt_service = |
GetBluetoothRemoteGattService(characteristic.service); |
DCHECK(gatt_service); |
@@ -292,7 +299,6 @@ void BluetoothLowEnergyDeviceMac::DidUpdateValue( |
void BluetoothLowEnergyDeviceMac::DidWriteValue( |
CBCharacteristic* characteristic, |
NSError* error) { |
- VLOG(1) << "DidWriteValue."; |
BluetoothRemoteGattServiceMac* gatt_service = |
GetBluetoothRemoteGattService(characteristic.service); |
DCHECK(gatt_service); |
@@ -302,7 +308,6 @@ void BluetoothLowEnergyDeviceMac::DidWriteValue( |
void BluetoothLowEnergyDeviceMac::DidUpdateNotificationState( |
CBCharacteristic* characteristic, |
NSError* error) { |
- VLOG(1) << "DidUpdateNotificationState"; |
BluetoothRemoteGattServiceMac* gatt_service = |
GetBluetoothRemoteGattService(characteristic.service); |
DCHECK(gatt_service); |
@@ -315,13 +320,13 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors( |
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: " |
+ VLOG(1) << *this << ": Can't discover descriptors: " |
<< error.localizedDescription.UTF8String << " (" << error.domain |
- << ": " << error.code << ")"; |
+ << ": " << error.code << ")."; |
return; |
} |
- VLOG(1) << "DidDiscoverDescriptors."; |
if (!IsGattConnected()) { |
+ VLOG(1) << *this << ": DidDiscoverDescriptors, disconnected."; |
// Don't discover descriptors if the device disconnected. |
return; |
} |
@@ -353,7 +358,8 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress( |
} |
void BluetoothLowEnergyDeviceMac::DiscoverPrimaryServices() { |
- VLOG(1) << "DidDiscoverDescriptors pending count" << discovery_pending_count_; |
+ VLOG(1) << *this << ": DiscoverPrimaryServices, pending count " |
+ << discovery_pending_count_; |
++discovery_pending_count_; |
[GetPeripheral() discoverServices:nil]; |
} |
@@ -370,6 +376,7 @@ void BluetoothLowEnergyDeviceMac::SendNotificationIfDiscoveryComplete() { |
->IsDiscoveryComplete(); |
}) == gatt_services_.end(); |
if (discovery_complete) { |
+ VLOG(1) << *this << ": Discovery complete."; |
device_uuids_.ReplaceServiceUUIDs(gatt_services_); |
SetGattServicesDiscoveryComplete(true); |
adapter_->NotifyGattServicesDiscovered(this); |
@@ -399,6 +406,11 @@ BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattService( |
} |
void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) { |
+ VLOG(1) << *this << ": Disconnected from peripheral."; |
+ if (error) { |
+ VLOG(1) << *this << ": Bluetooth error, domain: " << error.domain.UTF8String |
+ << ", error code: " << error.code; |
+ } |
SetGattServicesDiscoveryComplete(false); |
// Removing all services at once to ensure that calling GetGattService on |
// removed service in GattServiceRemoved returns null. |
@@ -419,3 +431,16 @@ void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) { |
// TODO(http://crbug.com/585897): Need to pass the error. |
DidFailToConnectGatt(BluetoothDevice::ConnectErrorCode::ERROR_FAILED); |
} |
+ |
+namespace device { |
+ |
+std::ostream& operator<<(std::ostream& out, |
+ const BluetoothLowEnergyDeviceMac& device) { |
+ // TODO(crbug.com/703878): Should use |
+ // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. |
+ base::Optional<std::string> name = device.GetName(); |
+ const char* name_cstr = name ? name->c_str() : ""; |
+ return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" |
+ << &device << ", \"" << name_cstr << "\">"; |
+} |
+} // namespace device |