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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 void WriteAttribute(dbus::MessageWriter* writer, | 26 void WriteAttribute(dbus::MessageWriter* writer, |
27 const BluetoothServiceAttributeValueBlueZ& attribute) { | 27 const BluetoothServiceAttributeValueBlueZ& attribute) { |
28 dbus::MessageWriter struct_writer(nullptr); | 28 dbus::MessageWriter struct_writer(nullptr); |
29 writer->OpenStruct(&struct_writer); | 29 writer->OpenStruct(&struct_writer); |
30 struct_writer.AppendByte(attribute.type()); | 30 struct_writer.AppendByte(attribute.type()); |
31 struct_writer.AppendUint32(attribute.size()); | 31 struct_writer.AppendUint32(attribute.size()); |
32 | 32 |
33 if (attribute.type() != BluetoothServiceAttributeValueBlueZ::SEQUENCE) { | 33 if (attribute.type() != BluetoothServiceAttributeValueBlueZ::SEQUENCE) { |
34 dbus::AppendValueDataAsVariant(&struct_writer, attribute.value()); | 34 dbus::AppendValueDataAsVariant(&struct_writer, attribute.value()); |
35 } else { | 35 } else { |
| 36 dbus::MessageWriter variant_writer(nullptr); |
36 dbus::MessageWriter array_writer(nullptr); | 37 dbus::MessageWriter array_writer(nullptr); |
37 struct_writer.OpenArray("v", &array_writer); | 38 struct_writer.OpenVariant("a(yuv)", &variant_writer); |
| 39 variant_writer.OpenArray("(yuv)", &array_writer); |
| 40 |
38 for (const auto& v : attribute.sequence()) | 41 for (const auto& v : attribute.sequence()) |
39 WriteAttribute(&array_writer, v); | 42 WriteAttribute(&array_writer, v); |
40 struct_writer.CloseContainer(&array_writer); | 43 variant_writer.CloseContainer(&array_writer); |
| 44 struct_writer.CloseContainer(&variant_writer); |
41 } | 45 } |
42 writer->CloseContainer(&struct_writer); | 46 writer->CloseContainer(&struct_writer); |
43 } | 47 } |
44 } | 48 |
| 49 } // namespace |
45 | 50 |
46 BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {} | 51 BluetoothAdapterClient::DiscoveryFilter::DiscoveryFilter() {} |
47 | 52 |
48 BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {} | 53 BluetoothAdapterClient::DiscoveryFilter::~DiscoveryFilter() {} |
49 | 54 |
50 void BluetoothAdapterClient::DiscoveryFilter::CopyFrom( | 55 void BluetoothAdapterClient::DiscoveryFilter::CopyFrom( |
51 const DiscoveryFilter& filter) { | 56 const DiscoveryFilter& filter) { |
52 if (filter.rssi.get()) | 57 if (filter.rssi.get()) |
53 rssi.reset(new int16_t(*filter.rssi)); | 58 rssi.reset(new int16_t(*filter.rssi)); |
54 else | 59 else |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 302 |
298 // BluetoothAdapterClient override. | 303 // BluetoothAdapterClient override. |
299 void CreateServiceRecord(const dbus::ObjectPath& object_path, | 304 void CreateServiceRecord(const dbus::ObjectPath& object_path, |
300 const bluez::BluetoothServiceRecordBlueZ& record, | 305 const bluez::BluetoothServiceRecordBlueZ& record, |
301 const ServiceRecordCallback& callback, | 306 const ServiceRecordCallback& callback, |
302 const ErrorCallback& error_callback) override { | 307 const ErrorCallback& error_callback) override { |
303 dbus::MethodCall method_call(bluetooth_adapter::kBluetoothAdapterInterface, | 308 dbus::MethodCall method_call(bluetooth_adapter::kBluetoothAdapterInterface, |
304 bluetooth_adapter::kCreateServiceRecord); | 309 bluetooth_adapter::kCreateServiceRecord); |
305 | 310 |
306 dbus::MessageWriter writer(&method_call); | 311 dbus::MessageWriter writer(&method_call); |
| 312 dbus::MessageWriter array_writer(&method_call); |
307 dbus::MessageWriter dict_entry_writer(nullptr); | 313 dbus::MessageWriter dict_entry_writer(nullptr); |
| 314 writer.OpenArray("{q(yuv)}", &array_writer); |
308 for (auto attribute_id : record.GetAttributeIds()) { | 315 for (auto attribute_id : record.GetAttributeIds()) { |
309 writer.OpenDictEntry(&dict_entry_writer); | 316 array_writer.OpenDictEntry(&dict_entry_writer); |
310 dict_entry_writer.AppendUint16(attribute_id); | 317 dict_entry_writer.AppendUint16(attribute_id); |
311 const BluetoothServiceAttributeValueBlueZ& attribute_value = | 318 const BluetoothServiceAttributeValueBlueZ& attribute_value = |
312 record.GetAttributeValue(attribute_id); | 319 record.GetAttributeValue(attribute_id); |
313 WriteAttribute(&dict_entry_writer, attribute_value); | 320 WriteAttribute(&dict_entry_writer, attribute_value); |
| 321 array_writer.CloseContainer(&dict_entry_writer); |
314 } | 322 } |
| 323 writer.CloseContainer(&array_writer); |
315 | 324 |
316 dbus::ObjectProxy* object_proxy = | 325 dbus::ObjectProxy* object_proxy = |
317 object_manager_->GetObjectProxy(object_path); | 326 object_manager_->GetObjectProxy(object_path); |
318 if (!object_proxy) { | 327 if (!object_proxy) { |
319 error_callback.Run(kUnknownAdapterError, ""); | 328 error_callback.Run(kUnknownAdapterError, ""); |
320 return; | 329 return; |
321 } | 330 } |
322 | 331 |
323 object_proxy->CallMethodWithErrorCallback( | 332 object_proxy->CallMethodWithErrorCallback( |
324 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 333 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 448 |
440 BluetoothAdapterClient::BluetoothAdapterClient() {} | 449 BluetoothAdapterClient::BluetoothAdapterClient() {} |
441 | 450 |
442 BluetoothAdapterClient::~BluetoothAdapterClient() {} | 451 BluetoothAdapterClient::~BluetoothAdapterClient() {} |
443 | 452 |
444 BluetoothAdapterClient* BluetoothAdapterClient::Create() { | 453 BluetoothAdapterClient* BluetoothAdapterClient::Create() { |
445 return new BluetoothAdapterClientImpl; | 454 return new BluetoothAdapterClientImpl; |
446 } | 455 } |
447 | 456 |
448 } // namespace bluez | 457 } // namespace bluez |
OLD | NEW |