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

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: refactor gatt permission to a const 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
« no previous file with comments | « components/arc/bluetooth/bluetooth_type_converters.h ('k') | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..af2e08b33ca1f97508d528d0c968156dc09906fb 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 the dashes inserted.
+ // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ std::string uuid_str =
+ base::HexEncode(address_bytes.data(), address_bytes.size());
+ const size_t uuid_dash_pos[] = {8, 13, 18, 23};
+ for (auto pos : uuid_dash_pos)
+ 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
« no previous file with comments | « components/arc/bluetooth/bluetooth_type_converters.h ('k') | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698