--ismas-connected: try to reach ismas 10x. Use "Broker" and "ISMAS" keys
in json-data. Timeout between tries: 5secs.
This commit is contained in:
parent
0dd731ff50
commit
6fc62863c1
@ -16,6 +16,7 @@
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDateTime>
|
||||
#include <QThread>
|
||||
|
||||
#include <optional>
|
||||
|
||||
@ -56,37 +57,50 @@ int main(int argc, char **argv) {
|
||||
QString updateRequestStatus{internal::UPDATE_NOT_REQUESTED};
|
||||
QDebug debug = qCritical();
|
||||
|
||||
if (std::optional<QString> result
|
||||
= IsmasClient::sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DIRECT_PORT,
|
||||
"#M=APISM#C=REQ_SELF#J={}")) {
|
||||
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
|
||||
for (QString const &k : d.object().keys()) {
|
||||
if (k.contains("CMD_GET_APISMSTATUS_RESPONSE")) {
|
||||
QJsonObject o = d.object()[k].toObject();
|
||||
QJsonObject::const_iterator it = o.find("Broker");
|
||||
if (it != o.constEnd()) {
|
||||
// value for "Broker"
|
||||
QString const &v = it->toString();
|
||||
if (v.contains(internal::ISMAS_CONNECTED, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_CONNECTED;
|
||||
} else
|
||||
if (v.contains(internal::ISMAS_NOT_CONNECTED, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
} else
|
||||
if (v.contains(internal::ISMAS_DISCONNECTED, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
} else
|
||||
if (v.contains(internal::ISMAS_CONNECTION_IN_PROGRESS, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
} else
|
||||
if (v.contains(internal::ISMAS_DISCONNECTING, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
int tries = 10;
|
||||
|
||||
while (--tries > 0) {
|
||||
if (std::optional<QString> result
|
||||
= IsmasClient::sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DIRECT_PORT,
|
||||
"#M=APISM#C=REQ_SELF#J={}")) {
|
||||
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
|
||||
for (QString const &k : d.object().keys()) {
|
||||
if (k.contains("CMD_GET_APISMSTATUS_RESPONSE")) {
|
||||
QJsonObject o = d.object()[k].toObject();
|
||||
QJsonObject::const_iterator bit = o.find("Broker");
|
||||
QJsonObject::const_iterator ismit = o.find("ISMAS");
|
||||
if (bit != o.constEnd() && ismit != o.constEnd()) {
|
||||
// value for "Broker"
|
||||
QString const &v = bit->toString();
|
||||
bool ismas = ismit->toBool();
|
||||
if (ismas && v.contains(internal::BROKER_CONNECTED, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_CONNECTED;
|
||||
break;
|
||||
} else
|
||||
if (v.contains(internal::BROKER_NOT_CONNECTED, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
} else
|
||||
if (v.contains(internal::BROKER_DISCONNECTED, Qt::CaseInsensitive)) {
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user