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

Unified Diff: components/arc/bluetooth/bluetooth_type_converters.cc

Issue 2149713002: arc: bluetooth: Add SDP host side support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rewind to the previous approach using generic attribute and type converter Created 4 years, 4 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: components/arc/bluetooth/bluetooth_type_converters.cc
diff --git a/components/arc/bluetooth/bluetooth_type_converters.cc b/components/arc/bluetooth/bluetooth_type_converters.cc
index f91139d0434d9b248e64f0b3e9456cfd2ea3c44a..8e46c183c6581a2879a16b87d36175929845e67d 100644
--- a/components/arc/bluetooth/bluetooth_type_converters.cc
+++ b/components/arc/bluetooth/bluetooth_type_converters.cc
@@ -6,6 +6,7 @@
#include <cctype>
#include <iomanip>
#include <ios>
+#include <memory>
#include <sstream>
#include <string>
#include <vector>
@@ -23,6 +24,13 @@ constexpr size_t kAddressSize = 6;
constexpr size_t kUUIDSize = 16;
constexpr char kInvalidAddress[] = "00:00:00:00:00:00";
+// SDP Service attribute IDs.
+constexpr uint16_t kServiceClassIDList = 0x0001;
+constexpr uint16_t kProtocolDescriptorList = 0x0004;
+constexpr uint16_t kBrowseGroupList = 0x0005;
+constexpr uint16_t kBluetoothProfileDescriptorList = 0x0009;
+constexpr uint16_t kServiceName = 0x0100;
+
bool IsNonHex(char c) {
return !isxdigit(c);
}
@@ -35,6 +43,8 @@ std::string StripNonHex(const std::string& str) {
return result;
}
+constexpr int BLUETOOTH_SDP_MAX_LAYER = 32;
+
} // namespace
namespace mojo {
@@ -150,4 +160,146 @@ TypeConverter<arc::mojom::BluetoothGattStatus,
return ret;
}
+// static
+arc::mojom::BluetoothSdpAttributePtr
+TypeConverter<arc::mojom::BluetoothSdpAttributePtr,
+ bluez::BluetoothServiceAttributeValueBlueZ>::
+ Convert(const bluez::BluetoothServiceAttributeValueBlueZ& attr_bluez,
+ int layer) {
+ auto result = arc::mojom::BluetoothSdpAttribute::New();
+ result->type = attr_bluez.type();
+ result->type_size = 0;
+
+ switch (result->type) {
+ case bluez::BluetoothServiceAttributeValueBlueZ::Type::NULLTYPE:
+ break;
+ case bluez::BluetoothServiceAttributeValueBlueZ::Type::UINT:
+ case bluez::BluetoothServiceAttributeValueBlueZ::Type::INT:
+ case bluez::BluetoothServiceAttributeValueBlueZ::Type::UUID:
+ case bluez::BluetoothServiceAttributeValueBlueZ::Type::STRING:
+ case bluez::BluetoothServiceAttributeValueBlueZ::Type::URL:
+ case bluez::BluetoothServiceAttributeValueBlueZ::Type::BOOL: {
puthik_chromium 2016/08/28 00:05:39 nit: Remove brace.
Miao 2016/09/01 18:37:24 Done.
+ result->type_size = attr_bluez.size();
+ result->value->Append(attr_bluez.value().DeepCopy());
+ break;
+ }
+ case bluez::BluetoothServiceAttributeValueBlueZ::Type::SEQUENCE:
+ if (layer + 1 >= BLUETOOTH_SDP_MAX_LAYER) {
+ NOTREACHED();
+ return result;
+ }
+ result->type_size = result->sequence.size();
rickyz (no longer on Chrome) 2016/08/29 00:48:06 Is this correct? This will always be zero. This co
Miao 2016/09/01 18:37:24 Done.
+ for (auto& child : attr_bluez.sequence()) {
puthik_chromium 2016/08/28 00:05:39 const auto &
Miao 2016/09/01 18:37:24 Done.
+ result->sequence.push_back(Convert(child, layer + 1));
+ }
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ return result;
+}
+
+// static
+bluez::BluetoothServiceAttributeValueBlueZ
+TypeConverter<bluez::BluetoothServiceAttributeValueBlueZ,
+ arc::mojom::BluetoothSdpAttributePtr>::
+ Convert(const arc::mojom::BluetoothSdpAttributePtr& attr, int layer) {
+ bluez::BluetoothServiceAttributeValueBlueZ::Type type = attr->type;
+ std::unique_ptr<base::Value> value;
rickyz (no longer on Chrome) 2016/08/29 00:48:06 not used
Miao 2016/09/01 18:37:24 Done.
+
+ switch (type) {
+ case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE:
+ return bluez::BluetoothServiceAttributeValueBlueZ();
+ break;
rickyz (no longer on Chrome) 2016/08/29 00:48:06 break is not needed after return here and below.
Miao 2016/09/01 18:37:24 Done.
+ case bluez::BluetoothServiceAttributeValueBlueZ::UINT:
+ case bluez::BluetoothServiceAttributeValueBlueZ::INT:
+ case bluez::BluetoothServiceAttributeValueBlueZ::UUID:
+ case bluez::BluetoothServiceAttributeValueBlueZ::STRING:
+ case bluez::BluetoothServiceAttributeValueBlueZ::URL:
+ case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: {
+ std::unique_ptr<base::Value> value;
+ attr->value->Remove(0, &value);
rickyz (no longer on Chrome) 2016/08/29 00:48:06 If the ListValue has 0 elements, this will constru
Miao 2016/09/01 18:37:24 Done.
+
+ return bluez::BluetoothServiceAttributeValueBlueZ(
+ type, static_cast<size_t>(attr->type_size), std::move(value));
+ break;
+ }
+ case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: {
+ if (layer + 1 >= BLUETOOTH_SDP_MAX_LAYER || !attr->sequence ||
+ attr->sequence.size() == 0) {
+ NOTREACHED();
+ return bluez::BluetoothServiceAttributeValueBlueZ(
+ type, 0, base::Value::CreateNullValue());
+ }
+ auto bluez_sequence = base::MakeUnique<
+ bluez::BluetoothServiceAttributeValueBlueZ::Sequence>();
+ for (auto& child : attr->sequence) {
puthik_chromium 2016/08/28 00:05:39 const auto &
Miao 2016/09/01 18:37:24 Done.
+ bluez_sequence->push_back(Convert(child, layer + 1));
+ }
+ return bluez::BluetoothServiceAttributeValueBlueZ(
+ std::move(bluez_sequence));
+ break;
+ }
+ default:
+ NOTREACHED();
+ }
+ return bluez::BluetoothServiceAttributeValueBlueZ(
+ type, 0, base::Value::CreateNullValue());
+}
+
+// static
+arc::mojom::BluetoothSdpRecordPtr
+TypeConverter<arc::mojom::BluetoothSdpRecordPtr,
+ bluez::BluetoothServiceRecordBlueZ>::
+ Convert(const bluez::BluetoothServiceRecordBlueZ& record_bluez) {
+ arc::mojom::BluetoothSdpRecordPtr result =
+ arc::mojom::BluetoothSdpRecord::New();
+
+ for (auto id : record_bluez.GetAttributeIds()) {
+ switch (id) {
+ case kServiceClassIDList:
+ case kProtocolDescriptorList:
+ case kBrowseGroupList:
+ case kBluetoothProfileDescriptorList:
+ case kServiceName:
+ result->attrs[id] = arc::mojom::BluetoothSdpAttribute::From(
+ record_bluez.GetAttributeValue(id));
+ break;
+ default:
+ // Android does not support this.
+ break;
+ }
+ }
+
+ return result;
+}
+
+// static
+bluez::BluetoothServiceRecordBlueZ
+TypeConverter<bluez::BluetoothServiceRecordBlueZ,
+ arc::mojom::BluetoothSdpRecordPtr>::
+ Convert(const arc::mojom::BluetoothSdpRecordPtr& record) {
+ bluez::BluetoothServiceRecordBlueZ record_bluez;
+
+ for (const auto& pair : record->attrs) {
+ switch (pair.first) {
+ case kServiceClassIDList:
+ case kProtocolDescriptorList:
+ case kBrowseGroupList:
+ case kBluetoothProfileDescriptorList:
+ case kServiceName:
+ record_bluez.AddRecordEntry(
+ pair.first,
+ pair.second.To<bluez::BluetoothServiceAttributeValueBlueZ>());
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ }
+
+ return record_bluez;
+}
+
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698