MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / publishCustomOnWorker

Method publishCustomOnWorker

app/src/MQTT/Publisher.cpp:645–665  ·  view source on GitHub ↗

* @brief Publishes a user-supplied payload to an arbitrary topic. */

Source from the content-addressed store, hash-verified

643 * @brief Publishes a user-supplied payload to an arbitrary topic.
644 */
645void 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.

Callers

nothing calls this directly

Calls 5

isEmptyMethod · 0.80
publishMethod · 0.80
clampFunction · 0.50
isValidMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected