Index: device/bluetooth/bluetooth_service_record_mac.mm |
diff --git a/device/bluetooth/bluetooth_service_record_mac.mm b/device/bluetooth/bluetooth_service_record_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..10badd6369138ee67c24d2cfa7a0bcb43463aa77 |
--- /dev/null |
+++ b/device/bluetooth/bluetooth_service_record_mac.mm |
@@ -0,0 +1,66 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "device/bluetooth/bluetooth_service_record_mac.h" |
+ |
+#include <IOBluetooth/Bluetooth.h> |
+#include <IOBluetooth/IOBluetoothUtilities.h> |
Mark Mentovai
2013/03/12 16:02:54
If you look at this header, you’ll see that this o
youngki
2013/03/12 19:45:47
Done.
|
+#import <IOBluetooth/objc/IOBluetoothDevice.h> |
+#import <IOBluetooth/objc/IOBluetoothSDPDataElement.h> |
+#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> |
+#import <IOBluetooth/objc/IOBluetoothSDPUUID.h> |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/stringprintf.h" |
+#include "base/strings/sys_string_conversions.h" |
+ |
+namespace { |
+ |
+const BluetoothSDPServiceAttributeID kServiceClassId = 1; |
Mark Mentovai
2013/03/12 16:02:54
This doesn’t need to be file-scoped, you can move
youngki
2013/03/12 19:45:47
Done.
|
+ |
+void ExtractUuid(IOBluetoothSDPDataElement* service_class_data, |
+ std::string* uuid) { |
+ NSArray* inner_elements = [service_class_data getArrayValue]; |
+ IOBluetoothSDPUUID* sdp_uuid = nil; |
+ for (IOBluetoothSDPDataElement* inner_element in inner_elements) { |
Mark Mentovai
2013/03/12 16:02:54
Assuming -getArrayValue did return an array (as op
youngki
2013/03/12 19:45:47
I think it's safe to assume the type is only IOBlu
|
+ if ([inner_element getTypeDescriptor] == kBluetoothSDPDataElementTypeUUID) { |
+ sdp_uuid = [[inner_element getUUIDValue] getUUIDWithLength:16]; |
+ break; |
+ } |
+ } |
+ if (sdp_uuid != nil) { |
+ const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]); |
+ *uuid = base::StringPrintf( |
+ "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
+ uuid_bytes[0], uuid_bytes[1], uuid_bytes[2], uuid_bytes[3], |
+ uuid_bytes[4], uuid_bytes[5], uuid_bytes[6], uuid_bytes[7], |
+ uuid_bytes[8], uuid_bytes[9], uuid_bytes[10], uuid_bytes[11], |
+ uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]); |
+ } |
+} |
+ |
+} // namespace |
+ |
+namespace device { |
+ |
+BluetoothServiceRecordMac::BluetoothServiceRecordMac( |
+ IOBluetoothSDPServiceRecord* record) : device_([record device]) { |
Mark Mentovai
2013/03/12 16:02:54
Since you already had to break the line for the fi
youngki
2013/03/12 19:45:47
Done.
|
+ name_ = base::SysNSStringToUTF8([record getServiceName]); |
Mark Mentovai
2013/03/12 16:02:54
There are fields in BluetoothServiceRecord that ar
Mark Mentovai
2013/03/12 16:02:54
Why don’t you initialize the rest of the fields in
youngki
2013/03/12 19:45:47
Done.
youngki
2013/03/12 19:45:47
Done.
|
+ address_ = base::SysNSStringToUTF8(IOBluetoothNSStringFromDeviceAddress( |
+ [device_ getAddress])); |
+ |
+ supports_rfcomm_ = |
+ [record getRFCOMMChannelID:&rfcomm_channel_] == kIOReturnSuccess; |
+ |
+ IOBluetoothSDPDataElement* service_class_data = |
+ [record getAttributeDataElement:kServiceClassId]; |
+ if ([service_class_data getTypeDescriptor] == |
+ kBluetoothSDPDataElementTypeDataElementSequence) { |
+ ExtractUuid(service_class_data, &uuid_); |
+ } |
+} |
+ |
+} // namespace device |