--ismas-connected: try to reach ismas 10x. Use "Broker" and "ISMAS" keys

in json-data. Timeout between tries: 5secs.
This commit is contained in:
Gerhard Hoffmann 2025-03-07 13:50:40 +01:00
parent 0dd731ff50
commit 6fc62863c1

View File

@ -16,6 +16,7 @@
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include <QDateTime> #include <QDateTime>
#include <QThread>
#include <optional> #include <optional>
@ -56,37 +57,50 @@ int main(int argc, char **argv) {
QString updateRequestStatus{internal::UPDATE_NOT_REQUESTED}; QString updateRequestStatus{internal::UPDATE_NOT_REQUESTED};
QDebug debug = qCritical(); QDebug debug = qCritical();
if (std::optional<QString> result int tries = 10;
= IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT, while (--tries > 0) {
"#M=APISM#C=REQ_SELF#J={}")) { if (std::optional<QString> result
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8()); = IsmasClient::sendRequestReceiveResponse(
for (QString const &k : d.object().keys()) { IsmasClient::APISM::DIRECT_PORT,
if (k.contains("CMD_GET_APISMSTATUS_RESPONSE")) { "#M=APISM#C=REQ_SELF#J={}")) {
QJsonObject o = d.object()[k].toObject(); QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
QJsonObject::const_iterator it = o.find("Broker"); for (QString const &k : d.object().keys()) {
if (it != o.constEnd()) { if (k.contains("CMD_GET_APISMSTATUS_RESPONSE")) {
// value for "Broker" QJsonObject o = d.object()[k].toObject();
QString const &v = it->toString(); QJsonObject::const_iterator bit = o.find("Broker");
if (v.contains(internal::ISMAS_CONNECTED, Qt::CaseInsensitive)) { QJsonObject::const_iterator ismit = o.find("ISMAS");
connectionStatus = internal::ISMAS_CONNECTED; if (bit != o.constEnd() && ismit != o.constEnd()) {
} else // value for "Broker"
if (v.contains(internal::ISMAS_NOT_CONNECTED, Qt::CaseInsensitive)) { QString const &v = bit->toString();
connectionStatus = internal::ISMAS_NOT_CONNECTED; bool ismas = ismit->toBool();
} else if (ismas && v.contains(internal::BROKER_CONNECTED, Qt::CaseInsensitive)) {
if (v.contains(internal::ISMAS_DISCONNECTED, Qt::CaseInsensitive)) { connectionStatus = internal::ISMAS_CONNECTED;
connectionStatus = internal::ISMAS_NOT_CONNECTED; break;
} else } else
if (v.contains(internal::ISMAS_CONNECTION_IN_PROGRESS, Qt::CaseInsensitive)) { if (v.contains(internal::BROKER_NOT_CONNECTED, Qt::CaseInsensitive)) {
connectionStatus = internal::ISMAS_NOT_CONNECTED; connectionStatus = internal::ISMAS_NOT_CONNECTED;
} else } else
if (v.contains(internal::ISMAS_DISCONNECTING, Qt::CaseInsensitive)) { if (v.contains(internal::BROKER_DISCONNECTED, Qt::CaseInsensitive)) {
connectionStatus = internal::ISMAS_NOT_CONNECTED; connectionStatus = internal::ISMAS_NOT_CONNECTED;
} else
if (v.contains(internal::BROKER_CONNECTION_IN_PROGRESS, Qt::CaseInsensitive)) {
connectionStatus = internal::ISMAS_NOT_CONNECTED;
} else
if (v.contains(internal::BROKER_DISCONNECTING, Qt::CaseInsensitive)) {
connectionStatus = internal::ISMAS_NOT_CONNECTED;
}
break;
} }
break;
} }
} }
} }
if (connectionStatus == internal::ISMAS_CONNECTED) {
break;
}
QThread::sleep(5);
} }
if (connectionStatus != internal::ISMAS_CONNECTED) { if (connectionStatus != internal::ISMAS_CONNECTED) {