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