| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/test/bluetooth_test_bluez.h" | 5 #include "device/bluetooth/test/bluetooth_test_bluez.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 adapter_ = new bluez::BluetoothAdapterBlueZ( | 87 adapter_ = new bluez::BluetoothAdapterBlueZ( |
| 88 base::Bind(&AdapterCallback, run_loop.QuitClosure())); | 88 base::Bind(&AdapterCallback, run_loop.QuitClosure())); |
| 89 run_loop.Run(); | 89 run_loop.Run(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( | 92 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( |
| 93 int device_ordinal) { | 93 int device_ordinal) { |
| 94 if (device_ordinal > 6 || device_ordinal < 1) | 94 if (device_ordinal > 6 || device_ordinal < 1) |
| 95 return nullptr; | 95 return nullptr; |
| 96 | 96 |
| 97 std::string device_name = kTestDeviceName; | 97 base::Optional<std::string> device_name = kTestDeviceName; |
| 98 std::string device_address = kTestDeviceAddress1; | 98 std::string device_address = kTestDeviceAddress1; |
| 99 std::vector<std::string> service_uuids; | 99 std::vector<std::string> service_uuids; |
| 100 BluetoothTransport device_type = BLUETOOTH_TRANSPORT_LE; | 100 BluetoothTransport device_type = BLUETOOTH_TRANSPORT_LE; |
| 101 | 101 |
| 102 switch (device_ordinal) { | 102 switch (device_ordinal) { |
| 103 case 1: | 103 case 1: |
| 104 service_uuids.push_back(kTestUUIDGenericAccess); | 104 service_uuids.push_back(kTestUUIDGenericAccess); |
| 105 service_uuids.push_back(kTestUUIDGenericAttribute); | 105 service_uuids.push_back(kTestUUIDGenericAttribute); |
| 106 break; | 106 break; |
| 107 case 2: | 107 case 2: |
| 108 service_uuids.push_back(kTestUUIDImmediateAlert); | 108 service_uuids.push_back(kTestUUIDImmediateAlert); |
| 109 service_uuids.push_back(kTestUUIDLinkLoss); | 109 service_uuids.push_back(kTestUUIDLinkLoss); |
| 110 break; | 110 break; |
| 111 case 3: | 111 case 3: |
| 112 device_name = kTestDeviceNameEmpty; | 112 device_name = kTestDeviceNameEmpty; |
| 113 break; | 113 break; |
| 114 case 4: | 114 case 4: |
| 115 device_name = kTestDeviceNameEmpty; | 115 device_name = kTestDeviceNameEmpty; |
| 116 device_address = kTestDeviceAddress2; | 116 device_address = kTestDeviceAddress2; |
| 117 break; | 117 break; |
| 118 case 5: | 118 case 5: |
| 119 // TODO: implement. See crbug.com/622432 | 119 device_name = base::nullopt; |
| 120 NOTIMPLEMENTED(); | |
| 121 return nullptr; | |
| 122 case 6: | 120 case 6: |
| 123 device_address = kTestDeviceAddress2; | 121 device_address = kTestDeviceAddress2; |
| 124 device_type = BLUETOOTH_TRANSPORT_DUAL; | 122 device_type = BLUETOOTH_TRANSPORT_DUAL; |
| 125 break; | 123 break; |
| 126 } | 124 } |
| 127 | 125 |
| 128 if (!adapter_->GetDevice(device_address)) { | 126 if (!adapter_->GetDevice(device_address)) { |
| 129 fake_bluetooth_device_client_->CreateTestDevice( | 127 fake_bluetooth_device_client_->CreateTestDevice( |
| 130 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 128 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 131 device_name /* name */, device_name /* alias */, device_address, | 129 /* name */ device_name, |
| 130 /* alias */ device_name.value_or("") + "(alias)", device_address, |
| 132 service_uuids, device_type); | 131 service_uuids, device_type); |
| 133 } | 132 } |
| 134 BluetoothDevice* device = adapter_->GetDevice(device_address); | 133 BluetoothDevice* device = adapter_->GetDevice(device_address); |
| 135 | 134 |
| 136 return device; | 135 return device; |
| 137 } | 136 } |
| 138 | 137 |
| 139 BluetoothDevice* BluetoothTestBlueZ::SimulateClassicDevice() { | 138 BluetoothDevice* BluetoothTestBlueZ::SimulateClassicDevice() { |
| 140 std::string device_name = kTestDeviceName; | 139 std::string device_name = kTestDeviceName; |
| 141 std::string device_address = kTestDeviceAddress3; | 140 std::string device_address = kTestDeviceAddress3; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 std::vector<BluetoothLocalGattService*> services; | 317 std::vector<BluetoothLocalGattService*> services; |
| 319 bluez::BluetoothAdapterBlueZ* adapter_bluez = | 318 bluez::BluetoothAdapterBlueZ* adapter_bluez = |
| 320 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); | 319 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); |
| 321 | 320 |
| 322 for (const auto& iter : adapter_bluez->registered_gatt_services_) | 321 for (const auto& iter : adapter_bluez->registered_gatt_services_) |
| 323 services.push_back(iter.second); | 322 services.push_back(iter.second); |
| 324 return services; | 323 return services; |
| 325 } | 324 } |
| 326 | 325 |
| 327 } // namespace device | 326 } // namespace device |
| OLD | NEW |