| 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 #include "device/bluetooth/bluetooth_low_energy_win_fake.h" | 5 #include "device/bluetooth/bluetooth_low_energy_win_fake.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 PVOID context, | 254 PVOID context, |
| 255 BLUETOOTH_GATT_EVENT_HANDLE* out_handle) { | 255 BLUETOOTH_GATT_EVENT_HANDLE* out_handle) { |
| 256 // Right now, only CharacteristicValueChangedEvent is supported. | 256 // Right now, only CharacteristicValueChangedEvent is supported. |
| 257 CHECK(CharacteristicValueChangedEvent == type); | 257 CHECK(CharacteristicValueChangedEvent == type); |
| 258 | 258 |
| 259 std::unique_ptr<GattCharacteristicObserver> observer( | 259 std::unique_ptr<GattCharacteristicObserver> observer( |
| 260 new GattCharacteristicObserver()); | 260 new GattCharacteristicObserver()); |
| 261 observer->callback = callback; | 261 observer->callback = callback; |
| 262 observer->context = context; | 262 observer->context = context; |
| 263 *out_handle = (BLUETOOTH_GATT_EVENT_HANDLE)observer.get(); | 263 *out_handle = (BLUETOOTH_GATT_EVENT_HANDLE)observer.get(); |
| 264 gatt_characteristic_observers_[*out_handle] = std::move(observer); | |
| 265 | 264 |
| 266 PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION parameter = | 265 PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION parameter = |
| 267 (PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION)event_parameter; | 266 (PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION)event_parameter; |
| 268 for (USHORT i = 0; i < parameter->NumCharacteristics; i++) { | 267 for (USHORT i = 0; i < parameter->NumCharacteristics; i++) { |
| 269 GattCharacteristic* target_characteristic = GetSimulatedGattCharacteristic( | 268 GattCharacteristic* target_characteristic = GetSimulatedGattCharacteristic( |
| 270 service_path, ¶meter->Characteristics[i]); | 269 service_path, ¶meter->Characteristics[i]); |
| 271 CHECK(target_characteristic); | 270 CHECK(target_characteristic); |
| 271 |
| 272 // Return error simulated by SimulateGattCharacteristicSetNotifyError. |
| 273 if (target_characteristic->notify_errors.size()) { |
| 274 HRESULT error = target_characteristic->notify_errors[0]; |
| 275 target_characteristic->notify_errors.erase( |
| 276 target_characteristic->notify_errors.begin()); |
| 277 return error; |
| 278 } |
| 279 |
| 272 target_characteristic->observers.push_back(*out_handle); | 280 target_characteristic->observers.push_back(*out_handle); |
| 273 } | 281 } |
| 282 gatt_characteristic_observers_[*out_handle] = std::move(observer); |
| 274 | 283 |
| 275 if (observer_) | 284 if (observer_) |
| 276 observer_->OnStartCharacteristicNotification(); | 285 observer_->OnStartCharacteristicNotification(); |
| 277 | 286 |
| 278 return S_OK; | 287 return S_OK; |
| 279 } | 288 } |
| 280 | 289 |
| 281 HRESULT BluetoothLowEnergyWrapperFake::UnregisterGattEvent( | 290 HRESULT BluetoothLowEnergyWrapperFake::UnregisterGattEvent( |
| 282 BLUETOOTH_GATT_EVENT_HANDLE event_handle) { | 291 BLUETOOTH_GATT_EVENT_HANDLE event_handle) { |
| 283 gatt_characteristic_observers_.erase(event_handle); | 292 gatt_characteristic_observers_.erase(event_handle); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 target_characteristic->characteristic_info->AttributeHandle; | 483 target_characteristic->characteristic_info->AttributeHandle; |
| 475 event.CharacteristicValueDataSize = | 484 event.CharacteristicValueDataSize = |
| 476 target_characteristic->value->DataSize + sizeof(ULONG); | 485 target_characteristic->value->DataSize + sizeof(ULONG); |
| 477 event.CharacteristicValue = target_characteristic->value.get(); | 486 event.CharacteristicValue = target_characteristic->value.get(); |
| 478 it->second->callback(CharacteristicValueChangedEvent, &event, | 487 it->second->callback(CharacteristicValueChangedEvent, &event, |
| 479 it->second->context); | 488 it->second->context); |
| 480 } | 489 } |
| 481 } | 490 } |
| 482 } | 491 } |
| 483 | 492 |
| 493 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicSetNotifyError( |
| 494 GattCharacteristic* characteristic, |
| 495 HRESULT error) { |
| 496 characteristic->notify_errors.push_back(error); |
| 497 } |
| 498 |
| 484 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicReadError( | 499 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicReadError( |
| 485 GattCharacteristic* characteristic, | 500 GattCharacteristic* characteristic, |
| 486 HRESULT error) { | 501 HRESULT error) { |
| 487 CHECK(characteristic); | 502 CHECK(characteristic); |
| 488 characteristic->read_errors.push_back(error); | 503 characteristic->read_errors.push_back(error); |
| 489 } | 504 } |
| 490 | 505 |
| 491 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicWriteError( | 506 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicWriteError( |
| 492 GattCharacteristic* characteristic, | 507 GattCharacteristic* characteristic, |
| 493 HRESULT error) { | 508 HRESULT error) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 std::string BluetoothLowEnergyWrapperFake::BluetoothAddressToCanonicalString( | 636 std::string BluetoothLowEnergyWrapperFake::BluetoothAddressToCanonicalString( |
| 622 const BLUETOOTH_ADDRESS& btha) { | 637 const BLUETOOTH_ADDRESS& btha) { |
| 623 std::string result = base::StringPrintf( | 638 std::string result = base::StringPrintf( |
| 624 "%02X:%02X:%02X:%02X:%02X:%02X", btha.rgBytes[5], btha.rgBytes[4], | 639 "%02X:%02X:%02X:%02X:%02X:%02X", btha.rgBytes[5], btha.rgBytes[4], |
| 625 btha.rgBytes[3], btha.rgBytes[2], btha.rgBytes[1], btha.rgBytes[0]); | 640 btha.rgBytes[3], btha.rgBytes[2], btha.rgBytes[1], btha.rgBytes[0]); |
| 626 return result; | 641 return result; |
| 627 } | 642 } |
| 628 | 643 |
| 629 } // namespace win | 644 } // namespace win |
| 630 } // namespace device | 645 } // namespace device |
| OLD | NEW |