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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "device/bluetooth/bluetooth_service_record_mac.h"
6
7 #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.
8 #import <IOBluetooth/objc/IOBluetoothDevice.h>
9 #import <IOBluetooth/objc/IOBluetoothSDPDataElement.h>
10 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
11 #import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
12 #import <IOBluetooth/IOBluetoothUtilities.h>
13
14 #include <string>
15
16 #include "base/basictypes.h"
17 #include "base/stringprintf.h"
18 #include "base/strings/sys_string_conversions.h"
19
20 namespace {
21
22 const BluetoothSDPServiceAttributeID kServiceClassId = 1;
23
24 void ExtractUuid(IOBluetoothSDPDataElement* service_class_data,
25 std::string* uuid) {
26 NSArray* inner_elements = [service_class_data getArrayValue];
27 IOBluetoothSDPUUID* sdp_uuid = nil;
28 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.
29 IOBluetoothSDPDataElement* inner_element =
30 [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.
31 if ([inner_element getTypeDescriptor] ==
32 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.
33 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.
34 break;
35 }
36 }
37 if (sdp_uuid != nil) {
38 const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]);
39 *uuid = base::StringPrintf(
40 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
41 uuid_bytes[0], uuid_bytes[1], uuid_bytes[2], uuid_bytes[3],
42 uuid_bytes[4], uuid_bytes[5], uuid_bytes[6], uuid_bytes[7],
43 uuid_bytes[8], uuid_bytes[9], uuid_bytes[10], uuid_bytes[11],
44 uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]);
45 }
46 }
47
48 }
49
50 namespace device {
51
52 BluetoothServiceRecordMac::BluetoothServiceRecordMac(
53 IOBluetoothSDPServiceRecord* record) {
54 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.
55 device_ = [record device];
56 address_ = base::SysNSStringToUTF8(IOBluetoothNSStringFromDeviceAddress(
57 [device_ getAddress]));
58
59 supports_rfcomm_ =
60 [record getRFCOMMChannelID: &rfcomm_channel_] == kIOReturnSuccess;
61
62 IOBluetoothSDPDataElement* service_class_data =
63 [record getAttributeDataElement: kServiceClassId];
64 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.
65 [service_class_data getTypeDescriptor] ==
66 kBluetoothSDPDataElementTypeDataElementSequence) {
67 ExtractUuid(service_class_data, &uuid_);
68 }
69 }
70
71 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698