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

Unified Diff: device/bluetooth/dbus/bluetooth_adapter_client.cc

Issue 2288823003: device/bluetooth: Fix Interger type for DBus message construction (Closed)
Patch Set: Add todo 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/dbus/bluetooth_adapter_client.cc
diff --git a/device/bluetooth/dbus/bluetooth_adapter_client.cc b/device/bluetooth/dbus/bluetooth_adapter_client.cc
index 884c1bbf2d46b271fceda3045edd6b3b4ea41fae..d763696d7453be33b34b2634d7d488e7f3a2b62d 100644
--- a/device/bluetooth/dbus/bluetooth_adapter_client.cc
+++ b/device/bluetooth/dbus/bluetooth_adapter_client.cc
@@ -4,6 +4,8 @@
#include "device/bluetooth/dbus/bluetooth_adapter_client.h"
+#include <string>
+
#include "base/bind.h"
#include "base/callback.h"
#include "base/logging.h"
@@ -23,6 +25,37 @@ namespace bluez {
namespace {
+// TODO(rkc) Find better way to do this.
+void WriteNumberAttribute(dbus::MessageWriter* writer,
+ const BluetoothServiceAttributeValueBlueZ& attribute,
+ bool is_signed) {
+ int value;
+ attribute.value().GetAsInteger(&value);
+
+ switch (attribute.size()) {
+ case 1:
+ if (is_signed)
+ writer->AppendVariantOfByte(static_cast<int8_t>(value));
+ else
+ writer->AppendVariantOfByte(static_cast<uint8_t>(value));
+ break;
+ case 2:
+ if (is_signed)
+ writer->AppendVariantOfInt16(static_cast<int16_t>(value));
+ else
+ writer->AppendVariantOfUint16(static_cast<uint16_t>(value));
+ break;
+ case 4:
+ if (is_signed)
+ writer->AppendVariantOfInt32(static_cast<int32_t>(value));
+ else
+ writer->AppendVariantOfUint32(static_cast<uint32_t>(value));
+ break;
+ default:
+ NOTREACHED();
+ }
+}
+
void WriteAttribute(dbus::MessageWriter* writer,
const BluetoothServiceAttributeValueBlueZ& attribute) {
dbus::MessageWriter struct_writer(nullptr);
@@ -30,18 +63,34 @@ void WriteAttribute(dbus::MessageWriter* writer,
struct_writer.AppendByte(attribute.type());
struct_writer.AppendUint32(attribute.size());
- if (attribute.type() != BluetoothServiceAttributeValueBlueZ::SEQUENCE) {
- dbus::AppendValueDataAsVariant(&struct_writer, attribute.value());
- } else {
- dbus::MessageWriter variant_writer(nullptr);
- dbus::MessageWriter array_writer(nullptr);
- struct_writer.OpenVariant("a(yuv)", &variant_writer);
- variant_writer.OpenArray("(yuv)", &array_writer);
-
- for (const auto& v : attribute.sequence())
- WriteAttribute(&array_writer, v);
- variant_writer.CloseContainer(&array_writer);
- struct_writer.CloseContainer(&variant_writer);
+ switch (attribute.type()) {
+ case bluez::BluetoothServiceAttributeValueBlueZ::UINT:
+ WriteNumberAttribute(&struct_writer, attribute, false);
+ break;
+ case bluez::BluetoothServiceAttributeValueBlueZ::INT:
+ WriteNumberAttribute(&struct_writer, attribute, true);
+ break;
+ case bluez::BluetoothServiceAttributeValueBlueZ::BOOL:
+ case bluez::BluetoothServiceAttributeValueBlueZ::UUID:
+ case bluez::BluetoothServiceAttributeValueBlueZ::STRING:
+ case bluez::BluetoothServiceAttributeValueBlueZ::URL:
+ dbus::AppendValueDataAsVariant(&struct_writer, attribute.value());
+ break;
+ case BluetoothServiceAttributeValueBlueZ::SEQUENCE: {
+ dbus::MessageWriter variant_writer(nullptr);
+ dbus::MessageWriter array_writer(nullptr);
+ struct_writer.OpenVariant("a(yuv)", &variant_writer);
+ variant_writer.OpenArray("(yuv)", &array_writer);
+
+ for (const auto& v : attribute.sequence())
+ WriteAttribute(&array_writer, v);
+ variant_writer.CloseContainer(&array_writer);
+ struct_writer.CloseContainer(&variant_writer);
+ break;
+ }
+ case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE:
+ default:
+ NOTREACHED();
}
writer->CloseContainer(&struct_writer);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698