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 <tuple> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" | 16 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
16 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" | 17 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
17 #include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h" | 18 #include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = | 272 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = |
272 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( | 273 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( |
273 characteristic->GetService()); | 274 characteristic->GetService()); |
274 static_cast<TestBluetoothLocalGattServiceDelegate*>( | 275 static_cast<TestBluetoothLocalGattServiceDelegate*>( |
275 service_bluez->GetDelegate()) | 276 service_bluez->GetDelegate()) |
276 ->set_expected_characteristic(characteristic); | 277 ->set_expected_characteristic(characteristic); |
277 | 278 |
278 return characteristic_provider->NotificationsChange(start); | 279 return characteristic_provider->NotificationsChange(start); |
279 } | 280 } |
280 | 281 |
281 std::vector<uint8_t> BluetoothTestBlueZ::LastNotifactionValueForCharacteristic( | 282 BluetoothTestBase::NotificationType |
| 283 BluetoothTestBlueZ::LastNotifactionValueForCharacteristic( |
282 BluetoothLocalGattCharacteristic* characteristic) { | 284 BluetoothLocalGattCharacteristic* characteristic) { |
283 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = | 285 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = |
284 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( | 286 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( |
285 characteristic); | 287 characteristic); |
286 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 288 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
287 static_cast<bluez::FakeBluetoothGattManagerClient*>( | 289 static_cast<bluez::FakeBluetoothGattManagerClient*>( |
288 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 290 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
289 bluez::FakeBluetoothGattCharacteristicServiceProvider* | 291 bluez::FakeBluetoothGattCharacteristicServiceProvider* |
290 characteristic_provider = | 292 characteristic_provider = |
291 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( | 293 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( |
292 characteristic_bluez->object_path()); | 294 characteristic_bluez->object_path()); |
293 | 295 |
294 return characteristic_provider ? characteristic_provider->sent_value() | 296 if (!characteristic_provider) |
295 : std::vector<uint8_t>(); | 297 return NotificationType(); |
| 298 |
| 299 bluez::BluetoothAdapterBlueZ* adapter_bluez = |
| 300 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); |
| 301 |
| 302 std::string device_id; |
| 303 bluez::BluetoothDeviceBlueZ* device = adapter_bluez->GetDeviceWithPath( |
| 304 characteristic_provider->last_device_path()); |
| 305 if (device) |
| 306 device_id = device->GetIdentifier(); |
| 307 |
| 308 NotificationType notification = { |
| 309 device_id, characteristic_provider->last_value(), |
| 310 characteristic_provider->last_indicate_flag()}; |
| 311 return notification; |
296 } | 312 } |
297 | 313 |
298 std::vector<BluetoothLocalGattService*> | 314 std::vector<BluetoothLocalGattService*> |
299 BluetoothTestBlueZ::RegisteredGattServices() { | 315 BluetoothTestBlueZ::RegisteredGattServices() { |
300 std::vector<BluetoothLocalGattService*> services; | 316 std::vector<BluetoothLocalGattService*> services; |
301 bluez::BluetoothAdapterBlueZ* adapter_bluez = | 317 bluez::BluetoothAdapterBlueZ* adapter_bluez = |
302 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); | 318 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); |
303 | 319 |
304 for (const auto& iter : adapter_bluez->registered_gatt_services_) | 320 for (const auto& iter : adapter_bluez->registered_gatt_services_) |
305 services.push_back(iter.second); | 321 services.push_back(iter.second); |
306 return services; | 322 return services; |
307 } | 323 } |
308 | 324 |
309 } // namespace device | 325 } // namespace device |
OLD | NEW |