Commit d01b7c9e authored by Kinuko Yasuda's avatar Kinuko Yasuda Committed by Commit Bot

Revert "[Bluetooth][WinRT] Implement Reading and Writing of Descriptors"

This reverts commit f61df6f9.

Reason for revert: Multiple BluetoothTestWinrt{,Only} tests failing on Win10 Tests bot after around this change.

Sample builds:
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Win10%20Tests%20x64%20%28dbg%29/2242
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Win10%20Tests%20x64%20%28dbg%29/2240
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Win10%20Tests%20x64%20%28dbg%29/2236
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Win10%20Tests%20x64%20%28dbg%29/2235

failures:
BluetoothTestWinrtOnly.GattServices_ObserversCalls/0
BluetoothTestWinrt.GetPrimaryServices/1
BluetoothRemoteGattServiceTestWinrt.SimulateGattServiceRemove/1
BluetoothTestWinrt.GetPrimaryServicesByUUID/1
BluetoothTestWinrtOnly.BluetoothGattConnection_DisconnectGatt_Cleanup/0
BluetoothTestWinrt.GetGattServices_and_GetGattService/1
BluetoothRemoteGattServiceTestWinrt.GetCharacteristicsByUUID/1
BluetoothTestWinrtOnly.GattServicesDiscovered_Success/0

Original change's description:
> [Bluetooth][WinRT] Implement Reading and Writing of Descriptors
> 
> This change implements reading and writing of Remote Gatt Descriptors
> for WinRT. Furthermore, it enables corresponding tests.
> 
> Bug: 821766
> Change-Id: I3ac07969c3fbf3806b71543ae79807c95efe78fe
> Reviewed-on: https://chromium-review.googlesource.com/1156703
> Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#579838}

TBR=reillyg@chromium.org,ortuno@chromium.org,jdoerrie@chromium.org

Change-Id: Icb716ed05f9b8bec2a5b1bdd33692006314a99e7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 821766
Reviewed-on: https://chromium-review.googlesource.com/1159961Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580062}
parent a0896c26
......@@ -45,14 +45,12 @@ class BluetoothRemoteGattDescriptorTest :
ASSERT_EQ(1u, device_->GetGattServices().size());
service_ = device_->GetGattServices()[0];
SimulateGattCharacteristic(service_, kTestUUIDDeviceName, 0);
base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, service_->GetCharacteristics().size());
characteristic_ = service_->GetCharacteristics()[0];
SimulateGattDescriptor(characteristic_,
kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(characteristic_,
kTestUUIDClientCharacteristicConfiguration);
base::RunLoop().RunUntilIdle();
ASSERT_EQ(2u, characteristic_->GetDescriptors().size());
descriptor1_ = characteristic_->GetDescriptors()[0];
descriptor2_ = characteristic_->GetDescriptors()[1];
......@@ -225,11 +223,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_GetUUID) {
#define MAYBE_ReadRemoteDescriptor_Empty DISABLED_ReadRemoteDescriptor_Empty
#endif
// Tests ReadRemoteDescriptor and GetValue with empty value buffer.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly, ReadRemoteDescriptor_Empty) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadRemoteDescriptor_Empty) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -257,12 +251,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadRemoteDescriptor_Empty) {
#define MAYBE_WriteRemoteDescriptor_Empty DISABLED_WriteRemoteDescriptor_Empty
#endif
// Tests WriteRemoteDescriptor with empty value buffer.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly,
WriteRemoteDescriptor_Empty) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteRemoteDescriptor_Empty) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -351,11 +340,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest,
#define MAYBE_ReadRemoteDescriptor DISABLED_ReadRemoteDescriptor
#endif
// Tests ReadRemoteDescriptor and GetValue with non-empty value buffer.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly, ReadRemoteDescriptor) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadRemoteDescriptor) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -386,11 +371,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadRemoteDescriptor) {
#define MAYBE_WriteRemoteDescriptor DISABLED_WriteRemoteDescriptor
#endif
// Tests WriteRemoteDescriptor with non-empty value buffer.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly, WriteRemoteDescriptor) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteRemoteDescriptor) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -415,11 +396,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteRemoteDescriptor) {
#define MAYBE_ReadRemoteDescriptor_Twice DISABLED_ReadRemoteDescriptor_Twice
#endif
// Tests ReadRemoteDescriptor and GetValue multiple times.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly, ReadRemoteDescriptor_Twice) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadRemoteDescriptor_Twice) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -459,12 +436,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadRemoteDescriptor_Twice) {
#define MAYBE_WriteRemoteDescriptor_Twice DISABLED_WriteRemoteDescriptor_Twice
#endif
// Tests WriteRemoteDescriptor multiple times.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly,
WriteRemoteDescriptor_Twice) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteRemoteDescriptor_Twice) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -504,13 +476,8 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteRemoteDescriptor_Twice) {
DISABLED_ReadRemoteDescriptor_MultipleDescriptors
#endif
// Tests ReadRemoteDescriptor on two descriptors.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly,
ReadRemoteDescriptor_MultipleDescriptors) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest,
MAYBE_ReadRemoteDescriptor_MultipleDescriptors) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -551,13 +518,8 @@ TEST_F(BluetoothRemoteGattDescriptorTest,
DISABLED_WriteRemoteDescriptor_MultipleDescriptors
#endif
// Tests WriteRemoteDescriptor on two descriptors.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly,
WriteRemoteDescriptor_MultipleDescriptors) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest,
MAYBE_WriteRemoteDescriptor_MultipleDescriptors) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -594,11 +556,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest,
#define MAYBE_ReadError DISABLED_ReadError
#endif
// Tests ReadRemoteDescriptor asynchronous error.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly, ReadError) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadError) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -622,11 +580,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadError) {
#define MAYBE_WriteError DISABLED_WriteError
#endif
// Tests WriteRemoteDescriptor asynchronous error.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly, WriteError) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteError) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -729,13 +683,8 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteSynchronousError) {
DISABLED_ReadRemoteDescriptor_ReadPending
#endif
// Tests ReadRemoteDescriptor error with a pending read operation.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly,
ReadRemoteDescriptor_ReadPending) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest,
MAYBE_ReadRemoteDescriptor_ReadPending) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -771,13 +720,8 @@ TEST_F(BluetoothRemoteGattDescriptorTest,
DISABLED_WriteRemoteDescriptor_WritePending
#endif
// Tests WriteRemoteDescriptor error with a pending write operation.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly,
WriteRemoteDescriptor_WritePending) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest,
MAYBE_WriteRemoteDescriptor_WritePending) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -814,13 +758,8 @@ TEST_F(BluetoothRemoteGattDescriptorTest,
DISABLED_ReadRemoteDescriptor_WritePending
#endif
// Tests ReadRemoteDescriptor error with a pending write operation.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly,
ReadRemoteDescriptor_WritePending) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest,
MAYBE_ReadRemoteDescriptor_WritePending) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -856,13 +795,8 @@ TEST_F(BluetoothRemoteGattDescriptorTest,
DISABLED_WriteRemoteDescriptor_ReadPending
#endif
// Tests WriteRemoteDescriptor error with a pending Read operation.
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly,
WriteRemoteDescriptor_ReadPending) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest,
MAYBE_WriteRemoteDescriptor_ReadPending) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......
......@@ -9,34 +9,13 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/win/winrt_storage_util.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_winrt.h"
#include "device/bluetooth/event_utils_winrt.h"
namespace device {
namespace {
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattCommunicationStatus;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattCommunicationStatus_Success;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::GattReadResult;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattWriteResult;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptor2;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptor;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattReadResult2;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattReadResult;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattWriteResult;
using ABI::Windows::Foundation::IAsyncOperation;
using ABI::Windows::Storage::Streams::IBuffer;
using Microsoft::WRL::ComPtr;
} // namespace
......@@ -97,135 +76,16 @@ BluetoothRemoteGattDescriptorWinrt::GetCharacteristic() const {
void BluetoothRemoteGattDescriptorWinrt::ReadRemoteDescriptor(
const ValueCallback& callback,
const ErrorCallback& error_callback) {
if (pending_read_callbacks_ || pending_write_callbacks_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(error_callback,
BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS));
return;
}
ComPtr<IAsyncOperation<GattReadResult*>> read_value_op;
HRESULT hr = descriptor_->ReadValueAsync(&read_value_op);
if (FAILED(hr)) {
VLOG(2) << "GattDescriptor::ReadValueAsync failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(error_callback,
BluetoothRemoteGattService::GATT_ERROR_FAILED));
return;
}
hr = PostAsyncResults(
std::move(read_value_op),
base::BindOnce(&BluetoothRemoteGattDescriptorWinrt::OnReadValue,
weak_ptr_factory_.GetWeakPtr()));
if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(error_callback,
BluetoothRemoteGattService::GATT_ERROR_FAILED));
return;
}
pending_read_callbacks_ =
std::make_unique<PendingReadCallbacks>(callback, error_callback);
NOTIMPLEMENTED();
}
void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor(
const std::vector<uint8_t>& value,
const base::Closure& callback,
const ErrorCallback& error_callback) {
if (pending_read_callbacks_ || pending_write_callbacks_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(error_callback,
BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS));
return;
}
ComPtr<IGattDescriptor2> descriptor_2;
HRESULT hr = descriptor_.As(&descriptor_2);
if (FAILED(hr)) {
VLOG(2) << "As IGattDescriptor2 failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(error_callback,
BluetoothRemoteGattService::GATT_ERROR_FAILED));
return;
}
ComPtr<IBuffer> buffer;
hr = base::win::CreateIBufferFromData(value.data(), value.size(), &buffer);
if (FAILED(hr)) {
VLOG(2) << "base::win::CreateIBufferFromData failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(error_callback,
BluetoothRemoteGattService::GATT_ERROR_FAILED));
return;
}
ComPtr<IAsyncOperation<GattWriteResult*>> write_value_op;
hr = descriptor_2->WriteValueWithResultAsync(buffer.Get(), &write_value_op);
if (FAILED(hr)) {
VLOG(2) << "GattDescriptor::WriteValueWithResultAsync failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(error_callback,
BluetoothRemoteGattService::GATT_ERROR_FAILED));
return;
}
hr = PostAsyncResults(
std::move(write_value_op),
base::BindOnce(
&BluetoothRemoteGattDescriptorWinrt::OnWriteValueWithResult,
weak_ptr_factory_.GetWeakPtr()));
if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(error_callback,
BluetoothRemoteGattService::GATT_ERROR_FAILED));
return;
}
pending_write_callbacks_ =
std::make_unique<PendingWriteCallbacks>(callback, error_callback);
}
IGattDescriptor* BluetoothRemoteGattDescriptorWinrt::GetDescriptorForTesting() {
return descriptor_.Get();
NOTIMPLEMENTED();
}
BluetoothRemoteGattDescriptorWinrt::PendingReadCallbacks::PendingReadCallbacks(
ValueCallback callback,
ErrorCallback error_callback)
: callback(std::move(callback)),
error_callback(std::move(error_callback)) {}
BluetoothRemoteGattDescriptorWinrt::PendingReadCallbacks::
~PendingReadCallbacks() = default;
BluetoothRemoteGattDescriptorWinrt::PendingWriteCallbacks::
PendingWriteCallbacks(base::OnceClosure callback,
ErrorCallback error_callback)
: callback(std::move(callback)),
error_callback(std::move(error_callback)) {}
BluetoothRemoteGattDescriptorWinrt::PendingWriteCallbacks::
~PendingWriteCallbacks() = default;
BluetoothRemoteGattDescriptorWinrt::BluetoothRemoteGattDescriptorWinrt(
BluetoothRemoteGattCharacteristic* characteristic,
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
......@@ -239,101 +99,6 @@ BluetoothRemoteGattDescriptorWinrt::BluetoothRemoteGattDescriptorWinrt(
identifier_(base::StringPrintf("%s/%s_%04x",
characteristic_->GetIdentifier().c_str(),
uuid_.value().c_str(),
attribute_handle)),
weak_ptr_factory_(this) {}
void BluetoothRemoteGattDescriptorWinrt::OnReadValue(
ComPtr<IGattReadResult> read_result) {
DCHECK(pending_read_callbacks_);
auto pending_read_callbacks = std::move(pending_read_callbacks_);
if (!read_result) {
pending_read_callbacks->error_callback.Run(
BluetoothGattService::GATT_ERROR_FAILED);
return;
}
GattCommunicationStatus status;
HRESULT hr = read_result->get_Status(&status);
if (FAILED(hr)) {
VLOG(2) << "Getting GATT Communication Status failed: "
<< logging::SystemErrorCodeToString(hr);
pending_read_callbacks->error_callback.Run(
BluetoothGattService::GATT_ERROR_FAILED);
return;
}
if (status != GattCommunicationStatus_Success) {
VLOG(2) << "Unexpected GattCommunicationStatus: " << status;
ComPtr<IGattReadResult2> read_result_2;
hr = read_result.As(&read_result_2);
if (FAILED(hr)) {
VLOG(2) << "As IGattReadResult2 failed: "
<< logging::SystemErrorCodeToString(hr);
pending_read_callbacks->error_callback.Run(
BluetoothGattService::GATT_ERROR_FAILED);
return;
}
pending_read_callbacks->error_callback.Run(
BluetoothRemoteGattServiceWinrt::GetGattErrorCode(read_result_2.Get()));
return;
}
ComPtr<IBuffer> value;
hr = read_result->get_Value(&value);
if (FAILED(hr)) {
VLOG(2) << "Getting Descriptor Value failed: "
<< logging::SystemErrorCodeToString(hr);
pending_read_callbacks->error_callback.Run(
BluetoothGattService::GATT_ERROR_FAILED);
return;
}
uint8_t* data = nullptr;
uint32_t length = 0;
hr = base::win::GetPointerToBufferData(value.Get(), &data, &length);
if (FAILED(hr)) {
VLOG(2) << "Getting Pointer To Buffer Data failed: "
<< logging::SystemErrorCodeToString(hr);
pending_read_callbacks->error_callback.Run(
BluetoothGattService::GATT_ERROR_FAILED);
return;
}
value_.assign(data, data + length);
pending_read_callbacks->callback.Run(value_);
}
void BluetoothRemoteGattDescriptorWinrt::OnWriteValueWithResult(
ComPtr<IGattWriteResult> write_result) {
DCHECK(pending_write_callbacks_);
auto pending_write_callbacks = std::move(pending_write_callbacks_);
if (!write_result) {
pending_write_callbacks->error_callback.Run(
BluetoothGattService::GATT_ERROR_FAILED);
return;
}
GattCommunicationStatus status;
HRESULT hr = write_result->get_Status(&status);
if (FAILED(hr)) {
VLOG(2) << "Getting GATT Communication Status failed: "
<< logging::SystemErrorCodeToString(hr);
pending_write_callbacks->error_callback.Run(
BluetoothGattService::GATT_ERROR_FAILED);
return;
}
if (status != GattCommunicationStatus_Success) {
VLOG(2) << "Unexpected GattCommunicationStatus: " << status;
pending_write_callbacks->error_callback.Run(
BluetoothRemoteGattServiceWinrt::GetGattErrorCode(write_result.Get()));
return;
}
std::move(pending_write_callbacks->callback).Run();
}
attribute_handle)) {}
} // namespace device
......@@ -16,7 +16,6 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "device/bluetooth/bluetooth_export.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
......@@ -48,27 +47,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorWinrt
const base::Closure& callback,
const ErrorCallback& error_callback) override;
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::IGattDescriptor*
GetDescriptorForTesting();
private:
struct PendingReadCallbacks {
PendingReadCallbacks(ValueCallback callback, ErrorCallback error_callback);
~PendingReadCallbacks();
ValueCallback callback;
ErrorCallback error_callback;
};
struct PendingWriteCallbacks {
PendingWriteCallbacks(base::OnceClosure callback,
ErrorCallback error_callback);
~PendingWriteCallbacks();
base::OnceClosure callback;
ErrorCallback error_callback;
};
BluetoothRemoteGattDescriptorWinrt(
BluetoothRemoteGattCharacteristic* characteristic,
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
......@@ -77,15 +56,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorWinrt
BluetoothUUID uuid,
uint16_t attribute_handle);
void OnReadValue(Microsoft::WRL::ComPtr<
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattReadResult> read_result);
void OnWriteValueWithResult(
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattWriteResult>
write_result);
// Weak. This object is owned by |characteristic_|.
BluetoothRemoteGattCharacteristic* characteristic_;
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
......@@ -94,10 +64,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorWinrt
BluetoothUUID uuid_;
std::string identifier_;
std::vector<uint8_t> value_;
std::unique_ptr<PendingReadCallbacks> pending_read_callbacks_;
std::unique_ptr<PendingWriteCallbacks> pending_write_callbacks_;
base::WeakPtrFactory<BluetoothRemoteGattDescriptorWinrt> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattDescriptorWinrt);
};
......
......@@ -33,7 +33,6 @@
#include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic_winrt.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor_winrt.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_win.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "device/bluetooth/test/fake_bluetooth_adapter_winrt.h"
......@@ -41,7 +40,6 @@
#include "device/bluetooth/test/fake_bluetooth_le_device_winrt.h"
#include "device/bluetooth/test/fake_device_information_winrt.h"
#include "device/bluetooth/test/fake_gatt_characteristic_winrt.h"
#include "device/bluetooth/test/fake_gatt_descriptor_winrt.h"
// Note: As UWP does not provide int specializations for IObservableVector and
// VectorChangedEventHandler we need to supply our own. UUIDs were generated
......@@ -815,41 +813,6 @@ void BluetoothTestWinrt::SimulateGattCharacteristicWriteError(
->SimulateGattCharacteristicWriteError(error_code);
}
void BluetoothTestWinrt::SimulateGattDescriptorRead(
BluetoothRemoteGattDescriptor* descriptor,
const std::vector<uint8_t>& value) {
static_cast<FakeGattDescriptorWinrt*>(
static_cast<BluetoothRemoteGattDescriptorWinrt*>(descriptor)
->GetDescriptorForTesting())
->SimulateGattDescriptorRead(value);
}
void BluetoothTestWinrt::SimulateGattDescriptorReadError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothRemoteGattService::GattErrorCode error_code) {
static_cast<FakeGattDescriptorWinrt*>(
static_cast<BluetoothRemoteGattDescriptorWinrt*>(descriptor)
->GetDescriptorForTesting())
->SimulateGattDescriptorReadError(error_code);
}
void BluetoothTestWinrt::SimulateGattDescriptorWrite(
BluetoothRemoteGattDescriptor* descriptor) {
static_cast<FakeGattDescriptorWinrt*>(
static_cast<BluetoothRemoteGattDescriptorWinrt*>(descriptor)
->GetDescriptorForTesting())
->SimulateGattDescriptorWrite();
}
void BluetoothTestWinrt::SimulateGattDescriptorWriteError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothRemoteGattService::GattErrorCode error_code) {
static_cast<FakeGattDescriptorWinrt*>(
static_cast<BluetoothRemoteGattDescriptorWinrt*>(descriptor)
->GetDescriptorForTesting())
->SimulateGattDescriptorWriteError(error_code);
}
void BluetoothTestWinrt::SimulateGattDescriptor(
BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid) {
......@@ -888,14 +851,4 @@ void BluetoothTestWinrt::OnFakeBluetoothCharacteristicWriteValue(
++gatt_write_characteristic_attempts_;
}
void BluetoothTestWinrt::OnFakeBluetoothDescriptorReadValue() {
++gatt_read_descriptor_attempts_;
}
void BluetoothTestWinrt::OnFakeBluetoothDescriptorWriteValue(
std::vector<uint8_t> value) {
last_write_value_ = std::move(value);
++gatt_write_descriptor_attempts_;
}
} // namespace device
......@@ -149,24 +149,12 @@ class BluetoothTestWinrt : public BluetoothTestWin,
BluetoothRemoteGattService::GattErrorCode error_code) override;
void SimulateGattDescriptor(BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid) override;
void SimulateGattDescriptorRead(BluetoothRemoteGattDescriptor* descriptor,
const std::vector<uint8_t>& value) override;
void SimulateGattDescriptorReadError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothRemoteGattService::GattErrorCode error_code) override;
void SimulateGattDescriptorWrite(
BluetoothRemoteGattDescriptor* descriptor) override;
void SimulateGattDescriptorWriteError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothRemoteGattService::GattErrorCode error_code) override;
void DeleteDevice(BluetoothDevice* device) override;
void OnFakeBluetoothDeviceConnectGattCalled();
void OnFakeBluetoothGattDisconnect();
void OnFakeBluetoothCharacteristicReadValue();
void OnFakeBluetoothCharacteristicWriteValue(std::vector<uint8_t> value);
void OnFakeBluetoothDescriptorReadValue();
void OnFakeBluetoothDescriptorWriteValue(std::vector<uint8_t> value);
private:
base::test::ScopedFeatureList scoped_feature_list_;
......
......@@ -269,8 +269,8 @@ void FakeGattCharacteristicWinrt::SimulateGattCharacteristicWriteError(
void FakeGattCharacteristicWinrt::SimulateGattDescriptor(
base::StringPiece uuid) {
fake_descriptors_.push_back(Make<FakeGattDescriptorWinrt>(
bluetooth_test_winrt_, uuid, ++last_descriptor_attribute_handle_));
fake_descriptors_.push_back(
Make<FakeGattDescriptorWinrt>(uuid, ++last_descriptor_attribute_handle_));
}
} // namespace device
......@@ -4,15 +4,8 @@
#include "device/bluetooth/test/fake_gatt_descriptor_winrt.h"
#include <utility>
#include "base/strings/string_piece.h"
#include "base/win/async_operation.h"
#include "base/win/winrt_storage_util.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "device/bluetooth/test/bluetooth_test_win.h"
#include "device/bluetooth/test/fake_gatt_read_result_winrt.h"
#include "device/bluetooth/test/fake_gatt_write_result_winrt.h"
namespace device {
......@@ -28,16 +21,12 @@ using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattWriteResult;
using ABI::Windows::Foundation::IAsyncOperation;
using ABI::Windows::Storage::Streams::IBuffer;
using Microsoft::WRL::Make;
} // namespace
FakeGattDescriptorWinrt::FakeGattDescriptorWinrt(
BluetoothTestWinrt* bluetooth_test_winrt,
base::StringPiece uuid,
uint16_t attribute_handle)
: bluetooth_test_winrt_(bluetooth_test_winrt),
uuid_(BluetoothUUID::GetCanonicalValueAsGUID(uuid)),
FakeGattDescriptorWinrt::FakeGattDescriptorWinrt(base::StringPiece uuid,
uint16_t attribute_handle)
: uuid_(BluetoothUUID::GetCanonicalValueAsGUID(uuid)),
attribute_handle_(attribute_handle) {}
FakeGattDescriptorWinrt::~FakeGattDescriptorWinrt() = default;
......@@ -64,12 +53,7 @@ HRESULT FakeGattDescriptorWinrt::get_AttributeHandle(uint16_t* value) {
HRESULT FakeGattDescriptorWinrt::ReadValueAsync(
IAsyncOperation<GattReadResult*>** value) {
auto async_op = Make<base::win::AsyncOperation<GattReadResult*>>();
DCHECK(!read_value_callback_);
read_value_callback_ = async_op->callback();
*value = async_op.Detach();
bluetooth_test_winrt_->OnFakeBluetoothDescriptorReadValue();
return S_OK;
return E_NOTIMPL;
}
HRESULT FakeGattDescriptorWinrt::ReadValueWithCacheModeAsync(
......@@ -87,43 +71,7 @@ HRESULT FakeGattDescriptorWinrt::WriteValueAsync(
HRESULT FakeGattDescriptorWinrt::WriteValueWithResultAsync(
IBuffer* value,
IAsyncOperation<GattWriteResult*>** operation) {
uint8_t* data;
uint32_t size;
base::win::GetPointerToBufferData(value, &data, &size);
bluetooth_test_winrt_->OnFakeBluetoothDescriptorWriteValue(
std::vector<uint8_t>(data, data + size));
auto async_op = Make<base::win::AsyncOperation<GattWriteResult*>>();
DCHECK(!write_value_callback_);
write_value_callback_ = async_op->callback();
*operation = async_op.Detach();
return S_OK;
}
void FakeGattDescriptorWinrt::SimulateGattDescriptorRead(
const std::vector<uint8_t>& data) {
if (read_value_callback_)
std::move(read_value_callback_).Run(Make<FakeGattReadResultWinrt>(data));
}
void FakeGattDescriptorWinrt::SimulateGattDescriptorReadError(
BluetoothGattService::GattErrorCode error_code) {
if (read_value_callback_) {
std::move(read_value_callback_)
.Run(Make<FakeGattReadResultWinrt>(error_code));
}
}
void FakeGattDescriptorWinrt::SimulateGattDescriptorWrite() {
if (write_value_callback_)
std::move(write_value_callback_).Run(Make<FakeGattWriteResultWinrt>());
}
void FakeGattDescriptorWinrt::SimulateGattDescriptorWriteError(
BluetoothGattService::GattErrorCode error_code) {
if (write_value_callback_) {
std::move(write_value_callback_)
.Run(Make<FakeGattWriteResultWinrt>(error_code));
}
return E_NOTIMPL;
}
} // namespace device
......@@ -6,22 +6,15 @@
#define DEVICE_BLUETOOTH_TEST_FAKE_GATT_DESCRIPTOR_WINRT_H_
#include <windows.devices.bluetooth.genericattributeprofile.h>
#include <wrl/client.h>
#include <wrl/implements.h>
#include <stdint.h>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string_piece_forward.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
namespace device {
class BluetoothTestWinrt;
class FakeGattDescriptorWinrt
: public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags<
......@@ -31,9 +24,7 @@ class FakeGattDescriptorWinrt
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptor2> {
public:
FakeGattDescriptorWinrt(BluetoothTestWinrt* bluetooth_test_winrt,
base::StringPiece uuid,
uint16_t attribute_handle);
FakeGattDescriptorWinrt(base::StringPiece uuid, uint16_t attribute_handle);
~FakeGattDescriptorWinrt() override;
// IGattDescriptor:
......@@ -67,28 +58,10 @@ class FakeGattDescriptorWinrt
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattWriteResult*>** operation) override;
void SimulateGattDescriptorRead(const std::vector<uint8_t>& data);
void SimulateGattDescriptorReadError(
BluetoothGattService::GattErrorCode error_code);
void SimulateGattDescriptorWrite();
void SimulateGattDescriptorWriteError(
BluetoothGattService::GattErrorCode error_code);
private:
BluetoothTestWinrt* bluetooth_test_winrt_;
GUID uuid_;
uint16_t attribute_handle_;
base::OnceCallback<void(
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattReadResult>)>
read_value_callback_;
base::OnceCallback<void(
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattWriteResult>)>
write_value_callback_;
DISALLOW_COPY_AND_ASSIGN(FakeGattDescriptorWinrt);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment