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

Method publishAndCount

app/src/MQTT/Publisher.cpp:469–485  ·  view source on GitHub ↗

* @brief Publishes a payload and increments the stats counters. */

Source from the content-addressed store, hash-verified

467 * @brief Publishes a payload and increments the stats counters.
468 */
469void MQTT::PublisherWorker::publishAndCount(const QMqttTopicName& topic, const QByteArray& payload)
470{
471 const auto id = m_client->publish(topic, payload);
472 qCDebug(lcMqttPub) << "publish topic=" << topic.name() << "size=" << payload.size() << "id=" << id
473 << "preview=" << payload.left(80);
474
475 if (id < 0) {
476 qCWarning(lcMqttPub) << "publish returned -1 for topic" << topic.name();
477 return;
478 }
479
480 if (m_messagesSent)
481 m_messagesSent->fetch_add(1, std::memory_order_relaxed);
482
483 if (m_bytesSent)
484 m_bytesSent->fetch_add(static_cast<quint64>(payload.size()), std::memory_order_relaxed);
485}
486
487/**
488 * @brief Applies a fresh broker config snapshot. Reconnects when broker-affecting fields change.

Callers

nothing calls this directly

Calls 3

publishMethod · 0.80
nameMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected