OLD | NEW |
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> |
| 11 #include <unordered_map> |
| 12 |
10 namespace device { | 13 namespace device { |
11 namespace win { | 14 namespace win { |
12 | 15 |
| 16 struct BLEDevice; |
| 17 struct BLEGattService; |
| 18 struct BLEGattCharacteristic; |
| 19 struct BLEGattDescriptor; |
| 20 |
| 21 // The key of BLEDevicesMap is the string of the BLE device address. |
| 22 typedef std::unordered_map<std::string, scoped_ptr<BLEDevice>> BLEDevicesMap; |
| 23 // The key of BLEGattServicesMap, BLEGattCharacteristicsMap and |
| 24 // BLEGattDescriptorsMap is the string of the attribute handle. |
| 25 typedef std::unordered_map<std::string, scoped_ptr<BLEGattService>> |
| 26 BLEGattServicesMap; |
| 27 typedef std::unordered_map<std::string, scoped_ptr<BLEGattCharacteristic>> |
| 28 BLEGattCharacteristicsMap; |
| 29 typedef std::unordered_map<std::string, scoped_ptr<BLEGattDescriptor>> |
| 30 BLEGattDescriptorsMap; |
| 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>>> |
| 33 BLEAttributeHandleTable; |
| 34 |
| 35 struct BLEDevice { |
| 36 scoped_ptr<BluetoothLowEnergyDeviceInfo> device_info; |
| 37 BLEGattServicesMap primary_services; |
| 38 }; |
| 39 |
| 40 struct BLEGattService { |
| 41 scoped_ptr<BTH_LE_GATT_SERVICE> service_info; |
| 42 BLEGattServicesMap included_services; |
| 43 BLEGattCharacteristicsMap included_characteristics; |
| 44 }; |
| 45 |
| 46 struct BLEGattCharacteristic { |
| 47 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristic_info; |
| 48 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> value; |
| 49 BLEGattDescriptorsMap included_descriptors; |
| 50 }; |
| 51 |
| 52 struct BLEGattDescriptor { |
| 53 scoped_ptr<BTH_LE_GATT_DESCRIPTOR> descriptor_info; |
| 54 scoped_ptr<BTH_LE_GATT_DESCRIPTOR_VALUE> value; |
| 55 }; |
| 56 |
13 // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin. | 57 // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin. |
14 class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper { | 58 class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper { |
15 public: | 59 public: |
16 BluetoothLowEnergyWrapperFake(); | 60 BluetoothLowEnergyWrapperFake(); |
17 ~BluetoothLowEnergyWrapperFake() override; | 61 ~BluetoothLowEnergyWrapperFake() override; |
18 | 62 |
19 bool EnumerateKnownBluetoothLowEnergyDevices( | 63 bool EnumerateKnownBluetoothLowEnergyDevices( |
20 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 64 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, |
21 std::string* error) override; | 65 std::string* error) override; |
22 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( | 66 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( |
23 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 67 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, |
24 std::string* error) override; | 68 std::string* error) override; |
25 bool EnumerateKnownBluetoothLowEnergyServices( | 69 bool EnumerateKnownBluetoothLowEnergyServices( |
26 const base::FilePath& device_path, | 70 const base::FilePath& device_path, |
27 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 71 ScopedVector<BluetoothLowEnergyServiceInfo>* services, |
28 std::string* error) override; | 72 std::string* error) override; |
| 73 |
| 74 BLEDevice* SimulateBLEDevice(std::string device_name, |
| 75 BLUETOOTH_ADDRESS device_address); |
| 76 BLEGattService* SimulateBLEGattService(BLEDevice* device, std::string uuid); |
| 77 |
| 78 private: |
| 79 // Generate an unique attribute handle on |device_address|. |
| 80 USHORT GenerateAUniqueAttributeHandle(std::string device_address); |
| 81 |
| 82 // Generate device path for the BLE device with |device_address|. |
| 83 base::string16 GenerateBLEDevicePath(std::string device_address); |
| 84 |
| 85 // Generate GATT service device path of the service with |
| 86 // |service_attribute_handle|. |resident_device_path| is the BLE device this |
| 87 // GATT service belongs to. |
| 88 base::string16 GenerateBLEGattServiceDevicePath( |
| 89 base::string16 resident_device_path, |
| 90 USHORT service_attribute_handle); |
| 91 |
| 92 // Extract device address from the device |path| generated by |
| 93 // GenerateBLEDevicePath or GenerateBLEGattServiceDevicePath. |
| 94 base::string16 ExtractDeviceAddressFromDevicePath(base::string16 path); |
| 95 |
| 96 // Extract service attribute handle from the |path| generated by |
| 97 // GenerateBLEGattServiceDevicePath. |
| 98 base::string16 ExtractServiceAttributeHandleFromDevicePath( |
| 99 base::string16 path); |
| 100 |
| 101 // The canonical BLE device address string format is the |
| 102 // BluetoothDevice::CanonicalizeAddress. |
| 103 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); |
| 104 |
| 105 // The canonical UUID string format is device::BluetoothUUID.value(). |
| 106 BTH_LE_UUID CanonicalStringToBTH_LE_UUID(std::string uuid); |
| 107 |
| 108 // Table to store allocated attribute handle for a device. |
| 109 BLEAttributeHandleTable attribute_handle_table_; |
| 110 BLEDevicesMap simulated_devices_; |
29 }; | 111 }; |
30 | 112 |
31 } // namespace win | 113 } // namespace win |
32 } // namespace device | 114 } // namespace device |
33 | 115 |
34 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ | 116 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ |
OLD | NEW |