| 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 // TODO(rkc) Find better way to do this. |
| 29 void WriteNumberAttribute(dbus::MessageWriter* writer, |
| 30 const BluetoothServiceAttributeValueBlueZ& attribute, |
| 31 bool is_signed) { |
| 32 int value; |
| 33 attribute.value().GetAsInteger(&value); |
| 34 |
| 35 switch (attribute.size()) { |
| 36 case 1: |
| 37 if (is_signed) |
| 38 writer->AppendVariantOfByte(static_cast<int8_t>(value)); |
| 39 else |
| 40 writer->AppendVariantOfByte(static_cast<uint8_t>(value)); |
| 41 break; |
| 42 case 2: |
| 43 if (is_signed) |
| 44 writer->AppendVariantOfInt16(static_cast<int16_t>(value)); |
| 45 else |
| 46 writer->AppendVariantOfUint16(static_cast<uint16_t>(value)); |
| 47 break; |
| 48 case 4: |
| 49 if (is_signed) |
| 50 writer->AppendVariantOfInt32(static_cast<int32_t>(value)); |
| 51 else |
| 52 writer->AppendVariantOfUint32(static_cast<uint32_t>(value)); |
| 53 break; |
| 54 default: |
| 55 NOTREACHED(); |
| 56 } |
| 57 } |
| 58 |
| 26 void WriteAttribute(dbus::MessageWriter* writer, | 59 void WriteAttribute(dbus::MessageWriter* writer, |
| 27 const BluetoothServiceAttributeValueBlueZ& attribute) { | 60 const BluetoothServiceAttributeValueBlueZ& attribute) { |
| 28 dbus::MessageWriter struct_writer(nullptr); | 61 dbus::MessageWriter struct_writer(nullptr); |
| 29 writer->OpenStruct(&struct_writer); | 62 writer->OpenStruct(&struct_writer); |
| 30 struct_writer.AppendByte(attribute.type()); | 63 struct_writer.AppendByte(attribute.type()); |
| 31 struct_writer.AppendUint32(attribute.size()); | 64 struct_writer.AppendUint32(attribute.size()); |
| 32 | 65 |
| 33 if (attribute.type() != BluetoothServiceAttributeValueBlueZ::SEQUENCE) { | 66 switch (attribute.type()) { |
| 34 dbus::AppendValueDataAsVariant(&struct_writer, attribute.value()); | 67 case bluez::BluetoothServiceAttributeValueBlueZ::UINT: |
| 35 } else { | 68 WriteNumberAttribute(&struct_writer, attribute, false); |
| 36 dbus::MessageWriter variant_writer(nullptr); | 69 break; |
| 37 dbus::MessageWriter array_writer(nullptr); | 70 case bluez::BluetoothServiceAttributeValueBlueZ::INT: |
| 38 struct_writer.OpenVariant("a(yuv)", &variant_writer); | 71 WriteNumberAttribute(&struct_writer, attribute, true); |
| 39 variant_writer.OpenArray("(yuv)", &array_writer); | 72 break; |
| 73 case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: |
| 74 case bluez::BluetoothServiceAttributeValueBlueZ::UUID: |
| 75 case bluez::BluetoothServiceAttributeValueBlueZ::STRING: |
| 76 case bluez::BluetoothServiceAttributeValueBlueZ::URL: |
| 77 dbus::AppendValueDataAsVariant(&struct_writer, attribute.value()); |
| 78 break; |
| 79 case BluetoothServiceAttributeValueBlueZ::SEQUENCE: { |
| 80 dbus::MessageWriter variant_writer(nullptr); |
| 81 dbus::MessageWriter array_writer(nullptr); |
| 82 struct_writer.OpenVariant("a(yuv)", &variant_writer); |
| 83 variant_writer.OpenArray("(yuv)", &array_writer); |
| 40 | 84 |
| 41 for (const auto& v : attribute.sequence()) | 85 for (const auto& v : attribute.sequence()) |
| 42 WriteAttribute(&array_writer, v); | 86 WriteAttribute(&array_writer, v); |
| 43 variant_writer.CloseContainer(&array_writer); | 87 variant_writer.CloseContainer(&array_writer); |
| 44 struct_writer.CloseContainer(&variant_writer); | 88 struct_writer.CloseContainer(&variant_writer); |
| 89 break; |
| 90 } |
| 91 case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE: |
| 92 default: |
| 93 NOTREACHED(); |
| 45 } | 94 } |
| 46 writer->CloseContainer(&struct_writer); | 95 writer->CloseContainer(&struct_writer); |
| 47 } | 96 } |
| 48 | 97 |
| 49 } // namespace | 98 } // namespace |
| 50 | 99 |
| 51 BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {} | 100 BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {} |
| 52 | 101 |
| 53 BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {} | 102 BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {} |
| 54 | 103 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 497 |
| 449 BluetoothAdapterClient::BluetoothAdapterClient() {} | 498 BluetoothAdapterClient::BluetoothAdapterClient() {} |
| 450 | 499 |
| 451 BluetoothAdapterClient::~BluetoothAdapterClient() {} | 500 BluetoothAdapterClient::~BluetoothAdapterClient() {} |
| 452 | 501 |
| 453 BluetoothAdapterClient* BluetoothAdapterClient::Create() { | 502 BluetoothAdapterClient* BluetoothAdapterClient::Create() { |
| 454 return new BluetoothAdapterClientImpl; | 503 return new BluetoothAdapterClientImpl; |
| 455 } | 504 } |
| 456 | 505 |
| 457 } // namespace bluez | 506 } // namespace bluez |
| OLD | NEW |