diff --git a/Check/main.cpp b/Check/main.cpp index 60a14b6..7fa0237 100644 --- a/Check/main.cpp +++ b/Check/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -56,37 +57,50 @@ int main(int argc, char **argv) { QString updateRequestStatus{internal::UPDATE_NOT_REQUESTED}; QDebug debug = qCritical(); - if (std::optional 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 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) {