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

Unified Diff: device/bluetooth/bluetooth_low_energy_win_fake.cc

Issue 1749403002: Implement BluetoothRemoteGattCharacteristicWin::StartNotifySession and related unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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.cc
diff --git a/device/bluetooth/bluetooth_low_energy_win_fake.cc b/device/bluetooth/bluetooth_low_energy_win_fake.cc
index 548286d3a2335deda27fa714774a568b128feae5..d8dacee22840a4e7a8d84ff7b0180ad50e690acc 100644
--- a/device/bluetooth/bluetooth_low_energy_win_fake.cc
+++ b/device/bluetooth/bluetooth_low_energy_win_fake.cc
@@ -27,6 +27,9 @@ GattCharacteristic::~GattCharacteristic() {}
GattDescriptor::GattDescriptor() {}
GattDescriptor::~GattDescriptor() {}
+GattCharacteristicObserver::GattCharacteristicObserver() {}
+GattCharacteristicObserver::~GattCharacteristicObserver() {}
+
BluetoothLowEnergyWrapperFake::BluetoothLowEnergyWrapperFake()
: observer_(nullptr) {}
BluetoothLowEnergyWrapperFake::~BluetoothLowEnergyWrapperFake() {}
@@ -204,6 +207,8 @@ HRESULT BluetoothLowEnergyWrapperFake::ReadCharacteristicValue(
for (ULONG i = 0; i < ret_value->DataSize; i++)
ret_value->Data[i] = target_characteristic->value->Data[i];
out_value->reset(ret_value);
+ if (observer_)
+ observer_->OnReadGattCharacteristicValue();
return S_OK;
}
@@ -214,7 +219,7 @@ HRESULT BluetoothLowEnergyWrapperFake::WriteCharacteristicValue(
GattCharacteristic* target_characteristic =
GetSimulatedGattCharacteristic(service_path, characteristic);
if (target_characteristic == nullptr)
- return ERROR_NOT_FOUND;
+ return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
// Return error simulated by SimulateGattCharacteristicWriteError.
if (target_characteristic->write_errors.size()) {
@@ -232,7 +237,59 @@ HRESULT BluetoothLowEnergyWrapperFake::WriteCharacteristicValue(
win_value->DataSize = new_value->DataSize;
target_characteristic->value.reset(win_value);
if (observer_)
- observer_->onWriteGattCharacteristicValue(win_value);
+ observer_->OnWriteGattCharacteristicValue(win_value);
+ return S_OK;
+}
+
+HRESULT BluetoothLowEnergyWrapperFake::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) {
+ // Right now, only CharacteristicValueChangedEvent is supported.
+ CHECK(CharacteristicValueChangedEvent == type);
+
+ base::string16 device_address =
ortuno 2016/03/15 02:55:31 Why do you go through all the trouble of retrievin
gogerald1 2016/03/15 18:28:22 Done. Residual of removing CCCD
+ ExtractDeviceAddressFromDevicePath(service_path.value());
+ BLEDevice* target_device = GetSimulatedBLEDevice(
+ std::string(device_address.begin(), device_address.end()));
+ if (target_device == nullptr)
+ return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
+ const std::vector<std::string> service_att_handles =
+ ExtractServiceAttributeHandlesFromDevicePath(service_path.value());
+ GattService* target_service =
+ GetSimulatedGattService(target_device, service_att_handles);
+ if (target_service == nullptr)
+ return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
+
+ scoped_ptr<GattCharacteristicObserver> observer(
+ new GattCharacteristicObserver());
+ observer->callback = callback;
+ observer->context = context;
+ *out_handle = (BLUETOOTH_GATT_EVENT_HANDLE)observer.get();
+ gatt_characteristic_observers_[*out_handle] = std::move(observer);
+
+ PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION parameter =
+ (PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION)event_parameter;
+ for (USHORT i = 0; i < parameter->NumCharacteristics; i++) {
+ GattCharacteristic* target_characteristic = GetSimulatedGattCharacteristic(
+ target_service,
+ std::to_string(parameter->Characteristics[i].AttributeHandle));
+ CHECK(target_characteristic);
+ target_characteristic->observers.push_back(*out_handle);
+ }
+
+ if (observer_)
+ observer_->OnStartCharacteristicNotification();
+
+ return S_OK;
+}
+
+HRESULT BluetoothLowEnergyWrapperFake::UnregisterGattEvent(
+ BLUETOOTH_GATT_EVENT_HANDLE event_handle) {
+ gatt_characteristic_observers_.erase(event_handle);
return S_OK;
}
@@ -377,6 +434,26 @@ void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicValue(
characteristic->value.reset(win_value);
}
+void BluetoothLowEnergyWrapperFake::
+ SimulateCharacteristicValueChangeNotification(
+ GattCharacteristic* characteristic) {
+ for (const auto& observer : characteristic->observers) {
+ GattCharacteristicObserverTable::const_iterator it =
+ gatt_characteristic_observers_.find(observer);
+ // Check if |observer| has been unregistered by UnregisterGattEvent.
+ if (it != gatt_characteristic_observers_.end()) {
+ BLUETOOTH_GATT_VALUE_CHANGED_EVENT event;
+ event.ChangedAttributeHandle =
+ characteristic->characteristic_info->AttributeHandle;
+ event.CharacteristicValueDataSize =
+ characteristic->value->DataSize + sizeof(ULONG);
ortuno 2016/03/15 02:55:31 Why isn't event.CharacteristicValueDataSize == cha
gogerald1 2016/03/15 18:28:22 BTH_LE_GATT_CHARACTERISTIC_VALUE is a structure, i
+ event.CharacteristicValue = characteristic->value.get();
+ it->second->callback(CharacteristicValueChangedEvent, &event,
+ it->second->context);
+ }
+ }
+}
+
void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicReadError(
GattCharacteristic* characteristic,
HRESULT error) {

Powered by Google App Engine
This is Rietveld 408576698