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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, | 575 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, |
576 NSError* error) { | 576 NSError* error) { |
577 BluetoothLowEnergyDeviceMac* device_mac = | 577 BluetoothLowEnergyDeviceMac* device_mac = |
578 GetBluetoothLowEnergyDeviceMac(peripheral); | 578 GetBluetoothLowEnergyDeviceMac(peripheral); |
579 if (!device_mac) { | 579 if (!device_mac) { |
580 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; | 580 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; |
581 return; | 581 return; |
582 } | 582 } |
583 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String | 583 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String |
584 << ", error code: " << error.code; | 584 << ", error code: " << error.code; |
585 // TODO(http://crbug.com/585894): Need to convert the error. | 585 BluetoothDevice::ConnectErrorCode error_code = |
586 device_mac->DidFailToConnectGatt(BluetoothClassicDeviceMac::ERROR_UNKNOWN); | 586 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); |
| 587 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String |
| 588 << ", error code: " << error.code |
| 589 << ", converted into: " << error_code; |
| 590 device_mac->DidFailToConnectGatt(error_code); |
587 } | 591 } |
588 | 592 |
589 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, | 593 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, |
590 NSError* error) { | 594 NSError* error) { |
591 BluetoothLowEnergyDeviceMac* device_mac = | 595 BluetoothLowEnergyDeviceMac* device_mac = |
592 GetBluetoothLowEnergyDeviceMac(peripheral); | 596 GetBluetoothLowEnergyDeviceMac(peripheral); |
593 if (!device_mac) { | 597 if (!device_mac) { |
594 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; | 598 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; |
595 return; | 599 return; |
596 } | 600 } |
597 // TODO(http://crbug.com/585897): Need to pass the error. | 601 VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String |
598 device_mac->DidDisconnectPeripheral(); | 602 << ", error code: " << error.code; |
| 603 BluetoothDevice::ConnectErrorCode error_code = |
| 604 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); |
| 605 device_mac->DidDisconnectPeripheral(error_code); |
599 } | 606 } |
600 | 607 |
601 BluetoothLowEnergyDeviceMac* | 608 BluetoothLowEnergyDeviceMac* |
602 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { | 609 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { |
603 std::string device_address = | 610 std::string device_address = |
604 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); | 611 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); |
605 DevicesMap::const_iterator iter = devices_.find(device_address); | 612 DevicesMap::const_iterator iter = devices_.find(device_address); |
606 if (iter == devices_.end()) { | 613 if (iter == devices_.end()) { |
607 return nil; | 614 return nil; |
608 } | 615 } |
609 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); | 616 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); |
610 } | 617 } |
611 | 618 |
612 } // namespace device | 619 } // namespace device |
OLD | NEW |