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

Unified Diff: device/bluetooth/bluetooth_device_mac.mm

Issue 246603008: Expose device RSSI and Tx power via the chrome.bluetooth API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forward-declare more APIs introduced in Lion Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_device_mac.h ('k') | device/bluetooth/bluetooth_device_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_device_mac.mm
diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm
index 24c2b45664655a671b79ede15c794208dd7f2c08..aaeffb8fa6327ec785a14b9b8dee1b994659f066 100644
--- a/device/bluetooth/bluetooth_device_mac.mm
+++ b/device/bluetooth/bluetooth_device_mac.mm
@@ -4,11 +4,6 @@
#include "device/bluetooth/bluetooth_device_mac.h"
-#include <IOBluetooth/Bluetooth.h>
-#import <IOBluetooth/objc/IOBluetoothDevice.h>
-#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
-#import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
-
#include <string>
#include "base/basictypes.h"
@@ -28,13 +23,23 @@
@interface IOBluetoothDevice (LionSDKDeclarations)
- (NSString*)addressString;
-- (NSString*)name;
- (unsigned int)classOfDevice;
+- (BluetoothConnectionHandle)connectionHandle;
+- (BluetoothHCIRSSIValue)rawRSSI;
- (NSArray*)services;
@end
#endif // MAC_OS_X_VERSION_10_7
+// Undocumented API for accessing the Bluetooth transmit power level.
+// Similar to the API defined here [ http://goo.gl/20Q5vE ].
+@interface IOBluetoothHostController (UndocumentedAPI)
+- (IOReturn)
+ BluetoothHCIReadTransmitPowerLevel:(BluetoothConnectionHandle)connection
+ inType:(BluetoothHCITransmitPowerLevelType)type
+ outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level;
+@end
+
namespace device {
BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device)
@@ -84,6 +89,30 @@ uint16 BluetoothDeviceMac::GetDeviceID() const {
return 0;
}
+int BluetoothDeviceMac::GetRSSI() const {
+ if (![device_ isConnected]) {
+ NOTIMPLEMENTED();
+ return kUnknownPower;
+ }
+
+ int rssi = [device_ rawRSSI];
+
+ // The API guarantees that +127 is returned in case the RSSI is not readable:
+ // http://goo.gl/bpURYv
+ if (rssi == 127)
+ return kUnknownPower;
+
+ return rssi;
+}
+
+int BluetoothDeviceMac::GetCurrentHostTransmitPower() const {
+ return GetHostTransmitPower(kReadCurrentTransmitPowerLevel);
+}
+
+int BluetoothDeviceMac::GetMaximumHostTransmitPower() const {
+ return GetHostTransmitPower(kReadMaximumTransmitPowerLevel);
+}
+
bool BluetoothDeviceMac::IsPaired() const {
return [device_ isPaired];
}
@@ -183,4 +212,26 @@ void BluetoothDeviceMac::ClearOutOfBandPairingData(
NOTIMPLEMENTED();
}
+int BluetoothDeviceMac::GetHostTransmitPower(
+ BluetoothHCITransmitPowerLevelType power_level_type) const {
+ IOBluetoothHostController* controller =
+ [IOBluetoothHostController defaultController];
+
+ // Bail if the undocumented API is unavailable on this machine.
+ SEL selector = @selector(
+ BluetoothHCIReadTransmitPowerLevel:inType:outTransmitPowerLevel:);
+ if (![controller respondsToSelector:selector])
+ return kUnknownPower;
+
+ BluetoothHCITransmitPowerLevel power_level;
+ IOReturn result =
+ [controller BluetoothHCIReadTransmitPowerLevel:[device_ connectionHandle]
+ inType:power_level_type
+ outTransmitPowerLevel:&power_level];
+ if (result != kIOReturnSuccess)
+ return kUnknownPower;
+
+ return power_level;
+}
+
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_device_mac.h ('k') | device/bluetooth/bluetooth_device_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698