Index: device/bluetooth/bluetooth_device_mac.mm |
diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm |
index d0a676203e29454e61b43c1d73cbdee12ff66462..183b9c2d6b5c60e590b94a1ac868ccc231b23dd1 100644 |
--- a/device/bluetooth/bluetooth_device_mac.mm |
+++ b/device/bluetooth/bluetooth_device_mac.mm |
@@ -4,23 +4,49 @@ |
#include "device/bluetooth/bluetooth_device_mac.h" |
+#include <IOBluetooth/Bluetooth.h> |
+#import <IOBluetooth/objc/IOBluetoothDevice.h> |
+#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> |
+ |
#include <string> |
#include "base/basictypes.h" |
+#include "base/hash.h" |
+#include "base/stringprintf.h" |
+#include "base/strings/sys_string_conversions.h" |
#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
#include "device/bluetooth/bluetooth_service_record_mac.h" |
+// Replicate specific 10.7 SDK declarations for building with prior SDKs. |
+#if !defined(MAC_OS_X_VERSION_10_7) || \ |
+MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
+ |
+@interface IOBluetoothDevice (LionSDKDeclarations) |
+- (NSString*)addressString; |
+- (NSString*)name; |
+- (BluetoothClassOfDevice)classOfDevice; |
+- (NSArray*)services; |
+@end |
+ |
+#endif // MAC_OS_X_VERSION_10_7 |
+ |
namespace device { |
-BluetoothDeviceMac::BluetoothDeviceMac() |
- : BluetoothDevice() { |
+BluetoothDeviceMac::BluetoothDeviceMac(const IOBluetoothDevice* device) |
+ : BluetoothDevice(base::SysNSStringToUTF8([device name]), |
+ base::SysNSStringToUTF8([device addressString]), |
+ [device classOfDevice], |
+ [device isConnected], |
+ [device isPaired]), |
+ device_fingerprint_(ComputeDeviceFingerprint(device)) { |
+ visible_ = true; |
} |
BluetoothDeviceMac::~BluetoothDeviceMac() { |
} |
bool BluetoothDeviceMac::IsPaired() const { |
- return false; |
+ return bonded_; |
} |
const BluetoothDevice::ServiceList& BluetoothDeviceMac::GetServices() const { |
@@ -107,4 +133,25 @@ void BluetoothDeviceMac::ClearOutOfBandPairingData( |
NOTIMPLEMENTED(); |
} |
+// static |
+uint32 BluetoothDeviceMac::ComputeDeviceFingerprint( |
+ const IOBluetoothDevice* device) { |
+ std::string device_string = base::StringPrintf("%s|%s|%lu|%d|%d", |
+ base::SysNSStringToUTF8([device name]).c_str(), |
+ base::SysNSStringToUTF8([device addressString]).c_str(), |
+ [device classOfDevice], |
+ [device isConnected], |
+ [device isPaired]); |
+ |
+ for (IOBluetoothSDPServiceRecord* record in [device services]) { |
+ base::StringAppendF( |
+ &device_string, |
+ "|%s|%u", |
+ base::SysNSStringToUTF8([record getServiceName]).c_str(), |
+ [[record attributes] count]); |
+ } |
+ |
+ return base::Hash(device_string); |
+} |
+ |
} // namespace device |