File indexing completed on 2024-04-28 15:17:52

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2021 Ivan Podkurkov <podkiva2@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #ifndef BLUEZQT_GATTDESCRIPTORREMOTE_H
0010 #define BLUEZQT_GATTDESCRIPTORREMOTE_H
0011 
0012 #include <QObject>
0013 #include <QMap>
0014 
0015 #include "types.h"
0016 #include "bluezqt_export.h"
0017 
0018 namespace BluezQt
0019 {
0020 
0021 class GattCharacteristicRemote;
0022 class PendingCall;
0023 
0024 /**
0025  * @class BluezQt::GattDescriptorRemote gattdescriptorremote.h <BluezQt/GattDescriptorRemote>
0026  *
0027  * Bluetooth LE GATT descriptor.
0028  *
0029  * This class represents a Bluetooth LE GATT descriptor for the clients.
0030  */
0031 class BLUEZQT_EXPORT GattDescriptorRemote : public QObject
0032 {
0033     Q_OBJECT
0034     Q_PROPERTY(QString ubi READ ubi CONSTANT)
0035     Q_PROPERTY(QString uuid READ uuid NOTIFY uuidChanged)
0036     Q_PROPERTY(QByteArray value READ value NOTIFY valueChanged)
0037     Q_PROPERTY(QStringList flags READ flags NOTIFY flagsChanged)
0038     Q_PROPERTY(quint16 handle READ handle NOTIFY handleChanged)
0039     Q_PROPERTY(GattCharacteristicRemotePtr characteristic READ characteristic CONSTANT)
0040 
0041 
0042 public:
0043     /**
0044      * Destroys a GattDescriptor object.
0045      */
0046     ~GattDescriptorRemote() override;
0047 
0048     /**
0049      * Returns a shared pointer from this.
0050      *
0051      * @return DevicePtr
0052      */
0053     GattDescriptorRemotePtr toSharedPtr() const;
0054 
0055     /**
0056      * Returns an UBI of the GATT descriptor.
0057      *
0058      * Example UBI: "/org/bluez/hci0/dev_40_79_6A_0C_39_75"
0059      *
0060      * @return UBI of descriptor
0061      */
0062     QString ubi() const;
0063 
0064     /**
0065      * Returns an uuid of the descriptor.
0066      *
0067      * @return uuid of the descriptor
0068      */
0069     QString uuid() const;
0070 
0071     /**
0072      * Returns an value of the descriptor.
0073      *
0074      * @return value of the descriptor
0075      */
0076     QByteArray value() const;
0077 
0078     /**
0079      * Returns flags the descriptor.
0080      *
0081      * @return flags of descriptor
0082      */
0083     QStringList flags() const;
0084 
0085     /**
0086      * Returns descriptor handle.
0087      *
0088      * @return qint16 descriptor handle
0089      */
0090     quint16 handle() const;
0091 
0092     /**
0093      * Sets the descriptor handle.
0094      *
0095      * @param handle descriptor handle
0096      * @return void pending call
0097      */
0098     PendingCall *setHandle(quint16 handle);
0099 
0100     /**
0101      * Returns a characteristic that owns that descriptor.
0102      *
0103      * @return characteristic of descriptor
0104      */
0105     GattCharacteristicRemotePtr characteristic() const;
0106 
0107 public Q_SLOTS:
0108     /**
0109      * Read the value of the GATT descriptor.
0110      *
0111      * Issues a request to read the value of the descriptor and
0112      * returns the value if the operation was successful.
0113      *
0114      * Possible errors: PendingCall::NotReady, PendingCall::Failed,
0115      *                  PendingCall::InProgress, PendingCall::AlreadyConnected
0116      *
0117      * @return QByteArray pending call
0118      */
0119     PendingCall *readValue(const QVariantMap &options);
0120 
0121     /**
0122      * Write the value of the GATT descriptor.
0123      *
0124      * Issues a request to write the value of the descriptor.
0125      *
0126      * Possible errors: PendingCall::NotReady, PendingCall::Failed,
0127      *                  PendingCall::InProgress, PendingCall::AlreadyConnected
0128      *
0129      * @return void pending call
0130      */
0131     PendingCall *writeValue(const QByteArray &value, const QVariantMap &options);
0132 
0133 Q_SIGNALS:
0134     /**
0135      * Indicates that at least one of the descriptors's properties have changed.
0136      */
0137     void descriptorChanged(GattDescriptorRemotePtr descriptor);
0138 
0139     /**
0140      * Indicates that descriptor's uuid have changed.
0141      */
0142     void uuidChanged(const QString &uuid);
0143 
0144     /**
0145      * Indicates that descriptor's value have changed.
0146      */
0147     void valueChanged(const QByteArray value);
0148 
0149     /**
0150      * Indicates that descriptor's flags have changed.
0151      */
0152     void flagsChanged(QStringList flags);
0153 
0154     /**
0155      * Indicates that descriptor's handle have changed.
0156      */
0157     void handleChanged(quint16 handle);
0158 
0159 private:
0160     BLUEZQT_NO_EXPORT explicit GattDescriptorRemote(const QString &path, const QVariantMap &properties, GattCharacteristicRemotePtr characteristic);
0161 
0162     const std::unique_ptr<class GattDescriptorRemotePrivate> d;
0163 
0164     friend class DevicePrivate;
0165     friend class GattServiceRemotePrivate;
0166     friend class GattCharacteristicRemotePrivate;
0167     friend class GattDescriptorRemotePrivate;
0168     friend class ManagerPrivate;
0169     friend class Adapter;
0170 };
0171 
0172 }  // namespace BluezQt
0173 
0174 #endif // BLUEZQT_GATTDESCRIPTORREMOTE_H