bluetooth_remote_gatt_descriptor_winrt.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_WINRT_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_WINRT_H_
  6. #include <windows.devices.bluetooth.genericattributeprofile.h>
  7. #include <wrl/client.h>
  8. #include <stdint.h>
  9. #include <memory>
  10. #include <string>
  11. #include <vector>
  12. #include "base/callback_forward.h"
  13. #include "base/memory/raw_ptr.h"
  14. #include "base/memory/weak_ptr.h"
  15. #include "device/bluetooth/bluetooth_export.h"
  16. #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
  17. #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
  18. #include "device/bluetooth/public/cpp/bluetooth_uuid.h"
  19. namespace device {
  20. class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorWinrt
  21. : public BluetoothRemoteGattDescriptor {
  22. public:
  23. static std::unique_ptr<BluetoothRemoteGattDescriptorWinrt> Create(
  24. BluetoothRemoteGattCharacteristic* characteristic,
  25. Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
  26. GenericAttributeProfile::IGattDescriptor>
  27. descriptor);
  28. BluetoothRemoteGattDescriptorWinrt(
  29. const BluetoothRemoteGattDescriptorWinrt&) = delete;
  30. BluetoothRemoteGattDescriptorWinrt& operator=(
  31. const BluetoothRemoteGattDescriptorWinrt&) = delete;
  32. ~BluetoothRemoteGattDescriptorWinrt() override;
  33. // BluetoothGattDescriptor:
  34. std::string GetIdentifier() const override;
  35. BluetoothUUID GetUUID() const override;
  36. BluetoothGattCharacteristic::Permissions GetPermissions() const override;
  37. // BluetoothRemoteGattDescriptor:
  38. const std::vector<uint8_t>& GetValue() const override;
  39. BluetoothRemoteGattCharacteristic* GetCharacteristic() const override;
  40. void ReadRemoteDescriptor(ValueCallback callback) override;
  41. void WriteRemoteDescriptor(const std::vector<uint8_t>& value,
  42. base::OnceClosure callback,
  43. ErrorCallback error_callback) override;
  44. ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::IGattDescriptor*
  45. GetDescriptorForTesting();
  46. private:
  47. struct PendingWriteCallbacks {
  48. PendingWriteCallbacks(base::OnceClosure callback,
  49. ErrorCallback error_callback);
  50. ~PendingWriteCallbacks();
  51. base::OnceClosure callback;
  52. ErrorCallback error_callback;
  53. };
  54. BluetoothRemoteGattDescriptorWinrt(
  55. BluetoothRemoteGattCharacteristic* characteristic,
  56. Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
  57. GenericAttributeProfile::IGattDescriptor>
  58. descriptor,
  59. BluetoothUUID uuid,
  60. uint16_t attribute_handle);
  61. void OnReadValue(Microsoft::WRL::ComPtr<
  62. ABI::Windows::Devices::Bluetooth::GenericAttributeProfile::
  63. IGattReadResult> read_result);
  64. void OnWriteValueWithResult(
  65. Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
  66. GenericAttributeProfile::IGattWriteResult>
  67. write_result);
  68. // Weak. This object is owned by |characteristic_|.
  69. raw_ptr<BluetoothRemoteGattCharacteristic> characteristic_;
  70. Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::
  71. GenericAttributeProfile::IGattDescriptor>
  72. descriptor_;
  73. BluetoothUUID uuid_;
  74. std::string identifier_;
  75. std::vector<uint8_t> value_;
  76. ValueCallback pending_read_callback_;
  77. std::unique_ptr<PendingWriteCallbacks> pending_write_callbacks_;
  78. base::WeakPtrFactory<BluetoothRemoteGattDescriptorWinrt> weak_ptr_factory_{
  79. this};
  80. };
  81. } // namespace device
  82. #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_WINRT_H_