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

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

Issue 1927803002: arc: bluetooth: Add gatt client functionality (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove std:move for temporary Created 4 years, 6 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 ada02b3f21434664088def53c6bee0172a1a73ba..4b545f92bc214bf6a2de98d172aede40299cbeaa 100644
--- a/components/arc/bluetooth/bluetooth_type_converters.cc
+++ b/components/arc/bluetooth/bluetooth_type_converters.cc
@@ -13,6 +13,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "components/arc/bluetooth/bluetooth_type_converters.h"
+#include "device/bluetooth/bluetooth_gatt_service.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "mojo/public/cpp/bindings/array.h"
@@ -83,4 +84,62 @@ TypeConverter<arc::mojom::BluetoothUUIDPtr, device::BluetoothUUID>::Convert(
return uuidp;
}
+// static
+device::BluetoothUUID
+TypeConverter<device::BluetoothUUID, arc::mojom::BluetoothUUIDPtr>::Convert(
+ const arc::mojom::BluetoothUUIDPtr& uuid) {
+ std::vector<uint8_t> address_bytes = uuid->uuid.To<std::vector<uint8_t>>();
+
+ // BluetoothUUID expects the format below with dash inserted.
palmer 2016/06/13 19:07:18 Typo: "...with the dashes inserted."
puthik_chromium 2016/06/13 20:50:26 Done.
+ // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ std::string uuid_str =
+ base::HexEncode(address_bytes.data(), address_bytes.size());
dcheng 2016/06/13 20:19:27 This can be sent from ARC right? We can't assume a
puthik_chromium 2016/06/13 20:50:26 The size is constant. Here is excerpt from mojom f
+ const int uuid_dash_pos[] = {8, 13, 18, 23};
palmer 2016/06/13 19:07:18 Nit: size_t, not int. (Note that string::insert ta
puthik_chromium 2016/06/13 20:50:26 Done.
+ for (auto& pos : uuid_dash_pos)
palmer 2016/06/13 19:07:18 Nit: Just auto, not auto&. Don't need to take a re
puthik_chromium 2016/06/13 20:50:26 Done.
+ uuid_str = uuid_str.insert(pos, "-");
+
+ device::BluetoothUUID result(uuid_str);
+
+ DCHECK(result.IsValid());
+ return result;
+}
+
+// static
+arc::mojom::BluetoothGattStatus
+TypeConverter<arc::mojom::BluetoothGattStatus,
+ device::BluetoothGattService::GattErrorCode>::
+ Convert(const device::BluetoothGattService::GattErrorCode& error_code) {
+ arc::mojom::BluetoothGattStatus ret;
+
+ switch (error_code) {
+ case device::BluetoothGattService::GattErrorCode::GATT_ERROR_INVALID_LENGTH:
+ ret = arc::mojom::BluetoothGattStatus::GATT_INVALID_ATTRIBUTE_LENGTH;
+ break;
+
+ case device::BluetoothGattService::GattErrorCode::GATT_ERROR_NOT_PERMITTED:
+ ret = arc::mojom::BluetoothGattStatus::GATT_READ_NOT_PERMITTED;
+ break;
+
+ case device::BluetoothGattService::GattErrorCode::GATT_ERROR_NOT_AUTHORIZED:
+ ret = arc::mojom::BluetoothGattStatus::GATT_INSUFFICIENT_AUTHENTICATION;
+ break;
+
+ case device::BluetoothGattService::GattErrorCode::GATT_ERROR_NOT_SUPPORTED:
+ ret = arc::mojom::BluetoothGattStatus::GATT_REQUEST_NOT_SUPPORTED;
+ break;
+
+ case device::BluetoothGattService::GattErrorCode::GATT_ERROR_UNKNOWN:
+ case device::BluetoothGattService::GattErrorCode::GATT_ERROR_FAILED:
+ case device::BluetoothGattService::GattErrorCode::GATT_ERROR_IN_PROGRESS:
+ case device::BluetoothGattService::GattErrorCode::GATT_ERROR_NOT_PAIRED:
+ ret = arc::mojom::BluetoothGattStatus::GATT_FAILURE;
+ break;
+
+ default:
+ ret = arc::mojom::BluetoothGattStatus::GATT_FAILURE;
+ break;
+ }
+ return ret;
+}
+
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698