Chromium Code Reviews| 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..f48431e3804501ec136d5c91c074a243436eb2d4 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,36 @@ namespace bluez { |
| namespace { |
| +void WriteNumberAttribute(dbus::MessageWriter* writer, |
|
Rahul Chaturvedi
2016/08/30 05:35:37
Nit: Add a TODO(rkc) here to find a better way to
puthik_chromium
2016/08/30 06:05:32
Done.
|
| + 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 +62,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); |
| } |