| 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_mac.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 characteristic_value_read_or_write_in_progress_ = false; | 250 characteristic_value_read_or_write_in_progress_ = false; |
| 251 if (error) { | 251 if (error) { |
| 252 VLOG(1) << "Bluetooth error while reading for characteristic, domain: " | 252 VLOG(1) << "Bluetooth error while reading for characteristic, domain: " |
| 253 << base::SysNSStringToUTF8(error.domain) | 253 << base::SysNSStringToUTF8(error.domain) |
| 254 << ", error code: " << error.code; | 254 << ", error code: " << error.code; |
| 255 BluetoothGattService::GattErrorCode error_code = | 255 BluetoothGattService::GattErrorCode error_code = |
| 256 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 256 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
| 257 callbacks.second.Run(error_code); | 257 callbacks.second.Run(error_code); |
| 258 return; | 258 return; |
| 259 } | 259 } |
| 260 UpdateValueAndNotify(); | 260 UpdateValue(); |
| 261 callbacks.first.Run(value_); | 261 callbacks.first.Run(value_); |
| 262 } else if (IsNotifying()) { | 262 } else if (IsNotifying()) { |
| 263 UpdateValueAndNotify(); | 263 UpdateValue(); |
| 264 gatt_service_->GetMacAdapter()->NotifyGattCharacteristicValueChanged( |
| 265 this, value_); |
| 264 } else { | 266 } else { |
| 265 // In case of buggy device, nothing should be done if receiving extra | 267 // In case of buggy device, nothing should be done if receiving extra |
| 266 // read confirmation. | 268 // read confirmation. |
| 267 VLOG(1) << "Characteristic value updated while having no pending read nor " | 269 VLOG(1) << "Characteristic value updated while having no pending read nor " |
| 268 "notification."; | 270 "notification."; |
| 269 } | 271 } |
| 270 } | 272 } |
| 271 | 273 |
| 272 void BluetoothRemoteGattCharacteristicMac::UpdateValueAndNotify() { | 274 void BluetoothRemoteGattCharacteristicMac::UpdateValue() { |
| 273 NSData* nsdata_value = cb_characteristic_.get().value; | 275 NSData* nsdata_value = cb_characteristic_.get().value; |
| 274 const uint8_t* buffer = static_cast<const uint8_t*>(nsdata_value.bytes); | 276 const uint8_t* buffer = static_cast<const uint8_t*>(nsdata_value.bytes); |
| 275 value_.assign(buffer, buffer + nsdata_value.length); | 277 value_.assign(buffer, buffer + nsdata_value.length); |
| 276 gatt_service_->GetMacAdapter()->NotifyGattCharacteristicValueChanged(this, | |
| 277 value_); | |
| 278 } | 278 } |
| 279 | 279 |
| 280 void BluetoothRemoteGattCharacteristicMac::DidWriteValue(NSError* error) { | 280 void BluetoothRemoteGattCharacteristicMac::DidWriteValue(NSError* error) { |
| 281 CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected); | 281 CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected); |
| 282 if (!characteristic_value_read_or_write_in_progress_) { | 282 if (!characteristic_value_read_or_write_in_progress_) { |
| 283 // In case of buggy device, nothing should be done if receiving extra | 283 // In case of buggy device, nothing should be done if receiving extra |
| 284 // write confirmation. | 284 // write confirmation. |
| 285 VLOG(1) << "Write notification while no write operation pending."; | 285 VLOG(1) << "Write notification while no write operation pending."; |
| 286 return; | 286 return; |
| 287 } | 287 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 pair) { | 414 pair) { |
| 415 return pair.second->GetCBDescriptor() == cb_descriptor; | 415 return pair.second->GetCBDescriptor() == cb_descriptor; |
| 416 }); | 416 }); |
| 417 if (found == gatt_descriptor_macs_.end()) { | 417 if (found == gatt_descriptor_macs_.end()) { |
| 418 return nullptr; | 418 return nullptr; |
| 419 } else { | 419 } else { |
| 420 return found->second.get(); | 420 return found->second.get(); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 } // namespace device. | 423 } // namespace device. |
| OLD | NEW |