| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 GattServicesMap included_services; | 46 GattServicesMap included_services; |
| 47 GattCharacteristicsMap included_characteristics; | 47 GattCharacteristicsMap included_characteristics; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 struct GattCharacteristic { | 50 struct GattCharacteristic { |
| 51 GattCharacteristic(); | 51 GattCharacteristic(); |
| 52 ~GattCharacteristic(); | 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 GattDescriptorsMap included_descriptors; | 55 GattDescriptorsMap included_descriptors; |
| 56 std::vector<HRESULT> read_errors; |
| 57 std::vector<HRESULT> write_errors; |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 struct GattDescriptor { | 60 struct GattDescriptor { |
| 59 GattDescriptor(); | 61 GattDescriptor(); |
| 60 ~GattDescriptor(); | 62 ~GattDescriptor(); |
| 61 scoped_ptr<BTH_LE_GATT_DESCRIPTOR> descriptor_info; | 63 scoped_ptr<BTH_LE_GATT_DESCRIPTOR> descriptor_info; |
| 62 scoped_ptr<BTH_LE_GATT_DESCRIPTOR_VALUE> value; | 64 scoped_ptr<BTH_LE_GATT_DESCRIPTOR_VALUE> value; |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin. | 67 // Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin. |
| 66 class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper { | 68 class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper { |
| 67 public: | 69 public: |
| 70 class Observer { |
| 71 public: |
| 72 Observer() {} |
| 73 ~Observer() {} |
| 74 |
| 75 virtual void onWriteGattCharacteristicValue( |
| 76 const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) = 0; |
| 77 }; |
| 78 |
| 68 BluetoothLowEnergyWrapperFake(); | 79 BluetoothLowEnergyWrapperFake(); |
| 69 ~BluetoothLowEnergyWrapperFake() override; | 80 ~BluetoothLowEnergyWrapperFake() override; |
| 70 | 81 |
| 71 bool IsBluetoothLowEnergySupported() override; | 82 bool IsBluetoothLowEnergySupported() override; |
| 72 bool EnumerateKnownBluetoothLowEnergyDevices( | 83 bool EnumerateKnownBluetoothLowEnergyDevices( |
| 73 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 84 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, |
| 74 std::string* error) override; | 85 std::string* error) override; |
| 75 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( | 86 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( |
| 76 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 87 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, |
| 77 std::string* error) override; | 88 std::string* error) override; |
| 78 bool EnumerateKnownBluetoothLowEnergyServices( | 89 bool EnumerateKnownBluetoothLowEnergyServices( |
| 79 const base::FilePath& device_path, | 90 const base::FilePath& device_path, |
| 80 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 91 ScopedVector<BluetoothLowEnergyServiceInfo>* services, |
| 81 std::string* error) override; | 92 std::string* error) override; |
| 82 HRESULT ReadCharacteristicsOfAService( | 93 HRESULT ReadCharacteristicsOfAService( |
| 83 base::FilePath& service_path, | 94 base::FilePath& service_path, |
| 84 const PBTH_LE_GATT_SERVICE service, | 95 const PBTH_LE_GATT_SERVICE service, |
| 85 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>* out_included_characteristics, | 96 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>* out_included_characteristics, |
| 86 USHORT* out_counts) override; | 97 USHORT* out_counts) override; |
| 87 HRESULT ReadDescriptorsOfACharacteristic( | 98 HRESULT ReadDescriptorsOfACharacteristic( |
| 88 base::FilePath& service_path, | 99 base::FilePath& service_path, |
| 89 const PBTH_LE_GATT_CHARACTERISTIC characteristic, | 100 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 90 scoped_ptr<BTH_LE_GATT_DESCRIPTOR>* out_included_descriptors, | 101 scoped_ptr<BTH_LE_GATT_DESCRIPTOR>* out_included_descriptors, |
| 91 USHORT* out_counts) override; | 102 USHORT* out_counts) override; |
| 103 HRESULT ReadCharacteristicValue( |
| 104 base::FilePath& service_path, |
| 105 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 106 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) override; |
| 107 HRESULT WriteCharacteristicValue( |
| 108 base::FilePath& service_path, |
| 109 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 110 PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) override; |
| 92 | 111 |
| 93 BLEDevice* SimulateBLEDevice(std::string device_name, | 112 BLEDevice* SimulateBLEDevice(std::string device_name, |
| 94 BLUETOOTH_ADDRESS device_address); | 113 BLUETOOTH_ADDRESS device_address); |
| 95 BLEDevice* GetSimulatedBLEDevice(std::string device_address); | 114 BLEDevice* GetSimulatedBLEDevice(std::string device_address); |
| 115 void RemoveSimulatedBLEDevice(std::string device_address); |
| 96 | 116 |
| 97 // Note: |parent_service| may be nullptr to indicate a primary service. | 117 // Note: |parent_service| may be nullptr to indicate a primary service. |
| 98 GattService* SimulateGattService(BLEDevice* device, | 118 GattService* SimulateGattService(BLEDevice* device, |
| 99 GattService* parent_service, | 119 GattService* parent_service, |
| 100 const BTH_LE_UUID& uuid); | 120 const BTH_LE_UUID& uuid); |
| 101 | 121 |
| 102 // Note: |parent_service| may be nullptr to indicate a primary service. | 122 // Note: |parent_service| may be nullptr to indicate a primary service. |
| 103 void SimulateGattServiceRemoved(BLEDevice* device, | 123 void SimulateGattServiceRemoved(BLEDevice* device, |
| 104 GattService* parent_service, | 124 GattService* parent_service, |
| 105 std::string attribute_handle); | 125 std::string attribute_handle); |
| 106 | 126 |
| 107 // Note: |chain_of_att_handle| contains the attribute handles of the services | 127 // 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 | 128 // in order from primary service to target service. The last item in |
| 109 // |chain_of_att_handle| is the target service's attribute handle. | 129 // |chain_of_att_handle| is the target service's attribute handle. |
| 110 GattService* GetSimulatedGattService( | 130 GattService* GetSimulatedGattService( |
| 111 BLEDevice* device, | 131 BLEDevice* device, |
| 112 const std::vector<std::string>& chain_of_att_handle); | 132 const std::vector<std::string>& chain_of_att_handle); |
| 113 GattCharacteristic* SimulateGattCharacterisc( | 133 GattCharacteristic* SimulateGattCharacterisc( |
| 114 std::string device_address, | 134 std::string device_address, |
| 115 GattService* parent_service, | 135 GattService* parent_service, |
| 116 const BTH_LE_GATT_CHARACTERISTIC& characteristic); | 136 const BTH_LE_GATT_CHARACTERISTIC& characteristic); |
| 117 void SimulateGattCharacteriscRemove(GattService* parent_service, | 137 void SimulateGattCharacteriscRemove(GattService* parent_service, |
| 118 std::string attribute_handle); | 138 std::string attribute_handle); |
| 119 GattCharacteristic* GetSimulatedGattCharacteristic( | 139 GattCharacteristic* GetSimulatedGattCharacteristic( |
| 120 GattService* parent_service, | 140 GattService* parent_service, |
| 121 std::string attribute_handle); | 141 std::string attribute_handle); |
| 142 void SimulateGattCharacteristicValue(GattCharacteristic* characteristic, |
| 143 const std::vector<uint8_t>& value); |
| 144 void SimulateGattCharacteristicReadError(GattCharacteristic* characteristic, |
| 145 HRESULT error); |
| 146 void SimulateGattCharacteristicWriteError(GattCharacteristic* characteristic, |
| 147 HRESULT error); |
| 122 void SimulateGattDescriptor(std::string device_address, | 148 void SimulateGattDescriptor(std::string device_address, |
| 123 GattCharacteristic* characteristic, | 149 GattCharacteristic* characteristic, |
| 124 const BTH_LE_UUID& uuid); | 150 const BTH_LE_UUID& uuid); |
| 151 void AddObserver(Observer* observer); |
| 125 | 152 |
| 126 private: | 153 private: |
| 127 // Get simulated characteristic by |service_path| and |characteristic| info. | 154 // Get simulated characteristic by |service_path| and |characteristic| info. |
| 128 GattCharacteristic* GetSimulatedGattCharacteristic( | 155 GattCharacteristic* GetSimulatedGattCharacteristic( |
| 129 base::FilePath& service_path, | 156 base::FilePath& service_path, |
| 130 const PBTH_LE_GATT_CHARACTERISTIC characteristic); | 157 const PBTH_LE_GATT_CHARACTERISTIC characteristic); |
| 131 | 158 |
| 132 // Generate an unique attribute handle on |device_address|. | 159 // Generate an unique attribute handle on |device_address|. |
| 133 USHORT GenerateAUniqueAttributeHandle(std::string device_address); | 160 USHORT GenerateAUniqueAttributeHandle(std::string device_address); |
| 134 | 161 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 151 std::vector<std::string> ExtractServiceAttributeHandlesFromDevicePath( | 178 std::vector<std::string> ExtractServiceAttributeHandlesFromDevicePath( |
| 152 base::string16 path); | 179 base::string16 path); |
| 153 | 180 |
| 154 // The canonical BLE device address string format is the | 181 // The canonical BLE device address string format is the |
| 155 // BluetoothDevice::CanonicalizeAddress. | 182 // BluetoothDevice::CanonicalizeAddress. |
| 156 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); | 183 std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha); |
| 157 | 184 |
| 158 // Table to store allocated attribute handle for a device. | 185 // Table to store allocated attribute handle for a device. |
| 159 BLEAttributeHandleTable attribute_handle_table_; | 186 BLEAttributeHandleTable attribute_handle_table_; |
| 160 BLEDevicesMap simulated_devices_; | 187 BLEDevicesMap simulated_devices_; |
| 188 Observer* observer_; |
| 161 }; | 189 }; |
| 162 | 190 |
| 163 } // namespace win | 191 } // namespace win |
| 164 } // namespace device | 192 } // namespace device |
| 165 | 193 |
| 166 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ | 194 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_FAKE_H_ |
| OLD | NEW |