OLD | NEW |
---|---|
(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 #include <IOBluetooth/Bluetooth.h> | |
8 #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.
| |
9 #import <IOBluetooth/objc/IOBluetoothDevice.h> | |
10 #import <IOBluetooth/objc/IOBluetoothSDPDataElement.h> | |
11 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> | |
12 #import <IOBluetooth/objc/IOBluetoothSDPUUID.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; | |
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.
| |
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 (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
| |
29 if ([inner_element getTypeDescriptor] == kBluetoothSDPDataElementTypeUUID) { | |
30 sdp_uuid = [[inner_element getUUIDValue] getUUIDWithLength:16]; | |
31 break; | |
32 } | |
33 } | |
34 if (sdp_uuid != nil) { | |
35 const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]); | |
36 *uuid = base::StringPrintf( | |
37 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", | |
38 uuid_bytes[0], uuid_bytes[1], uuid_bytes[2], uuid_bytes[3], | |
39 uuid_bytes[4], uuid_bytes[5], uuid_bytes[6], uuid_bytes[7], | |
40 uuid_bytes[8], uuid_bytes[9], uuid_bytes[10], uuid_bytes[11], | |
41 uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]); | |
42 } | |
43 } | |
44 | |
45 } // namespace | |
46 | |
47 namespace device { | |
48 | |
49 BluetoothServiceRecordMac::BluetoothServiceRecordMac( | |
50 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.
| |
51 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.
| |
52 address_ = base::SysNSStringToUTF8(IOBluetoothNSStringFromDeviceAddress( | |
53 [device_ getAddress])); | |
54 | |
55 supports_rfcomm_ = | |
56 [record getRFCOMMChannelID:&rfcomm_channel_] == kIOReturnSuccess; | |
57 | |
58 IOBluetoothSDPDataElement* service_class_data = | |
59 [record getAttributeDataElement:kServiceClassId]; | |
60 if ([service_class_data getTypeDescriptor] == | |
61 kBluetoothSDPDataElementTypeDataElementSequence) { | |
62 ExtractUuid(service_class_data, &uuid_); | |
63 } | |
64 } | |
65 | |
66 } // namespace device | |
OLD | NEW |