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

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

Issue 2288823003: device/bluetooth: Fix Interger type for DBus message construction (Closed)
Patch Set: 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..65044f587da4173b972ed628011ce22964290074 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,51 @@ namespace bluez {
namespace {
+void WriteNumberAttribute(dbus::MessageWriter* writer,
+ const BluetoothServiceAttributeValueBlueZ& attribute,
+ bool is_signed) {
+ dbus::MessageWriter variant_writer(nullptr);
+ int value;
+
+ attribute.value().GetAsInteger(&value);
+
+ switch (attribute.size()) {
+ case 1:
+ writer->OpenVariant(std::string(1, dbus::Message::DataType::BYTE),
Rahul Chaturvedi 2016/08/29 22:00:29 Instead of doing OpenVariant, then Append and Clos
puthik_chromium 2016/08/29 22:17:10 Done. Forgot that we have those API.
+ &variant_writer);
+ if (is_signed)
+ variant_writer.AppendByte(static_cast<int8_t>(value));
+ else
+ variant_writer.AppendByte(static_cast<uint8_t>(value));
+ break;
+ case 2:
+ if (is_signed) {
+ writer->OpenVariant(std::string(1, dbus::Message::DataType::INT16),
+ &variant_writer);
+ variant_writer.AppendInt16(static_cast<int16_t>(value));
+ } else {
+ writer->OpenVariant(std::string(1, dbus::Message::DataType::UINT16),
+ &variant_writer);
+ variant_writer.AppendUint16(static_cast<uint16_t>(value));
+ }
+ break;
+ case 4:
+ if (is_signed) {
+ writer->OpenVariant(std::string(1, dbus::Message::DataType::INT32),
+ &variant_writer);
+ variant_writer.AppendInt32(static_cast<int32_t>(value));
+ } else {
+ writer->OpenVariant(std::string(1, dbus::Message::DataType::UINT32),
+ &variant_writer);
+ variant_writer.AppendUint32(static_cast<uint32_t>(value));
+ }
+ break;
+ default:
+ NOTREACHED();
+ }
+ writer->CloseContainer(&variant_writer);
+}
+
void WriteAttribute(dbus::MessageWriter* writer,
const BluetoothServiceAttributeValueBlueZ& attribute) {
dbus::MessageWriter struct_writer(nullptr);
@@ -30,18 +77,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