| 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; |
| 564 BluetoothDevice::ConnectErrorCode error_code = | 566 BluetoothDevice::ConnectErrorCode error_code = |
| 565 BluetoothDevice::ConnectErrorCode::ERROR_FAILED; | 567 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); |
| 566 VLOG(1) << "Fail to connect to peripheral"; | 568 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String |
| 567 if (error) { | 569 << ", error code: " << error.code |
| 568 error_code = BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); | 570 << ", converted into: " << error_code; |
| 569 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String | |
| 570 << ", error code: " << error.code | |
| 571 << ", converted into: " << error_code; | |
| 572 } | |
| 573 device_mac->DidFailToConnectGatt(error_code); | 571 device_mac->DidFailToConnectGatt(error_code); |
| 574 } | 572 } |
| 575 | 573 |
| 576 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, | 574 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, |
| 577 NSError* error) { | 575 NSError* error) { |
| 578 BluetoothLowEnergyDeviceMac* device_mac = | 576 BluetoothLowEnergyDeviceMac* device_mac = |
| 579 GetBluetoothLowEnergyDeviceMac(peripheral); | 577 GetBluetoothLowEnergyDeviceMac(peripheral); |
| 580 if (!device_mac) { | 578 if (!device_mac) { |
| 581 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; | 579 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; |
| 582 return; | 580 return; |
| 583 } | 581 } |
| 584 VLOG(1) << "Peripheral disconnected"; | 582 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String |
| 585 if (error) { | 583 << ", error code: " << error.code; |
| 586 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String | 584 BluetoothDevice::ConnectErrorCode error_code = |
| 587 << ", error code: " << error.code; | 585 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); |
| 588 // TODO(http://crbug.com/585897): Need to pass the error to | 586 device_mac->DidDisconnectPeripheral(error_code); |
| 589 // DidDisconnectPeripheral(). | |
| 590 } | |
| 591 device_mac->DidDisconnectPeripheral(); | |
| 592 } | 587 } |
| 593 | 588 |
| 594 BluetoothLowEnergyDeviceMac* | 589 BluetoothLowEnergyDeviceMac* |
| 595 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { | 590 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { |
| 596 std::string device_address = | 591 std::string device_address = |
| 597 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 592 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
| 598 DevicesMap::const_iterator iter = devices_.find(device_address); | 593 DevicesMap::const_iterator iter = devices_.find(device_address); |
| 599 if (iter == devices_.end()) { | 594 if (iter == devices_.end()) { |
| 600 return nil; | 595 return nil; |
| 601 } | 596 } |
| 602 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); | 597 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); |
| 603 } | 598 } |
| 604 | 599 |
| 605 } // namespace device | 600 } // namespace device |
| OLD | NEW |