Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 2784373003: bluetooth: macOS: Adding explicit function to log NSError (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 68
69 // static 69 // static
70 BluetoothUUID BluetoothAdapterMac::BluetoothUUIDWithCBUUID(CBUUID* uuid) { 70 BluetoothUUID BluetoothAdapterMac::BluetoothUUIDWithCBUUID(CBUUID* uuid) {
71 // UUIDString only available OS X >= 10.10. 71 // UUIDString only available OS X >= 10.10.
72 DCHECK(base::mac::IsAtLeastOS10_10()); 72 DCHECK(base::mac::IsAtLeastOS10_10());
73 std::string uuid_c_string = base::SysNSStringToUTF8([uuid UUIDString]); 73 std::string uuid_c_string = base::SysNSStringToUTF8([uuid UUIDString]);
74 return device::BluetoothUUID(uuid_c_string); 74 return device::BluetoothUUID(uuid_c_string);
75 } 75 }
76 76
77 // static
78 std::string BluetoothAdapterMac::String(NSError* error) {
79 if (!error) {
80 return "no error";
81 }
82 return std::string("error domain: ") + base::SysNSStringToUTF8(error.domain) +
83 ", code: " + std::to_string(error.code) + ", description: " +
84 base::SysNSStringToUTF8(error.localizedDescription);
85 }
86
77 BluetoothAdapterMac::BluetoothAdapterMac() 87 BluetoothAdapterMac::BluetoothAdapterMac()
78 : BluetoothAdapter(), 88 : BluetoothAdapter(),
79 classic_powered_(false), 89 classic_powered_(false),
80 num_discovery_sessions_(0), 90 num_discovery_sessions_(0),
81 should_update_name_(true), 91 should_update_name_(true),
82 classic_discovery_manager_( 92 classic_discovery_manager_(
83 BluetoothDiscoveryManagerMac::CreateClassic(this)), 93 BluetoothDiscoveryManagerMac::CreateClassic(this)),
84 weak_ptr_factory_(this) { 94 weak_ptr_factory_(this) {
85 if (IsLowEnergyAvailable()) { 95 if (IsLowEnergyAvailable()) {
86 low_energy_discovery_manager_.reset( 96 low_energy_discovery_manager_.reset(
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 if (!device_mac) { 679 if (!device_mac) {
670 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; 680 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
671 return; 681 return;
672 } 682 }
673 BluetoothDevice::ConnectErrorCode error_code = 683 BluetoothDevice::ConnectErrorCode error_code =
674 BluetoothDevice::ConnectErrorCode::ERROR_UNKNOWN; 684 BluetoothDevice::ConnectErrorCode::ERROR_UNKNOWN;
675 if (error) { 685 if (error) {
676 error_code = BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error); 686 error_code = BluetoothDeviceMac::GetConnectErrorCodeFromNSError(error);
677 } 687 }
678 VLOG(1) << *device_mac << ": Failed to connect to peripheral with error " 688 VLOG(1) << *device_mac << ": Failed to connect to peripheral with error "
679 << error << ", error code: " << error_code; 689 << BluetoothAdapterMac::String(error)
690 << ", error code: " << error_code;
680 device_mac->DidFailToConnectGatt(error_code); 691 device_mac->DidFailToConnectGatt(error_code);
681 } 692 }
682 693
683 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, 694 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral,
684 NSError* error) { 695 NSError* error) {
685 BluetoothLowEnergyDeviceMac* device_mac = 696 BluetoothLowEnergyDeviceMac* device_mac =
686 GetBluetoothLowEnergyDeviceMac(peripheral); 697 GetBluetoothLowEnergyDeviceMac(peripheral);
687 if (!device_mac) { 698 if (!device_mac) {
688 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; 699 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
689 return; 700 return;
(...skipping 27 matching lines...) Expand all
717 // Collision, two identifiers map to the same hash address. With a 48 bit 728 // Collision, two identifiers map to the same hash address. With a 48 bit
718 // hash the probability of this occuring with 10,000 devices 729 // hash the probability of this occuring with 10,000 devices
719 // simultaneously present is 1e-6 (see 730 // simultaneously present is 1e-6 (see
720 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We 731 // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We
721 // ignore the second device by returning. 732 // ignore the second device by returning.
722 return true; 733 return true;
723 } 734 }
724 return false; 735 return false;
725 } 736 }
726 737
727 DEVICE_BLUETOOTH_EXPORT std::ostream& operator<<(std::ostream& out,
728 NSError* error) {
729 if (!error) {
730 return out << "no error";
731 }
732 return out << "error domain: " << base::SysNSStringToUTF8(error.domain)
733 << ", code: " << std::to_string(error.code) << ", description: "
734 << base::SysNSStringToUTF8(error.localizedDescription);
735 }
736
737 } // namespace device 738 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.h ('k') | device/bluetooth/bluetooth_low_energy_device_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698