#ifndef DEVICE_BLUETOOTH_FLOSS_BLUETOOTH_LOCAL_GATT_SERVICE_FLOSS_H_
#define DEVICE_BLUETOOTH_FLOSS_BLUETOOTH_LOCAL_GATT_SERVICE_FLOSS_H_
#include <string>
#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_local_gatt_service.h"
#include "device/bluetooth/floss/bluetooth_adapter_floss.h"
#include "device/bluetooth/floss/bluetooth_gatt_service_floss.h"
#include "device/bluetooth/floss/bluetooth_local_gatt_characteristic_floss.h"
#include "device/bluetooth/floss/floss_gatt_manager_client.h"
#include "device/bluetooth/public/cpp/bluetooth_uuid.h"
namespace floss {
class BluetoothLocalGattCharacteristicFloss;
class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattServiceFloss
: public BluetoothGattServiceFloss,
public device::BluetoothLocalGattService {
public:
static base::WeakPtr<BluetoothLocalGattServiceFloss> Create(
BluetoothAdapterFloss* adapter,
const device::BluetoothUUID& uuid,
bool is_primary,
device::BluetoothLocalGattService::Delegate* delegate);
BluetoothLocalGattServiceFloss(const BluetoothLocalGattServiceFloss&) =
delete;
BluetoothLocalGattServiceFloss& operator=(
const BluetoothLocalGattServiceFloss&) = delete;
~BluetoothLocalGattServiceFloss() override;
device::BluetoothUUID GetUUID() const override;
bool IsPrimary() const override;
void Register(base::OnceClosure callback,
ErrorCallback error_callback) override;
void Unregister(base::OnceClosure callback,
ErrorCallback error_callback) override;
bool IsRegistered() override;
void Delete() override;
device::BluetoothLocalGattCharacteristic* GetCharacteristic(
const std::string& identifier) override;
std::string GetIdentifier() const override;
base::WeakPtr<device::BluetoothLocalGattCharacteristic> CreateCharacteristic(
const device::BluetoothUUID& uuid,
device::BluetoothGattCharacteristic::Properties properties,
device::BluetoothGattCharacteristic::Permissions permissions) override;
void GattServerServiceAdded(GattStatus status, GattService service) override;
void GattServerServiceRemoved(GattStatus status, int32_t handle) override;
void SetRegistered(bool is_registered);
GattService ToGattService();
void ResolveInstanceId(const GattService& service);
int32_t InstanceId() const { return floss_instance_id_; }
private:
friend class BluetoothLocalGattCharacteristicFloss;
friend class BluetoothLocalGattDescriptorFloss;
friend class BluetoothLocalGattServiceFlossTest;
BluetoothLocalGattServiceFloss(
BluetoothAdapterFloss* adapter,
const device::BluetoothUUID& uuid,
bool is_primary,
device::BluetoothLocalGattService::Delegate* delegate);
void OnRegistrationError(const ErrorCallback& error_callback,
const std::string& error_name,
const std::string& error_message);
int32_t AddCharacteristic(
std::unique_ptr<BluetoothLocalGattCharacteristicFloss> characteristic);
bool is_included_service_ = false;
static uint32_t NewInstanceId();
static uint32_t instance_id_tracker_;
const bool is_primary_;
bool is_registered_ = false;
device::BluetoothUUID uuid_;
int32_t client_instance_id_;
int32_t floss_instance_id_ = -1;
std::pair<base::OnceClosure, device::BluetoothGattService::ErrorCallback>
register_callbacks_;
std::pair<base::OnceClosure, device::BluetoothGattService::ErrorCallback>
unregister_callbacks_;
raw_ptr<device::BluetoothLocalGattService::Delegate> delegate_;
std::vector<std::unique_ptr<BluetoothLocalGattServiceFloss>>
included_services_;
std::vector<std::unique_ptr<BluetoothLocalGattCharacteristicFloss>>
characteristics_;
base::WeakPtrFactory<BluetoothLocalGattServiceFloss> weak_ptr_factory_{this};
};
}
#endif