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 #import <IOBluetooth/objc/IOBluetoothSDPUUID.h> | |
11 | |
12 #include <string> | 7 #include <string> |
13 | 8 |
14 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
15 #include "base/hash.h" | 10 #include "base/hash.h" |
16 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
17 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
19 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
20 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 15 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
21 #include "device/bluetooth/bluetooth_profile_mac.h" | 16 #include "device/bluetooth/bluetooth_profile_mac.h" |
22 #include "device/bluetooth/bluetooth_service_record_mac.h" | 17 #include "device/bluetooth/bluetooth_service_record_mac.h" |
23 #include "device/bluetooth/bluetooth_socket_mac.h" | 18 #include "device/bluetooth/bluetooth_socket_mac.h" |
24 | 19 |
25 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 20 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
26 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 21 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
27 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 22 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
28 | 23 |
29 @interface IOBluetoothDevice (LionSDKDeclarations) | 24 @interface IOBluetoothDevice (LionSDKDeclarations) |
30 - (NSString*)addressString; | 25 - (NSString*)addressString; |
31 - (NSString*)name; | 26 - (NSString*)name; |
32 - (unsigned int)classOfDevice; | 27 - (unsigned int)classOfDevice; |
33 - (NSArray*)services; | 28 - (NSArray*)services; |
34 @end | 29 @end |
35 | 30 |
36 #endif // MAC_OS_X_VERSION_10_7 | 31 #endif // MAC_OS_X_VERSION_10_7 |
37 | 32 |
| 33 // TODO(isherman): Check with Mac experts as to whether this sort of thing is ok |
| 34 // or not in Chromium. |
| 35 @interface IOBluetoothHostController (PrivateOSAPIThatIProbablyShouldntMessWith) |
| 36 - (IOReturn) |
| 37 BluetoothHCIReadTransmitPowerLevel:(BluetoothConnectionHandle) |
| 38 inType:(BluetoothHCITransmitPowerLevelType) |
| 39 outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*); |
| 40 @end |
| 41 |
38 namespace device { | 42 namespace device { |
39 | 43 |
40 BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) | 44 BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) |
41 : device_([device retain]) { | 45 : device_([device retain]) { |
42 } | 46 } |
43 | 47 |
44 BluetoothDeviceMac::~BluetoothDeviceMac() { | 48 BluetoothDeviceMac::~BluetoothDeviceMac() { |
45 } | 49 } |
46 | 50 |
47 void BluetoothDeviceMac::AddObserver( | 51 void BluetoothDeviceMac::AddObserver( |
(...skipping 29 matching lines...) Expand all Loading... |
77 } | 81 } |
78 | 82 |
79 uint16 BluetoothDeviceMac::GetProductID() const { | 83 uint16 BluetoothDeviceMac::GetProductID() const { |
80 return 0; | 84 return 0; |
81 } | 85 } |
82 | 86 |
83 uint16 BluetoothDeviceMac::GetDeviceID() const { | 87 uint16 BluetoothDeviceMac::GetDeviceID() const { |
84 return 0; | 88 return 0; |
85 } | 89 } |
86 | 90 |
| 91 int BluetoothDeviceMac::GetRSSI() const { |
| 92 int rssi = [device_ rawRSSI]; |
| 93 |
| 94 // The API guarantees that +127 is returned in case the RSSI is not readable. |
| 95 if (rssi == 127) |
| 96 return kUnknownPower; |
| 97 |
| 98 return rssi; |
| 99 } |
| 100 |
| 101 int BluetoothDeviceMac::GetCurrentHostTransmitPower() const { |
| 102 return GetHostTransmitPower(kReadCurrentTransmitPowerLevel); |
| 103 } |
| 104 |
| 105 int BluetoothDeviceMac::GetMaximumHostTransmitPower() const { |
| 106 return GetHostTransmitPower(kReadMaximumTransmitPowerLevel); |
| 107 } |
| 108 |
87 bool BluetoothDeviceMac::IsPaired() const { | 109 bool BluetoothDeviceMac::IsPaired() const { |
88 return [device_ isPaired]; | 110 return [device_ isPaired]; |
89 } | 111 } |
90 | 112 |
91 bool BluetoothDeviceMac::IsConnected() const { | 113 bool BluetoothDeviceMac::IsConnected() const { |
92 return [device_ isConnected]; | 114 return [device_ isConnected]; |
93 } | 115 } |
94 | 116 |
95 bool BluetoothDeviceMac::IsConnectable() const { | 117 bool BluetoothDeviceMac::IsConnectable() const { |
96 return false; | 118 return false; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 const ErrorCallback& error_callback) { | 198 const ErrorCallback& error_callback) { |
177 NOTIMPLEMENTED(); | 199 NOTIMPLEMENTED(); |
178 } | 200 } |
179 | 201 |
180 void BluetoothDeviceMac::ClearOutOfBandPairingData( | 202 void BluetoothDeviceMac::ClearOutOfBandPairingData( |
181 const base::Closure& callback, | 203 const base::Closure& callback, |
182 const ErrorCallback& error_callback) { | 204 const ErrorCallback& error_callback) { |
183 NOTIMPLEMENTED(); | 205 NOTIMPLEMENTED(); |
184 } | 206 } |
185 | 207 |
| 208 int BluetoothDeviceMac::GetHostTransmitPower( |
| 209 BluetoothHCITransmitPowerLevelType power_level_type) const { |
| 210 IOBluetoothHostController* controller = |
| 211 [IOBluetoothHostController defaultController]; |
| 212 BluetoothHCITransmitPowerLevel power_level; |
| 213 IOReturn result = |
| 214 [controller BluetoothHCIReadTransmitPowerLevel:[device_ connectionHandle] |
| 215 inType:power_level_type |
| 216 outTransmitPowerLevel:&power_level]; |
| 217 if (result != kIOReturnSuccess) |
| 218 return kUnknownPower; |
| 219 |
| 220 return power_level; |
| 221 } |
| 222 |
186 } // namespace device | 223 } // namespace device |
OLD | NEW |