/*! * * Copyright (c) 2026 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file MqttPublisher.h * \author (original) Stephen Quong * \date (original) 30-Jul-2026 * */ #pragma once #include #include #include #include #include #include #include "MqttTransport.h" /*! * \brief Publishes messages to the cloud over MQTT and reports their delivery. */ class MqttPublisher : public QObject { Q_OBJECT public: explicit MqttPublisher(QObject *parent = nullptr); ~MqttPublisher() override; bool init(QSharedPointer transport, const MqttTransport::Config &config); bool init(QSharedPointer transport, const MqttTransport::Config &config, QThread &thread); bool isConnected() const; public Q_SLOTS: bool open(); void close(); bool publish(const QString &topic, const QByteArray &payload, qint64 messageId = -1); bool reconnect(const QString &certPath, const QString &keyPath, const QString &clientId); void quit(); Q_SIGNALS: /*! * \brief didConnectionChange * \details Emitted when the MQTT session is established or lost. * \param connected - true when the session came up, false when it went down */ void didConnectionChange(bool connected); /*! * \brief didPublishAck * \details Emitted when a publish is confirmed or fails. * \param messageId - the value passed to publish(); -1 when the caller supplied none * \param success - true when the broker acknowledged the message */ void didPublishAck(qint64 messageId, bool success); private: void initThread(QThread &thread); void quitThread(); void onTransportState(bool connected); void onTransportAck(qint64 messageId, bool success); QSharedPointer _transport; MqttTransport::Config _config; QSharedPointer> _alive; QAtomicInteger _connected{0}; bool _init = false; };