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

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

Issue 1728163006: Implement BluetoothRemoteGattCharacteristicWin::GetDescriptors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments 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 BLEGattService; 17 struct GattService;
18 struct BLEGattCharacteristic; 18 struct GattCharacteristic;
19 struct BLEGattDescriptor; 19 struct GattDescriptor;
20 20
21 // The key of BLEDevicesMap is the string of the BLE device address. 21 // The key of BLEDevicesMap is the string of the BLE device address.
22 typedef std::unordered_map<std::string, scoped_ptr<BLEDevice>> BLEDevicesMap; 22 typedef std::unordered_map<std::string, scoped_ptr<BLEDevice>> BLEDevicesMap;
23 // The key of BLEGattServicesMap, BLEGattCharacteristicsMap and 23 // The key of GattServicesMap, GattCharacteristicsMap and GattDescriptorsMap is
24 // BLEGattDescriptorsMap is the string of the attribute handle. 24 // the string of the attribute handle.
25 typedef std::unordered_map<std::string, scoped_ptr<BLEGattService>> 25 typedef std::unordered_map<std::string, scoped_ptr<GattService>>
26 BLEGattServicesMap; 26 GattServicesMap;
27 typedef std::unordered_map<std::string, scoped_ptr<BLEGattCharacteristic>> 27 typedef std::unordered_map<std::string, scoped_ptr<GattCharacteristic>>
28 BLEGattCharacteristicsMap; 28 GattCharacteristicsMap;
29 typedef std::unordered_map<std::string, scoped_ptr<BLEGattDescriptor>> 29 typedef std::unordered_map<std::string, scoped_ptr<GattDescriptor>>
30 BLEGattDescriptorsMap; 30 GattDescriptorsMap;
31 // The key of BLEAttributeHandleTable is the string of the BLE device address. 31 // The key of BLEAttributeHandleTable is the string of the BLE device address.
32 typedef std::unordered_map<std::string, scoped_ptr<std::set<USHORT>>> 32 typedef std::unordered_map<std::string, scoped_ptr<std::set<USHORT>>>
33 BLEAttributeHandleTable; 33 BLEAttributeHandleTable;
34 34
35 struct BLEDevice { 35 struct BLEDevice {
36 BLEDevice(); 36 BLEDevice();
37 ~BLEDevice(); 37 ~BLEDevice();
38 scoped_ptr<BluetoothLowEnergyDeviceInfo> device_info; 38 scoped_ptr<BluetoothLowEnergyDeviceInfo> device_info;
39 BLEGattServicesMap primary_services; 39 GattServicesMap primary_services;
40 }; 40 };
41 41
42 struct BLEGattService { 42 struct GattService {
43 BLEGattService(); 43 GattService();
44 ~BLEGattService(); 44 ~GattService();
45 scoped_ptr<BTH_LE_GATT_SERVICE> service_info; 45 scoped_ptr<BTH_LE_GATT_SERVICE> service_info;
46 BLEGattServicesMap included_services; 46 GattServicesMap included_services;
47 BLEGattCharacteristicsMap included_characteristics; 47 GattCharacteristicsMap included_characteristics;
48 }; 48 };
49 49
50 struct BLEGattCharacteristic { 50 struct GattCharacteristic {
51 BLEGattCharacteristic(); 51 GattCharacteristic();
52 ~BLEGattCharacteristic(); 52 ~GattCharacteristic();
53 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristic_info; 53 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristic_info;
54 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> value; 54 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> value;
55 BLEGattDescriptorsMap included_descriptors; 55 GattDescriptorsMap included_descriptors;
56 }; 56 };
57 57
58 struct BLEGattDescriptor { 58 struct GattDescriptor {
59 BLEGattDescriptor(); 59 GattDescriptor();
60 ~BLEGattDescriptor(); 60 ~GattDescriptor();
61 scoped_ptr<BTH_LE_GATT_DESCRIPTOR> descriptor_info; 61 scoped_ptr<BTH_LE_GATT_DESCRIPTOR> descriptor_info;
62 scoped_ptr<BTH_LE_GATT_DESCRIPTOR_VALUE> value; 62 scoped_ptr<BTH_LE_GATT_DESCRIPTOR_VALUE> value;
63 }; 63 };
64 64
65 // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin. 65 // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin.
66 class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper { 66 class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper {
67 public: 67 public:
68 BluetoothLowEnergyWrapperFake(); 68 BluetoothLowEnergyWrapperFake();
69 ~BluetoothLowEnergyWrapperFake() override; 69 ~BluetoothLowEnergyWrapperFake() override;
70 70
71 bool IsBluetoothLowEnergySupported() override; 71 bool IsBluetoothLowEnergySupported() override;
72 bool EnumerateKnownBluetoothLowEnergyDevices( 72 bool EnumerateKnownBluetoothLowEnergyDevices(
73 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 73 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices,
74 std::string* error) override; 74 std::string* error) override;
75 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( 75 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices(
76 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 76 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices,
77 std::string* error) override; 77 std::string* error) override;
78 bool EnumerateKnownBluetoothLowEnergyServices( 78 bool EnumerateKnownBluetoothLowEnergyServices(
79 const base::FilePath& device_path, 79 const base::FilePath& device_path,
80 ScopedVector<BluetoothLowEnergyServiceInfo>* services, 80 ScopedVector<BluetoothLowEnergyServiceInfo>* services,
81 std::string* error) override; 81 std::string* error) override;
82 HRESULT ReadCharacteristicsOfAService( 82 HRESULT ReadCharacteristicsOfAService(
83 base::FilePath& service_path, 83 base::FilePath& service_path,
84 const PBTH_LE_GATT_SERVICE service, 84 const PBTH_LE_GATT_SERVICE service,
85 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>* out_included_characteristics, 85 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>* out_included_characteristics,
86 USHORT* out_counts) override; 86 USHORT* out_counts) override;
87 HRESULT ReadDescriptorsOfACharacteristic(
88 base::FilePath& service_path,
89 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
90 scoped_ptr<BTH_LE_GATT_DESCRIPTOR>* out_included_descriptors,
91 USHORT* out_counts) override;
87 92
88 BLEDevice* SimulateBLEDevice(std::string device_name, 93 BLEDevice* SimulateBLEDevice(std::string device_name,
89 BLUETOOTH_ADDRESS device_address); 94 BLUETOOTH_ADDRESS device_address);
90 BLEDevice* GetSimulatedBLEDevice(std::string device_address); 95 BLEDevice* GetSimulatedBLEDevice(std::string device_address);
91 96
92 // Note: |parent_service| may be nullptr to indicate a primary service. 97 // Note: |parent_service| may be nullptr to indicate a primary service.
93 BLEGattService* SimulateBLEGattService(BLEDevice* device, 98 GattService* SimulateGattService(BLEDevice* device,
94 BLEGattService* parent_service, 99 GattService* parent_service,
95 const BTH_LE_UUID& uuid); 100 const BTH_LE_UUID& uuid);
96 101
97 // Note: |parent_service| may be nullptr to indicate a primary service. 102 // Note: |parent_service| may be nullptr to indicate a primary service.
98 void SimulateBLEGattServiceRemoved(BLEDevice* device, 103 void SimulateGattServiceRemoved(BLEDevice* device,
99 BLEGattService* parent_service, 104 GattService* parent_service,
100 std::string attribute_handle); 105 std::string attribute_handle);
101 106
102 // Note: |chain_of_att_handle| contains the attribute handles of the services 107 // Note: |chain_of_att_handle| contains the attribute handles of the services
103 // in order from primary service to target service. The last item in 108 // in order from primary service to target service. The last item in
104 // |chain_of_att_handle| is the target service's attribute handle. 109 // |chain_of_att_handle| is the target service's attribute handle.
105 BLEGattService* GetSimulatedGattService( 110 GattService* GetSimulatedGattService(
106 BLEDevice* device, 111 BLEDevice* device,
107 const std::vector<std::string>& chain_of_att_handle); 112 const std::vector<std::string>& chain_of_att_handle);
108 BLEGattCharacteristic* SimulateBLEGattCharacterisc( 113 GattCharacteristic* SimulateGattCharacterisc(
109 std::string device_address, 114 std::string device_address,
110 BLEGattService* parent_service, 115 GattService* parent_service,
111 const BTH_LE_GATT_CHARACTERISTIC& characteristic); 116 const BTH_LE_GATT_CHARACTERISTIC& characteristic);
112 void SimulateBLEGattCharacteriscRemove(BLEGattService* parent_service, 117 void SimulateGattCharacteriscRemove(GattService* parent_service,
113 std::string attribute_handle); 118 std::string attribute_handle);
119 GattCharacteristic* GetSimulatedGattCharacteristic(
120 GattService* parent_service,
121 std::string attribute_handle);
122 void SimulateGattDescriptor(std::string device_address,
123 GattCharacteristic* characteristic,
124 const BTH_LE_UUID& uuid);
114 125
115 private: 126 private:
127 // Get simulated characteristic by |service_path| and |characteristic| info.
128 GattCharacteristic* GetSimulatedGattCharacteristic(
129 base::FilePath& service_path,
130 const PBTH_LE_GATT_CHARACTERISTIC characteristic);
131
116 // Generate an unique attribute handle on |device_address|. 132 // Generate an unique attribute handle on |device_address|.
117 USHORT GenerateAUniqueAttributeHandle(std::string device_address); 133 USHORT GenerateAUniqueAttributeHandle(std::string device_address);
118 134
119 // Generate device path for the BLE device with |device_address|. 135 // Generate device path for the BLE device with |device_address|.
120 base::string16 GenerateBLEDevicePath(std::string device_address); 136 base::string16 GenerateBLEDevicePath(std::string device_address);
121 137
122 // Generate GATT service device path of the service with 138 // Generate GATT service device path of the service with
123 // |service_attribute_handle|. |resident_device_path| is the BLE device this 139 // |service_attribute_handle|. |resident_device_path| is the BLE device this
124 // GATT service belongs to. 140 // GATT service belongs to.
125 base::string16 GenerateBLEGattServiceDevicePath( 141 base::string16 GenerateGattServiceDevicePath(
126 base::string16 resident_device_path, 142 base::string16 resident_device_path,
127 USHORT service_attribute_handle); 143 USHORT service_attribute_handle);
128 144
129 // Extract device address from the device |path| generated by 145 // Extract device address from the device |path| generated by
130 // GenerateBLEDevicePath or GenerateBLEGattServiceDevicePath. 146 // GenerateBLEDevicePath or GenerateGattServiceDevicePath.
131 base::string16 ExtractDeviceAddressFromDevicePath(base::string16 path); 147 base::string16 ExtractDeviceAddressFromDevicePath(base::string16 path);
132 148
133 // Extract service attribute handles from the |path| generated by 149 // Extract service attribute handles from the |path| generated by
134 // GenerateBLEGattServiceDevicePath. 150 // GenerateGattServiceDevicePath.
135 std::vector<std::string> ExtractServiceAttributeHandlesFromDevicePath( 151 std::vector<std::string> ExtractServiceAttributeHandlesFromDevicePath(
136 base::string16 path); 152 base::string16 path);
137 153
138 // The canonical BLE device address string format is the 154 // The canonical BLE device address string format is the
139 // BluetoothDevice::CanonicalizeAddress. 155 // BluetoothDevice::CanonicalizeAddress.
140 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); 156 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha);
141 157
142 // Table to store allocated attribute handle for a device. 158 // Table to store allocated attribute handle for a device.
143 BLEAttributeHandleTable attribute_handle_table_; 159 BLEAttributeHandleTable attribute_handle_table_;
144 BLEDevicesMap simulated_devices_; 160 BLEDevicesMap simulated_devices_;
145 }; 161 };
146 162
147 } // namespace win 163 } // namespace win
148 } // namespace device 164 } // namespace device
149 165
150 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ 166 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_win.cc ('k') | device/bluetooth/bluetooth_low_energy_win_fake.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698