Chromium Code Reviews| 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_characteristic_win.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "device/bluetooth/bluetooth_adapter_win.h" | 8 #include "device/bluetooth/bluetooth_adapter_win.h" |
| 9 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h" | 9 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h" |
| 10 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" | 10 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 | 49 |
| 50 BluetoothUUID BluetoothRemoteGattCharacteristicWin::GetUUID() const { | 50 BluetoothUUID BluetoothRemoteGattCharacteristicWin::GetUUID() const { |
| 51 return characteristic_uuid_; | 51 return characteristic_uuid_; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool BluetoothRemoteGattCharacteristicWin::IsLocal() const { | 54 bool BluetoothRemoteGattCharacteristicWin::IsLocal() const { |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 std::vector<uint8_t>& BluetoothRemoteGattCharacteristicWin::GetValue() const { | 58 std::vector<uint8_t>& BluetoothRemoteGattCharacteristicWin::GetValue() const { |
| 59 NOTIMPLEMENTED(); | |
| 60 return const_cast<std::vector<uint8_t>&>(characteristic_value_); | 59 return const_cast<std::vector<uint8_t>&>(characteristic_value_); |
| 61 } | 60 } |
| 62 | 61 |
| 63 BluetoothGattService* BluetoothRemoteGattCharacteristicWin::GetService() const { | 62 BluetoothGattService* BluetoothRemoteGattCharacteristicWin::GetService() const { |
| 64 return parent_service_; | 63 return parent_service_; |
| 65 } | 64 } |
| 66 | 65 |
| 67 BluetoothGattCharacteristic::Properties | 66 BluetoothGattCharacteristic::Properties |
| 68 BluetoothRemoteGattCharacteristicWin::GetProperties() const { | 67 BluetoothRemoteGattCharacteristicWin::GetProperties() const { |
| 69 BluetoothGattCharacteristic::Properties properties = PROPERTY_NONE; | 68 BluetoothGattCharacteristic::Properties properties = PROPERTY_NONE; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 void BluetoothRemoteGattCharacteristicWin::StartNotifySession( | 139 void BluetoothRemoteGattCharacteristicWin::StartNotifySession( |
| 141 const NotifySessionCallback& callback, | 140 const NotifySessionCallback& callback, |
| 142 const ErrorCallback& error_callback) { | 141 const ErrorCallback& error_callback) { |
| 143 NOTIMPLEMENTED(); | 142 NOTIMPLEMENTED(); |
| 144 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); | 143 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); |
| 145 } | 144 } |
| 146 | 145 |
| 147 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( | 146 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( |
| 148 const ValueCallback& callback, | 147 const ValueCallback& callback, |
| 149 const ErrorCallback& error_callback) { | 148 const ErrorCallback& error_callback) { |
| 150 NOTIMPLEMENTED(); | 149 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 151 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); | 150 |
| 151 if (!characteristic_info_.get()->IsReadable) { | |
| 152 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_PERMITTED); | |
| 153 return; | |
| 154 } | |
| 155 | |
| 156 read_remote_characteristic_value_callbacks_.push_back( | |
|
scheib
2016/03/02 05:59:05
Android is supporting only one outstanding read op
gogerald1
2016/03/02 23:56:29
Done.
| |
| 157 std::make_pair(callback, error_callback)); | |
| 158 task_manager_->PostReadGattCharacteristicValue( | |
| 159 parent_service_->GetServicePath(), characteristic_info_.get(), | |
| 160 base::Bind(&BluetoothRemoteGattCharacteristicWin:: | |
| 161 OnReadRemoteCharacteristicValueCallback, | |
| 162 weak_ptr_factory_.GetWeakPtr())); | |
| 152 } | 163 } |
| 153 | 164 |
| 154 void BluetoothRemoteGattCharacteristicWin::WriteRemoteCharacteristic( | 165 void BluetoothRemoteGattCharacteristicWin::WriteRemoteCharacteristic( |
| 155 const std::vector<uint8_t>& new_value, | 166 const std::vector<uint8_t>& new_value, |
| 156 const base::Closure& callback, | 167 const base::Closure& callback, |
| 157 const ErrorCallback& error_callback) { | 168 const ErrorCallback& error_callback) { |
| 158 NOTIMPLEMENTED(); | 169 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 159 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); | 170 |
| 171 if (!characteristic_info_.get()->IsWritable) { | |
| 172 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_PERMITTED); | |
| 173 return; | |
| 174 } | |
| 175 | |
| 176 write_remote_characteristic_value_callbacks_.push_back( | |
| 177 std::make_pair(callback, error_callback)); | |
| 178 task_manager_->PostWriteGattCharacteristicValue( | |
| 179 parent_service_->GetServicePath(), characteristic_info_.get(), new_value, | |
| 180 base::Bind(&BluetoothRemoteGattCharacteristicWin:: | |
| 181 OnWriteRemoteCharacteristicValueCallback, | |
| 182 weak_ptr_factory_.GetWeakPtr())); | |
| 160 } | 183 } |
| 161 | 184 |
| 162 void BluetoothRemoteGattCharacteristicWin::Update() { | 185 void BluetoothRemoteGattCharacteristicWin::Update() { |
| 163 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 186 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 164 | 187 |
| 165 task_manager_->PostGetGattIncludedDescriptors( | 188 task_manager_->PostGetGattIncludedDescriptors( |
| 166 parent_service_->GetServicePath(), characteristic_info_.get(), | 189 parent_service_->GetServicePath(), characteristic_info_.get(), |
| 167 base::Bind(&BluetoothRemoteGattCharacteristicWin:: | 190 base::Bind(&BluetoothRemoteGattCharacteristicWin:: |
| 168 OnGetIncludedDescriptorsCallback, | 191 OnGetIncludedDescriptorsCallback, |
| 169 weak_ptr_factory_.GetWeakPtr())); | 192 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 BluetoothTaskManagerWin::BluetoothLowEnergyUuidToBluetoothUuid( | 269 BluetoothTaskManagerWin::BluetoothLowEnergyUuidToBluetoothUuid( |
| 247 descriptors[i].DescriptorUuid); | 270 descriptors[i].DescriptorUuid); |
| 248 if (descriptor->GetUUID() == uuid && | 271 if (descriptor->GetUUID() == uuid && |
| 249 descriptor->GetAttributeHandle() == descriptors[i].AttributeHandle) { | 272 descriptor->GetAttributeHandle() == descriptors[i].AttributeHandle) { |
| 250 return true; | 273 return true; |
| 251 } | 274 } |
| 252 } | 275 } |
| 253 return false; | 276 return false; |
| 254 } | 277 } |
| 255 | 278 |
| 279 void BluetoothRemoteGattCharacteristicWin:: | |
| 280 OnReadRemoteCharacteristicValueCallback( | |
| 281 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> value, | |
| 282 HRESULT hr) { | |
| 283 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | |
| 284 | |
| 285 if (FAILED(hr)) { | |
| 286 for (const auto& callback : read_remote_characteristic_value_callbacks_) | |
| 287 callback.second.Run(HRESULTToGattErrorCode(hr)); | |
| 288 } else { | |
| 289 characteristic_value_.clear(); | |
| 290 for (ULONG i = 0; i < value->DataSize; i++) | |
| 291 characteristic_value_.push_back(value->Data[i]); | |
| 292 for (const auto& callback : read_remote_characteristic_value_callbacks_) | |
|
scheib
2016/03/02 05:59:05
When running callbacks always clear the member var
gogerald1
2016/03/02 23:56:29
Done.
| |
| 293 callback.first.Run(characteristic_value_); | |
| 294 } | |
| 295 | |
| 296 read_remote_characteristic_value_callbacks_.clear(); | |
| 297 } | |
| 298 | |
| 299 void BluetoothRemoteGattCharacteristicWin:: | |
| 300 OnWriteRemoteCharacteristicValueCallback(HRESULT hr) { | |
| 301 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | |
| 302 | |
| 303 if (FAILED(hr)) { | |
| 304 for (const auto& callback : write_remote_characteristic_value_callbacks_) | |
| 305 callback.second.Run(HRESULTToGattErrorCode(hr)); | |
| 306 } else { | |
| 307 for (const auto& callback : write_remote_characteristic_value_callbacks_) | |
| 308 callback.first.Run(); | |
| 309 } | |
| 310 | |
| 311 write_remote_characteristic_value_callbacks_.clear(); | |
| 312 } | |
| 313 | |
| 314 BluetoothGattService::GattErrorCode | |
| 315 BluetoothRemoteGattCharacteristicWin::HRESULTToGattErrorCode(HRESULT hr) { | |
| 316 switch (hr) { | |
| 317 case E_BLUETOOTH_ATT_READ_NOT_PERMITTED: | |
| 318 case E_BLUETOOTH_ATT_WRITE_NOT_PERMITTED: | |
| 319 return BluetoothGattService::GATT_ERROR_NOT_PERMITTED; | |
| 320 case E_BLUETOOTH_ATT_UNKNOWN_ERROR: | |
| 321 return BluetoothGattService::GATT_ERROR_UNKNOWN; | |
| 322 case ERROR_INVALID_USER_BUFFER: | |
| 323 case E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH: | |
| 324 return BluetoothGattService::GATT_ERROR_INVALID_LENGTH; | |
| 325 default: | |
| 326 return BluetoothGattService::GATT_ERROR_FAILED; | |
| 327 } | |
| 328 } | |
| 329 | |
| 256 } // namespace device. | 330 } // namespace device. |
| OLD | NEW |