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 #ifndef DEVICE_BLUETOOTH_TEST_FAKE_PERIPHERAL_H_ | 4 #ifndef DEVICE_BLUETOOTH_TEST_FAKE_PERIPHERAL_H_ |
5 #define DEVICE_BLUETOOTH_TEST_FAKE_PERIPHERAL_H_ | 5 #define DEVICE_BLUETOOTH_TEST_FAKE_PERIPHERAL_H_ |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
11 #include "base/optional.h" | 12 #include "base/optional.h" |
12 #include "device/bluetooth/bluetooth_device.h" | 13 #include "device/bluetooth/bluetooth_device.h" |
13 #include "device/bluetooth/test/fake_central.h" | 14 #include "device/bluetooth/test/fake_central.h" |
14 | 15 |
15 namespace bluetooth { | 16 namespace bluetooth { |
16 | 17 |
17 // Implements device::BluetoothDevice. Meant to be used by FakeCentral | 18 // Implements device::BluetoothDevice. Meant to be used by FakeCentral |
18 // to keep track of the peripheral's state and attributes. | 19 // to keep track of the peripheral's state and attributes. |
19 class FakePeripheral : public device::BluetoothDevice { | 20 class FakePeripheral : public device::BluetoothDevice { |
20 public: | 21 public: |
21 FakePeripheral(FakeCentral* fake_central, const std::string& address); | 22 FakePeripheral(FakeCentral* fake_central, const std::string& address); |
22 ~FakePeripheral() override; | 23 ~FakePeripheral() override; |
23 | 24 |
24 // Changes the name of the device. | 25 // Changes the name of the device. |
25 void SetName(base::Optional<std::string> name); | 26 void SetName(base::Optional<std::string> name); |
26 | 27 |
27 // Set it to indicate if the Peripheral is connected or not. | 28 // Set it to indicate if the system has connected to the Peripheral outside of |
28 void SetGattConnected(bool gatt_connected); | 29 // the Bluetooth interface e.g. the user connected to the device through |
| 30 // system settings. |
| 31 void SetSystemConnected(bool gatt_connected); |
29 | 32 |
30 // Updates the peripheral's UUIDs that are returned by | 33 // Updates the peripheral's UUIDs that are returned by |
31 // BluetoothDevice::GetUUIDs(). | 34 // BluetoothDevice::GetUUIDs(). |
32 void SetServiceUUIDs(UUIDSet service_uuids); | 35 void SetServiceUUIDs(UUIDSet service_uuids); |
33 | 36 |
| 37 // If |code| is kHCISuccess calls a pending success callback for |
| 38 // CreateGattConnection. Otherwise calls a pending error callback |
| 39 // with the ConnectErrorCode corresponding to |code|. |
| 40 void SetNextGATTConnectionResponse(uint16_t code); |
| 41 |
34 // BluetoothDevice overrides: | 42 // BluetoothDevice overrides: |
35 uint32_t GetBluetoothClass() const override; | 43 uint32_t GetBluetoothClass() const override; |
36 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 44 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
37 device::BluetoothTransport GetType() const override; | 45 device::BluetoothTransport GetType() const override; |
38 #endif | 46 #endif |
39 std::string GetIdentifier() const override; | 47 std::string GetIdentifier() const override; |
40 std::string GetAddress() const override; | 48 std::string GetAddress() const override; |
41 VendorIDSource GetVendorIDSource() const override; | 49 VendorIDSource GetVendorIDSource() const override; |
42 uint16_t GetVendorID() const override; | 50 uint16_t GetVendorID() const override; |
43 uint16_t GetProductID() const override; | 51 uint16_t GetProductID() const override; |
(...skipping 27 matching lines...) Expand all Loading... |
71 void Forget(const base::Closure& callback, | 79 void Forget(const base::Closure& callback, |
72 const ErrorCallback& error_callback) override; | 80 const ErrorCallback& error_callback) override; |
73 void ConnectToService( | 81 void ConnectToService( |
74 const device::BluetoothUUID& uuid, | 82 const device::BluetoothUUID& uuid, |
75 const ConnectToServiceCallback& callback, | 83 const ConnectToServiceCallback& callback, |
76 const ConnectToServiceErrorCallback& error_callback) override; | 84 const ConnectToServiceErrorCallback& error_callback) override; |
77 void ConnectToServiceInsecurely( | 85 void ConnectToServiceInsecurely( |
78 const device::BluetoothUUID& uuid, | 86 const device::BluetoothUUID& uuid, |
79 const ConnectToServiceCallback& callback, | 87 const ConnectToServiceCallback& callback, |
80 const ConnectToServiceErrorCallback& error_callback) override; | 88 const ConnectToServiceErrorCallback& error_callback) override; |
| 89 void CreateGattConnection( |
| 90 const GattConnectionCallback& callback, |
| 91 const ConnectErrorCallback& error_callback) override; |
81 | 92 |
82 protected: | 93 protected: |
83 void CreateGattConnectionImpl() override; | 94 void CreateGattConnectionImpl() override; |
84 void DisconnectGatt() override; | 95 void DisconnectGatt() override; |
85 | 96 |
86 private: | 97 private: |
| 98 void DispatchConnectionResponse(); |
| 99 |
87 const std::string address_; | 100 const std::string address_; |
88 base::Optional<std::string> name_; | 101 base::Optional<std::string> name_; |
| 102 UUIDSet service_uuids_; |
| 103 // True when the system has connected to the device outside of the Bluetooth |
| 104 // interface e.g. the user connected to the device through system settings. |
| 105 bool system_connected_; |
| 106 // True when this Bluetooth interface is connected to the device. |
89 bool gatt_connected_; | 107 bool gatt_connected_; |
90 UUIDSet service_uuids_; | 108 |
| 109 // Used to decide which callback should be called when |
| 110 // CreateGattConnection is called. |
| 111 base::Optional<uint16_t> next_connection_response_; |
| 112 |
| 113 base::WeakPtrFactory<FakePeripheral> weak_ptr_factory_; |
91 | 114 |
92 DISALLOW_COPY_AND_ASSIGN(FakePeripheral); | 115 DISALLOW_COPY_AND_ASSIGN(FakePeripheral); |
93 }; | 116 }; |
94 | 117 |
95 } // namespace bluetooth | 118 } // namespace bluetooth |
96 | 119 |
97 #endif // DEVICE_BLUETOOTH_TEST_FAKE_PERIPHERAL_H_ | 120 #endif // DEVICE_BLUETOOTH_TEST_FAKE_PERIPHERAL_H_ |
OLD | NEW |