summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-07 05:14:42 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-07 05:14:42 +0000
commitfdbc49d04f558989362bfb6d3f273ce33ea9be36 (patch)
tree72f8c469442643c76321fa4ea59d9007c31bd393
parent66580239c269aa4bab91f7832fb46f78a9b9b2c0 (diff)
downloadchromium_src-fdbc49d04f558989362bfb6d3f273ce33ea9be36.zip
chromium_src-fdbc49d04f558989362bfb6d3f273ce33ea9be36.tar.gz
chromium_src-fdbc49d04f558989362bfb6d3f273ce33ea9be36.tar.bz2
[Bluetooth] Clean up code to extract a UUID from SDP data.
BUG=372495 TEST=none R=keybuk@chromium.org Review URL: https://codereview.chromium.org/317333002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275622 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--device/bluetooth/bluetooth_device_mac.mm40
1 files changed, 21 insertions, 19 deletions
diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm
index 1baa514..987ada0 100644
--- a/device/bluetooth/bluetooth_device_mac.mm
+++ b/device/bluetooth/bluetooth_device_mac.mm
@@ -12,7 +12,6 @@
#include "base/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "device/bluetooth/bluetooth_profile_mac.h"
#include "device/bluetooth/bluetooth_socket_mac.h"
@@ -27,10 +26,12 @@
outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level;
@end
+namespace device {
namespace {
-void ExtractUuid(IOBluetoothSDPDataElement* service_class_data,
- std::string* uuid) {
+// Returns the first (should be, only) UUID contained within the
+// |service_class_data|. Returns an invalid (empty) UUID if none is found.
+BluetoothUUID ExtractUuid(IOBluetoothSDPDataElement* service_class_data) {
NSArray* inner_elements = [service_class_data getArrayValue];
IOBluetoothSDPUUID* sdp_uuid = nil;
for (IOBluetoothSDPDataElement* inner_element in inner_elements) {
@@ -39,21 +40,22 @@ void ExtractUuid(IOBluetoothSDPDataElement* service_class_data,
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]);
- }
+
+ if (!sdp_uuid)
+ return BluetoothUUID();
+
+ const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]);
+ std::string uuid_str = base::HexEncode(uuid_bytes, 16);
+ DCHECK_EQ(uuid_str.size(), 32U);
+ uuid_str.insert(8, "-");
+ uuid_str.insert(13, "-");
+ uuid_str.insert(18, "-");
+ uuid_str.insert(23, "-");
+ return BluetoothUUID(uuid_str);
}
} // namespace
-namespace device {
-
BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device)
: device_([device retain]) {
}
@@ -144,14 +146,14 @@ bool BluetoothDeviceMac::IsConnecting() const {
BluetoothDevice::UUIDList BluetoothDeviceMac::GetUUIDs() const {
UUIDList uuids;
for (IOBluetoothSDPServiceRecord* service_record in [device_ services]) {
- const BluetoothSDPServiceAttributeID service_class_id = 1;
IOBluetoothSDPDataElement* service_class_data =
- [service_record getAttributeDataElement:service_class_id];
+ [service_record getAttributeDataElement:
+ kBluetoothSDPAttributeIdentifierServiceClassIDList];
if ([service_class_data getTypeDescriptor] ==
kBluetoothSDPDataElementTypeDataElementSequence) {
- std::string uuid_str;
- ExtractUuid(service_class_data, &uuid_str);
- uuids.push_back(BluetoothUUID(uuid_str));
+ BluetoothUUID uuid = ExtractUuid(service_class_data);
+ if (uuid.IsValid())
+ uuids.push_back(uuid);
}
}
return uuids;