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

Unified Diff: device/bluetooth/bluetooth_low_energy_win_fake.h

Issue 1749403002: Implement BluetoothRemoteGattCharacteristicWin::StartNotifySession and related unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change new_value->at(i) to (*new_value)[i] 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_low_energy_win_fake.h
diff --git a/device/bluetooth/bluetooth_low_energy_win_fake.h b/device/bluetooth/bluetooth_low_energy_win_fake.h
index 46b56318925ac2ab804aba8b73f5711373034db2..87706b7a78a3a9e6460bbef714d83fbef96a46ba 100644
--- a/device/bluetooth/bluetooth_low_energy_win_fake.h
+++ b/device/bluetooth/bluetooth_low_energy_win_fake.h
@@ -15,6 +15,7 @@ namespace win {
struct BLEDevice;
struct GattService;
+struct GattServiceObserver;
struct GattCharacteristic;
struct GattDescriptor;
@@ -31,6 +32,11 @@ typedef std::unordered_map<std::string, scoped_ptr<GattDescriptor>>
// The key of BLEAttributeHandleTable is the string of the BLE device address.
typedef std::unordered_map<std::string, scoped_ptr<std::set<USHORT>>>
BLEAttributeHandleTable;
+// The key of GattServiceObserverTable is GattServiceObserver pointer.
+// Note: The underlying data type of BLUETOOTH_GATT_EVENT_HANDLE is PVOID.
+typedef std::unordered_map<BLUETOOTH_GATT_EVENT_HANDLE,
+ scoped_ptr<GattServiceObserver>>
+ GattServiceObserverTable;
struct BLEDevice {
BLEDevice();
@@ -45,6 +51,7 @@ struct GattService {
scoped_ptr<BTH_LE_GATT_SERVICE> service_info;
GattServicesMap included_services;
GattCharacteristicsMap included_characteristics;
+ std::vector<BLUETOOTH_GATT_EVENT_HANDLE> observers;
};
struct GattCharacteristic {
@@ -55,6 +62,7 @@ struct GattCharacteristic {
GattDescriptorsMap included_descriptors;
std::vector<HRESULT> read_errors;
std::vector<HRESULT> write_errors;
+ std::vector<HRESULT> notify_errors;
};
struct GattDescriptor {
@@ -62,6 +70,14 @@ struct GattDescriptor {
~GattDescriptor();
scoped_ptr<BTH_LE_GATT_DESCRIPTOR> descriptor_info;
scoped_ptr<BTH_LE_GATT_DESCRIPTOR_VALUE> value;
+ std::vector<HRESULT> write_errors;
+};
+
+struct GattServiceObserver {
+ GattServiceObserver();
+ ~GattServiceObserver();
+ PFNBLUETOOTH_GATT_EVENT_CALLBACK callback;
+ PVOID context;
};
// Fake implementation of BluetoothLowEnergyWrapper. Used for BluetoothTestWin.
@@ -72,8 +88,12 @@ class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper {
Observer() {}
~Observer() {}
- virtual void onWriteGattCharacteristicValue(
+ virtual void OnReadGattCharacteristicValue() = 0;
+ virtual void OnWriteGattCharacteristicValue(
const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) = 0;
+ virtual void OnWriteGattDescriptorValue(
+ const PBTH_LE_GATT_DESCRIPTOR_VALUE value) = 0;
+ virtual void OnStartCharacteristicNotification() = 0;
};
BluetoothLowEnergyWrapperFake();
@@ -108,6 +128,14 @@ class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper {
base::FilePath& service_path,
const PBTH_LE_GATT_CHARACTERISTIC characteristic,
PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) override;
+ HRESULT RegisterGattEvents(base::FilePath& service_path,
+ BTH_LE_GATT_EVENT_TYPE type,
+ PVOID event_parameter,
+ PFNBLUETOOTH_GATT_EVENT_CALLBACK callback,
+ PVOID context,
+ BLUETOOTH_GATT_EVENT_HANDLE* out_handle) override;
+ HRESULT UnregisterGattEvent(
+ BLUETOOTH_GATT_EVENT_HANDLE event_handle) override;
BLEDevice* SimulateBLEDevice(std::string device_name,
BLUETOOTH_ADDRESS device_address);
@@ -141,13 +169,26 @@ class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper {
std::string attribute_handle);
void SimulateGattCharacteristicValue(GattCharacteristic* characteristic,
const std::vector<uint8_t>& value);
+ void SimulateCharacteristicValueChangeNotification(
+ GattService* parent_service,
+ GattCharacteristic* characteristic);
void SimulateGattCharacteristicReadError(GattCharacteristic* characteristic,
HRESULT error);
void SimulateGattCharacteristicWriteError(GattCharacteristic* characteristic,
HRESULT error);
+ void SimulateGattCharacteristicSetNotifyError(
+ GattCharacteristic* characteristic,
+ HRESULT error);
void SimulateGattDescriptor(std::string device_address,
GattCharacteristic* characteristic,
const BTH_LE_UUID& uuid);
+ GattDescriptor* GetSimulatedDescriptor(
+ GattCharacteristic* parent_characteristic,
+ std::string attribute_handle);
+ void SimulateGattDescriptorWrite(GattDescriptor* descriptor,
+ const std::vector<uint8_t>& value);
+ void SimulateGattDescriptorWriteError(GattDescriptor* descriptor,
+ HRESULT error);
void AddObserver(Observer* observer);
private:
@@ -182,10 +223,15 @@ class BluetoothLowEnergyWrapperFake : public BluetoothLowEnergyWrapper {
// BluetoothDevice::CanonicalizeAddress.
std::string BluetoothAddressToCanonicalString(const BLUETOOTH_ADDRESS& btha);
+ // Get client |characteristic| configuration descriptor which has standard
+ // UUID = 00002902-0000-1000-8000-00805f9b34fb.
+ GattDescriptor* GetCCCDescriptor(GattCharacteristic* characteristic);
+
// Table to store allocated attribute handle for a device.
BLEAttributeHandleTable attribute_handle_table_;
BLEDevicesMap simulated_devices_;
Observer* observer_;
+ GattServiceObserverTable gatt_service_observers_;
};
} // namespace win

Powered by Google App Engine
This is Rietveld 408576698