OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" | 5 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" |
6 | 6 |
7 #import <CoreFoundation/CoreFoundation.h> | 7 #import <CoreFoundation/CoreFoundation.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 VLOG(1) << *this | 194 VLOG(1) << *this |
195 << ": BluetoothLowEnergyDeviceMac::discovery_pending_count_ " | 195 << ": BluetoothLowEnergyDeviceMac::discovery_pending_count_ " |
196 << discovery_pending_count_; | 196 << discovery_pending_count_; |
197 discovery_pending_count_ = 0; | 197 discovery_pending_count_ = 0; |
198 return; | 198 return; |
199 } | 199 } |
200 if (error) { | 200 if (error) { |
201 // TODO(http://crbug.com/609320): Need to pass the error. | 201 // TODO(http://crbug.com/609320): Need to pass the error. |
202 // TODO(http://crbug.com/609844): Decide what to do if discover failed | 202 // TODO(http://crbug.com/609844): Decide what to do if discover failed |
203 // a device services. | 203 // a device services. |
204 VLOG(1) << *this << ": Can't discover primary services: " | 204 VLOG(1) << *this << ": Can't discover primary services: " << error; |
205 << error.localizedDescription.UTF8String << " (" << error.domain | |
206 << ": " << error.code << ")."; | |
207 return; | 205 return; |
208 } | 206 } |
209 | 207 |
210 if (!IsGattConnected()) { | 208 if (!IsGattConnected()) { |
211 // Don't create services if the device disconnected. | 209 // Don't create services if the device disconnected. |
212 VLOG(1) << *this << ": DidDiscoverPrimaryServices, gatt not connected."; | 210 VLOG(1) << *this << ": DidDiscoverPrimaryServices, gatt not connected."; |
213 return; | 211 return; |
214 } | 212 } |
215 VLOG(1) << *this << ": DidDiscoverPrimaryServices, pending count: " | 213 VLOG(1) << *this << ": DidDiscoverPrimaryServices, pending count: " |
216 << discovery_pending_count_; | 214 << discovery_pending_count_; |
(...skipping 23 matching lines...) Expand all Loading... |
240 SendNotificationIfDiscoveryComplete(); | 238 SendNotificationIfDiscoveryComplete(); |
241 } | 239 } |
242 } | 240 } |
243 | 241 |
244 void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics( | 242 void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics( |
245 CBService* cb_service, | 243 CBService* cb_service, |
246 NSError* error) { | 244 NSError* error) { |
247 if (error) { | 245 if (error) { |
248 // TODO(http://crbug.com/609320): Need to pass the error. | 246 // TODO(http://crbug.com/609320): Need to pass the error. |
249 // TODO(http://crbug.com/609844): Decide what to do if discover failed | 247 // TODO(http://crbug.com/609844): Decide what to do if discover failed |
250 VLOG(1) << *this << ": Can't discover characteristics: " | 248 VLOG(1) << *this << ": Can't discover characteristics: " << error; |
251 << error.localizedDescription.UTF8String << " (" << error.domain | |
252 << ": " << error.code << ")."; | |
253 return; | 249 return; |
254 } | 250 } |
255 | 251 |
256 if (!IsGattConnected()) { | 252 if (!IsGattConnected()) { |
257 VLOG(1) << *this << ": DidDiscoverCharacteristics, gatt disconnected."; | 253 VLOG(1) << *this << ": DidDiscoverCharacteristics, gatt disconnected."; |
258 // Don't create characteristics if the device disconnected. | 254 // Don't create characteristics if the device disconnected. |
259 return; | 255 return; |
260 } | 256 } |
261 | 257 |
262 BluetoothRemoteGattServiceMac* gatt_service = | 258 BluetoothRemoteGattServiceMac* gatt_service = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 DCHECK(gatt_service); | 309 DCHECK(gatt_service); |
314 gatt_service->DidUpdateNotificationState(characteristic, error); | 310 gatt_service->DidUpdateNotificationState(characteristic, error); |
315 } | 311 } |
316 | 312 |
317 void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors( | 313 void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors( |
318 CBCharacteristic* cb_characteristic, | 314 CBCharacteristic* cb_characteristic, |
319 NSError* error) { | 315 NSError* error) { |
320 if (error) { | 316 if (error) { |
321 // TODO(http://crbug.com/609320): Need to pass the error. | 317 // TODO(http://crbug.com/609320): Need to pass the error. |
322 // TODO(http://crbug.com/609844): Decide what to do if discover failed | 318 // TODO(http://crbug.com/609844): Decide what to do if discover failed |
323 VLOG(1) << *this << ": Can't discover descriptors: " | 319 VLOG(1) << *this << ": Can't discover descriptors: " << error; |
324 << error.localizedDescription.UTF8String << " (" << error.domain | |
325 << ": " << error.code << ")."; | |
326 return; | 320 return; |
327 } | 321 } |
328 if (!IsGattConnected()) { | 322 if (!IsGattConnected()) { |
329 VLOG(1) << *this << ": DidDiscoverDescriptors, disconnected."; | 323 VLOG(1) << *this << ": DidDiscoverDescriptors, disconnected."; |
330 // Don't discover descriptors if the device disconnected. | 324 // Don't discover descriptors if the device disconnected. |
331 return; | 325 return; |
332 } | 326 } |
333 BluetoothRemoteGattServiceMac* gatt_service = | 327 BluetoothRemoteGattServiceMac* gatt_service = |
334 GetBluetoothRemoteGattService(cb_characteristic.service); | 328 GetBluetoothRemoteGattService(cb_characteristic.service); |
335 DCHECK(gatt_service); | 329 DCHECK(gatt_service); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); | 395 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); |
402 if (gatt_service_mac->GetService() == cb_service) | 396 if (gatt_service_mac->GetService() == cb_service) |
403 return gatt_service_mac; | 397 return gatt_service_mac; |
404 } | 398 } |
405 return nullptr; | 399 return nullptr; |
406 } | 400 } |
407 | 401 |
408 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) { | 402 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) { |
409 VLOG(1) << *this << ": Disconnected from peripheral."; | 403 VLOG(1) << *this << ": Disconnected from peripheral."; |
410 if (error) { | 404 if (error) { |
411 VLOG(1) << *this << ": Bluetooth error, domain: " << error.domain.UTF8String | 405 VLOG(1) << *this << ": Bluetooth error: " << error; |
412 << ", error code: " << error.code; | |
413 } | 406 } |
414 SetGattServicesDiscoveryComplete(false); | 407 SetGattServicesDiscoveryComplete(false); |
415 // Removing all services at once to ensure that calling GetGattService on | 408 // Removing all services at once to ensure that calling GetGattService on |
416 // removed service in GattServiceRemoved returns null. | 409 // removed service in GattServiceRemoved returns null. |
417 GattServiceMap gatt_services_swapped; | 410 GattServiceMap gatt_services_swapped; |
418 gatt_services_swapped.swap(gatt_services_); | 411 gatt_services_swapped.swap(gatt_services_); |
419 gatt_services_swapped.clear(); | 412 gatt_services_swapped.clear(); |
420 device_uuids_.ClearServiceUUIDs(); | 413 device_uuids_.ClearServiceUUIDs(); |
421 // There are two cases in which this function will be called: | 414 // There are two cases in which this function will be called: |
422 // 1. When the connection to the device breaks (either because | 415 // 1. When the connection to the device breaks (either because |
(...skipping 14 matching lines...) Expand all Loading... |
437 std::ostream& operator<<(std::ostream& out, | 430 std::ostream& operator<<(std::ostream& out, |
438 const BluetoothLowEnergyDeviceMac& device) { | 431 const BluetoothLowEnergyDeviceMac& device) { |
439 // TODO(crbug.com/703878): Should use | 432 // TODO(crbug.com/703878): Should use |
440 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. | 433 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. |
441 base::Optional<std::string> name = device.GetName(); | 434 base::Optional<std::string> name = device.GetName(); |
442 const char* name_cstr = name ? name->c_str() : ""; | 435 const char* name_cstr = name ? name->c_str() : ""; |
443 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" | 436 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" |
444 << &device << ", \"" << name_cstr << "\">"; | 437 << &device << ", \"" << name_cstr << "\">"; |
445 } | 438 } |
446 } // namespace device | 439 } // namespace device |
OLD | NEW |