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

source code of qtmqtt/src/mqtt/qmqttsubscription.h