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

Side by Side Diff: device/bluetooth/dbus/bluetooth_adapter_client.cc

Issue 2288823003: device/bluetooth: Fix Interger type for DBus message construction (Closed)
Patch Set: Use append varientOf... Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
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.
29 const BluetoothServiceAttributeValueBlueZ& attribute,
30 bool is_signed) {
31 int value;
32 attribute.value().GetAsInteger(&value);
33
34 switch (attribute.size()) {
35 case 1:
36 if (is_signed)
37 writer->AppendVariantOfByte(static_cast<int8_t>(value));
38 else
39 writer->AppendVariantOfByte(static_cast<uint8_t>(value));
40 break;
41 case 2:
42 if (is_signed)
43 writer->AppendVariantOfInt16(static_cast<int16_t>(value));
44 else
45 writer->AppendVariantOfUint16(static_cast<uint16_t>(value));
46 break;
47 case 4:
48 if (is_signed)
49 writer->AppendVariantOfInt32(static_cast<int32_t>(value));
50 else
51 writer->AppendVariantOfUint32(static_cast<uint32_t>(value));
52 break;
53 default:
54 NOTREACHED();
55 }
56 }
57
26 void WriteAttribute(dbus::MessageWriter* writer, 58 void WriteAttribute(dbus::MessageWriter* writer,
27 const BluetoothServiceAttributeValueBlueZ& attribute) { 59 const BluetoothServiceAttributeValueBlueZ& attribute) {
28 dbus::MessageWriter struct_writer(nullptr); 60 dbus::MessageWriter struct_writer(nullptr);
29 writer->OpenStruct(&struct_writer); 61 writer->OpenStruct(&struct_writer);
30 struct_writer.AppendByte(attribute.type()); 62 struct_writer.AppendByte(attribute.type());
31 struct_writer.AppendUint32(attribute.size()); 63 struct_writer.AppendUint32(attribute.size());
32 64
33 if (attribute.type() != BluetoothServiceAttributeValueBlueZ::SEQUENCE) { 65 switch (attribute.type()) {
34 dbus::AppendValueDataAsVariant(&struct_writer, attribute.value()); 66 case bluez::BluetoothServiceAttributeValueBlueZ::UINT:
35 } else { 67 WriteNumberAttribute(&struct_writer, attribute, false);
36 dbus::MessageWriter variant_writer(nullptr); 68 break;
37 dbus::MessageWriter array_writer(nullptr); 69 case bluez::BluetoothServiceAttributeValueBlueZ::INT:
38 struct_writer.OpenVariant("a(yuv)", &variant_writer); 70 WriteNumberAttribute(&struct_writer, attribute, true);
39 variant_writer.OpenArray("(yuv)", &array_writer); 71 break;
72 case bluez::BluetoothServiceAttributeValueBlueZ::BOOL:
73 case bluez::BluetoothServiceAttributeValueBlueZ::UUID:
74 case bluez::BluetoothServiceAttributeValueBlueZ::STRING:
75 case bluez::BluetoothServiceAttributeValueBlueZ::URL:
76 dbus::AppendValueDataAsVariant(&struct_writer, attribute.value());
77 break;
78 case BluetoothServiceAttributeValueBlueZ::SEQUENCE: {
79 dbus::MessageWriter variant_writer(nullptr);
80 dbus::MessageWriter array_writer(nullptr);
81 struct_writer.OpenVariant("a(yuv)", &variant_writer);
82 variant_writer.OpenArray("(yuv)", &array_writer);
40 83
41 for (const auto& v : attribute.sequence()) 84 for (const auto& v : attribute.sequence())
42 WriteAttribute(&array_writer, v); 85 WriteAttribute(&array_writer, v);
43 variant_writer.CloseContainer(&array_writer); 86 variant_writer.CloseContainer(&array_writer);
44 struct_writer.CloseContainer(&variant_writer); 87 struct_writer.CloseContainer(&variant_writer);
88 break;
89 }
90 case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE:
91 default:
92 NOTREACHED();
45 } 93 }
46 writer->CloseContainer(&struct_writer); 94 writer->CloseContainer(&struct_writer);
47 } 95 }
48 96
49 } // namespace 97 } // namespace
50 98
51 BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {} 99 BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {}
52 100
53 BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {} 101 BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {}
54 102
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 496
449 BluetoothAdapterClient::BluetoothAdapterClient() {} 497 BluetoothAdapterClient::BluetoothAdapterClient() {}
450 498
451 BluetoothAdapterClient::~BluetoothAdapterClient() {} 499 BluetoothAdapterClient::~BluetoothAdapterClient() {}
452 500
453 BluetoothAdapterClient* BluetoothAdapterClient::Create() { 501 BluetoothAdapterClient* BluetoothAdapterClient::Create() {
454 return new BluetoothAdapterClientImpl; 502 return new BluetoothAdapterClientImpl;
455 } 503 }
456 504
457 } // namespace bluez 505 } // namespace bluez
OLDNEW
« 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