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 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1544 if (iter == properties_map_.end()) { | 1544 if (iter == properties_map_.end()) { |
1545 VLOG(2) << "Fake device does not exist: " << object_path.value(); | 1545 VLOG(2) << "Fake device does not exist: " << object_path.value(); |
1546 return; | 1546 return; |
1547 } | 1547 } |
1548 Properties* properties = iter->second.get(); | 1548 Properties* properties = iter->second.get(); |
1549 DCHECK(properties); | 1549 DCHECK(properties); |
1550 properties->rssi.set_valid(true); | 1550 properties->rssi.set_valid(true); |
1551 properties->rssi.ReplaceValue(rssi); | 1551 properties->rssi.ReplaceValue(rssi); |
1552 } | 1552 } |
1553 | 1553 |
1554 void FakeBluetoothDeviceClient::UpdateServiceData( | |
1555 const dbus::ObjectPath& object_path, | |
1556 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) { | |
1557 PropertiesMap::const_iterator iter = properties_map_.find(object_path); | |
1558 if (iter == properties_map_.end()) { | |
1559 VLOG(2) << "Fake device does not exist: " << object_path.value(); | |
1560 return; | |
1561 } | |
1562 Properties* properties = iter->second.get(); | |
1563 DCHECK(properties); | |
1564 properties->service_data.set_valid(true); | |
1565 properties->service_data.ReplaceValue(service_data); | |
ortuno
2017/03/30 02:58:14
+scheib fyi
*sigh* I wish BlueZ worked like this.
scheib
2017/03/30 03:44:10
Grr... Bluez.
I didn't go dig into Bluez code to
Miao
2017/03/30 21:20:07
As Ortuno mentioned, the current BlueZ caches all
ortuno
2017/03/30 22:18:17
We discussed a solution with puthik a while ago. L
xiaoyinh(OOO Sep 11-29)
2017/03/31 16:26:53
Changed it to merge data like what BlueZ does.
xiaoyinh(OOO Sep 11-29)
2017/03/31 16:26:53
Done.
| |
1566 } | |
1567 | |
1554 void FakeBluetoothDeviceClient::UpdateConnectionInfo( | 1568 void FakeBluetoothDeviceClient::UpdateConnectionInfo( |
1555 uint16_t connection_rssi, | 1569 uint16_t connection_rssi, |
1556 uint16_t transmit_power, | 1570 uint16_t transmit_power, |
1557 uint16_t max_transmit_power) { | 1571 uint16_t max_transmit_power) { |
1558 connection_rssi_ = connection_rssi; | 1572 connection_rssi_ = connection_rssi; |
1559 transmit_power_ = transmit_power; | 1573 transmit_power_ = transmit_power; |
1560 max_transmit_power_ = max_transmit_power; | 1574 max_transmit_power_ = max_transmit_power; |
1561 } | 1575 } |
1562 | 1576 |
1563 void FakeBluetoothDeviceClient::PinCodeCallback( | 1577 void FakeBluetoothDeviceClient::PinCodeCallback( |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1768 void FakeBluetoothDeviceClient::RemoveAllDevices() { | 1782 void FakeBluetoothDeviceClient::RemoveAllDevices() { |
1769 device_list_.clear(); | 1783 device_list_.clear(); |
1770 } | 1784 } |
1771 | 1785 |
1772 void FakeBluetoothDeviceClient::CreateTestDevice( | 1786 void FakeBluetoothDeviceClient::CreateTestDevice( |
1773 const dbus::ObjectPath& adapter_path, | 1787 const dbus::ObjectPath& adapter_path, |
1774 const base::Optional<std::string> name, | 1788 const base::Optional<std::string> name, |
1775 const std::string alias, | 1789 const std::string alias, |
1776 const std::string device_address, | 1790 const std::string device_address, |
1777 const std::vector<std::string>& service_uuids, | 1791 const std::vector<std::string>& service_uuids, |
1778 device::BluetoothTransport type) { | 1792 device::BluetoothTransport type, |
1793 const std::unordered_map<std::string, std::vector<uint8_t>>& service_data) { | |
1779 // Create a random device path. | 1794 // Create a random device path. |
1780 dbus::ObjectPath device_path; | 1795 dbus::ObjectPath device_path; |
1781 std::string id; | 1796 std::string id; |
1782 do { | 1797 do { |
1783 // Construct an id that is valid according to the DBUS specification. | 1798 // Construct an id that is valid according to the DBUS specification. |
1784 base::Base64Encode(base::RandBytesAsString(10), &id); | 1799 base::Base64Encode(base::RandBytesAsString(10), &id); |
1785 base::RemoveChars(id, "+/=", &id); | 1800 base::RemoveChars(id, "+/=", &id); |
1786 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id); | 1801 device_path = dbus::ObjectPath(adapter_path.value() + "/dev" + id); |
1787 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != | 1802 } while (std::find(device_list_.begin(), device_list_.end(), device_path) != |
1788 device_list_.end()); | 1803 device_list_.end()); |
(...skipping 22 matching lines...) Expand all Loading... | |
1811 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); | 1826 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeLe); |
1812 break; | 1827 break; |
1813 case device::BLUETOOTH_TRANSPORT_DUAL: | 1828 case device::BLUETOOTH_TRANSPORT_DUAL: |
1814 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual); | 1829 properties->type.ReplaceValue(BluetoothDeviceClient::kTypeDual); |
1815 break; | 1830 break; |
1816 default: | 1831 default: |
1817 NOTREACHED(); | 1832 NOTREACHED(); |
1818 } | 1833 } |
1819 properties->type.set_valid(true); | 1834 properties->type.set_valid(true); |
1820 | 1835 |
1836 if (!service_data.empty()) { | |
1837 properties->service_data.ReplaceValue(service_data); | |
1838 properties->service_data.set_valid(true); | |
1839 } | |
1840 | |
1821 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 1841 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
1822 device_list_.push_back(device_path); | 1842 device_list_.push_back(device_path); |
1823 for (auto& observer : observers_) | 1843 for (auto& observer : observers_) |
1824 observer.DeviceAdded(device_path); | 1844 observer.DeviceAdded(device_path); |
1825 } | 1845 } |
1826 | 1846 |
1827 } // namespace bluez | 1847 } // namespace bluez |
OLD | NEW |