| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_adapter_mac.h" | 5 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 6 | 6 |
| 7 #import <IOBluetooth/objc/IOBluetoothDevice.h> | 7 #import <IOBluetooth/objc/IOBluetoothDevice.h> |
| 8 #import <IOBluetooth/objc/IOBluetoothHostController.h> | 8 #import <IOBluetooth/objc/IOBluetoothHostController.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } | 554 } |
| 555 | 555 |
| 556 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, | 556 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, |
| 557 NSError* error) { | 557 NSError* error) { |
| 558 BluetoothLowEnergyDeviceMac* device_mac = | 558 BluetoothLowEnergyDeviceMac* device_mac = |
| 559 GetBluetoothLowEnergyDeviceMac(peripheral); | 559 GetBluetoothLowEnergyDeviceMac(peripheral); |
| 560 if (!device_mac) { | 560 if (!device_mac) { |
| 561 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; | 561 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; |
| 562 return; | 562 return; |
| 563 } | 563 } |
| 564 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String | |
| 565 << ", error code: " << error.code; | |
| 566 BluetoothDevice::ConnectErrorCode error_code = | 564 BluetoothDevice::ConnectErrorCode error_code = |
| 567 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); | 565 BluetoothDevice::ConnectErrorCode::ERROR_FAILED; |
| 568 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String | 566 VLOG(1) << "Fail to connect to peripheral"; |
| 569 << ", error code: " << error.code | 567 if (error) { |
| 570 << ", converted into: " << error_code; | 568 error_code = BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); |
| 569 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String |
| 570 << ", error code: " << error.code |
| 571 << ", converted into: " << error_code; |
| 572 } |
| 571 device_mac->DidFailToConnectGatt(error_code); | 573 device_mac->DidFailToConnectGatt(error_code); |
| 572 } | 574 } |
| 573 | 575 |
| 574 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, | 576 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, |
| 575 NSError* error) { | 577 NSError* error) { |
| 576 BluetoothLowEnergyDeviceMac* device_mac = | 578 BluetoothLowEnergyDeviceMac* device_mac = |
| 577 GetBluetoothLowEnergyDeviceMac(peripheral); | 579 GetBluetoothLowEnergyDeviceMac(peripheral); |
| 578 if (!device_mac) { | 580 if (!device_mac) { |
| 579 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; | 581 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; |
| 580 return; | 582 return; |
| 581 } | 583 } |
| 582 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String | 584 VLOG(1) << "Peripheral disconnected"; |
| 583 << ", error code: " << error.code; | 585 if (error) { |
| 584 BluetoothDevice::ConnectErrorCode error_code = | 586 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String |
| 585 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); | 587 << ", error code: " << error.code; |
| 586 device_mac->DidDisconnectPeripheral(error_code); | 588 // TODO(http://crbug.com/585897): Need to pass the error to |
| 589 // DidDisconnectPeripheral(). |
| 590 } |
| 591 device_mac->DidDisconnectPeripheral(); |
| 587 } | 592 } |
| 588 | 593 |
| 589 BluetoothLowEnergyDeviceMac* | 594 BluetoothLowEnergyDeviceMac* |
| 590 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { | 595 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { |
| 591 std::string device_address = | 596 std::string device_address = |
| 592 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 597 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
| 593 DevicesMap::const_iterator iter = devices_.find(device_address); | 598 DevicesMap::const_iterator iter = devices_.find(device_address); |
| 594 if (iter == devices_.end()) { | 599 if (iter == devices_.end()) { |
| 595 return nil; | 600 return nil; |
| 596 } | 601 } |
| 597 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); | 602 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); |
| 598 } | 603 } |
| 599 | 604 |
| 600 } // namespace device | 605 } // namespace device |
| OLD | NEW |