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