File indexing completed on 2024-05-05 03:52:29

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2022 Pontus Sjögren
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #ifndef GATTDESCRIPTOR_H
0010 #define GATTDESCRIPTOR_H
0011 
0012 #include <QDBusObjectPath>
0013 #include <QObject>
0014 
0015 #include "bluezqt_export.h"
0016 
0017 #include <memory>
0018 
0019 namespace BluezQt
0020 {
0021 
0022 class GattCharacteristic;
0023 
0024 /**
0025  * Bluetooth GATT Descriptor
0026  *
0027  * GATT Descriptors contain additional information and attributes of a GATT characteristic.
0028 
0029  * @since 6.0
0030  */
0031 class BLUEZQT_EXPORT GattDescriptor : public QObject
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     /**
0037      * Convenience method to create a User Description for the given charactersitic.
0038      *
0039      * @param description The User Description the characteristic should have
0040      * @param characteristic The characteristic to assign the descriptor to
0041      * @return A pointer to the created descriptor
0042      */
0043     static GattDescriptor *createUserDescription(const QString &description, GattCharacteristic *characteristic);
0044 
0045     /**
0046      * Creates a GattDescriptor with the given UUID.
0047      *
0048      * @param uuid UUID of the descriptor
0049      * @param parent Parent characteristic
0050      */
0051     GattDescriptor(const QString &uuid, GattCharacteristic *parent);
0052 
0053     /**
0054      * Creates a GattDescriptor with the given UUID and flags.
0055      *
0056      * @param uuid UUID of the descriptor
0057      * @param flags The flags of the descriptor
0058      * @param parent Parent characteristic
0059      */
0060     GattDescriptor(const QString &uuid, const QStringList &flags, GattCharacteristic *parent);
0061 
0062     /**
0063      * Creates a GattDescriptor with the given UUID, flags and initial value.
0064      *
0065      * @param uuid UUID of the descriptor
0066      * @param flags The flags of the descriptor
0067      * @param initialValue The value of the descriptor
0068      * @param parent Parent characteristic
0069      */
0070     GattDescriptor(const QString &uuid, const QStringList &flags, const QByteArray &initialValue, GattCharacteristic *parent);
0071 
0072     /**
0073      * Destroys the GattDescriptor.
0074      */
0075     ~GattDescriptor() override;
0076 
0077     /**
0078      * Reads the current value of the descriptor.
0079      *
0080      * @return A QByteArray representing the current value
0081      */
0082     QByteArray readValue();
0083 
0084     /**
0085      * Writes the value of the descriptor.
0086      *
0087      * @param value A QByteArray representing the new value
0088      */
0089     void writeValue(const QByteArray &value);
0090 
0091     /**
0092      * Returns the UUID of the descriptor.
0093      *
0094      * @return A QString representing the UUID
0095      */
0096     QString uuid() const;
0097 
0098     /**
0099      * Return the DBus object path of the parent characteristic.
0100      *
0101      * @return A QDBusObjectPath representing the DBus object path
0102      */
0103     QDBusObjectPath characteristic() const;
0104 
0105     /**
0106      * Return the flags of the descriptor.
0107      *
0108      * @return A QStringList representing the flags
0109      */
0110     QStringList flags() const;
0111 
0112 protected:
0113     virtual QDBusObjectPath objectPath() const;
0114 
0115 private:
0116     std::unique_ptr<class GattDescriptorPrivate> const d;
0117 
0118     friend class GattManager;
0119     friend class GattApplicationPrivate;
0120 };
0121 
0122 }
0123 
0124 #endif