Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2738)

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc

Issue 1739383002: Implement read & write remote GATT characteristic value for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix conversion from 'size_t' to 'ULONG' error on trybot Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 baf4a73467996ec9f7a2c7f90109cf8e859d1df0..f93f6fc977181348b9d8e25acad6ca39c3f305fb 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_win.cc
@@ -56,7 +56,6 @@ bool BluetoothRemoteGattCharacteristicWin::IsLocal() const {
}
std::vector<uint8_t>& BluetoothRemoteGattCharacteristicWin::GetValue() const {
- NOTIMPLEMENTED();
return const_cast<std::vector<uint8_t>&>(characteristic_value_);
}
@@ -147,16 +146,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(
scheib 2016/03/02 05:59:05 Android is supporting only one outstanding read op
gogerald1 2016/03/02 23:56:29 Done.
+ std::make_pair(callback, error_callback));
+ task_manager_->PostReadGattCharacteristicValue(
+ 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_->PostWriteGattCharacteristicValue(
+ parent_service_->GetServicePath(), characteristic_info_.get(), new_value,
+ base::Bind(&BluetoothRemoteGattCharacteristicWin::
+ OnWriteRemoteCharacteristicValueCallback,
+ weak_ptr_factory_.GetWeakPtr()));
}
void BluetoothRemoteGattCharacteristicWin::Update() {
@@ -253,4 +276,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_)
scheib 2016/03/02 05:59:05 When running callbacks always clear the member var
gogerald1 2016/03/02 23:56:29 Done.
+ 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.

Powered by Google App Engine
This is Rietveld 408576698