File indexing completed on 2024-12-01 12:29:48

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_GATTSERVICEREMOTE_H
0010 #define BLUEZQT_GATTSERVICEREMOTE_H
0011 
0012 #include <QObject>
0013 #include <QMap>
0014 #include <QDBusObjectPath>
0015 
0016 #include "types.h"
0017 #include "bluezqt_export.h"
0018 
0019 namespace BluezQt
0020 {
0021 
0022 class Device;
0023 class PendingCall;
0024 
0025 /**
0026  * @class BluezQt::GattService gattservice.h <BluezQt/GattService>
0027  *
0028  * Bluetooth LE GATT service.
0029  *
0030  * This class represents a Bluetooth LE GATT service.
0031  */
0032 class BLUEZQT_EXPORT GattServiceRemote : public QObject
0033 {
0034     Q_OBJECT
0035 
0036     Q_PROPERTY(QString uuid READ uuid NOTIFY uuidChanged)
0037     Q_PROPERTY(bool primary READ isPrimary NOTIFY primaryChanged)
0038     Q_PROPERTY(DevicePtr device READ device CONSTANT)
0039     Q_PROPERTY(QList<QDBusObjectPath> includes READ includes NOTIFY includesChanged)
0040     Q_PROPERTY(quint16 handle READ handle WRITE setHandle NOTIFY handleChanged)
0041     Q_PROPERTY(QList<GattCharacteristicRemotePtr> characteristics READ characteristics NOTIFY characteristicsChanged)
0042 
0043 public:
0044     /**
0045      * Destroys a GattService object.
0046      */
0047     ~GattServiceRemote() override;
0048 
0049     /**
0050      * Returns a shared pointer from this.
0051      *
0052      * @return GattServicePtr
0053      */
0054     GattServiceRemotePtr toSharedPtr() const;
0055 
0056     /**
0057      * Returns an UBI of the gatt service.
0058      *
0059      * Example UBI: "/org/bluez/hci0/dev_40_79_6A_0C_39_75/service01"
0060      *
0061      * @return UBI of gatt service
0062      */
0063     QString ubi() const;
0064 
0065     /**
0066      * Returns an uuid of the service.
0067      *
0068      * @return uuid of the service
0069      */
0070     QString uuid() const;
0071 
0072     /**
0073      * Returns whether the service is primary.
0074      *
0075      * @return true if service is primary
0076      */
0077     bool isPrimary() const;
0078 
0079     /**
0080      * Returns a device that has this service.
0081      *
0082      * @return device of service
0083      */
0084     DevicePtr device() const;
0085 
0086     /**
0087      * Returns object paths representing the included
0088      * services of this service.
0089      *
0090      * @return Object paths of included services
0091      */
0092     QList<QDBusObjectPath> includes() const;
0093 
0094     /**
0095      * Returns service handle.
0096      *
0097      * @return qint16 service handle
0098      */
0099     quint16 handle() const;
0100 
0101     /**
0102      * Sets the service handle.
0103      *
0104      * @param handle service handle
0105      * @return void pending call
0106      */
0107     PendingCall *setHandle(quint16 handle);
0108 
0109     /**
0110      * Returns object paths representing the included
0111      * services of this service.
0112      *
0113      * @return Object paths of included services
0114      */
0115     QList<GattCharacteristicRemotePtr> characteristics() const;
0116 
0117 Q_SIGNALS:
0118     /**
0119      * Indicates that at least one of the service's properties have changed.
0120      */
0121     void serviceChanged(GattServiceRemotePtr service);
0122 
0123     /**
0124      * Indicates that a new characteristic was added (eg. found by connection).
0125      */
0126     void gattCharacteristicAdded(GattCharacteristicRemotePtr characteristic);
0127 
0128     /**
0129      * Indicates that service characteristics list has changed
0130      */
0131     void characteristicsChanged(QList<GattCharacteristicRemotePtr> characteristics);
0132 
0133     /**
0134      * Indicates that a characteristic was removed.
0135      */
0136     void gattCharacteristicRemoved(GattCharacteristicRemotePtr characteristic);
0137 
0138     /**
0139      * Indicates that at least one of the characteristic's properties have changed.
0140      */
0141     void gattCharacteristicChanged(GattCharacteristicRemotePtr characteristic);
0142 
0143     /**
0144      * Indicates that services's uuid have changed.
0145      */
0146     void uuidChanged(const QString &uuid);
0147 
0148     /**
0149      * Indicates that services's primary state have changed.
0150      */
0151     void primaryChanged(bool primary);
0152 
0153     /**
0154      * Indicates that services's handle have changed.
0155      */
0156     void handleChanged(quint16 handle);
0157 
0158     /**
0159      * Indicates that object paths representing the included
0160      * services have changed.
0161      */
0162     void includesChanged(const QList<QDBusObjectPath> &includes);
0163 
0164 private:
0165     BLUEZQT_NO_EXPORT explicit GattServiceRemote(const QString &path, const QVariantMap &properties, DevicePtr device);
0166 
0167     const std::unique_ptr<class GattServiceRemotePrivate> d;
0168 
0169     friend class GattServiceRemotePrivate;
0170     friend class DevicePrivate;
0171     friend class ManagerPrivate;
0172     friend class Adapter;
0173 };
0174 
0175 } // namespace BluezQt
0176 
0177 #endif // BLUEZQT_GATTSERVICEREMOTE_H