Commit 67ca5a07 authored by Christos Froussios's avatar Christos Froussios Committed by Commit Bot

Revert "[Bluetooth][WinRT] Implement Obtaining Gatt Descriptors"

This reverts commit 20f64257.

Reason for revert: Suspected of breaking device_unittests on Win10 Tests x64 (dbg)

Original change's description:
> [Bluetooth][WinRT] Implement Obtaining Gatt Descriptors
> 
> This change implements obtainining Remote Gatt Descriptors for WinRT by
> hooking up the appropriate logic into GattDiscovererWinrt. Furthermore,
> appropriate tests are enabled.
> 
> Bug: 821766
> Change-Id: I20475478367c2ab6b18940b4271de70ec138f676
> Reviewed-on: https://chromium-review.googlesource.com/1156392
> Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
> Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org>
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#579830}

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

Change-Id: If5128ebf0c9dd1f585bd98b9729a57340f4493a0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 821766, 870208
Reviewed-on: https://chromium-review.googlesource.com/1159943Reviewed-by: default avatarChristos Froussios <cfroussios@chromium.org>
Commit-Queue: Christos Froussios <cfroussios@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580106}
parent 4a9a04fe
......@@ -25,28 +25,23 @@ using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattCommunicationStatus;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattCommunicationStatus_Success;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::GattDescriptor;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattDescriptorsResult;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattDeviceService;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
GattDeviceServicesResult;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattCharacteristic3;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattCharacteristicsResult;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptorsResult;
IGattDeviceService;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDeviceService3;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDeviceServicesResult;
using ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice3;
using ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice;
using ABI::Windows::Foundation::Collections::IVectorView;
using ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice3;
using ABI::Windows::Foundation::IAsyncOperation;
using ABI::Windows::Foundation::IReference;
using ABI::Windows::Foundation::Collections::IVectorView;
using Microsoft::WRL::ComPtr;
template <typename IGattResult>
......@@ -154,15 +149,6 @@ BluetoothGattDiscovererWinrt::GetCharacteristics(
: nullptr;
}
const BluetoothGattDiscovererWinrt::GattDescriptorList*
BluetoothGattDiscovererWinrt::GetDescriptors(
uint16_t characteristic_attribute_handle) const {
auto iter =
characteristic_to_descriptors_map_.find(characteristic_attribute_handle);
return iter != characteristic_to_descriptors_map_.end() ? &iter->second
: nullptr;
}
void BluetoothGattDiscovererWinrt::OnGetGattServices(
ComPtr<IGattDeviceServicesResult> services_result) {
if (!CheckCommunicationStatus(services_result.Get())) {
......@@ -184,7 +170,6 @@ void BluetoothGattDiscovererWinrt::OnGetGattServices(
return;
}
num_services_ = gatt_services_.size();
for (const auto& gatt_service : gatt_services_) {
uint16_t service_attribute_handle;
hr = gatt_service->get_AttributeHandle(&service_attribute_handle);
......@@ -248,80 +233,9 @@ void BluetoothGattDiscovererWinrt::OnGetCharacteristics(
DCHECK(!base::ContainsKey(service_to_characteristics_map_,
service_attribute_handle));
auto& characteristics_list =
service_to_characteristics_map_[service_attribute_handle];
if (!GetAsVector(characteristics.Get(), &characteristics_list)) {
std::move(callback_).Run(false);
return;
}
num_characteristics_ += characteristics_list.size();
for (const auto& gatt_characteristic : characteristics_list) {
uint16_t characteristic_attribute_handle;
hr = gatt_characteristic->get_AttributeHandle(
&characteristic_attribute_handle);
if (FAILED(hr)) {
VLOG(2) << "Getting AttributeHandle failed: "
<< logging::SystemErrorCodeToString(hr);
std::move(callback_).Run(false);
return;
}
ComPtr<IGattCharacteristic3> gatt_characteristic_3;
hr = gatt_characteristic.As(&gatt_characteristic_3);
if (FAILED(hr)) {
VLOG(2) << "Obtaining IGattCharacteristic3 failed: "
<< logging::SystemErrorCodeToString(hr);
std::move(callback_).Run(false);
return;
}
ComPtr<IAsyncOperation<GattDescriptorsResult*>> get_descriptors_op;
hr = gatt_characteristic_3->GetDescriptorsAsync(&get_descriptors_op);
if (FAILED(hr)) {
VLOG(2) << "GattCharacteristic::GetDescriptorsAsync() failed: "
<< logging::SystemErrorCodeToString(hr);
std::move(callback_).Run(false);
return;
}
hr = PostAsyncResults(
std::move(get_descriptors_op),
base::BindOnce(&BluetoothGattDiscovererWinrt::OnGetDescriptors,
weak_ptr_factory_.GetWeakPtr(),
characteristic_attribute_handle));
if (FAILED(hr)) {
VLOG(2) << "PostAsyncResults failed: "
<< logging::SystemErrorCodeToString(hr);
std::move(callback_).Run(false);
}
}
RunCallbackIfDone();
}
void BluetoothGattDiscovererWinrt::OnGetDescriptors(
uint16_t characteristic_attribute_handle,
ComPtr<IGattDescriptorsResult> descriptors_result) {
if (!CheckCommunicationStatus(descriptors_result.Get())) {
std::move(callback_).Run(false);
return;
}
ComPtr<IVectorView<GattDescriptor*>> descriptors;
HRESULT hr = descriptors_result->get_Descriptors(&descriptors);
if (FAILED(hr)) {
VLOG(2) << "Getting Descriptors failed: "
<< logging::SystemErrorCodeToString(hr);
std::move(callback_).Run(false);
return;
}
DCHECK(!base::ContainsKey(characteristic_to_descriptors_map_,
characteristic_attribute_handle));
if (!GetAsVector(descriptors.Get(), &characteristic_to_descriptors_map_
[characteristic_attribute_handle])) {
if (!GetAsVector(
characteristics.Get(),
&service_to_characteristics_map_[service_attribute_handle])) {
std::move(callback_).Run(false);
return;
}
......@@ -331,10 +245,8 @@ void BluetoothGattDiscovererWinrt::OnGetDescriptors(
void BluetoothGattDiscovererWinrt::RunCallbackIfDone() {
DCHECK(callback_);
if (service_to_characteristics_map_.size() == num_services_ &&
characteristic_to_descriptors_map_.size() == num_characteristics_) {
if (service_to_characteristics_map_.size() == gatt_services_.size())
std::move(callback_).Run(true);
}
}
} // namespace device
......@@ -38,24 +38,16 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothGattDiscovererWinrt {
using GattCharacteristicList = std::vector<
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattCharacteristic>>;
using GattDescriptorList = std::vector<
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattDescriptor>>;
BluetoothGattDiscovererWinrt(
Microsoft::WRL::ComPtr<
ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice> ble_device);
~BluetoothGattDiscovererWinrt();
// Note: In order to avoid running |callback| multiple times on errors,
// clients are expected to synchronously destroy the GattDiscoverer after
// |callback| has been invoked for the first time.
void StartGattDiscovery(GattDiscoveryCallback callback);
const GattServiceList& GetGattServices() const;
const GattCharacteristicList* GetCharacteristics(
uint16_t service_attribute_handle) const;
const GattDescriptorList* GetDescriptors(
uint16_t characteristic_attribute_handle) const;
private:
void OnGetGattServices(
......@@ -69,12 +61,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothGattDiscovererWinrt {
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattCharacteristicsResult> characteristics_result);
void OnGetDescriptors(
uint16_t characteristic_attribute_handle,
Microsoft::WRL::ComPtr<
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptorsResult> descriptors_result);
void RunCallbackIfDone();
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::IBluetoothLEDevice>
......@@ -84,10 +70,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothGattDiscovererWinrt {
GattServiceList gatt_services_;
base::flat_map<uint16_t, GattCharacteristicList>
service_to_characteristics_map_;
base::flat_map<uint16_t, GattDescriptorList>
characteristic_to_descriptors_map_;
size_t num_services_ = 0;
size_t num_characteristics_ = 0;
THREAD_CHECKER(thread_checker_);
......
......@@ -169,10 +169,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristic
virtual bool WriteWithoutResponse(base::span<const uint8_t> value);
protected:
using DescriptorMap =
base::flat_map<std::string,
std::unique_ptr<BluetoothRemoteGattDescriptor>>;
BluetoothRemoteGattCharacteristic();
// Writes to the Client Characteristic Configuration descriptor to enable
......@@ -210,7 +206,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristic
// Descriptors owned by the chracteristic. The descriptors' identifiers serve
// as keys.
DescriptorMap descriptors_;
base::flat_map<std::string, std::unique_ptr<BluetoothRemoteGattDescriptor>>
descriptors_;
private:
friend class BluetoothGattNotifySession;
......
......@@ -3013,15 +3013,11 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
#define MAYBE_GetDescriptors_FindNone DISABLED_GetDescriptors_FindNone
#endif
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattCharacteristicTestWinrt, GetDescriptors_FindNone) {
TEST_P(BluetoothRemoteGattCharacteristicTestWin32Only,
GetDescriptors_FindNone) {
#else
TEST_F(BluetoothRemoteGattCharacteristicTest, MAYBE_GetDescriptors_FindNone) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
}
ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
EXPECT_EQ(0u, characteristic1_->GetDescriptors().size());
......@@ -3034,17 +3030,12 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, MAYBE_GetDescriptors_FindNone) {
DISABLED_GetDescriptors_and_GetDescriptor
#endif
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattCharacteristicTestWinrt,
TEST_P(BluetoothRemoteGattCharacteristicTestWin32Only,
GetDescriptors_and_GetDescriptor) {
#else
TEST_F(BluetoothRemoteGattCharacteristicTest,
MAYBE_GetDescriptors_and_GetDescriptor) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
}
ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
// Add several Descriptors:
......@@ -3056,7 +3047,6 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
SimulateGattDescriptor(characteristic1_, uuid2.canonical_value());
SimulateGattDescriptor(characteristic2_, uuid3.canonical_value());
SimulateGattDescriptor(characteristic2_, uuid4.canonical_value());
base::RunLoop().RunUntilIdle();
// Verify that GetDescriptor can retrieve descriptors again by ID,
// and that the same Descriptor is returned when searched by ID.
......@@ -3094,15 +3084,10 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
#define MAYBE_GetDescriptorsByUUID DISABLED_GetDescriptorsByUUID
#endif
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattCharacteristicTestWinrt, GetDescriptorsByUUID) {
TEST_P(BluetoothRemoteGattCharacteristicTestWin32Only, GetDescriptorsByUUID) {
#else
TEST_F(BluetoothRemoteGattCharacteristicTest, MAYBE_GetDescriptorsByUUID) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
}
ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
// Add several Descriptors:
......@@ -3113,7 +3098,6 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, MAYBE_GetDescriptorsByUUID) {
SimulateGattDescriptor(characteristic1_, id2.canonical_value());
SimulateGattDescriptor(characteristic2_, id3.canonical_value());
SimulateGattDescriptor(characteristic2_, id3.canonical_value());
base::RunLoop().RunUntilIdle();
EXPECT_NE(characteristic2_->GetDescriptorsByUUID(id3).at(0)->GetIdentifier(),
characteristic2_->GetDescriptorsByUUID(id3).at(1)->GetIdentifier());
......
......@@ -12,8 +12,6 @@
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/win/winrt_storage_util.h"
#include "device/bluetooth/bluetooth_gatt_discoverer_winrt.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor_winrt.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_winrt.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "device/bluetooth/event_utils_winrt.h"
......@@ -258,33 +256,6 @@ void BluetoothRemoteGattCharacteristicWinrt::WriteRemoteCharacteristic(
std::make_unique<PendingWriteCallbacks>(callback, error_callback);
}
void BluetoothRemoteGattCharacteristicWinrt::UpdateDescriptors(
BluetoothGattDiscovererWinrt* gatt_discoverer) {
const auto* gatt_descriptors =
gatt_discoverer->GetDescriptors(attribute_handle_);
DCHECK(gatt_descriptors);
// Instead of clearing out |descriptors_| and creating each descriptor
// from scratch, we create a new map and move already existing descriptors
// into it in order to preserve pointer stability.
DescriptorMap descriptors;
for (const auto& gatt_descriptor : *gatt_descriptors) {
auto descriptor =
BluetoothRemoteGattDescriptorWinrt::Create(this, gatt_descriptor.Get());
if (!descriptor)
continue;
std::string identifier = descriptor->GetIdentifier();
auto iter = descriptors_.find(identifier);
if (iter != descriptors_.end())
descriptors.emplace(std::move(*iter));
else
descriptors.emplace(std::move(identifier), std::move(descriptor));
}
std::swap(descriptors, descriptors_);
}
bool BluetoothRemoteGattCharacteristicWinrt::WriteWithoutResponse(
base::span<const uint8_t> value) {
if (!(GetProperties() & PROPERTY_WRITE_WITHOUT_RESPONSE))
......@@ -374,11 +345,10 @@ BluetoothRemoteGattCharacteristicWinrt::BluetoothRemoteGattCharacteristicWinrt(
characteristic_(std::move(characteristic)),
uuid_(std::move(uuid)),
properties_(properties),
attribute_handle_(attribute_handle),
identifier_(base::StringPrintf("%s/%s_%04x",
service_->GetIdentifier().c_str(),
uuid_.value().c_str(),
attribute_handle_)),
attribute_handle)),
weak_ptr_factory_(this) {}
void BluetoothRemoteGattCharacteristicWinrt::OnReadValue(
......
......@@ -23,7 +23,6 @@
namespace device {
class BluetoothRemoteGattDescriptor;
class BluetoothGattDiscovererWinrt;
class BluetoothRemoteGattService;
class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicWinrt
......@@ -52,8 +51,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicWinrt
const ErrorCallback& error_callback) override;
bool WriteWithoutResponse(base::span<const uint8_t> value) override;
void UpdateDescriptors(BluetoothGattDiscovererWinrt* gatt_discoverer);
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattCharacteristic*
GetCharacteristicForTesting();
......@@ -110,7 +107,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicWinrt
characteristic_;
BluetoothUUID uuid_;
Properties properties_;
uint16_t attribute_handle_;
std::string identifier_;
std::vector<uint8_t> value_;
std::unique_ptr<PendingReadCallbacks> pending_read_callbacks_;
......
......@@ -22,12 +22,7 @@
namespace device {
class BluetoothRemoteGattDescriptorTest :
#if defined(OS_WIN)
public BluetoothTestWinrt {
#else
public BluetoothTest {
#endif
class BluetoothRemoteGattDescriptorTest : public BluetoothTest {
public:
// Creates adapter_, device_, service_, characteristic_,
// descriptor1_, & descriptor2_.
......@@ -64,21 +59,12 @@ class BluetoothRemoteGattDescriptorTest :
BluetoothRemoteGattDescriptor* descriptor2_ = nullptr;
};
#if defined(OS_WIN)
using BluetoothRemoteGattDescriptorTestWinrtOnly =
BluetoothRemoteGattDescriptorTest;
#endif
#if defined(OS_ANDROID) || defined(OS_MACOSX)
#define MAYBE_GetIdentifier GetIdentifier
#else
#define MAYBE_GetIdentifier DISABLED_GetIdentifier
#endif
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly, GetIdentifier) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_GetIdentifier) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -116,7 +102,6 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_GetIdentifier) {
SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
base::RunLoop().RunUntilIdle();
BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0];
BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1];
BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0];
......@@ -132,7 +117,6 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_GetIdentifier) {
SimulateGattDescriptor(char4, kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(char5, kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(char6, kTestUUIDCharacteristicUserDescription);
base::RunLoop().RunUntilIdle();
BluetoothRemoteGattDescriptor* desc1 = char1->GetDescriptors()[0];
BluetoothRemoteGattDescriptor* desc2 = char2->GetDescriptors()[0];
BluetoothRemoteGattDescriptor* desc3 = char3->GetDescriptors()[0];
......@@ -167,11 +151,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_GetIdentifier) {
#else
#define MAYBE_GetUUID DISABLED_GetUUID
#endif
#if defined(OS_WIN)
TEST_P(BluetoothRemoteGattDescriptorTestWinrtOnly, GetUUID) {
#else
TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_GetUUID) {
#endif
if (!PlatformSupportsLowEnergy()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return;
......@@ -190,7 +170,6 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_GetUUID) {
SimulateGattCharacteristic(service, kTestUUIDDeviceName,
/* properties */ 0);
base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, service->GetCharacteristics().size());
BluetoothRemoteGattCharacteristic* characteristic =
service->GetCharacteristics()[0];
......@@ -202,7 +181,6 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_GetUUID) {
kTestUUIDCharacteristicUserDescription);
SimulateGattDescriptor(characteristic,
kTestUUIDClientCharacteristicConfiguration);
base::RunLoop().RunUntilIdle();
ASSERT_EQ(2u, characteristic->GetDescriptors().size());
BluetoothRemoteGattDescriptor* descriptor1 =
characteristic->GetDescriptors()[0];
......@@ -926,11 +904,4 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_NSNumber) {
}
#endif // defined(OS_MACOSX)
#if defined(OS_WIN)
INSTANTIATE_TEST_CASE_P(
/* no prefix */,
BluetoothRemoteGattDescriptorTestWinrtOnly,
::testing::Values(true));
#endif // defined(OS_WIN)
} // namespace device
......@@ -4,57 +4,25 @@
#include "device/bluetooth/bluetooth_remote_gatt_descriptor_winrt.h"
#include <utility>
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
#include "device/bluetooth/bluetooth_uuid.h"
namespace device {
namespace {
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptor;
using Microsoft::WRL::ComPtr;
} // namespace
// static
std::unique_ptr<BluetoothRemoteGattDescriptorWinrt>
BluetoothRemoteGattDescriptorWinrt::Create(
BluetoothRemoteGattCharacteristic* characteristic,
ComPtr<IGattDescriptor> descriptor) {
DCHECK(descriptor);
GUID guid;
HRESULT hr = descriptor->get_Uuid(&guid);
if (FAILED(hr)) {
VLOG(2) << "Getting UUID failed: " << logging::SystemErrorCodeToString(hr);
return nullptr;
}
uint16_t attribute_handle;
hr = descriptor->get_AttributeHandle(&attribute_handle);
if (FAILED(hr)) {
VLOG(2) << "Getting AttributeHandle failed: "
<< logging::SystemErrorCodeToString(hr);
return nullptr;
}
return base::WrapUnique(new BluetoothRemoteGattDescriptorWinrt(
characteristic, std::move(descriptor), BluetoothUUID(guid),
attribute_handle));
}
BluetoothRemoteGattDescriptorWinrt::BluetoothRemoteGattDescriptorWinrt() =
default;
BluetoothRemoteGattDescriptorWinrt::~BluetoothRemoteGattDescriptorWinrt() =
default;
std::string BluetoothRemoteGattDescriptorWinrt::GetIdentifier() const {
return identifier_;
NOTIMPLEMENTED();
return std::string();
}
BluetoothUUID BluetoothRemoteGattDescriptorWinrt::GetUUID() const {
return uuid_;
NOTIMPLEMENTED();
return BluetoothUUID();
}
BluetoothGattCharacteristic::Permissions
......@@ -70,7 +38,8 @@ const std::vector<uint8_t>& BluetoothRemoteGattDescriptorWinrt::GetValue()
BluetoothRemoteGattCharacteristic*
BluetoothRemoteGattDescriptorWinrt::GetCharacteristic() const {
return characteristic_;
NOTIMPLEMENTED();
return nullptr;
}
void BluetoothRemoteGattDescriptorWinrt::ReadRemoteDescriptor(
......@@ -86,19 +55,4 @@ void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor(
NOTIMPLEMENTED();
}
BluetoothRemoteGattDescriptorWinrt::BluetoothRemoteGattDescriptorWinrt(
BluetoothRemoteGattCharacteristic* characteristic,
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattDescriptor>
descriptor,
BluetoothUUID uuid,
uint16_t attribute_handle)
: characteristic_(characteristic),
descriptor_(std::move(descriptor)),
uuid_(std::move(uuid)),
identifier_(base::StringPrintf("%s/%s_%04x",
characteristic_->GetIdentifier().c_str(),
uuid_.value().c_str(),
attribute_handle)) {}
} // namespace device
......@@ -5,12 +5,8 @@
#ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_WINRT_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_WINRT_H_
#include <windows.devices.bluetooth.genericattributeprofile.h>
#include <wrl/client.h>
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
......@@ -19,18 +15,15 @@
#include "device/bluetooth/bluetooth_export.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
#include "device/bluetooth/bluetooth_uuid.h"
namespace device {
class BluetoothUUID;
class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorWinrt
: public BluetoothRemoteGattDescriptor {
public:
static std::unique_ptr<BluetoothRemoteGattDescriptorWinrt> Create(
BluetoothRemoteGattCharacteristic* characteristic,
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattDescriptor>
descriptor);
BluetoothRemoteGattDescriptorWinrt();
~BluetoothRemoteGattDescriptorWinrt() override;
// BluetoothGattDescriptor:
......@@ -48,21 +41,6 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorWinrt
const ErrorCallback& error_callback) override;
private:
BluetoothRemoteGattDescriptorWinrt(
BluetoothRemoteGattCharacteristic* characteristic,
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattDescriptor>
descriptor,
BluetoothUUID uuid,
uint16_t attribute_handle);
// Weak. This object is owned by |characteristic_|.
BluetoothRemoteGattCharacteristic* characteristic_;
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattDescriptor>
descriptor_;
BluetoothUUID uuid_;
std::string identifier_;
std::vector<uint8_t> value_;
DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattDescriptorWinrt);
......
......@@ -91,16 +91,10 @@ void BluetoothRemoteGattServiceWinrt::UpdateCharacteristics(
std::string identifier = characteristic->GetIdentifier();
auto iter = characteristics_.find(identifier);
if (iter != characteristics_.end()) {
iter = characteristics.emplace(std::move(*iter)).first;
} else {
iter = characteristics
.emplace(std::move(identifier), std::move(characteristic))
.first;
}
static_cast<BluetoothRemoteGattCharacteristicWinrt*>(iter->second.get())
->UpdateDescriptors(gatt_discoverer);
if (iter != characteristics_.end())
characteristics.emplace(std::move(*iter));
else
characteristics.emplace(std::move(identifier), std::move(characteristic));
}
std::swap(characteristics, characteristics_);
......
......@@ -813,19 +813,6 @@ void BluetoothTestWinrt::SimulateGattCharacteristicWriteError(
->SimulateGattCharacteristicWriteError(error_code);
}
void BluetoothTestWinrt::SimulateGattDescriptor(
BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid) {
if (!GetParam() || !PlatformSupportsLowEnergy())
return BluetoothTestWin::SimulateGattDescriptor(characteristic, uuid);
auto* const ble_device = static_cast<TestBluetoothDeviceWinrt*>(
characteristic->GetService()->GetDevice())
->ble_device();
DCHECK(ble_device);
ble_device->SimulateGattDescriptor(characteristic, uuid);
}
void BluetoothTestWinrt::DeleteDevice(BluetoothDevice* device) {
(!GetParam() || !PlatformSupportsLowEnergy())
? BluetoothTestWin::DeleteDevice(device)
......
......@@ -147,8 +147,6 @@ class BluetoothTestWinrt : public BluetoothTestWin,
void SimulateGattCharacteristicWriteError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothRemoteGattService::GattErrorCode error_code) override;
void SimulateGattDescriptor(BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid) override;
void DeleteDevice(BluetoothDevice* device) override;
void OnFakeBluetoothDeviceConnectGattCalled();
......
......@@ -15,7 +15,6 @@
#include "base/win/async_operation.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_winrt.h"
#include "device/bluetooth/test/bluetooth_test_win.h"
#include "device/bluetooth/test/fake_gatt_characteristic_winrt.h"
#include "device/bluetooth/test/fake_gatt_device_service_winrt.h"
#include "device/bluetooth/test/fake_gatt_device_services_result_winrt.h"
......@@ -199,11 +198,8 @@ void FakeBluetoothLEDeviceWinrt::SimulateGattDisconnection() {
void FakeBluetoothLEDeviceWinrt::SimulateGattServicesDiscovered(
const std::vector<std::string>& uuids) {
for (const auto& uuid : uuids) {
// Attribute handles need to be unique for a given BLE device. Increasing by
// a large number ensures enough address space for the contained
// characteristics and descriptors.
fake_services_.push_back(Make<FakeGattDeviceServiceWinrt>(
bluetooth_test_winrt_, uuid, service_attribute_handle_ += 0x0400));
bluetooth_test_winrt_, uuid, service_attribute_handle_++));
}
DCHECK(gatt_services_callback_);
......@@ -245,23 +241,6 @@ void FakeBluetoothLEDeviceWinrt::SimulateGattCharacteristic(
.Run(Make<FakeGattDeviceServicesResultWinrt>(fake_services_));
}
void FakeBluetoothLEDeviceWinrt::SimulateGattDescriptor(
BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid) {
// Simulate the fake descriptor on the GATT service and trigger a GATT
// re-scan via GattServicesChanged().
auto* const fake_characteristic = static_cast<FakeGattCharacteristicWinrt*>(
static_cast<BluetoothRemoteGattCharacteristicWinrt*>(characteristic)
->GetCharacteristicForTesting());
DCHECK(fake_characteristic);
fake_characteristic->SimulateGattDescriptor(uuid);
SimulateGattServicesChanged();
DCHECK(gatt_services_callback_);
std::move(gatt_services_callback_)
.Run(Make<FakeGattDeviceServicesResultWinrt>(fake_services_));
}
void FakeBluetoothLEDeviceWinrt::SimulateGattServicesChanged() {
DCHECK(gatt_services_changed_handler_);
gatt_services_changed_handler_->Invoke(this, nullptr);
......
......@@ -112,8 +112,6 @@ class FakeBluetoothLEDeviceWinrt
void SimulateGattCharacteristic(BluetoothRemoteGattService* service,
const std::string& uuid,
int properties);
void SimulateGattDescriptor(BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid);
void SimulateGattServicesDiscoveryError();
private:
......
......@@ -13,8 +13,6 @@
#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_descriptor_winrt.h"
#include "device/bluetooth/test/fake_gatt_descriptors_result_winrt.h"
#include "device/bluetooth/test/fake_gatt_read_result_winrt.h"
#include "device/bluetooth/test/fake_gatt_write_result_winrt.h"
......@@ -71,8 +69,7 @@ FakeGattCharacteristicWinrt::FakeGattCharacteristicWinrt(
: bluetooth_test_winrt_(bluetooth_test_winrt),
properties_(static_cast<GattCharacteristicProperties>(properties)),
uuid_(BluetoothUUID::GetCanonicalValueAsGUID(uuid)),
attribute_handle_(attribute_handle),
last_descriptor_attribute_handle_(attribute_handle) {}
attribute_handle_(attribute_handle) {}
FakeGattCharacteristicWinrt::~FakeGattCharacteristicWinrt() = default;
......@@ -176,13 +173,7 @@ HRESULT FakeGattCharacteristicWinrt::remove_ValueChanged(
HRESULT FakeGattCharacteristicWinrt::GetDescriptorsAsync(
IAsyncOperation<GattDescriptorsResult*>** operation) {
auto async_op = Make<base::win::AsyncOperation<GattDescriptorsResult*>>();
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(async_op->callback(),
Make<FakeGattDescriptorsResultWinrt>(fake_descriptors_)));
*operation = async_op.Detach();
return S_OK;
return E_NOTIMPL;
}
HRESULT FakeGattCharacteristicWinrt::GetDescriptorsWithCacheModeAsync(
......@@ -267,10 +258,4 @@ void FakeGattCharacteristicWinrt::SimulateGattCharacteristicWriteError(
}
}
void FakeGattCharacteristicWinrt::SimulateGattDescriptor(
base::StringPiece uuid) {
fake_descriptors_.push_back(
Make<FakeGattDescriptorWinrt>(uuid, ++last_descriptor_attribute_handle_));
}
} // namespace device
......@@ -22,7 +22,6 @@
namespace device {
class BluetoothTestWinrt;
class FakeGattDescriptorWinrt;
class FakeGattCharacteristicWinrt
: public Microsoft::WRL::RuntimeClass<
......@@ -153,7 +152,6 @@ class FakeGattCharacteristicWinrt
void SimulateGattCharacteristicWrite();
void SimulateGattCharacteristicWriteError(
BluetoothGattService::GattErrorCode error_code);
void SimulateGattDescriptor(base::StringPiece uuid);
private:
BluetoothTestWinrt* bluetooth_test_winrt_;
......@@ -171,10 +169,6 @@ class FakeGattCharacteristicWinrt
GenericAttributeProfile::IGattWriteResult>)>
write_value_callback_;
std::vector<Microsoft::WRL::ComPtr<FakeGattDescriptorWinrt>>
fake_descriptors_;
uint16_t last_descriptor_attribute_handle_;
DISALLOW_COPY_AND_ASSIGN(FakeGattCharacteristicWinrt);
};
......
......@@ -4,9 +4,6 @@
#include "device/bluetooth/test/fake_gatt_descriptor_winrt.h"
#include "base/strings/string_piece.h"
#include "device/bluetooth/bluetooth_uuid.h"
namespace device {
namespace {
......@@ -24,10 +21,7 @@ using ABI::Windows::Storage::Streams::IBuffer;
} // namespace
FakeGattDescriptorWinrt::FakeGattDescriptorWinrt(base::StringPiece uuid,
uint16_t attribute_handle)
: uuid_(BluetoothUUID::GetCanonicalValueAsGUID(uuid)),
attribute_handle_(attribute_handle) {}
FakeGattDescriptorWinrt::FakeGattDescriptorWinrt() = default;
FakeGattDescriptorWinrt::~FakeGattDescriptorWinrt() = default;
......@@ -42,13 +36,11 @@ HRESULT FakeGattDescriptorWinrt::put_ProtectionLevel(
}
HRESULT FakeGattDescriptorWinrt::get_Uuid(GUID* value) {
*value = uuid_;
return S_OK;
return E_NOTIMPL;
}
HRESULT FakeGattDescriptorWinrt::get_AttributeHandle(uint16_t* value) {
*value = attribute_handle_;
return S_OK;
return E_NOTIMPL;
}
HRESULT FakeGattDescriptorWinrt::ReadValueAsync(
......
......@@ -11,7 +11,6 @@
#include <stdint.h>
#include "base/macros.h"
#include "base/strings/string_piece_forward.h"
namespace device {
......@@ -24,7 +23,7 @@ class FakeGattDescriptorWinrt
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptor2> {
public:
FakeGattDescriptorWinrt(base::StringPiece uuid, uint16_t attribute_handle);
FakeGattDescriptorWinrt();
~FakeGattDescriptorWinrt() override;
// IGattDescriptor:
......@@ -59,9 +58,6 @@ class FakeGattDescriptorWinrt
GattWriteResult*>** operation) override;
private:
GUID uuid_;
uint16_t attribute_handle_;
DISALLOW_COPY_AND_ASSIGN(FakeGattDescriptorWinrt);
};
......
......@@ -4,68 +4,25 @@
#include "device/bluetooth/test/fake_gatt_descriptors_result_winrt.h"
#include "base/win/vector.h"
#include "device/bluetooth/test/fake_gatt_descriptor_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::GattDescriptor;
using ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptor;
using ABI::Windows::Foundation::Collections::IVectorView;
using ABI::Windows::Foundation::IReference;
using Microsoft::WRL::ComPtr;
using Microsoft::WRL::Make;
} // namespace
// Note: As UWP does not provide GattDescriptor specializations for
// IObservableVector, VectorChangedEventHandler and IVector we need to supply
// our own. UUIDs were generated using `uuidgen`.
namespace ABI {
namespace Windows {
namespace Foundation {
namespace Collections {
template <>
struct __declspec(uuid("b259bb8d-2a87-44f6-9f9c-321cb98b7750"))
IObservableVector<GattDescriptor*>
: IObservableVector_impl<
Internal::AggregateType<GattDescriptor*, IGattDescriptor*>> {};
template <>
struct __declspec(uuid("39bc2e35-9a9a-4f93-ba00-7caaf965457e"))
VectorChangedEventHandler<GattDescriptor*>
: VectorChangedEventHandler_impl<
Internal::AggregateType<GattDescriptor*, IGattDescriptor*>> {};
template <>
struct __declspec(
uuid("1865abfa-a793-4b20-910c-f43e3fd12c3c")) IVector<GattDescriptor*>
: IVector_impl<Internal::AggregateType<GattDescriptor*, IGattDescriptor*>> {
};
} // namespace Collections
} // namespace Foundation
} // namespace Windows
} // namespace ABI
namespace device {
FakeGattDescriptorsResultWinrt::FakeGattDescriptorsResultWinrt(
const std::vector<ComPtr<FakeGattDescriptorWinrt>>& fake_descriptors)
: descriptors_(fake_descriptors.begin(), fake_descriptors.end()) {}
FakeGattDescriptorsResultWinrt::FakeGattDescriptorsResultWinrt() = default;
FakeGattDescriptorsResultWinrt::~FakeGattDescriptorsResultWinrt() = default;
HRESULT FakeGattDescriptorsResultWinrt::get_Status(
GattCommunicationStatus* value) {
*value = GattCommunicationStatus_Success;
return S_OK;
return E_NOTIMPL;
}
HRESULT FakeGattDescriptorsResultWinrt::get_ProtocolError(
......@@ -75,7 +32,7 @@ HRESULT FakeGattDescriptorsResultWinrt::get_ProtocolError(
HRESULT FakeGattDescriptorsResultWinrt::get_Descriptors(
IVectorView<GattDescriptor*>** value) {
return Make<base::win::Vector<GattDescriptor*>>(descriptors_)->GetView(value);
return E_NOTIMPL;
}
} // namespace device
......@@ -8,19 +8,14 @@
#include <windows.devices.bluetooth.genericattributeprofile.h>
#include <windows.foundation.collections.h>
#include <windows.foundation.h>
#include <wrl/client.h>
#include <wrl/implements.h>
#include <stdint.h>
#include <vector>
#include "base/macros.h"
namespace device {
class FakeGattDescriptorWinrt;
class FakeGattDescriptorsResultWinrt
: public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags<
......@@ -28,9 +23,7 @@ class FakeGattDescriptorsResultWinrt
ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
IGattDescriptorsResult> {
public:
explicit FakeGattDescriptorsResultWinrt(
const std::vector<Microsoft::WRL::ComPtr<FakeGattDescriptorWinrt>>&
fake_descriptors);
FakeGattDescriptorsResultWinrt();
~FakeGattDescriptorsResultWinrt() override;
// IGattDescriptorsResult:
......@@ -45,11 +38,6 @@ class FakeGattDescriptorsResultWinrt
GattDescriptor*>** value) override;
private:
std::vector<
Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
GenericAttributeProfile::IGattDescriptor>>
descriptors_;
DISALLOW_COPY_AND_ASSIGN(FakeGattDescriptorsResultWinrt);
};
......
......@@ -48,8 +48,7 @@ FakeGattDeviceServiceWinrt::FakeGattDeviceServiceWinrt(
uint16_t attribute_handle)
: bluetooth_test_winrt_(bluetooth_test_winrt),
uuid_(BluetoothUUID::GetCanonicalValueAsGUID(uuid)),
attribute_handle_(attribute_handle),
characteristic_attribute_handle_(attribute_handle_) {}
attribute_handle_(attribute_handle) {}
FakeGattDeviceServiceWinrt::~FakeGattDeviceServiceWinrt() = default;
......@@ -161,13 +160,9 @@ FakeGattDeviceServiceWinrt::GetIncludedServicesForUuidWithCacheModeAsync(
void FakeGattDeviceServiceWinrt::SimulateGattCharacteristic(
base::StringPiece uuid,
int properties) {
// In order to ensure attribute handles are unique across the Gatt Server
// we reserve sufficient address space for descriptors for each
// characteristic. We allocate space for 32 descriptors, which should be
// enough for tests.
fake_characteristics_.push_back(Make<FakeGattCharacteristicWinrt>(
bluetooth_test_winrt_, properties, uuid,
characteristic_attribute_handle_ += 0x20));
fake_characteristics_.push_back(
Make<FakeGattCharacteristicWinrt>(bluetooth_test_winrt_, properties, uuid,
characteristic_attribute_handle_++));
}
} // namespace device
......@@ -120,7 +120,7 @@ class FakeGattDeviceServiceWinrt
std::vector<Microsoft::WRL::ComPtr<FakeGattCharacteristicWinrt>>
fake_characteristics_;
uint16_t characteristic_attribute_handle_;
uint16_t characteristic_attribute_handle_ = 0;
DISALLOW_COPY_AND_ASSIGN(FakeGattDeviceServiceWinrt);
};
......
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