Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" | 5 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 12 #include "base/values.h" | 14 #include "base/values.h" |
| 13 #include "dbus/bus.h" | 15 #include "dbus/bus.h" |
| 14 #include "dbus/message.h" | 16 #include "dbus/message.h" |
| 15 #include "dbus/object_manager.h" | 17 #include "dbus/object_manager.h" |
| 16 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
| 17 #include "dbus/values_util.h" | 19 #include "dbus/values_util.h" |
| 18 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" | 20 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" |
| 19 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h" | 21 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h" |
| 20 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 21 | 23 |
| 22 namespace bluez { | 24 namespace bluez { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 28 void WriteNumberAttribute(dbus::MessageWriter* writer, | |
| 29 const BluetoothServiceAttributeValueBlueZ& attribute, | |
| 30 bool is_signed) { | |
| 31 dbus::MessageWriter variant_writer(nullptr); | |
| 32 int value; | |
| 33 | |
| 34 attribute.value().GetAsInteger(&value); | |
| 35 | |
| 36 switch (attribute.size()) { | |
| 37 case 1: | |
| 38 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.
| |
| 39 &variant_writer); | |
| 40 if (is_signed) | |
| 41 variant_writer.AppendByte(static_cast<int8_t>(value)); | |
| 42 else | |
| 43 variant_writer.AppendByte(static_cast<uint8_t>(value)); | |
| 44 break; | |
| 45 case 2: | |
| 46 if (is_signed) { | |
| 47 writer->OpenVariant(std::string(1, dbus::Message::DataType::INT16), | |
| 48 &variant_writer); | |
| 49 variant_writer.AppendInt16(static_cast<int16_t>(value)); | |
| 50 } else { | |
| 51 writer->OpenVariant(std::string(1, dbus::Message::DataType::UINT16), | |
| 52 &variant_writer); | |
| 53 variant_writer.AppendUint16(static_cast<uint16_t>(value)); | |
| 54 } | |
| 55 break; | |
| 56 case 4: | |
| 57 if (is_signed) { | |
| 58 writer->OpenVariant(std::string(1, dbus::Message::DataType::INT32), | |
| 59 &variant_writer); | |
| 60 variant_writer.AppendInt32(static_cast<int32_t>(value)); | |
| 61 } else { | |
| 62 writer->OpenVariant(std::string(1, dbus::Message::DataType::UINT32), | |
| 63 &variant_writer); | |
| 64 variant_writer.AppendUint32(static_cast<uint32_t>(value)); | |
| 65 } | |
| 66 break; | |
| 67 default: | |
| 68 NOTREACHED(); | |
| 69 } | |
| 70 writer->CloseContainer(&variant_writer); | |
| 71 } | |
| 72 | |
| 26 void WriteAttribute(dbus::MessageWriter* writer, | 73 void WriteAttribute(dbus::MessageWriter* writer, |
| 27 const BluetoothServiceAttributeValueBlueZ& attribute) { | 74 const BluetoothServiceAttributeValueBlueZ& attribute) { |
| 28 dbus::MessageWriter struct_writer(nullptr); | 75 dbus::MessageWriter struct_writer(nullptr); |
| 29 writer->OpenStruct(&struct_writer); | 76 writer->OpenStruct(&struct_writer); |
| 30 struct_writer.AppendByte(attribute.type()); | 77 struct_writer.AppendByte(attribute.type()); |
| 31 struct_writer.AppendUint32(attribute.size()); | 78 struct_writer.AppendUint32(attribute.size()); |
| 32 | 79 |
| 33 if (attribute.type() != BluetoothServiceAttributeValueBlueZ::SEQUENCE) { | 80 switch (attribute.type()) { |
| 34 dbus::AppendValueDataAsVariant(&struct_writer, attribute.value()); | 81 case bluez::BluetoothServiceAttributeValueBlueZ::UINT: |
| 35 } else { | 82 WriteNumberAttribute(&struct_writer, attribute, false); |
| 36 dbus::MessageWriter variant_writer(nullptr); | 83 break; |
| 37 dbus::MessageWriter array_writer(nullptr); | 84 case bluez::BluetoothServiceAttributeValueBlueZ::INT: |
| 38 struct_writer.OpenVariant("a(yuv)", &variant_writer); | 85 WriteNumberAttribute(&struct_writer, attribute, true); |
| 39 variant_writer.OpenArray("(yuv)", &array_writer); | 86 break; |
| 87 case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: | |
| 88 case bluez::BluetoothServiceAttributeValueBlueZ::UUID: | |
| 89 case bluez::BluetoothServiceAttributeValueBlueZ::STRING: | |
| 90 case bluez::BluetoothServiceAttributeValueBlueZ::URL: | |
| 91 dbus::AppendValueDataAsVariant(&struct_writer, attribute.value()); | |
| 92 break; | |
| 93 case BluetoothServiceAttributeValueBlueZ::SEQUENCE: { | |
| 94 dbus::MessageWriter variant_writer(nullptr); | |
| 95 dbus::MessageWriter array_writer(nullptr); | |
| 96 struct_writer.OpenVariant("a(yuv)", &variant_writer); | |
| 97 variant_writer.OpenArray("(yuv)", &array_writer); | |
| 40 | 98 |
| 41 for (const auto& v : attribute.sequence()) | 99 for (const auto& v : attribute.sequence()) |
| 42 WriteAttribute(&array_writer, v); | 100 WriteAttribute(&array_writer, v); |
| 43 variant_writer.CloseContainer(&array_writer); | 101 variant_writer.CloseContainer(&array_writer); |
| 44 struct_writer.CloseContainer(&variant_writer); | 102 struct_writer.CloseContainer(&variant_writer); |
| 103 break; | |
| 104 } | |
| 105 case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE: | |
| 106 default: | |
| 107 NOTREACHED(); | |
| 45 } | 108 } |
| 46 writer->CloseContainer(&struct_writer); | 109 writer->CloseContainer(&struct_writer); |
| 47 } | 110 } |
| 48 | 111 |
| 49 } // namespace | 112 } // namespace |
| 50 | 113 |
| 51 BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {} | 114 BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {} |
| 52 | 115 |
| 53 BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {} | 116 BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {} |
| 54 | 117 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 | 511 |
| 449 BluetoothAdapterClient::BluetoothAdapterClient() {} | 512 BluetoothAdapterClient::BluetoothAdapterClient() {} |
| 450 | 513 |
| 451 BluetoothAdapterClient::~BluetoothAdapterClient() {} | 514 BluetoothAdapterClient::~BluetoothAdapterClient() {} |
| 452 | 515 |
| 453 BluetoothAdapterClient* BluetoothAdapterClient::Create() { | 516 BluetoothAdapterClient* BluetoothAdapterClient::Create() { |
| 454 return new BluetoothAdapterClientImpl; | 517 return new BluetoothAdapterClientImpl; |
| 455 } | 518 } |
| 456 | 519 |
| 457 } // namespace bluez | 520 } // namespace bluez |
| OLD | NEW |