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

Function applyPublisherTopics

app/src/API/Handlers/MqttHandler.cpp:305–339  ·  view source on GitHub ↗

* @brief Applies topic + mode + frequency fields to the publisher; returns error on failure. */

Source from the content-addressed store, hash-verified

303 * @brief Applies topic + mode + frequency fields to the publisher; returns error on failure.
304 */
305[[nodiscard]] static std::optional<QString> applyPublisherTopics(MQTT::Publisher& p,
306 const QJsonObject& params)
307{
308 if (params.contains(QStringLiteral("topicBase")))
309 p.setTopicBase(params.value(QStringLiteral("topicBase")).toString());
310
311 if (params.contains(QStringLiteral("notificationTopic")))
312 p.setNotificationTopic(params.value(QStringLiteral("notificationTopic")).toString());
313
314 if (params.contains(QStringLiteral("publishNotifications")))
315 p.setPublishNotifications(params.value(QStringLiteral("publishNotifications")).toBool());
316
317 if (params.contains(QStringLiteral("mode"))) {
318 const int mode = params.value(QStringLiteral("mode")).toInt(-1);
319 if (!indexInRange(mode, p.modes().size()))
320 return QStringLiteral("mode index out of range (got %1, valid 0..%2)")
321 .arg(mode)
322 .arg(p.modes().size() - 1);
323
324 p.setMode(mode);
325 }
326
327 if (params.contains(QStringLiteral("publishFrequency"))) {
328 const int hz = params.value(QStringLiteral("publishFrequency")).toInt(-1);
329 if (hz < MQTT::Publisher::kMinPublishHz || hz > MQTT::Publisher::kMaxPublishHz)
330 return QStringLiteral("publishFrequency must be in [%1, %2] (got %3)")
331 .arg(MQTT::Publisher::kMinPublishHz)
332 .arg(MQTT::Publisher::kMaxPublishHz)
333 .arg(hz);
334
335 p.setPublishFrequency(hz);
336 }
337
338 return std::nullopt;
339}
340
341/**
342 * @brief Applies session + TLS fields to the publisher; returns error on failure.

Callers 1

publisherSetConfigMethod · 0.85

Calls 9

indexInRangeFunction · 0.85
setTopicBaseMethod · 0.80
setNotificationTopicMethod · 0.80
setPublishFrequencyMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45
setModeMethod · 0.45

Tested by

no test coverage detected