| 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_remote_gatt_service_win.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 : device_(device), | 26 : device_(device), |
| 27 service_path_(service_path), | 27 service_path_(service_path), |
| 28 service_uuid_(service_uuid), | 28 service_uuid_(service_uuid), |
| 29 service_attribute_handle_(service_attribute_handle), | 29 service_attribute_handle_(service_attribute_handle), |
| 30 is_primary_(is_primary), | 30 is_primary_(is_primary), |
| 31 parent_service_(parent_service), | 31 parent_service_(parent_service), |
| 32 ui_task_runner_(ui_task_runner), | 32 ui_task_runner_(ui_task_runner), |
| 33 discovery_complete_notified_(false), | 33 discovery_complete_notified_(false), |
| 34 included_characteristics_discovered_(false), | 34 included_characteristics_discovered_(false), |
| 35 weak_ptr_factory_(this) { | 35 weak_ptr_factory_(this) { |
| 36 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 36 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 37 DCHECK(!service_path_.empty()); | 37 DCHECK(!service_path_.empty()); |
| 38 DCHECK(service_uuid_.IsValid()); | 38 DCHECK(service_uuid_.IsValid()); |
| 39 DCHECK(service_attribute_handle_); | 39 DCHECK(service_attribute_handle_); |
| 40 DCHECK(device_); | 40 DCHECK(device_); |
| 41 if (!is_primary_) | 41 if (!is_primary_) |
| 42 DCHECK(parent_service_); | 42 DCHECK(parent_service_); |
| 43 | 43 |
| 44 adapter_ = static_cast<BluetoothAdapterWin*>(device_->GetAdapter()); | 44 adapter_ = static_cast<BluetoothAdapterWin*>(device_->GetAdapter()); |
| 45 DCHECK(adapter_); | 45 DCHECK(adapter_); |
| 46 task_manager_ = adapter_->GetWinBluetoothTaskManager(); | 46 task_manager_ = adapter_->GetWinBluetoothTaskManager(); |
| 47 DCHECK(task_manager_); | 47 DCHECK(task_manager_); |
| 48 service_identifier_ = device_->GetIdentifier() + "/" + service_uuid_.value() + | 48 service_identifier_ = device_->GetIdentifier() + "/" + service_uuid_.value() + |
| 49 "_" + std::to_string(service_attribute_handle_); | 49 "_" + std::to_string(service_attribute_handle_); |
| 50 Update(); | 50 Update(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 BluetoothRemoteGattServiceWin::~BluetoothRemoteGattServiceWin() { | 53 BluetoothRemoteGattServiceWin::~BluetoothRemoteGattServiceWin() { |
| 54 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 54 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 55 | 55 |
| 56 ClearIncludedCharacteristics(); | 56 ClearIncludedCharacteristics(); |
| 57 | 57 |
| 58 adapter_->NotifyGattServiceRemoved(this); | 58 adapter_->NotifyGattServiceRemoved(this); |
| 59 } | 59 } |
| 60 | 60 |
| 61 std::string BluetoothRemoteGattServiceWin::GetIdentifier() const { | 61 std::string BluetoothRemoteGattServiceWin::GetIdentifier() const { |
| 62 return service_identifier_; | 62 return service_identifier_; |
| 63 } | 63 } |
| 64 | 64 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 94 const std::string& identifier) const { | 94 const std::string& identifier) const { |
| 95 GattCharacteristicsMap::const_iterator it = | 95 GattCharacteristicsMap::const_iterator it = |
| 96 included_characteristics_.find(identifier); | 96 included_characteristics_.find(identifier); |
| 97 if (it != included_characteristics_.end()) | 97 if (it != included_characteristics_.end()) |
| 98 return it->second.get(); | 98 return it->second.get(); |
| 99 return nullptr; | 99 return nullptr; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void BluetoothRemoteGattServiceWin::GattCharacteristicDiscoveryComplete( | 102 void BluetoothRemoteGattServiceWin::GattCharacteristicDiscoveryComplete( |
| 103 BluetoothRemoteGattCharacteristicWin* characteristic) { | 103 BluetoothRemoteGattCharacteristicWin* characteristic) { |
| 104 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 104 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 105 DCHECK(included_characteristics_.find(characteristic->GetIdentifier()) != | 105 DCHECK(included_characteristics_.find(characteristic->GetIdentifier()) != |
| 106 included_characteristics_.end()); | 106 included_characteristics_.end()); |
| 107 | 107 |
| 108 discovery_completed_included_charateristics_.insert( | 108 discovery_completed_included_charateristics_.insert( |
| 109 characteristic->GetIdentifier()); | 109 characteristic->GetIdentifier()); |
| 110 adapter_->NotifyGattCharacteristicAdded(characteristic); | 110 adapter_->NotifyGattCharacteristicAdded(characteristic); |
| 111 NotifyGattDiscoveryCompleteForServiceIfNecessary(); | 111 NotifyGattDiscoveryCompleteForServiceIfNecessary(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void BluetoothRemoteGattServiceWin::Update() { | 114 void BluetoothRemoteGattServiceWin::Update() { |
| 115 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 115 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 116 | 116 |
| 117 task_manager_->PostGetGattIncludedCharacteristics( | 117 task_manager_->PostGetGattIncludedCharacteristics( |
| 118 service_path_, service_uuid_, service_attribute_handle_, | 118 service_path_, service_uuid_, service_attribute_handle_, |
| 119 base::Bind(&BluetoothRemoteGattServiceWin::OnGetIncludedCharacteristics, | 119 base::Bind(&BluetoothRemoteGattServiceWin::OnGetIncludedCharacteristics, |
| 120 weak_ptr_factory_.GetWeakPtr())); | 120 weak_ptr_factory_.GetWeakPtr())); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void BluetoothRemoteGattServiceWin::OnGetIncludedCharacteristics( | 123 void BluetoothRemoteGattServiceWin::OnGetIncludedCharacteristics( |
| 124 std::unique_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristics, | 124 std::unique_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristics, |
| 125 uint16_t num, | 125 uint16_t num, |
| 126 HRESULT hr) { | 126 HRESULT hr) { |
| 127 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 127 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
| 128 | 128 |
| 129 UpdateIncludedCharacteristics(characteristics.get(), num); | 129 UpdateIncludedCharacteristics(characteristics.get(), num); |
| 130 included_characteristics_discovered_ = true; | 130 included_characteristics_discovered_ = true; |
| 131 NotifyGattDiscoveryCompleteForServiceIfNecessary(); | 131 NotifyGattDiscoveryCompleteForServiceIfNecessary(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void BluetoothRemoteGattServiceWin::UpdateIncludedCharacteristics( | 134 void BluetoothRemoteGattServiceWin::UpdateIncludedCharacteristics( |
| 135 PBTH_LE_GATT_CHARACTERISTIC characteristics, | 135 PBTH_LE_GATT_CHARACTERISTIC characteristics, |
| 136 uint16_t num) { | 136 uint16_t num) { |
| 137 if (num == 0) { | 137 if (num == 0) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 void BluetoothRemoteGattServiceWin::ClearIncludedCharacteristics() { | 228 void BluetoothRemoteGattServiceWin::ClearIncludedCharacteristics() { |
| 229 discovery_completed_included_charateristics_.clear(); | 229 discovery_completed_included_charateristics_.clear(); |
| 230 // Explicitly reset to null to ensure that calling GetCharacteristic() on the | 230 // Explicitly reset to null to ensure that calling GetCharacteristic() on the |
| 231 // removed characteristic in GattDescriptorRemoved() returns null. | 231 // removed characteristic in GattDescriptorRemoved() returns null. |
| 232 for (auto& entry : included_characteristics_) | 232 for (auto& entry : included_characteristics_) |
| 233 entry.second.reset(); | 233 entry.second.reset(); |
| 234 included_characteristics_.clear(); | 234 included_characteristics_.clear(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 } // namespace device. | 237 } // namespace device. |
| OLD | NEW |