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

Unified Diff: device/bluetooth/bluetooth_device_mac.mm

Issue 12929003: Implemented BluetoothAdapterMac::AddDevices(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted BluetoothDevice interface. Created 7 years, 9 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/test/mock_bluetooth_device.cc » ('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 d0a676203e29454e61b43c1d73cbdee12ff66462..d7ddb54d524e7d8047e41576aec7b620305e5dd9 100644
--- a/device/bluetooth/bluetooth_device_mac.mm
+++ b/device/bluetooth/bluetooth_device_mac.mm
@@ -4,23 +4,50 @@
#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;
+- (unsigned int)classOfDevice;
+- (NSArray*)services;
+@end
+
+#endif // MAC_OS_X_VERSION_10_7
+
namespace device {
-BluetoothDeviceMac::BluetoothDeviceMac()
- : BluetoothDevice() {
+BluetoothDeviceMac::BluetoothDeviceMac(const IOBluetoothDevice* device)
+ : BluetoothDevice(),
+ device_fingerprint_(ComputeDeviceFingerprint(device)) {
+ name_ = base::SysNSStringToUTF8([device name]);
+ address_ = base::SysNSStringToUTF8([device addressString]);
+ bluetooth_class_ = [device classOfDevice];
+ connected_ = [device isConnected];
+ bonded_ = [device isPaired];
+ visible_ = true;
}
BluetoothDeviceMac::~BluetoothDeviceMac() {
}
bool BluetoothDeviceMac::IsPaired() const {
- return false;
+ return bonded_;
}
const BluetoothDevice::ServiceList& BluetoothDeviceMac::GetServices() const {
@@ -107,4 +134,25 @@ void BluetoothDeviceMac::ClearOutOfBandPairingData(
NOTIMPLEMENTED();
}
+// static
+uint32 BluetoothDeviceMac::ComputeDeviceFingerprint(
+ const IOBluetoothDevice* device) {
+ std::string device_string = base::StringPrintf("%s|%s|%u|%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]);
Avi (use Gerrit) 2013/03/26 19:15:51 This breaks the 64-bit build. NSUInteger shouldn't
+ }
+
+ return base::Hash(device_string);
+}
+
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_device_mac.h ('k') | device/bluetooth/test/mock_bluetooth_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698