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_device_mac.h" | 5 #include "device/bluetooth/bluetooth_device_mac.h" |
6 | 6 |
| 7 #include <IOBluetooth/Bluetooth.h> |
| 8 #import <IOBluetooth/objc/IOBluetoothDevice.h> |
| 9 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> |
| 10 |
7 #include <string> | 11 #include <string> |
8 | 12 |
9 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/hash.h" |
| 15 #include "base/stringprintf.h" |
| 16 #include "base/strings/sys_string_conversions.h" |
10 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 17 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
11 #include "device/bluetooth/bluetooth_service_record_mac.h" | 18 #include "device/bluetooth/bluetooth_service_record_mac.h" |
12 | 19 |
| 20 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| 21 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| 22 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 23 |
| 24 @interface IOBluetoothDevice (LionSDKDeclarations) |
| 25 - (NSString*)addressString; |
| 26 - (NSString*)name; |
| 27 - (BluetoothClassOfDevice)classOfDevice; |
| 28 - (NSArray*)services; |
| 29 @end |
| 30 |
| 31 #endif // MAC_OS_X_VERSION_10_7 |
| 32 |
13 namespace device { | 33 namespace device { |
14 | 34 |
15 BluetoothDeviceMac::BluetoothDeviceMac() | 35 BluetoothDeviceMac::BluetoothDeviceMac(const IOBluetoothDevice* device) |
16 : BluetoothDevice() { | 36 : BluetoothDevice(base::SysNSStringToUTF8([device name]), |
| 37 base::SysNSStringToUTF8([device addressString]), |
| 38 [device classOfDevice], |
| 39 [device isConnected], |
| 40 [device isPaired]), |
| 41 device_fingerprint_(ComputeDeviceFingerprint(device)) { |
| 42 visible_ = true; |
17 } | 43 } |
18 | 44 |
19 BluetoothDeviceMac::~BluetoothDeviceMac() { | 45 BluetoothDeviceMac::~BluetoothDeviceMac() { |
20 } | 46 } |
21 | 47 |
22 bool BluetoothDeviceMac::IsPaired() const { | 48 bool BluetoothDeviceMac::IsPaired() const { |
23 return false; | 49 return bonded_; |
24 } | 50 } |
25 | 51 |
26 const BluetoothDevice::ServiceList& BluetoothDeviceMac::GetServices() const { | 52 const BluetoothDevice::ServiceList& BluetoothDeviceMac::GetServices() const { |
27 return service_uuids_; | 53 return service_uuids_; |
28 } | 54 } |
29 | 55 |
30 void BluetoothDeviceMac::GetServiceRecords( | 56 void BluetoothDeviceMac::GetServiceRecords( |
31 const ServiceRecordsCallback& callback, | 57 const ServiceRecordsCallback& callback, |
32 const ErrorCallback& error_callback) { | 58 const ErrorCallback& error_callback) { |
33 } | 59 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 const ErrorCallback& error_callback) { | 126 const ErrorCallback& error_callback) { |
101 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
102 } | 128 } |
103 | 129 |
104 void BluetoothDeviceMac::ClearOutOfBandPairingData( | 130 void BluetoothDeviceMac::ClearOutOfBandPairingData( |
105 const base::Closure& callback, | 131 const base::Closure& callback, |
106 const ErrorCallback& error_callback) { | 132 const ErrorCallback& error_callback) { |
107 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
108 } | 134 } |
109 | 135 |
| 136 // static |
| 137 uint32 BluetoothDeviceMac::ComputeDeviceFingerprint( |
| 138 const IOBluetoothDevice* device) { |
| 139 std::string device_string = base::StringPrintf("%s|%s|%lu|%d|%d", |
| 140 base::SysNSStringToUTF8([device name]).c_str(), |
| 141 base::SysNSStringToUTF8([device addressString]).c_str(), |
| 142 [device classOfDevice], |
| 143 [device isConnected], |
| 144 [device isPaired]); |
| 145 |
| 146 for (IOBluetoothSDPServiceRecord* record in [device services]) { |
| 147 base::StringAppendF( |
| 148 &device_string, |
| 149 "|%s|%u", |
| 150 base::SysNSStringToUTF8([record getServiceName]).c_str(), |
| 151 [[record attributes] count]); |
| 152 } |
| 153 |
| 154 return base::Hash(device_string); |
| 155 } |
| 156 |
110 } // namespace device | 157 } // namespace device |
OLD | NEW |