This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
powersync-mqtt/libnymea-mqtt/mqttclient_p.h
2018-11-28 20:24:14 +01:00

87 lines
3.0 KiB
C++

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2018 Michael Zanetti <michael.zanetti@guh.io> *
* *
* This file is part of nymea. *
* *
* nymea is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* nymea is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with nymea. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef MQTTCLIENT_P_H
#define MQTTCLIENT_P_H
#include <QObject>
#include <QTcpSocket>
#include <QTimer>
#include <QLoggingCategory>
#include "mqttpacket.h"
#include "mqttclient.h"
#include "mqttsubscription.h"
Q_DECLARE_LOGGING_CATEGORY(dbgClient)
class MqttClientPrivate: public QObject
{
Q_OBJECT
public:
MqttClientPrivate(MqttClient *q);
MqttClient *q_ptr;
void connectToHost(const QString &hostName, quint16 port, bool cleanSession, bool useSsl, const QSslConfiguration &sslConfiguration);
void disconnectFromHost();
public slots:
void onConnected();
void onDisconnected();
void onReadyRead();
void onSocketStateChanged(QAbstractSocket::SocketState socketState);
void onSocketError(QAbstractSocket::SocketError error);
void onSslErrors(const QList<QSslError> &errors);
quint16 newPacketId();
void sendPingreq();
void restartKeepAliveTimer();
void reconnectTimerTimeout();
public:
QString serverHostname;
quint16 serverPort = 0;
bool useSsl = false;
QSslConfiguration sslConfiguration;
bool autoReconnect = true;
bool sessionActive = false;
bool cleanSession = true;
QSslSocket *socket = nullptr;
QTimer reconnectTimer;
int reconnectAttempt = 0;
quint16 maxReconnectTimeout = 36000;
QString clientId;
quint16 keepAlive;
QTimer keepAliveTimer;
QString willTopic;
QByteArray willMessage;
Mqtt::QoS willQoS = Mqtt::QoS0;
bool willRetain = false;
QString username;
QString password;
QVector<quint16> unackedPacketList;
QHash<quint16, MqttPacket> unackedPackets;
};
#endif // MQTTCLIENT_P_H