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

Side by Side Diff: device/bluetooth/bluetooth_low_energy_win_fake.h

Issue 1749403002: Implement BluetoothRemoteGattCharacteristicWin::StartNotifySession and related unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_
7 7
8 #include "device/bluetooth/bluetooth_low_energy_win.h" 8 #include "device/bluetooth/bluetooth_low_energy_win.h"
9 9
10 #include <set> 10 #include <set>
11 #include <unordered_map> 11 #include <unordered_map>
12 12
13 namespace device { 13 namespace device {
14 namespace win { 14 namespace win {
15 15
16 struct BLEDevice; 16 struct BLEDevice;
17 struct GattService; 17 struct GattService;
18 struct GattCharacteristic; 18 struct GattCharacteristic;
19 struct GattCharacteristicObserver;
19 struct GattDescriptor; 20 struct GattDescriptor;
20 21
21 // The key of BLEDevicesMap is the string of the BLE device address. 22 // The key of BLEDevicesMap is the string of the BLE device address.
22 typedef std::unordered_map<std::string, scoped_ptr<BLEDevice>> BLEDevicesMap; 23 typedef std::unordered_map<std::string, scoped_ptr<BLEDevice>> BLEDevicesMap;
23 // The key of GattServicesMap, GattCharacteristicsMap and GattDescriptorsMap is 24 // The key of GattServicesMap, GattCharacteristicsMap and GattDescriptorsMap is
24 // the string of the attribute handle. 25 // the string of the attribute handle.
25 typedef std::unordered_map<std::string, scoped_ptr<GattService>> 26 typedef std::unordered_map<std::string, scoped_ptr<GattService>>
26 GattServicesMap; 27 GattServicesMap;
27 typedef std::unordered_map<std::string, scoped_ptr<GattCharacteristic>> 28 typedef std::unordered_map<std::string, scoped_ptr<GattCharacteristic>>
28 GattCharacteristicsMap; 29 GattCharacteristicsMap;
29 typedef std::unordered_map<std::string, scoped_ptr<GattDescriptor>> 30 typedef std::unordered_map<std::string, scoped_ptr<GattDescriptor>>
30 GattDescriptorsMap; 31 GattDescriptorsMap;
31 // The key of BLEAttributeHandleTable is the string of the BLE device address. 32 // The key of BLEAttributeHandleTable is the string of the BLE device address.
32 typedef std::unordered_map<std::string, scoped_ptr<std::set<USHORT>>> 33 typedef std::unordered_map<std::string, scoped_ptr<std::set<USHORT>>>
33 BLEAttributeHandleTable; 34 BLEAttributeHandleTable;
35 // The key of GattCharacteristicObserverTable is GattCharacteristicObserver
36 // pointer.
37 // Note: The underlying data type of BLUETOOTH_GATT_EVENT_HANDLE is PVOID.
38 typedef std::unordered_map<BLUETOOTH_GATT_EVENT_HANDLE,
39 scoped_ptr<GattCharacteristicObserver>>
40 GattCharacteristicObserverTable;
34 41
35 struct BLEDevice { 42 struct BLEDevice {
36 BLEDevice(); 43 BLEDevice();
37 ~BLEDevice(); 44 ~BLEDevice();
38 scoped_ptr<BluetoothLowEnergyDeviceInfo> device_info; 45 scoped_ptr<BluetoothLowEnergyDeviceInfo> device_info;
39 GattServicesMap primary_services; 46 GattServicesMap primary_services;
40 }; 47 };
41 48
42 struct GattService { 49 struct GattService {
43 GattService(); 50 GattService();
44 ~GattService(); 51 ~GattService();
45 scoped_ptr<BTH_LE_GATT_SERVICE> service_info; 52 scoped_ptr<BTH_LE_GATT_SERVICE> service_info;
46 GattServicesMap included_services; 53 GattServicesMap included_services;
47 GattCharacteristicsMap included_characteristics; 54 GattCharacteristicsMap included_characteristics;
48 }; 55 };
49 56
50 struct GattCharacteristic { 57 struct GattCharacteristic {
51 GattCharacteristic(); 58 GattCharacteristic();
52 ~GattCharacteristic(); 59 ~GattCharacteristic();
53 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristic_info; 60 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristic_info;
54 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> value; 61 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> value;
55 GattDescriptorsMap included_descriptors; 62 GattDescriptorsMap included_descriptors;
56 std::vector<HRESULT> read_errors; 63 std::vector<HRESULT> read_errors;
57 std::vector<HRESULT> write_errors; 64 std::vector<HRESULT> write_errors;
65 std::vector<BLUETOOTH_GATT_EVENT_HANDLE> observers;
58 }; 66 };
59 67
60 struct GattDescriptor { 68 struct GattDescriptor {
61 GattDescriptor(); 69 GattDescriptor();
62 ~GattDescriptor(); 70 ~GattDescriptor();
63 scoped_ptr<BTH_LE_GATT_DESCRIPTOR> descriptor_info; 71 scoped_ptr<BTH_LE_GATT_DESCRIPTOR> descriptor_info;
64 scoped_ptr<BTH_LE_GATT_DESCRIPTOR_VALUE> value; 72 scoped_ptr<BTH_LE_GATT_DESCRIPTOR_VALUE> value;
65 }; 73 };
66 74
75 struct GattCharacteristicObserver {
76 GattCharacteristicObserver();
77 ~GattCharacteristicObserver();
78 PFNBLUETOOTH_GATT_EVENT_CALLBACK callback;
79 PVOID context;
80 };
81
67 // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin. 82 // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin.
68 class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper { 83 class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper {
69 public: 84 public:
70 class Observer { 85 class Observer {
71 public: 86 public:
72 Observer() {} 87 Observer() {}
73 ~Observer() {} 88 ~Observer() {}
74 89
75 virtual void onWriteGattCharacteristicValue( 90 virtual void OnReadGattCharacteristicValue() = 0;
91 virtual void OnWriteGattCharacteristicValue(
76 const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) = 0; 92 const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) = 0;
93 virtual void OnStartCharacteristicNotification() = 0;
77 }; 94 };
78 95
79 BluetoothLowEnergyWrapperFake(); 96 BluetoothLowEnergyWrapperFake();
80 ~BluetoothLowEnergyWrapperFake() override; 97 ~BluetoothLowEnergyWrapperFake() override;
81 98
82 bool IsBluetoothLowEnergySupported() override; 99 bool IsBluetoothLowEnergySupported() override;
83 bool EnumerateKnownBluetoothLowEnergyDevices( 100 bool EnumerateKnownBluetoothLowEnergyDevices(
84 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 101 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices,
85 std::string* error) override; 102 std::string* error) override;
86 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( 103 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices(
(...skipping 14 matching lines...) Expand all
101 scoped_ptr<BTH_LE_GATT_DESCRIPTOR>* out_included_descriptors, 118 scoped_ptr<BTH_LE_GATT_DESCRIPTOR>* out_included_descriptors,
102 USHORT* out_counts) override; 119 USHORT* out_counts) override;
103 HRESULT ReadCharacteristicValue( 120 HRESULT ReadCharacteristicValue(
104 base::FilePath& service_path, 121 base::FilePath& service_path,
105 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 122 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
106 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) override; 123 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) override;
107 HRESULT WriteCharacteristicValue( 124 HRESULT WriteCharacteristicValue(
108 base::FilePath& service_path, 125 base::FilePath& service_path,
109 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 126 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
110 PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) override; 127 PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) override;
128 HRESULT RegisterGattEvents(base::FilePath& service_path,
129 BTH_LE_GATT_EVENT_TYPE type,
130 PVOID event_parameter,
131 PFNBLUETOOTH_GATT_EVENT_CALLBACK callback,
132 PVOID context,
133 BLUETOOTH_GATT_EVENT_HANDLE* out_handle) override;
134 HRESULT UnregisterGattEvent(
135 BLUETOOTH_GATT_EVENT_HANDLE event_handle) override;
111 136
112 BLEDevice* SimulateBLEDevice(std::string device_name, 137 BLEDevice* SimulateBLEDevice(std::string device_name,
113 BLUETOOTH_ADDRESS device_address); 138 BLUETOOTH_ADDRESS device_address);
114 BLEDevice* GetSimulatedBLEDevice(std::string device_address); 139 BLEDevice* GetSimulatedBLEDevice(std::string device_address);
115 void RemoveSimulatedBLEDevice(std::string device_address); 140 void RemoveSimulatedBLEDevice(std::string device_address);
116 141
117 // Note: |parent_service| may be nullptr to indicate a primary service. 142 // Note: |parent_service| may be nullptr to indicate a primary service.
118 GattService* SimulateGattService(BLEDevice* device, 143 GattService* SimulateGattService(BLEDevice* device,
119 GattService* parent_service, 144 GattService* parent_service,
120 const BTH_LE_UUID& uuid); 145 const BTH_LE_UUID& uuid);
(...skipping 13 matching lines...) Expand all
134 std::string device_address, 159 std::string device_address,
135 GattService* parent_service, 160 GattService* parent_service,
136 const BTH_LE_GATT_CHARACTERISTIC& characteristic); 161 const BTH_LE_GATT_CHARACTERISTIC& characteristic);
137 void SimulateGattCharacteriscRemove(GattService* parent_service, 162 void SimulateGattCharacteriscRemove(GattService* parent_service,
138 std::string attribute_handle); 163 std::string attribute_handle);
139 GattCharacteristic* GetSimulatedGattCharacteristic( 164 GattCharacteristic* GetSimulatedGattCharacteristic(
140 GattService* parent_service, 165 GattService* parent_service,
141 std::string attribute_handle); 166 std::string attribute_handle);
142 void SimulateGattCharacteristicValue(GattCharacteristic* characteristic, 167 void SimulateGattCharacteristicValue(GattCharacteristic* characteristic,
143 const std::vector<uint8_t>& value); 168 const std::vector<uint8_t>& value);
169 void SimulateCharacteristicValueChangeNotification(
170 GattCharacteristic* characteristic);
144 void SimulateGattCharacteristicReadError(GattCharacteristic* characteristic, 171 void SimulateGattCharacteristicReadError(GattCharacteristic* characteristic,
145 HRESULT error); 172 HRESULT error);
146 void SimulateGattCharacteristicWriteError(GattCharacteristic* characteristic, 173 void SimulateGattCharacteristicWriteError(GattCharacteristic* characteristic,
147 HRESULT error); 174 HRESULT error);
148 void SimulateGattDescriptor(std::string device_address, 175 void SimulateGattDescriptor(std::string device_address,
149 GattCharacteristic* characteristic, 176 GattCharacteristic* characteristic,
150 const BTH_LE_UUID& uuid); 177 const BTH_LE_UUID& uuid);
151 void AddObserver(Observer* observer); 178 void AddObserver(Observer* observer);
152 179
153 private: 180 private:
(...skipping 25 matching lines...) Expand all
179 base::string16 path); 206 base::string16 path);
180 207
181 // The canonical BLE device address string format is the 208 // The canonical BLE device address string format is the
182 // BluetoothDevice::CanonicalizeAddress. 209 // BluetoothDevice::CanonicalizeAddress.
183 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); 210 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha);
184 211
185 // Table to store allocated attribute handle for a device. 212 // Table to store allocated attribute handle for a device.
186 BLEAttributeHandleTable attribute_handle_table_; 213 BLEAttributeHandleTable attribute_handle_table_;
187 BLEDevicesMap simulated_devices_; 214 BLEDevicesMap simulated_devices_;
188 Observer* observer_; 215 Observer* observer_;
216 GattCharacteristicObserverTable gatt_characteristic_observers_;
189 }; 217 };
190 218
191 } // namespace win 219 } // namespace win
192 } // namespace device 220 } // namespace device
193 221
194 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ 222 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698