| 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> | 10 #include <set> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 EnumerateKnownBluetoothLowEnergyDevices( | 72 bool EnumerateKnownBluetoothLowEnergyDevices( |
| 72 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 73 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, |
| 73 std::string* error) override; | 74 std::string* error) override; |
| 74 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( | 75 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( |
| 75 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 76 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, |
| 76 std::string* error) override; | 77 std::string* error) override; |
| 77 bool EnumerateKnownBluetoothLowEnergyServices( | 78 bool EnumerateKnownBluetoothLowEnergyServices( |
| 78 const base::FilePath& device_path, | 79 const base::FilePath& device_path, |
| 79 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 80 ScopedVector<BluetoothLowEnergyServiceInfo>* services, |
| 80 std::string* error) override; | 81 std::string* error) override; |
| 82 HRESULT ReadIncludedServicesOfAService( |
| 83 base::FilePath& service_path, |
| 84 const PBTH_LE_GATT_SERVICE service, |
| 85 scoped_ptr<BTH_LE_GATT_SERVICE>* out_included_services, |
| 86 USHORT* out_counts) override; |
| 87 HRESULT ReadCharacteristicsOfAService( |
| 88 base::FilePath& service_path, |
| 89 const PBTH_LE_GATT_SERVICE service, |
| 90 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>* out_included_characteristics, |
| 91 USHORT* out_counts) override; |
| 81 | 92 |
| 82 BLEDevice* SimulateBLEDevice(std::string device_name, | 93 BLEDevice* SimulateBLEDevice(std::string device_name, |
| 83 BLUETOOTH_ADDRESS device_address); | 94 BLUETOOTH_ADDRESS device_address); |
| 84 BLEDevice* GetSimulatedBLEDevice(std::string device_address); | 95 BLEDevice* GetSimulatedBLEDevice(std::string device_address); |
| 85 BLEGattService* SimulateBLEGattService(BLEDevice* device, std::string uuid); | 96 |
| 97 // Note: |parent_service| may be nullptr to indicate a primary service. |
| 98 BLEGattService* SimulateBLEGattService(BLEDevice* device, |
| 99 BLEGattService* parent_service, |
| 100 const BTH_LE_UUID& uuid); |
| 101 |
| 102 // Note: |parent_service| may be nullptr to indicate a primary service. |
| 103 void SimulateBLEGattServiceRemoved(BLEDevice* device, |
| 104 BLEGattService* parent_service, |
| 105 std::string attribute_handle); |
| 106 |
| 107 // Note: |chain_of_att_handle| contains the attribute handles of the services |
| 108 // in order from primary service to target service. The last item in |
| 109 // |chain_of_att_handle| is the target service's attribute handle. |
| 110 BLEGattService* GetSimulatedGattService( |
| 111 BLEDevice* device, |
| 112 const std::vector<std::string>& chain_of_att_handle); |
| 113 BLEGattCharacteristic* SimulateBLEGattCharacterisc( |
| 114 std::string device_address, |
| 115 BLEGattService* parent_service, |
| 116 const BTH_LE_GATT_CHARACTERISTIC& characteristic); |
| 117 void SimulateBLEGattCharacteriscRemove(BLEGattService* parent_service, |
| 118 std::string attribute_handle); |
| 86 | 119 |
| 87 private: | 120 private: |
| 88 // Generate an unique attribute handle on |device_address|. | 121 // Generate an unique attribute handle on |device_address|. |
| 89 USHORT GenerateAUniqueAttributeHandle(std::string device_address); | 122 USHORT GenerateAUniqueAttributeHandle(std::string device_address); |
| 90 | 123 |
| 91 // Generate device path for the BLE device with |device_address|. | 124 // Generate device path for the BLE device with |device_address|. |
| 92 base::string16 GenerateBLEDevicePath(std::string device_address); | 125 base::string16 GenerateBLEDevicePath(std::string device_address); |
| 93 | 126 |
| 94 // Generate GATT service device path of the service with | 127 // Generate GATT service device path of the service with |
| 95 // |service_attribute_handle|. |resident_device_path| is the BLE device this | 128 // |service_attribute_handle|. |resident_device_path| is the BLE device this |
| 96 // GATT service belongs to. | 129 // GATT service belongs to. |
| 97 base::string16 GenerateBLEGattServiceDevicePath( | 130 base::string16 GenerateBLEGattServiceDevicePath( |
| 98 base::string16 resident_device_path, | 131 base::string16 resident_device_path, |
| 99 USHORT service_attribute_handle); | 132 USHORT service_attribute_handle); |
| 100 | 133 |
| 101 // Extract device address from the device |path| generated by | 134 // Extract device address from the device |path| generated by |
| 102 // GenerateBLEDevicePath or GenerateBLEGattServiceDevicePath. | 135 // GenerateBLEDevicePath or GenerateBLEGattServiceDevicePath. |
| 103 base::string16 ExtractDeviceAddressFromDevicePath(base::string16 path); | 136 base::string16 ExtractDeviceAddressFromDevicePath(base::string16 path); |
| 104 | 137 |
| 105 // Extract service attribute handle from the |path| generated by | 138 // Extract service attribute handles from the |path| generated by |
| 106 // GenerateBLEGattServiceDevicePath. | 139 // GenerateBLEGattServiceDevicePath. |
| 107 base::string16 ExtractServiceAttributeHandleFromDevicePath( | 140 std::vector<std::string> ExtractServiceAttributeHandlesFromDevicePath( |
| 108 base::string16 path); | 141 base::string16 path); |
| 109 | 142 |
| 110 // The canonical BLE device address string format is the | 143 // The canonical BLE device address string format is the |
| 111 // BluetoothDevice::CanonicalizeAddress. | 144 // BluetoothDevice::CanonicalizeAddress. |
| 112 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); | 145 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); |
| 113 | 146 |
| 114 // The canonical UUID string format is device::BluetoothUUID.value(). | |
| 115 BTH_LE_UUID CanonicalStringToBTH_LE_UUID(std::string uuid); | |
| 116 | |
| 117 // Table to store allocated attribute handle for a device. | 147 // Table to store allocated attribute handle for a device. |
| 118 BLEAttributeHandleTable attribute_handle_table_; | 148 BLEAttributeHandleTable attribute_handle_table_; |
| 119 BLEDevicesMap simulated_devices_; | 149 BLEDevicesMap simulated_devices_; |
| 120 }; | 150 }; |
| 121 | 151 |
| 122 } // namespace win | 152 } // namespace win |
| 123 } // namespace device | 153 } // namespace device |
| 124 | 154 |
| 125 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ | 155 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ |
| OLD | NEW |