| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QMQTTSUBSCRIPTION_H |
| 6 | #define QMQTTSUBSCRIPTION_H |
| 7 | |
| 8 | #include <QtMqtt/qmqttglobal.h> |
| 9 | #include <QtMqtt/qmqttmessage.h> |
| 10 | #include <QtMqtt/qmqtttopicfilter.h> |
| 11 | |
| 12 | #include <QtCore/QObject> |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | class QMqttClient; |
| 17 | class QMqttSubscriptionPrivate; |
| 18 | |
| 19 | class Q_MQTT_EXPORT QMqttSubscription : public QObject |
| 20 | { |
| 21 | Q_OBJECT |
| 22 | Q_ENUMS(SubscriptionState) |
| 23 | Q_PROPERTY(SubscriptionState state READ state NOTIFY stateChanged) |
| 24 | Q_PROPERTY(quint8 qos READ qos NOTIFY qosChanged) |
| 25 | Q_PROPERTY(QMqttTopicFilter topic READ topic) |
| 26 | Q_PROPERTY(QString reason READ reason) |
| 27 | Q_PROPERTY(QMqtt::ReasonCode reasonCode READ reasonCode) |
| 28 | Q_PROPERTY(bool sharedSubscription READ isSharedSubscription) |
| 29 | Q_PROPERTY(QString sharedSubscriptionName READ sharedSubscriptionName) |
| 30 | public: |
| 31 | ~QMqttSubscription() override; |
| 32 | enum SubscriptionState { |
| 33 | Unsubscribed = 0, |
| 34 | SubscriptionPending, |
| 35 | Subscribed, |
| 36 | UnsubscriptionPending, |
| 37 | Error |
| 38 | }; |
| 39 | |
| 40 | SubscriptionState state() const; |
| 41 | QMqttTopicFilter topic() const; |
| 42 | quint8 qos() const; |
| 43 | QString reason() const; |
| 44 | QMqtt::ReasonCode reasonCode() const; |
| 45 | QMqttUserProperties userProperties() const; |
| 46 | |
| 47 | bool isSharedSubscription() const; |
| 48 | QString sharedSubscriptionName() const; |
| 49 | |
| 50 | Q_SIGNALS: |
| 51 | void stateChanged(SubscriptionState state); |
| 52 | void qosChanged(quint8); // only emitted when broker provides different QoS than requested |
| 53 | void messageReceived(QMqttMessage msg); |
| 54 | |
| 55 | public Q_SLOTS: |
| 56 | void unsubscribe(); |
| 57 | |
| 58 | private: |
| 59 | Q_DECLARE_PRIVATE(QMqttSubscription) |
| 60 | Q_DISABLE_COPY(QMqttSubscription) |
| 61 | void setState(SubscriptionState state); |
| 62 | void setTopic(const QMqttTopicFilter &topic); |
| 63 | void setClient(QMqttClient *client); |
| 64 | void setQos(quint8 qos); |
| 65 | void setSharedSubscription(bool s); |
| 66 | void setSharedSubscriptionName(const QString &name); |
| 67 | friend class QMqttConnection; |
| 68 | friend class QMqttClient; |
| 69 | explicit QMqttSubscription(QObject *parent = nullptr); |
| 70 | }; |
| 71 | |
| 72 | QT_END_NAMESPACE |
| 73 | |
| 74 | #endif // QMQTTSUBSCRIPTION_H |
| 75 | |