| Index: device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc
|
| diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc
|
| index dfefbd6f472e7470a3d5d6293750bc4343e23a83..a1110709a1243d6169c38eff0090ebb1a0aba589 100644
|
| --- a/device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc
|
| +++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc
|
| @@ -58,7 +58,6 @@ bool BluetoothRemoteGattCharacteristicWin::IsLocal() const {
|
| }
|
|
|
| std::vector<uint8_t>& BluetoothRemoteGattCharacteristicWin::GetValue() const {
|
| - NOTIMPLEMENTED();
|
| return const_cast<std::vector<uint8_t>&>(characteristic_value_);
|
| }
|
|
|
| @@ -149,16 +148,40 @@ void BluetoothRemoteGattCharacteristicWin::StartNotifySession(
|
| void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic(
|
| const ValueCallback& callback,
|
| const ErrorCallback& error_callback) {
|
| - NOTIMPLEMENTED();
|
| - error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED);
|
| + DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
|
| +
|
| + if (!characteristic_info_.get()->IsReadable) {
|
| + error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_PERMITTED);
|
| + return;
|
| + }
|
| +
|
| + read_remote_characteristic_value_callbacks_.push_back(
|
| + std::make_pair(callback, error_callback));
|
| + task_manager_->PostReadCharacteristicValue(
|
| + parent_service_->GetServicePath(), characteristic_info_.get(),
|
| + base::Bind(&BluetoothRemoteGattCharacteristicWin::
|
| + OnReadRemoteCharacteristicValueCallback,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| void BluetoothRemoteGattCharacteristicWin::WriteRemoteCharacteristic(
|
| const std::vector<uint8_t>& new_value,
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback) {
|
| - NOTIMPLEMENTED();
|
| - error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED);
|
| + DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
|
| +
|
| + if (!characteristic_info_.get()->IsWritable) {
|
| + error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_PERMITTED);
|
| + return;
|
| + }
|
| +
|
| + write_remote_characteristic_value_callbacks_.push_back(
|
| + std::make_pair(callback, error_callback));
|
| + task_manager_->PostWriteCharacteristicValue(
|
| + parent_service_->GetServicePath(), characteristic_info_.get(), new_value,
|
| + base::Bind(&BluetoothRemoteGattCharacteristicWin::
|
| + OnWriteRemoteCharacteristicValueCallback,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| void BluetoothRemoteGattCharacteristicWin::Update() {
|
| @@ -255,4 +278,55 @@ bool BluetoothRemoteGattCharacteristicWin::DoesDescriptorExist(
|
| return false;
|
| }
|
|
|
| +void BluetoothRemoteGattCharacteristicWin::
|
| + OnReadRemoteCharacteristicValueCallback(
|
| + scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> value,
|
| + HRESULT hr) {
|
| + DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
|
| +
|
| + if (FAILED(hr)) {
|
| + for (const auto& callback : read_remote_characteristic_value_callbacks_)
|
| + callback.second.Run(HRESULTToGattErrorCode(hr));
|
| + } else {
|
| + characteristic_value_.clear();
|
| + for (ULONG i = 0; i < value->DataSize; i++)
|
| + characteristic_value_.push_back(value->Data[i]);
|
| + for (const auto& callback : read_remote_characteristic_value_callbacks_)
|
| + callback.first.Run(characteristic_value_);
|
| + }
|
| +
|
| + read_remote_characteristic_value_callbacks_.clear();
|
| +}
|
| +
|
| +void BluetoothRemoteGattCharacteristicWin::
|
| + OnWriteRemoteCharacteristicValueCallback(HRESULT hr) {
|
| + DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
|
| +
|
| + if (FAILED(hr)) {
|
| + for (const auto& callback : write_remote_characteristic_value_callbacks_)
|
| + callback.second.Run(HRESULTToGattErrorCode(hr));
|
| + } else {
|
| + for (const auto& callback : write_remote_characteristic_value_callbacks_)
|
| + callback.first.Run();
|
| + }
|
| +
|
| + write_remote_characteristic_value_callbacks_.clear();
|
| +}
|
| +
|
| +BluetoothGattService::GattErrorCode
|
| +BluetoothRemoteGattCharacteristicWin::HRESULTToGattErrorCode(HRESULT hr) {
|
| + switch (hr) {
|
| + case E_BLUETOOTH_ATT_READ_NOT_PERMITTED:
|
| + case E_BLUETOOTH_ATT_WRITE_NOT_PERMITTED:
|
| + return BluetoothGattService::GATT_ERROR_NOT_PERMITTED;
|
| + case E_BLUETOOTH_ATT_UNKNOWN_ERROR:
|
| + return BluetoothGattService::GATT_ERROR_UNKNOWN;
|
| + case ERROR_INVALID_USER_BUFFER:
|
| + case E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH:
|
| + return BluetoothGattService::GATT_ERROR_INVALID_LENGTH;
|
| + default:
|
| + return BluetoothGattService::GATT_ERROR_FAILED;
|
| + }
|
| +}
|
| +
|
| } // namespace device.
|
|
|