bluetooth_remote_gatt_descriptor_android.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2016 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_ANDROID_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_ANDROID_H_
  6. #include <memory>
  7. #include "base/android/jni_android.h"
  8. #include "base/android/scoped_java_ref.h"
  9. #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
  10. #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
  11. namespace device {
  12. // BluetoothRemoteGattDescriptorAndroid along with its owned Java class
  13. // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattDescriptor
  14. // implement BluetootGattDescriptor.
  15. class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptorAndroid
  16. : public BluetoothRemoteGattDescriptor {
  17. public:
  18. // Create a BluetoothRemoteGattDescriptorAndroid instance and associated
  19. // Java ChromeBluetoothRemoteGattDescriptor using the provided
  20. // |bluetooth_gatt_descriptor_wrapper|.
  21. //
  22. // The ChromeBluetoothRemoteGattDescriptor instance will hold a Java
  23. // reference to |bluetooth_gatt_descriptor_wrapper|.
  24. static std::unique_ptr<BluetoothRemoteGattDescriptorAndroid> Create(
  25. const std::string& instanceId,
  26. const base::android::JavaRef<jobject>& /* BluetoothGattDescriptorWrapper
  27. */
  28. bluetooth_gatt_descriptor_wrapper,
  29. const base::android::JavaRef<
  30. jobject>& /* chromeBluetoothDevice */ chrome_bluetooth_device);
  31. BluetoothRemoteGattDescriptorAndroid(
  32. const BluetoothRemoteGattDescriptorAndroid&) = delete;
  33. BluetoothRemoteGattDescriptorAndroid& operator=(
  34. const BluetoothRemoteGattDescriptorAndroid&) = delete;
  35. ~BluetoothRemoteGattDescriptorAndroid() override;
  36. // Returns the associated ChromeBluetoothRemoteGattDescriptor Java object.
  37. base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
  38. // BluetoothRemoteGattDescriptor interface:
  39. std::string GetIdentifier() const override;
  40. BluetoothUUID GetUUID() const override;
  41. const std::vector<uint8_t>& GetValue() const override;
  42. BluetoothRemoteGattCharacteristic* GetCharacteristic() const override;
  43. BluetoothRemoteGattCharacteristic::Permissions GetPermissions()
  44. const override;
  45. void ReadRemoteDescriptor(ValueCallback callback) override;
  46. void WriteRemoteDescriptor(const std::vector<uint8_t>& value,
  47. base::OnceClosure callback,
  48. ErrorCallback error_callback) override;
  49. // Called when Read operation completes.
  50. void OnRead(JNIEnv* env,
  51. const base::android::JavaParamRef<jobject>& jcaller,
  52. int32_t status,
  53. const base::android::JavaParamRef<jbyteArray>& value);
  54. // Called when Write operation completes.
  55. void OnWrite(JNIEnv* env,
  56. const base::android::JavaParamRef<jobject>& jcaller,
  57. int32_t status);
  58. private:
  59. BluetoothRemoteGattDescriptorAndroid(const std::string& instanceId);
  60. // Java object
  61. // org.chromium.device.bluetooth.ChromeBluetoothRemoteGattDescriptor.
  62. base::android::ScopedJavaGlobalRef<jobject> j_descriptor_;
  63. // Adapter unique instance ID.
  64. std::string instance_id_;
  65. // ReadRemoteCharacteristic callbacks and pending state.
  66. bool read_pending_ = false;
  67. ValueCallback read_callback_;
  68. // WriteRemoteCharacteristic callbacks and pending state.
  69. bool write_pending_ = false;
  70. base::OnceClosure write_callback_;
  71. ErrorCallback write_error_callback_;
  72. std::vector<uint8_t> value_;
  73. };
  74. } // namespace device
  75. #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_ANDROID_H_