Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: device/bluetooth/test/fake_peripheral.h

Issue 2874873003: bluetooth: Implement simulateGATTConnectionResponse() (Closed)
Patch Set: clean up Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 Peripheral is connected or not.
scheib 2017/05/30 20:54:13 Member variable has better comments
ortuno 2017/05/31 05:47:27 Done.
28 void SetGattConnected(bool gatt_connected); 29 void SetSystemConnected(bool gatt_connected);
29 30
30 // Updates the peripheral's UUIDs that are returned by 31 // Updates the peripheral's UUIDs that are returned by
31 // BluetoothDevice::GetUUIDs(). 32 // BluetoothDevice::GetUUIDs().
32 void SetServiceUUIDs(UUIDSet service_uuids); 33 void SetServiceUUIDs(UUIDSet service_uuids);
33 34
35 // If |code| is kHCISuccess calls a pending success callback for
36 // CreateGattConnection. Otherwise calls a pending error callback
37 // with the ConnectErrorCode corresponding to |code|.
38 void SetNextGATTConnectionResponse(uint16_t code);
39
34 // BluetoothDevice overrides: 40 // BluetoothDevice overrides:
35 uint32_t GetBluetoothClass() const override; 41 uint32_t GetBluetoothClass() const override;
36 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 42 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
37 device::BluetoothTransport GetType() const override; 43 device::BluetoothTransport GetType() const override;
38 #endif 44 #endif
39 std::string GetIdentifier() const override; 45 std::string GetIdentifier() const override;
40 std::string GetAddress() const override; 46 std::string GetAddress() const override;
41 VendorIDSource GetVendorIDSource() const override; 47 VendorIDSource GetVendorIDSource() const override;
42 uint16_t GetVendorID() const override; 48 uint16_t GetVendorID() const override;
43 uint16_t GetProductID() const override; 49 uint16_t GetProductID() const override;
(...skipping 27 matching lines...) Expand all
71 void Forget(const base::Closure& callback, 77 void Forget(const base::Closure& callback,
72 const ErrorCallback& error_callback) override; 78 const ErrorCallback& error_callback) override;
73 void ConnectToService( 79 void ConnectToService(
74 const device::BluetoothUUID& uuid, 80 const device::BluetoothUUID& uuid,
75 const ConnectToServiceCallback& callback, 81 const ConnectToServiceCallback& callback,
76 const ConnectToServiceErrorCallback& error_callback) override; 82 const ConnectToServiceErrorCallback& error_callback) override;
77 void ConnectToServiceInsecurely( 83 void ConnectToServiceInsecurely(
78 const device::BluetoothUUID& uuid, 84 const device::BluetoothUUID& uuid,
79 const ConnectToServiceCallback& callback, 85 const ConnectToServiceCallback& callback,
80 const ConnectToServiceErrorCallback& error_callback) override; 86 const ConnectToServiceErrorCallback& error_callback) override;
87 void CreateGattConnection(
88 const GattConnectionCallback& callback,
89 const ConnectErrorCallback& error_callback) override;
81 90
82 protected: 91 protected:
83 void CreateGattConnectionImpl() override; 92 void CreateGattConnectionImpl() override;
84 void DisconnectGatt() override; 93 void DisconnectGatt() override;
85 94
86 private: 95 private:
96 void DispatchConnectionResponse();
97
87 const std::string address_; 98 const std::string address_;
88 base::Optional<std::string> name_; 99 base::Optional<std::string> name_;
100 UUIDSet service_uuids_;
101 // True when the system has connected to the device outside of the Bluetooth
102 // interface e.g. the user connected to the device through system settings.
103 bool system_connected_;
104 // True when this Bluetooth interface is connected to the device.
89 bool gatt_connected_; 105 bool gatt_connected_;
90 UUIDSet service_uuids_; 106
107 // Used to decide which callback should be called when
108 // CreateGattConnection is called.
109 base::Optional<uint16_t> next_connection_response_;
110
111 base::WeakPtrFactory<FakePeripheral> weak_ptr_factory_;
91 112
92 DISALLOW_COPY_AND_ASSIGN(FakePeripheral); 113 DISALLOW_COPY_AND_ASSIGN(FakePeripheral);
93 }; 114 };
94 115
95 } // namespace bluetooth 116 } // namespace bluetooth
96 117
97 #endif // DEVICE_BLUETOOTH_TEST_FAKE_PERIPHERAL_H_ 118 #endif // DEVICE_BLUETOOTH_TEST_FAKE_PERIPHERAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698