Commit fdbc49d0 authored by isherman@chromium.org's avatar isherman@chromium.org

[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
parent 66580239
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "device/bluetooth/bluetooth_profile_mac.h" #include "device/bluetooth/bluetooth_profile_mac.h"
#include "device/bluetooth/bluetooth_socket_mac.h" #include "device/bluetooth/bluetooth_socket_mac.h"
...@@ -27,10 +26,12 @@ ...@@ -27,10 +26,12 @@
outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level; outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level;
@end @end
namespace device {
namespace { namespace {
void ExtractUuid(IOBluetoothSDPDataElement* service_class_data, // Returns the first (should be, only) UUID contained within the
std::string* uuid) { // |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]; NSArray* inner_elements = [service_class_data getArrayValue];
IOBluetoothSDPUUID* sdp_uuid = nil; IOBluetoothSDPUUID* sdp_uuid = nil;
for (IOBluetoothSDPDataElement* inner_element in inner_elements) { for (IOBluetoothSDPDataElement* inner_element in inner_elements) {
...@@ -39,21 +40,22 @@ void ExtractUuid(IOBluetoothSDPDataElement* service_class_data, ...@@ -39,21 +40,22 @@ void ExtractUuid(IOBluetoothSDPDataElement* service_class_data,
break; break;
} }
} }
if (sdp_uuid != nil) {
const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]); if (!sdp_uuid)
*uuid = base::StringPrintf( return BluetoothUUID();
"%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], const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]);
uuid_bytes[4], uuid_bytes[5], uuid_bytes[6], uuid_bytes[7], std::string uuid_str = base::HexEncode(uuid_bytes, 16);
uuid_bytes[8], uuid_bytes[9], uuid_bytes[10], uuid_bytes[11], DCHECK_EQ(uuid_str.size(), 32U);
uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]); uuid_str.insert(8, "-");
} uuid_str.insert(13, "-");
uuid_str.insert(18, "-");
uuid_str.insert(23, "-");
return BluetoothUUID(uuid_str);
} }
} // namespace } // namespace
namespace device {
BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device)
: device_([device retain]) { : device_([device retain]) {
} }
...@@ -144,14 +146,14 @@ bool BluetoothDeviceMac::IsConnecting() const { ...@@ -144,14 +146,14 @@ bool BluetoothDeviceMac::IsConnecting() const {
BluetoothDevice::UUIDList BluetoothDeviceMac::GetUUIDs() const { BluetoothDevice::UUIDList BluetoothDeviceMac::GetUUIDs() const {
UUIDList uuids; UUIDList uuids;
for (IOBluetoothSDPServiceRecord* service_record in [device_ services]) { for (IOBluetoothSDPServiceRecord* service_record in [device_ services]) {
const BluetoothSDPServiceAttributeID service_class_id = 1;
IOBluetoothSDPDataElement* service_class_data = IOBluetoothSDPDataElement* service_class_data =
[service_record getAttributeDataElement:service_class_id]; [service_record getAttributeDataElement:
kBluetoothSDPAttributeIdentifierServiceClassIDList];
if ([service_class_data getTypeDescriptor] == if ([service_class_data getTypeDescriptor] ==
kBluetoothSDPDataElementTypeDataElementSequence) { kBluetoothSDPDataElementTypeDataElementSequence) {
std::string uuid_str; BluetoothUUID uuid = ExtractUuid(service_class_data);
ExtractUuid(service_class_data, &uuid_str); if (uuid.IsValid())
uuids.push_back(BluetoothUUID(uuid_str)); uuids.push_back(uuid);
} }
} }
return uuids; return uuids;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment