#ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
#define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
#include <stddef.h>
#include <stdint.h>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "dbus/object_path.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_remote_gatt_service.h"
#include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h"
#include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h"
#include "device/bluetooth/public/cpp/bluetooth_uuid.h"
namespace device {
class BluetoothRemoteGattDescriptor;
class BluetoothRemoteGattService;
}
namespace bluez {
class BluetoothRemoteGattServiceBlueZ;
class BluetoothRemoteGattCharacteristicBlueZ
: public BluetoothGattCharacteristicBlueZ,
public BluetoothGattDescriptorClient::Observer,
public device::BluetoothRemoteGattCharacteristic {
public:
BluetoothRemoteGattCharacteristicBlueZ(
const BluetoothRemoteGattCharacteristicBlueZ&) = delete;
BluetoothRemoteGattCharacteristicBlueZ& operator=(
const BluetoothRemoteGattCharacteristicBlueZ&) = delete;
~BluetoothRemoteGattCharacteristicBlueZ() override;
device::BluetoothUUID GetUUID() const override;
Properties GetProperties() const override;
Permissions GetPermissions() const override;
const std::vector<uint8_t>& GetValue() const override;
device::BluetoothRemoteGattService* GetService() const override;
bool IsNotifying() const override;
void ReadRemoteCharacteristic(ValueCallback callback) override;
void WriteRemoteCharacteristic(base::span<const uint8_t> value,
WriteType write_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void DeprecatedWriteRemoteCharacteristic(
base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#if BUILDFLAG(IS_CHROMEOS)
void PrepareWriteRemoteCharacteristic(base::span<const uint8_t> value,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#endif
protected:
#if BUILDFLAG(IS_CHROMEOS)
void SubscribeToNotifications(
device::BluetoothRemoteGattDescriptor* ccc_descriptor,
NotificationType notification_type,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#else
void SubscribeToNotifications(
device::BluetoothRemoteGattDescriptor* ccc_descriptor,
base::OnceClosure callback,
ErrorCallback error_callback) override;
#endif
void UnsubscribeFromNotifications(
device::BluetoothRemoteGattDescriptor* ccc_descriptor,
base::OnceClosure callback,
ErrorCallback error_callback) override;
private:
friend class BluetoothRemoteGattServiceBlueZ;
BluetoothRemoteGattCharacteristicBlueZ(
BluetoothRemoteGattServiceBlueZ* service,
const dbus::ObjectPath& object_path);
void GattDescriptorAdded(const dbus::ObjectPath& object_path) override;
void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override;
void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path,
const std::string& property_name) override;
void OnStartNotifySuccess(base::OnceClosure callback);
void OnStartNotifyError(ErrorCallback error_callback,
const std::string& error_name,
const std::string& error_message);
void OnStopNotifySuccess(base::OnceClosure callback);
void OnStopNotifyError(base::OnceClosure callback,
const std::string& error_name,
const std::string& error_message);
void OnReadError(ValueCallback callback,
const std::string& error_name,
const std::string& error_message);
void OnWriteError(ErrorCallback error_callback,
const std::string& error_name,
const std::string& error_message);
bool has_notify_session_;
raw_ptr<BluetoothRemoteGattServiceBlueZ> service_;
int num_of_characteristic_value_read_in_progress_;
base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ>
weak_ptr_factory_{this};
};
}
#endif