| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 117 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 118 device_name /* name */, device_name /* alias */, device_address, | 118 device_name /* name */, device_name /* alias */, device_address, |
| 119 service_uuids); | 119 service_uuids); |
| 120 } | 120 } |
| 121 BluetoothDevice* device = adapter_->GetDevice(device_address); | 121 BluetoothDevice* device = adapter_->GetDevice(device_address); |
| 122 | 122 |
| 123 return device; | 123 return device; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest( | 126 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest( |
| 127 BluetoothLocalGattService* service, | |
| 128 BluetoothLocalGattCharacteristic* characteristic, | 127 BluetoothLocalGattCharacteristic* characteristic, |
| 129 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, | 128 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, |
| 130 const base::Closure& error_callback) { | 129 const base::Closure& error_callback) { |
| 131 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = | 130 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = |
| 132 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( | 131 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( |
| 133 characteristic); | 132 characteristic); |
| 134 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 133 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 135 static_cast<bluez::FakeBluetoothGattManagerClient*>( | 134 static_cast<bluez::FakeBluetoothGattManagerClient*>( |
| 136 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 135 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 137 bluez::FakeBluetoothGattCharacteristicServiceProvider* | 136 bluez::FakeBluetoothGattCharacteristicServiceProvider* |
| 138 characteristic_provider = | 137 characteristic_provider = |
| 139 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( | 138 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( |
| 140 characteristic_bluez->object_path()); | 139 characteristic_bluez->object_path()); |
| 141 | 140 |
| 142 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = | 141 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = |
| 143 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service); | 142 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( |
| 143 characteristic->GetService()); |
| 144 static_cast<TestBluetoothLocalGattServiceDelegate*>( | 144 static_cast<TestBluetoothLocalGattServiceDelegate*>( |
| 145 service_bluez->GetDelegate()) | 145 service_bluez->GetDelegate()) |
| 146 ->set_expected_characteristic(characteristic); | 146 ->set_expected_characteristic(characteristic); |
| 147 | 147 |
| 148 base::RunLoop run_loop; | 148 base::RunLoop run_loop; |
| 149 characteristic_provider->GetValue( | 149 characteristic_provider->GetValue( |
| 150 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback), | 150 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback), |
| 151 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); | 151 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); |
| 152 run_loop.Run(); | 152 run_loop.Run(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueWriteRequest( | 155 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueWriteRequest( |
| 156 BluetoothLocalGattService* service, | |
| 157 BluetoothLocalGattCharacteristic* characteristic, | 156 BluetoothLocalGattCharacteristic* characteristic, |
| 158 const std::vector<uint8_t>& value_to_write, | 157 const std::vector<uint8_t>& value_to_write, |
| 159 const base::Closure& success_callback, | 158 const base::Closure& success_callback, |
| 160 const base::Closure& error_callback) { | 159 const base::Closure& error_callback) { |
| 161 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = | 160 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = |
| 162 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( | 161 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( |
| 163 characteristic); | 162 characteristic); |
| 164 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 163 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 165 static_cast<bluez::FakeBluetoothGattManagerClient*>( | 164 static_cast<bluez::FakeBluetoothGattManagerClient*>( |
| 166 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 165 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 167 bluez::FakeBluetoothGattCharacteristicServiceProvider* | 166 bluez::FakeBluetoothGattCharacteristicServiceProvider* |
| 168 characteristic_provider = | 167 characteristic_provider = |
| 169 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( | 168 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( |
| 170 characteristic_bluez->object_path()); | 169 characteristic_bluez->object_path()); |
| 171 | 170 |
| 172 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = | 171 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = |
| 173 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service); | 172 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( |
| 173 characteristic->GetService()); |
| 174 static_cast<TestBluetoothLocalGattServiceDelegate*>( | 174 static_cast<TestBluetoothLocalGattServiceDelegate*>( |
| 175 service_bluez->GetDelegate()) | 175 service_bluez->GetDelegate()) |
| 176 ->set_expected_characteristic(characteristic); | 176 ->set_expected_characteristic(characteristic); |
| 177 | 177 |
| 178 base::RunLoop run_loop; | 178 base::RunLoop run_loop; |
| 179 characteristic_provider->SetValue( | 179 characteristic_provider->SetValue( |
| 180 value_to_write, | 180 value_to_write, |
| 181 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback), | 181 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback), |
| 182 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); | 182 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); |
| 183 run_loop.Run(); | 183 run_loop.Run(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueReadRequest( | 186 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueReadRequest( |
| 187 BluetoothLocalGattService* service, | |
| 188 BluetoothLocalGattDescriptor* descriptor, | 187 BluetoothLocalGattDescriptor* descriptor, |
| 189 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, | 188 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, |
| 190 const base::Closure& error_callback) { | 189 const base::Closure& error_callback) { |
| 191 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez = | 190 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez = |
| 192 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor); | 191 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor); |
| 193 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 192 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 194 static_cast<bluez::FakeBluetoothGattManagerClient*>( | 193 static_cast<bluez::FakeBluetoothGattManagerClient*>( |
| 195 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 194 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 196 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider = | 195 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider = |
| 197 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider( | 196 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider( |
| 198 descriptor_bluez->object_path()); | 197 descriptor_bluez->object_path()); |
| 199 | 198 |
| 200 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = | 199 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = |
| 201 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service); | 200 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( |
| 201 descriptor->GetCharacteristic()->GetService()); |
| 202 static_cast<TestBluetoothLocalGattServiceDelegate*>( | 202 static_cast<TestBluetoothLocalGattServiceDelegate*>( |
| 203 service_bluez->GetDelegate()) | 203 service_bluez->GetDelegate()) |
| 204 ->set_expected_descriptor(descriptor); | 204 ->set_expected_descriptor(descriptor); |
| 205 | 205 |
| 206 base::RunLoop run_loop; | 206 base::RunLoop run_loop; |
| 207 descriptor_provider->GetValue( | 207 descriptor_provider->GetValue( |
| 208 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback), | 208 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback), |
| 209 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); | 209 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); |
| 210 run_loop.Run(); | 210 run_loop.Run(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueWriteRequest( | 213 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueWriteRequest( |
| 214 BluetoothLocalGattService* service, | |
| 215 BluetoothLocalGattDescriptor* descriptor, | 214 BluetoothLocalGattDescriptor* descriptor, |
| 216 const std::vector<uint8_t>& value_to_write, | 215 const std::vector<uint8_t>& value_to_write, |
| 217 const base::Closure& success_callback, | 216 const base::Closure& success_callback, |
| 218 const base::Closure& error_callback) { | 217 const base::Closure& error_callback) { |
| 219 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez = | 218 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez = |
| 220 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor); | 219 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor); |
| 221 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 220 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 222 static_cast<bluez::FakeBluetoothGattManagerClient*>( | 221 static_cast<bluez::FakeBluetoothGattManagerClient*>( |
| 223 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 222 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 224 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider = | 223 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider = |
| 225 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider( | 224 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider( |
| 226 descriptor_bluez->object_path()); | 225 descriptor_bluez->object_path()); |
| 227 | 226 |
| 228 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = | 227 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = |
| 229 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service); | 228 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( |
| 229 descriptor->GetCharacteristic()->GetService()); |
| 230 static_cast<TestBluetoothLocalGattServiceDelegate*>( | 230 static_cast<TestBluetoothLocalGattServiceDelegate*>( |
| 231 service_bluez->GetDelegate()) | 231 service_bluez->GetDelegate()) |
| 232 ->set_expected_descriptor(descriptor); | 232 ->set_expected_descriptor(descriptor); |
| 233 | 233 |
| 234 base::RunLoop run_loop; | 234 base::RunLoop run_loop; |
| 235 descriptor_provider->SetValue( | 235 descriptor_provider->SetValue( |
| 236 value_to_write, | 236 value_to_write, |
| 237 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback), | 237 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback), |
| 238 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); | 238 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); |
| 239 run_loop.Run(); | 239 run_loop.Run(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 bool BluetoothTestBlueZ::SimulateLocalGattCharacteristicNotificationsRequest( | 242 bool BluetoothTestBlueZ::SimulateLocalGattCharacteristicNotificationsRequest( |
| 243 BluetoothLocalGattService* service, | |
| 244 BluetoothLocalGattCharacteristic* characteristic, | 243 BluetoothLocalGattCharacteristic* characteristic, |
| 245 bool start) { | 244 bool start) { |
| 246 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = | 245 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = |
| 247 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( | 246 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( |
| 248 characteristic); | 247 characteristic); |
| 249 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 248 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 250 static_cast<bluez::FakeBluetoothGattManagerClient*>( | 249 static_cast<bluez::FakeBluetoothGattManagerClient*>( |
| 251 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 250 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 252 bluez::FakeBluetoothGattCharacteristicServiceProvider* | 251 bluez::FakeBluetoothGattCharacteristicServiceProvider* |
| 253 characteristic_provider = | 252 characteristic_provider = |
| 254 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( | 253 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( |
| 255 characteristic_bluez->object_path()); | 254 characteristic_bluez->object_path()); |
| 256 | 255 |
| 257 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = | 256 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = |
| 258 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service); | 257 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( |
| 258 characteristic->GetService()); |
| 259 static_cast<TestBluetoothLocalGattServiceDelegate*>( | 259 static_cast<TestBluetoothLocalGattServiceDelegate*>( |
| 260 service_bluez->GetDelegate()) | 260 service_bluez->GetDelegate()) |
| 261 ->set_expected_characteristic(characteristic); | 261 ->set_expected_characteristic(characteristic); |
| 262 | 262 |
| 263 return characteristic_provider->NotificationsChange(start); | 263 return characteristic_provider->NotificationsChange(start); |
| 264 } | 264 } |
| 265 | 265 |
| 266 std::vector<uint8_t> BluetoothTestBlueZ::LastNotifactionValueForCharacteristic( | 266 std::vector<uint8_t> BluetoothTestBlueZ::LastNotifactionValueForCharacteristic( |
| 267 BluetoothLocalGattCharacteristic* characteristic) { | 267 BluetoothLocalGattCharacteristic* characteristic) { |
| 268 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = | 268 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 285 std::vector<BluetoothLocalGattService*> services; | 285 std::vector<BluetoothLocalGattService*> services; |
| 286 bluez::BluetoothAdapterBlueZ* adapter_bluez = | 286 bluez::BluetoothAdapterBlueZ* adapter_bluez = |
| 287 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); | 287 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); |
| 288 | 288 |
| 289 for (const auto& iter : adapter_bluez->registered_gatt_services_) | 289 for (const auto& iter : adapter_bluez->registered_gatt_services_) |
| 290 services.push_back(iter.second); | 290 services.push_back(iter.second); |
| 291 return services; | 291 return services; |
| 292 } | 292 } |
| 293 | 293 |
| 294 } // namespace device | 294 } // namespace device |
| OLD | NEW |