OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/fake_peripheral.h" | 5 #include "device/bluetooth/test/fake_peripheral.h" |
6 | 6 |
7 #include "device/bluetooth/bluetooth_gatt_connection.h" | |
8 | |
7 namespace bluetooth { | 9 namespace bluetooth { |
8 | 10 |
9 FakePeripheral::FakePeripheral(FakeCentral* fake_central, | 11 FakePeripheral::FakePeripheral(FakeCentral* fake_central, |
10 const std::string& address) | 12 const std::string& address) |
11 : device::BluetoothDevice(fake_central), | 13 : device::BluetoothDevice(fake_central), |
12 address_(address), | 14 address_(address), |
13 gatt_connected_(false) {} | 15 gatt_connected_(false) {} |
14 | 16 |
15 FakePeripheral::~FakePeripheral() {} | 17 FakePeripheral::~FakePeripheral() {} |
16 | 18 |
17 void FakePeripheral::SetName(base::Optional<std::string> name) { | 19 void FakePeripheral::SetName(base::Optional<std::string> name) { |
18 name_ = std::move(name); | 20 name_ = std::move(name); |
19 } | 21 } |
20 | 22 |
21 void FakePeripheral::SetGattConnected(bool connected) { | 23 void FakePeripheral::SetGattConnected(bool connected) { |
22 gatt_connected_ = connected; | 24 gatt_connected_ = connected; |
23 } | 25 } |
24 | 26 |
25 void FakePeripheral::SetServiceUUIDs(UUIDSet service_uuids) { | 27 void FakePeripheral::SetServiceUUIDs(UUIDSet service_uuids) { |
26 service_uuids_ = std::move(service_uuids); | 28 service_uuids_ = std::move(service_uuids); |
27 } | 29 } |
28 | 30 |
31 void FakePeripheral::SimulateGATTConnectionResponse(uint16_t code) { | |
32 CreateGattConnectionCallbacks callbacks = | |
scheib
2017/05/12 05:43:55
Call up to BluetoothDevice::DidConnectGatt DidFail
ortuno
2017/05/15 07:01:30
Happy to change it but I would like to understand
| |
33 create_gatt_connection_callbacks_.front(); | |
34 create_gatt_connection_callbacks_.pop(); | |
35 if (code == mojom::kHCISuccess) { | |
36 gatt_connected_ = true; | |
37 callbacks.first.Run( | |
38 base::MakeUnique<device::BluetoothGattConnection>(adapter_, address_)); | |
39 adapter_->NotifyDeviceChanged(this); | |
40 } else if (code == mojom::kHCIConnectionTimeout) { | |
41 callbacks.second.Run(ERROR_FAILED); | |
42 } else { | |
43 callbacks.second.Run(ERROR_UNKNOWN); | |
44 } | |
45 } | |
46 | |
29 uint32_t FakePeripheral::GetBluetoothClass() const { | 47 uint32_t FakePeripheral::GetBluetoothClass() const { |
30 NOTREACHED(); | 48 NOTREACHED(); |
31 return 0; | 49 return 0; |
32 } | 50 } |
33 | 51 |
34 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 52 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
35 device::BluetoothTransport FakePeripheral::GetType() const { | 53 device::BluetoothTransport FakePeripheral::GetType() const { |
36 NOTREACHED(); | 54 NOTREACHED(); |
37 return device::BLUETOOTH_TRANSPORT_INVALID; | 55 return device::BLUETOOTH_TRANSPORT_INVALID; |
38 } | 56 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 NOTREACHED(); | 189 NOTREACHED(); |
172 } | 190 } |
173 | 191 |
174 void FakePeripheral::ConnectToServiceInsecurely( | 192 void FakePeripheral::ConnectToServiceInsecurely( |
175 const device::BluetoothUUID& uuid, | 193 const device::BluetoothUUID& uuid, |
176 const ConnectToServiceCallback& callback, | 194 const ConnectToServiceCallback& callback, |
177 const ConnectToServiceErrorCallback& error_callback) { | 195 const ConnectToServiceErrorCallback& error_callback) { |
178 NOTREACHED(); | 196 NOTREACHED(); |
179 } | 197 } |
180 | 198 |
199 void FakePeripheral::CreateGattConnection( | |
200 const GattConnectionCallback& callback, | |
201 const ConnectErrorCallback& error_callback) { | |
202 create_gatt_connection_callbacks_.push({callback, error_callback}); | |
203 } | |
204 | |
181 void FakePeripheral::CreateGattConnectionImpl() { | 205 void FakePeripheral::CreateGattConnectionImpl() { |
182 NOTREACHED(); | 206 NOTREACHED(); |
183 } | 207 } |
184 | 208 |
185 void FakePeripheral::DisconnectGatt() { | 209 void FakePeripheral::DisconnectGatt() { |
186 NOTREACHED(); | |
187 } | 210 } |
188 } // namespace bluetooth | 211 } // namespace bluetooth |
OLD | NEW |