/*! * * 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 MqttTransport.h * \author (original) Stephen Quong * \date (original) 30-Jul-2026 * */ #pragma once #include #include #include /*! * \brief Transport between MqttPublisher and a concrete MQTT client. */ class MqttTransport { public: /*! * \brief Parameters for one MQTT-over-mTLS session. */ struct Config { QString endpoint; ///< ATS endpoint FQDN; no scheme, port or trailing slash. quint16 port = 8883; ///< Port 443 additionally requires ALPN "x-amzn-mqtt-ca". QString certPath; ///< Client certificate, PEM. QString keyPath; ///< Unencrypted private key matching certPath, PEM. QString caPath; ///< Root CA bundle used to verify the broker. QString clientId; ///< Must equal the IoT Thing name; the device policy scopes iot:Connect to it. quint16 keepAliveSecs = 30; ///< MQTT keep-alive interval. bool cleanSession = true; ///< No broker-side queue; durability is the device's job. }; /// Reports a connection state transition, on the client library's thread. using StateCallback = std::function; /// Reports one publish outcome; messageId echoes the value publish() was given. using AckCallback = std::function; virtual ~MqttTransport() = default; /// Begins connecting. False means the attempt could not be started; success arrives via StateCallback. virtual bool open(const Config &config) = 0; /// Closes the connection. The transition is reported through StateCallback. virtual void close() = 0; /// True while the session is established. virtual bool isConnected() const = 0; /// Sends one QoS 1 publish. True means handed to the client, not delivered; delivery is the AckCallback. virtual bool publish(const QString &topic, const QByteArray &payload, qint64 messageId) = 0; /// Installs the callbacks. Must be called before open(). virtual void setCallbacks(StateCallback onState, AckCallback onAck) = 0; /// Removes the callbacks and waits for any still running to finish. virtual void clearCallbacks() = 0; };