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

Method applyProjectConfig

app/src/MQTT/Publisher.cpp:1210–1260  ·  view source on GitHub ↗

* @brief Loads configuration from a project-supplied JSON object. */

Source from the content-addressed store, hash-verified

1208 * @brief Loads configuration from a project-supplied JSON object.
1209 */
1210void MQTT::Publisher::applyProjectConfig(const QJsonObject& cfg)
1211{
1212 m_inApply = true;
1213
1214 setEnabled(cfg.value(kKeyEnabled).toBool(false));
1215 setMode(cfg.value(kKeyMode).toInt(static_cast<int>(Mode::RawRxData)));
1216 setPublishNotifications(cfg.value(kKeyPublishNotifications).toBool(false));
1217 setPublishFrequency(cfg.value(kKeyPublishFrequency).toInt(kDefaultPublishHz));
1218 setTopicBase(cfg.value(kKeyTopicBase).toString());
1219 setNotificationTopic(cfg.value(kKeyNotificationTopic).toString());
1220 setScriptCode(cfg.value(kKeyScriptCode).toString());
1221 setScriptTopic(cfg.value(kKeyScriptTopic).toString());
1222 setScriptLanguage(cfg.value(kKeyScriptLanguage).toInt(0));
1223
1224 setHostname(cfg.value(kKeyHostname).toString(QStringLiteral("127.0.0.1")));
1225 setPort(static_cast<quint16>(cfg.value(kKeyPort).toInt(1883)));
1226
1227 const bool customCid = cfg.value(kKeyCustomClientId).toBool(false);
1228 setCustomClientId(customCid);
1229
1230 const auto cid = cfg.value(kKeyClientId).toString();
1231 if (customCid && !cid.isEmpty())
1232 setClientId(cid);
1233 else
1234 regenerateClientId();
1235
1236 reloadCredentialsFromVault();
1237
1238 setCleanSession(cfg.value(kKeyCleanSession).toBool(true));
1239 setKeepAlive(static_cast<quint16>(cfg.value(kKeyKeepAlive).toInt(60)));
1240 setMqttVersion(static_cast<quint8>(cfg.value(kKeyMqttVersion).toInt(2)));
1241
1242 setSslEnabled(cfg.value(kKeySslEnabled).toBool(false));
1243 setSslProtocol(static_cast<quint8>(cfg.value(kKeySslProtocol).toInt(5)));
1244 setPeerVerifyMode(static_cast<quint8>(cfg.value(kKeyPeerVerifyMode).toInt(3)));
1245 setPeerVerifyDepth(cfg.value(kKeyPeerVerifyDepth).toInt(10));
1246
1247 m_inApply = false;
1248
1249 m_savingToProjectModel = true;
1250 DataModel::ProjectModel::instance().setMqttPublisher(toJson());
1251 m_savingToProjectModel = false;
1252
1253 m_skipNextSync = true;
1254 Q_EMIT configurationChanged();
1255 m_skipNextSync = false;
1256
1257 m_reportConnectionErrors = m_enabled;
1258 m_syncTimer.stop();
1259 syncToWorker();
1260}
1261
1262/**
1263 * @brief Resets the publisher to default state (used on project close / new).

Callers

nothing calls this directly

Calls 5

toJsonFunction · 0.85
isEmptyMethod · 0.80
setMqttPublisherMethod · 0.80
valueMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected