OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/fake_bluetooth_device_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 incoming_pairing_simulation_step_ = 0; | 664 incoming_pairing_simulation_step_ = 0; |
665 } | 665 } |
666 | 666 |
667 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { | 667 void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { |
668 simulation_interval_ms_ = interval_ms; | 668 simulation_interval_ms_ = interval_ms; |
669 } | 669 } |
670 | 670 |
671 void FakeBluetoothDeviceClient::CreateDevice( | 671 void FakeBluetoothDeviceClient::CreateDevice( |
672 const dbus::ObjectPath& adapter_path, | 672 const dbus::ObjectPath& adapter_path, |
673 const dbus::ObjectPath& device_path) { | 673 const dbus::ObjectPath& device_path) { |
674 if (std::find(device_list_.begin(), device_list_.end(), device_path) != | 674 if (base::ContainsValue(device_list_, device_path)) |
675 device_list_.end()) | |
676 return; | 675 return; |
677 | 676 |
678 std::unique_ptr<Properties> properties( | 677 std::unique_ptr<Properties> properties( |
679 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | 678 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
680 base::Unretained(this), device_path))); | 679 base::Unretained(this), device_path))); |
681 properties->adapter.ReplaceValue(adapter_path); | 680 properties->adapter.ReplaceValue(adapter_path); |
682 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeBredr); | 681 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeBredr); |
683 properties->type.set_valid(true); | 682 properties->type.set_valid(true); |
684 | 683 |
685 if (device_path == dbus::ObjectPath(kLegacyAutopairPath)) { | 684 if (device_path == dbus::ObjectPath(kLegacyAutopairPath)) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 device_list_.push_back(device_path); | 799 device_list_.push_back(device_path); |
801 | 800 |
802 for (auto& observer : observers_) | 801 for (auto& observer : observers_) |
803 observer.DeviceAdded(device_path); | 802 observer.DeviceAdded(device_path); |
804 } | 803 } |
805 | 804 |
806 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( | 805 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( |
807 const dbus::ObjectPath& adapter_path, | 806 const dbus::ObjectPath& adapter_path, |
808 const IncomingDeviceProperties& props) { | 807 const IncomingDeviceProperties& props) { |
809 dbus::ObjectPath device_path(props.device_path); | 808 dbus::ObjectPath device_path(props.device_path); |
810 if (std::find(device_list_.begin(), device_list_.end(), device_path) != | 809 if (base::ContainsValue(device_list_, device_path)) |
811 device_list_.end()) | |
812 return; | 810 return; |
813 | 811 |
814 std::unique_ptr<Properties> properties( | 812 std::unique_ptr<Properties> properties( |
815 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | 813 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
816 base::Unretained(this), device_path))); | 814 base::Unretained(this), device_path))); |
817 properties->adapter.ReplaceValue(adapter_path); | 815 properties->adapter.ReplaceValue(adapter_path); |
818 properties->name.ReplaceValue(props.device_name); | 816 properties->name.ReplaceValue(props.device_name); |
819 properties->name.set_valid(true); | 817 properties->name.set_valid(true); |
820 properties->alias.ReplaceValue(props.device_alias); | 818 properties->alias.ReplaceValue(props.device_alias); |
821 properties->address.ReplaceValue(props.device_address); | 819 properties->address.ReplaceValue(props.device_address); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1814 device::BluetoothTransport type, | 1812 device::BluetoothTransport type, |
1815 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) { | 1813 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) { |
1816 // Create a random device path. | 1814 // Create a random device path. |
1817 dbus::ObjectPath device_path; | 1815 dbus::ObjectPath device_path; |
1818 std::string id; | 1816 std::string id; |
1819 do { | 1817 do { |
1820 // Construct an id that is valid according to the DBUS specification. | 1818 // Construct an id that is valid according to the DBUS specification. |
1821 base::Base64Encode(base::RandBytesAsString(10), &id); | 1819 base::Base64Encode(base::RandBytesAsString(10), &id); |
1822 base::RemoveChars(id, "+/=", &id); | 1820 base::RemoveChars(id, "+/=", &id); |
1823 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id); | 1821 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id); |
1824 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != | 1822 } while (base::ContainsValue(device_list_, device_path)); |
1825 device_list_.end()); | |
1826 | 1823 |
1827 std::unique_ptr<Properties> properties( | 1824 std::unique_ptr<Properties> properties( |
1828 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, | 1825 new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
1829 base::Unretained(this), device_path))); | 1826 base::Unretained(this), device_path))); |
1830 properties->adapter.ReplaceValue(adapter_path); | 1827 properties->adapter.ReplaceValue(adapter_path); |
1831 | 1828 |
1832 properties->address.ReplaceValue(device_address); | 1829 properties->address.ReplaceValue(device_address); |
1833 properties->name.ReplaceValue( | 1830 properties->name.ReplaceValue( |
1834 name.value_or("Invalid Device Name set in " | 1831 name.value_or("Invalid Device Name set in " |
1835 "FakeBluetoothDeviceClient::CreateTestDevice")); | 1832 "FakeBluetoothDeviceClient::CreateTestDevice")); |
(...skipping 24 matching lines...) Expand all Loading... |
1860 properties->service_data.set_valid(true); | 1857 properties->service_data.set_valid(true); |
1861 } | 1858 } |
1862 | 1859 |
1863 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 1860 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
1864 device_list_.push_back(device_path); | 1861 device_list_.push_back(device_path); |
1865 for (auto& observer : observers_) | 1862 for (auto& observer : observers_) |
1866 observer.DeviceAdded(device_path); | 1863 observer.DeviceAdded(device_path); |
1867 } | 1864 } |
1868 | 1865 |
1869 } // namespace bluez | 1866 } // namespace bluez |
OLD | NEW |