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

Unified Diff: device/bluetooth/bluetooth_service_record_mac.mm

Issue 12539004: Implemented BluetoothServiceRecordMac with unittest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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..f0f62b7c77bb61e5c138ca058de8d4a519fe1b44
--- /dev/null
+++ b/device/bluetooth/bluetooth_service_record_mac.mm
@@ -0,0 +1,71 @@
+// 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"
+
+#import <IOBluetooth/Bluetooth.h>
Mark Mentovai 2013/03/11 22:38:48 You #include C[++] headers and #import Objective-C
youngki 2013/03/12 04:15:12 Done.
+#import <IOBluetooth/objc/IOBluetoothDevice.h>
+#import <IOBluetooth/objc/IOBluetoothSDPDataElement.h>
+#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
+#import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
+#import <IOBluetooth/IOBluetoothUtilities.h>
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/stringprintf.h"
+#include "base/strings/sys_string_conversions.h"
+
+namespace {
+
+const BluetoothSDPServiceAttributeID kServiceClassId = 1;
+
+void ExtractUuid(IOBluetoothSDPDataElement* service_class_data,
+ std::string* uuid) {
+ NSArray* inner_elements = [service_class_data getArrayValue];
+ IOBluetoothSDPUUID* sdp_uuid = nil;
+ for (NSUInteger i = 0; i < [inner_elements count]; i++) {
Mark Mentovai 2013/03/11 22:38:48 You can use fast enumeration: for (IOBluetoothS
youngki 2013/03/12 04:15:12 Done.
+ IOBluetoothSDPDataElement* inner_element =
+ [inner_elements objectAtIndex: i];
Mark Mentovai 2013/03/11 22:38:48 Continuation lines should be indented by 4, but yo
youngki 2013/03/12 04:15:12 Done.
+ if ([inner_element getTypeDescriptor] ==
+ kBluetoothSDPDataElementTypeUUID) {
Mark Mentovai 2013/03/11 22:38:48 I believe this will fit on a single line.
youngki 2013/03/12 04:15:12 Done.
+ sdp_uuid = [[inner_element getUUIDValue] getUUIDWithLength: 16];
Mark Mentovai 2013/03/11 22:38:48 There is no space between the : and its argument.
youngki 2013/03/12 04:15:12 Done.
+ 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 device {
+
+BluetoothServiceRecordMac::BluetoothServiceRecordMac(
+ IOBluetoothSDPServiceRecord* record) {
+ name_ = base::SysNSStringToUTF8([record getServiceName]);
Mark Mentovai 2013/03/11 22:38:48 Please use initializer list format instead of init
youngki 2013/03/12 04:15:12 Done.
+ device_ = [record device];
+ address_ = base::SysNSStringToUTF8(IOBluetoothNSStringFromDeviceAddress(
+ [device_ getAddress]));
+
+ supports_rfcomm_ =
+ [record getRFCOMMChannelID: &rfcomm_channel_] == kIOReturnSuccess;
+
+ IOBluetoothSDPDataElement* service_class_data =
+ [record getAttributeDataElement: kServiceClassId];
+ if (service_class_data != nil &&
Mark Mentovai 2013/03/11 22:38:48 You don’t need to check for nil. See http://google
youngki 2013/03/12 04:15:12 Done.
+ [service_class_data getTypeDescriptor] ==
+ kBluetoothSDPDataElementTypeDataElementSequence) {
+ ExtractUuid(service_class_data, &uuid_);
+ }
+}
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698