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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( | 116 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( |
117 int device_ordinal) { | 117 int device_ordinal) { |
118 if (device_ordinal > 6 || device_ordinal < 1) | 118 if (device_ordinal > 6 || device_ordinal < 1) |
119 return nullptr; | 119 return nullptr; |
120 | 120 |
121 base::Optional<std::string> device_name = kTestDeviceName; | 121 base::Optional<std::string> device_name = kTestDeviceName; |
122 std::string device_address = kTestDeviceAddress1; | 122 std::string device_address = kTestDeviceAddress1; |
123 std::vector<std::string> service_uuids; | 123 std::vector<std::string> service_uuids; |
124 BluetoothTransport device_type = BLUETOOTH_TRANSPORT_LE; | 124 BluetoothTransport device_type = BLUETOOTH_TRANSPORT_LE; |
125 std::unordered_map<std::string, std::vector<uint8_t>> service_data; | |
126 | 125 |
127 switch (device_ordinal) { | 126 switch (device_ordinal) { |
128 case 1: | 127 case 1: |
129 service_uuids.push_back(kTestUUIDGenericAccess); | 128 service_uuids.push_back(kTestUUIDGenericAccess); |
130 service_uuids.push_back(kTestUUIDGenericAttribute); | 129 service_uuids.push_back(kTestUUIDGenericAttribute); |
131 service_data[kTestUUIDHeartRate] = {0x01}; | |
132 break; | 130 break; |
133 case 2: | 131 case 2: |
134 service_uuids.push_back(kTestUUIDImmediateAlert); | 132 service_uuids.push_back(kTestUUIDImmediateAlert); |
135 service_uuids.push_back(kTestUUIDLinkLoss); | 133 service_uuids.push_back(kTestUUIDLinkLoss); |
136 service_data[kTestUUIDHeartRate] = {}; | |
137 service_data[kTestUUIDImmediateAlert] = {0x00, 0x02}; | |
138 break; | 134 break; |
139 case 3: | 135 case 3: |
140 device_name = kTestDeviceNameEmpty; | 136 device_name = kTestDeviceNameEmpty; |
141 break; | 137 break; |
142 case 4: | 138 case 4: |
143 device_name = kTestDeviceNameEmpty; | 139 device_name = kTestDeviceNameEmpty; |
144 device_address = kTestDeviceAddress2; | 140 device_address = kTestDeviceAddress2; |
145 break; | 141 break; |
146 case 5: | 142 case 5: |
147 device_name = base::nullopt; | 143 device_name = base::nullopt; |
148 case 6: | 144 case 6: |
149 device_address = kTestDeviceAddress2; | 145 device_address = kTestDeviceAddress2; |
150 device_type = BLUETOOTH_TRANSPORT_DUAL; | 146 device_type = BLUETOOTH_TRANSPORT_DUAL; |
151 break; | 147 break; |
152 } | 148 } |
153 | 149 |
| 150 if (!adapter_->GetDevice(device_address)) { |
| 151 fake_bluetooth_device_client_->CreateTestDevice( |
| 152 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 153 /* name */ device_name, |
| 154 /* alias */ device_name.value_or("") + "(alias)", device_address, |
| 155 service_uuids, device_type); |
| 156 } |
154 BluetoothDevice* device = adapter_->GetDevice(device_address); | 157 BluetoothDevice* device = adapter_->GetDevice(device_address); |
155 if (device) { | |
156 fake_bluetooth_device_client_->UpdateServiceData(GetDevicePath(device), | |
157 service_data); | |
158 return device; | |
159 } | |
160 | 158 |
161 fake_bluetooth_device_client_->CreateTestDevice( | 159 return device; |
162 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | |
163 /* name */ device_name, | |
164 /* alias */ device_name.value_or("") + "(alias)", device_address, | |
165 service_uuids, device_type, service_data); | |
166 | |
167 return adapter_->GetDevice(device_address); | |
168 } | 160 } |
169 | 161 |
170 BluetoothDevice* BluetoothTestBlueZ::SimulateClassicDevice() { | 162 BluetoothDevice* BluetoothTestBlueZ::SimulateClassicDevice() { |
171 std::string device_name = kTestDeviceName; | 163 std::string device_name = kTestDeviceName; |
172 std::string device_address = kTestDeviceAddress3; | 164 std::string device_address = kTestDeviceAddress3; |
173 std::vector<std::string> service_uuids; | 165 std::vector<std::string> service_uuids; |
174 std::unordered_map<std::string, std::vector<uint8_t>> service_data; | |
175 | 166 |
176 if (!adapter_->GetDevice(device_address)) { | 167 if (!adapter_->GetDevice(device_address)) { |
177 fake_bluetooth_device_client_->CreateTestDevice( | 168 fake_bluetooth_device_client_->CreateTestDevice( |
178 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 169 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
179 device_name /* name */, device_name /* alias */, device_address, | 170 device_name /* name */, device_name /* alias */, device_address, |
180 service_uuids, BLUETOOTH_TRANSPORT_CLASSIC, service_data); | 171 service_uuids, BLUETOOTH_TRANSPORT_CLASSIC); |
181 } | 172 } |
182 return adapter_->GetDevice(device_address); | 173 return adapter_->GetDevice(device_address); |
183 } | 174 } |
184 | 175 |
185 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest( | 176 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest( |
186 BluetoothDevice* from_device, | 177 BluetoothDevice* from_device, |
187 BluetoothLocalGattCharacteristic* characteristic, | 178 BluetoothLocalGattCharacteristic* characteristic, |
188 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, | 179 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, |
189 const base::Closure& error_callback) { | 180 const base::Closure& error_callback) { |
190 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = | 181 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 std::vector<BluetoothLocalGattService*> services; | 341 std::vector<BluetoothLocalGattService*> services; |
351 bluez::BluetoothAdapterBlueZ* adapter_bluez = | 342 bluez::BluetoothAdapterBlueZ* adapter_bluez = |
352 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); | 343 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); |
353 | 344 |
354 for (const auto& iter : adapter_bluez->registered_gatt_services_) | 345 for (const auto& iter : adapter_bluez->registered_gatt_services_) |
355 services.push_back(iter.second); | 346 services.push_back(iter.second); |
356 return services; | 347 return services; |
357 } | 348 } |
358 | 349 |
359 } // namespace device | 350 } // namespace device |
OLD | NEW |