* @brief Publishes a user-supplied payload to an arbitrary topic. */
| 643 | * @brief Publishes a user-supplied payload to an arbitrary topic. |
| 644 | */ |
| 645 | void MQTT::PublisherWorker::publishCustomOnWorker(const QString& topic, |
| 646 | const QByteArray& payload, |
| 647 | int qos, |
| 648 | bool retain) |
| 649 | { |
| 650 | if (!isResourceOpen() || topic.isEmpty()) |
| 651 | return; |
| 652 | |
| 653 | QMqttTopicName mqttTopic(topic); |
| 654 | if (!mqttTopic.isValid()) |
| 655 | return; |
| 656 | |
| 657 | const auto clampedQos = static_cast<quint8>(std::clamp(qos, 0, 2)); |
| 658 | if (m_client->publish(mqttTopic, payload, clampedQos, retain) >= 0) { |
| 659 | if (m_messagesSent) |
| 660 | m_messagesSent->fetch_add(1, std::memory_order_relaxed); |
| 661 | |
| 662 | if (m_bytesSent) |
| 663 | m_bytesSent->fetch_add(static_cast<quint64>(payload.size()), std::memory_order_relaxed); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * @brief Runs an out-of-band connection probe using a throwaway QMqttClient. |