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

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: use static_cast Created 4 years, 8 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;
94 virtual void OnWriteGattDescriptorValue(
95 const std::vector<uint8_t>& value) = 0;
77 }; 96 };
78 97
79 BluetoothLowEnergyWrapperFake(); 98 BluetoothLowEnergyWrapperFake();
80 ~BluetoothLowEnergyWrapperFake() override; 99 ~BluetoothLowEnergyWrapperFake() override;
81 100
82 bool IsBluetoothLowEnergySupported() override; 101 bool IsBluetoothLowEnergySupported() override;
83 bool EnumerateKnownBluetoothLowEnergyDevices( 102 bool EnumerateKnownBluetoothLowEnergyDevices(
84 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 103 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices,
85 std::string* error) override; 104 std::string* error) override;
86 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( 105 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices(
(...skipping 14 matching lines...) Expand all
101 scoped_ptr<BTH_LE_GATT_DESCRIPTOR>* out_included_descriptors, 120 scoped_ptr<BTH_LE_GATT_DESCRIPTOR>* out_included_descriptors,
102 USHORT* out_counts) override; 121 USHORT* out_counts) override;
103 HRESULT ReadCharacteristicValue( 122 HRESULT ReadCharacteristicValue(
104 base::FilePath& service_path, 123 base::FilePath& service_path,
105 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 124 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
106 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) override; 125 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) override;
107 HRESULT WriteCharacteristicValue( 126 HRESULT WriteCharacteristicValue(
108 base::FilePath& service_path, 127 base::FilePath& service_path,
109 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 128 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
110 PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) override; 129 PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) override;
130 HRESULT RegisterGattEvents(base::FilePath& service_path,
131 BTH_LE_GATT_EVENT_TYPE type,
132 PVOID event_parameter,
133 PFNBLUETOOTH_GATT_EVENT_CALLBACK callback,
134 PVOID context,
135 BLUETOOTH_GATT_EVENT_HANDLE* out_handle) override;
136 HRESULT UnregisterGattEvent(
137 BLUETOOTH_GATT_EVENT_HANDLE event_handle) override;
138 HRESULT WriteDescriptorValue(
139 base::FilePath& service_path,
140 const PBTH_LE_GATT_DESCRIPTOR descriptor,
141 PBTH_LE_GATT_DESCRIPTOR_VALUE new_value) override;
111 142
112 BLEDevice* SimulateBLEDevice(std::string device_name, 143 BLEDevice* SimulateBLEDevice(std::string device_name,
113 BLUETOOTH_ADDRESS device_address); 144 BLUETOOTH_ADDRESS device_address);
114 BLEDevice* GetSimulatedBLEDevice(std::string device_address); 145 BLEDevice* GetSimulatedBLEDevice(std::string device_address);
115 void RemoveSimulatedBLEDevice(std::string device_address); 146 void RemoveSimulatedBLEDevice(std::string device_address);
116 147
117 // Note: |parent_service| may be nullptr to indicate a primary service. 148 // Note: |parent_service| may be nullptr to indicate a primary service.
118 GattService* SimulateGattService(BLEDevice* device, 149 GattService* SimulateGattService(BLEDevice* device,
119 GattService* parent_service, 150 GattService* parent_service,
120 const BTH_LE_UUID& uuid); 151 const BTH_LE_UUID& uuid);
(...skipping 13 matching lines...) Expand all
134 std::string device_address, 165 std::string device_address,
135 GattService* parent_service, 166 GattService* parent_service,
136 const BTH_LE_GATT_CHARACTERISTIC& characteristic); 167 const BTH_LE_GATT_CHARACTERISTIC& characteristic);
137 void SimulateGattCharacteriscRemove(GattService* parent_service, 168 void SimulateGattCharacteriscRemove(GattService* parent_service,
138 std::string attribute_handle); 169 std::string attribute_handle);
139 GattCharacteristic* GetSimulatedGattCharacteristic( 170 GattCharacteristic* GetSimulatedGattCharacteristic(
140 GattService* parent_service, 171 GattService* parent_service,
141 std::string attribute_handle); 172 std::string attribute_handle);
142 void SimulateGattCharacteristicValue(GattCharacteristic* characteristic, 173 void SimulateGattCharacteristicValue(GattCharacteristic* characteristic,
143 const std::vector<uint8_t>& value); 174 const std::vector<uint8_t>& value);
175 void SimulateCharacteristicValueChangeNotification(
176 GattCharacteristic* characteristic);
144 void SimulateGattCharacteristicReadError(GattCharacteristic* characteristic, 177 void SimulateGattCharacteristicReadError(GattCharacteristic* characteristic,
145 HRESULT error); 178 HRESULT error);
146 void SimulateGattCharacteristicWriteError(GattCharacteristic* characteristic, 179 void SimulateGattCharacteristicWriteError(GattCharacteristic* characteristic,
147 HRESULT error); 180 HRESULT error);
181 void RememberCharacteristicForSubsequentAction(GattService* parent_service,
182 std::string attribute_handle);
148 void SimulateGattDescriptor(std::string device_address, 183 void SimulateGattDescriptor(std::string device_address,
149 GattCharacteristic* characteristic, 184 GattCharacteristic* characteristic,
150 const BTH_LE_UUID& uuid); 185 const BTH_LE_UUID& uuid);
151 void AddObserver(Observer* observer); 186 void AddObserver(Observer* observer);
152 187
153 private: 188 private:
154 // Get simulated characteristic by |service_path| and |characteristic| info. 189 // Get simulated characteristic by |service_path| and |characteristic| info.
155 GattCharacteristic* GetSimulatedGattCharacteristic( 190 GattCharacteristic* GetSimulatedGattCharacteristic(
156 base::FilePath& service_path, 191 base::FilePath& service_path,
157 const PBTH_LE_GATT_CHARACTERISTIC characteristic); 192 const PBTH_LE_GATT_CHARACTERISTIC characteristic);
(...skipping 21 matching lines...) Expand all
179 base::string16 path); 214 base::string16 path);
180 215
181 // The canonical BLE device address string format is the 216 // The canonical BLE device address string format is the
182 // BluetoothDevice::CanonicalizeAddress. 217 // BluetoothDevice::CanonicalizeAddress.
183 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); 218 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha);
184 219
185 // Table to store allocated attribute handle for a device. 220 // Table to store allocated attribute handle for a device.
186 BLEAttributeHandleTable attribute_handle_table_; 221 BLEAttributeHandleTable attribute_handle_table_;
187 BLEDevicesMap simulated_devices_; 222 BLEDevicesMap simulated_devices_;
188 Observer* observer_; 223 Observer* observer_;
224 GattCharacteristicObserverTable gatt_characteristic_observers_;
225 scoped_ptr<GattCharacteristic> remembered_characteristic_;
189 }; 226 };
190 227
191 } // namespace win 228 } // namespace win
192 } // namespace device 229 } // namespace device
193 230
194 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ 231 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698