#ifndef DEVICE_BLUETOOTH_CAST_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CAST_H_
#define DEVICE_BLUETOOTH_CAST_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CAST_H_
#include <stdint.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
namespace chromecast {
namespace bluetooth {
class RemoteCharacteristic;
}
}
namespace device {
class BluetoothRemoteGattServiceCast;
class BluetoothRemoteGattCharacteristicCast
: public BluetoothRemoteGattCharacteristic {
public:
BluetoothRemoteGattCharacteristicCast(
BluetoothRemoteGattServiceCast* service,
scoped_refptr<chromecast::bluetooth::RemoteCharacteristic>
characteristic);
BluetoothRemoteGattCharacteristicCast(
const BluetoothRemoteGattCharacteristicCast&) = delete;
BluetoothRemoteGattCharacteristicCast& operator=(
const BluetoothRemoteGattCharacteristicCast&) = delete;
~BluetoothRemoteGattCharacteristicCast() override;
std::string GetIdentifier() const override;
BluetoothUUID GetUUID() const override;
Properties GetProperties() const override;
Permissions GetPermissions() const override;
const std::vector<uint8_t>& GetValue() const override;
BluetoothRemoteGattService* GetService() 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;
void SetValue(std::vector<uint8_t> value) { value_ = std::move(value); }
private:
void SubscribeToNotifications(BluetoothRemoteGattDescriptor* ccc_descriptor,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void UnsubscribeFromNotifications(
BluetoothRemoteGattDescriptor* ccc_descriptor,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void OnReadRemoteCharacteristic(ValueCallback callback,
bool success,
const std::vector<uint8_t>& result);
void OnWriteRemoteCharacteristic(const std::vector<uint8_t>& written_value,
base::OnceClosure callback,
ErrorCallback error_callback,
bool success);
BluetoothRemoteGattServiceCast* const service_;
scoped_refptr<chromecast::bluetooth::RemoteCharacteristic>
remote_characteristic_;
std::vector<uint8_t> value_;
base::WeakPtrFactory<BluetoothRemoteGattCharacteristicCast> weak_factory_;
};
}
#endif