make sure to delete QDebug before termination
This commit is contained in:
		
							
								
								
									
										213
									
								
								Check/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										213
									
								
								Check/main.cpp
									
									
									
									
									
								
							@@ -55,122 +55,125 @@ int main(int argc, char **argv) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    QString connectionStatus{internal::ISMAS_NOT_CONNECTED};
 | 
					    QString connectionStatus{internal::ISMAS_NOT_CONNECTED};
 | 
				
			||||||
    QString updateRequestStatus{internal::UPDATE_NOT_REQUESTED};
 | 
					    QString updateRequestStatus{internal::UPDATE_NOT_REQUESTED};
 | 
				
			||||||
    QDebug debug = qCritical();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int tries = 10;
 | 
					    {
 | 
				
			||||||
 | 
					        QDebug debug = qCritical();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (--tries > 0) {
 | 
					        int tries = 10;
 | 
				
			||||||
        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;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (connectionStatus == internal::ISMAS_CONNECTED) {
 | 
					        while (--tries > 0) {
 | 
				
			||||||
            break;
 | 
					            if (std::optional<QString> result
 | 
				
			||||||
        }
 | 
					                    = IsmasClient::sendRequestReceiveResponse(
 | 
				
			||||||
 | 
					                        IsmasClient::APISM::DIRECT_PORT,
 | 
				
			||||||
        QThread::sleep(5);
 | 
					                        "#M=APISM#C=REQ_SELF#J={}")) {
 | 
				
			||||||
    }
 | 
					                QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
 | 
				
			||||||
 | 
					                for (QString const &k : d.object().keys()) {
 | 
				
			||||||
    if (connectionStatus != internal::ISMAS_CONNECTED) {
 | 
					                    if (k.contains("CMD_GET_APISMSTATUS_RESPONSE")) {
 | 
				
			||||||
        if (internal::customerRepoExists() == false) {
 | 
					                        QJsonObject o = d.object()[k].toObject();
 | 
				
			||||||
            debug.noquote() << internal::NO_CUSTOMER_REPOSITORY;
 | 
					                        QJsonObject::const_iterator bit = o.find("Broker");
 | 
				
			||||||
        }
 | 
					                        QJsonObject::const_iterator ismit = o.find("ISMAS");
 | 
				
			||||||
    }
 | 
					                        if (bit != o.constEnd() && ismit != o.constEnd()) {
 | 
				
			||||||
 | 
					                            // value for "Broker"
 | 
				
			||||||
    if (parser.isSet(updateRequestedOption)) {
 | 
					                            QString const &v = bit->toString();
 | 
				
			||||||
        if (internal::customerRepoExists() == false) {
 | 
					                            bool ismas = ismit->toBool();
 | 
				
			||||||
            // if the customer repository does not exists, it does not matter is
 | 
					                            if (ismas && v.contains(internal::BROKER_CONNECTED, Qt::CaseInsensitive)) {
 | 
				
			||||||
            // ISMAS is connected or how the setting for the WAIT-button is.
 | 
					                                connectionStatus = internal::ISMAS_CONNECTED;
 | 
				
			||||||
            updateRequestStatus = internal::NO_CUSTOMER_REPOSITORY;
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            if (connectionStatus == internal::ISMAS_CONNECTED) {
 | 
					 | 
				
			||||||
                if (std::optional<QString> result
 | 
					 | 
				
			||||||
                        = IsmasClient::sendRequestReceiveResponse(
 | 
					 | 
				
			||||||
                            IsmasClient::APISM::DIRECT_PORT,
 | 
					 | 
				
			||||||
                            "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
 | 
					 | 
				
			||||||
                    for (QString const &k : d.object().keys()) {
 | 
					 | 
				
			||||||
                        if (k.contains("REQ_ISMASPARAMETER")) {
 | 
					 | 
				
			||||||
                            QJsonObject o = d.object()[k].toObject();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            QJsonObject::const_iterator it = o.find("Aknoledge");
 | 
					 | 
				
			||||||
                            if (it == o.constEnd()) continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            QString const &v = it->toString();
 | 
					 | 
				
			||||||
                            if (v != "OK") break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            for (QString const &m : d.object().keys()) { // request ack
 | 
					 | 
				
			||||||
                                if (!m.contains("FileUpload", Qt::CaseInsensitive)) continue;
 | 
					 | 
				
			||||||
                                QJsonObject o2 = d.object()[m].toObject();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                                QJsonObject::const_iterator it2 = o2.find("TRG");
 | 
					 | 
				
			||||||
                                if (it2 == o2.constEnd()) break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                                QString const &v2 = it2->toString();
 | 
					 | 
				
			||||||
                                if (v2 == "WAIT") {
 | 
					 | 
				
			||||||
                                    updateRequestStatus = internal::UPDATE_REQUESTED;
 | 
					 | 
				
			||||||
                                } else {
 | 
					 | 
				
			||||||
                                    // the customer-repository does exist, and the ISMAS-trigger is
 | 
					 | 
				
			||||||
                                    // *NOT* "WAIT", but from 00:00:00 - 00:03:59 this counts as an
 | 
					 | 
				
			||||||
                                    // automatic update
 | 
					 | 
				
			||||||
                                    QDateTime const ¤t = QDateTime::currentDateTime();
 | 
					 | 
				
			||||||
                                    if (current.time().hour() < 4) {
 | 
					 | 
				
			||||||
                                        updateRequestStatus = internal::UPDATE_NOT_NECESSARY;
 | 
					 | 
				
			||||||
                                    } else {
 | 
					 | 
				
			||||||
                                        updateRequestStatus = internal::UPDATE_NOT_REQUESTED;
 | 
					 | 
				
			||||||
                                        exitCode = -2;
 | 
					 | 
				
			||||||
                                    }
 | 
					 | 
				
			||||||
                                }
 | 
					 | 
				
			||||||
                                break;
 | 
					                                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;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else {
 | 
					            }
 | 
				
			||||||
                // not connected (so its unknown if update has been requested),
 | 
					
 | 
				
			||||||
                // and customer repository exists. Assume 'not requested'.
 | 
					            if (connectionStatus == internal::ISMAS_CONNECTED) {
 | 
				
			||||||
                updateRequestStatus = internal::UPDATE_NOT_REQUESTED;
 | 
					                break;
 | 
				
			||||||
                exitCode = -1;
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            QThread::sleep(5);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (connectionStatus != internal::ISMAS_CONNECTED) {
 | 
				
			||||||
 | 
					            if (internal::customerRepoExists() == false) {
 | 
				
			||||||
 | 
					                debug.noquote() << internal::NO_CUSTOMER_REPOSITORY;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        debug.noquote() << updateRequestStatus;
 | 
					
 | 
				
			||||||
    } else
 | 
					        if (parser.isSet(updateRequestedOption)) {
 | 
				
			||||||
    if (parser.isSet(ismasConnectOption)) {
 | 
					            if (internal::customerRepoExists() == false) {
 | 
				
			||||||
        debug.noquote() << connectionStatus;
 | 
					                // if the customer repository does not exists, it does not matter is
 | 
				
			||||||
 | 
					                // ISMAS is connected or how the setting for the WAIT-button is.
 | 
				
			||||||
 | 
					                updateRequestStatus = internal::UPDATE_INITIAL;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                if (connectionStatus == internal::ISMAS_CONNECTED) {
 | 
				
			||||||
 | 
					                    if (std::optional<QString> result
 | 
				
			||||||
 | 
					                            = IsmasClient::sendRequestReceiveResponse(
 | 
				
			||||||
 | 
					                                IsmasClient::APISM::DIRECT_PORT,
 | 
				
			||||||
 | 
					                                "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
 | 
				
			||||||
 | 
					                        for (QString const &k : d.object().keys()) {
 | 
				
			||||||
 | 
					                            if (k.contains("REQ_ISMASPARAMETER")) {
 | 
				
			||||||
 | 
					                                QJsonObject o = d.object()[k].toObject();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                QJsonObject::const_iterator it = o.find("Aknoledge");
 | 
				
			||||||
 | 
					                                if (it == o.constEnd()) continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                QString const &v = it->toString();
 | 
				
			||||||
 | 
					                                if (v != "OK") break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                for (QString const &m : d.object().keys()) { // request ack
 | 
				
			||||||
 | 
					                                    if (!m.contains("FileUpload", Qt::CaseInsensitive)) continue;
 | 
				
			||||||
 | 
					                                    QJsonObject o2 = d.object()[m].toObject();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                    QJsonObject::const_iterator it2 = o2.find("TRG");
 | 
				
			||||||
 | 
					                                    if (it2 == o2.constEnd()) break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                    QString const &v2 = it2->toString();
 | 
				
			||||||
 | 
					                                    if (v2 == "WAIT") {
 | 
				
			||||||
 | 
					                                        updateRequestStatus = internal::UPDATE_REQUESTED;
 | 
				
			||||||
 | 
					                                    } else {
 | 
				
			||||||
 | 
					                                        // the customer-repository does exist, and the ISMAS-trigger is
 | 
				
			||||||
 | 
					                                        // *NOT* "WAIT", but from 00:00:00 - 00:03:59 this counts as an
 | 
				
			||||||
 | 
					                                        // automatic update
 | 
				
			||||||
 | 
					                                        QDateTime const ¤t = QDateTime::currentDateTime();
 | 
				
			||||||
 | 
					                                        if (current.time().hour() < 4) {
 | 
				
			||||||
 | 
					                                            updateRequestStatus = internal::UPDATE_NOT_NECESSARY;
 | 
				
			||||||
 | 
					                                        } else {
 | 
				
			||||||
 | 
					                                            updateRequestStatus = internal::UPDATE_NOT_REQUESTED;
 | 
				
			||||||
 | 
					                                            exitCode = -2;
 | 
				
			||||||
 | 
					                                        }
 | 
				
			||||||
 | 
					                                    }
 | 
				
			||||||
 | 
					                                    break;
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                                break;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    // not connected (so its unknown if update has been requested),
 | 
				
			||||||
 | 
					                    // and customer repository exists. Assume 'not requested'.
 | 
				
			||||||
 | 
					                    updateRequestStatus = internal::UPDATE_NOT_REQUESTED;
 | 
				
			||||||
 | 
					                    exitCode = -1;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            debug.noquote() << updateRequestStatus;
 | 
				
			||||||
 | 
					        } else
 | 
				
			||||||
 | 
					        if (parser.isSet(ismasConnectOption)) {
 | 
				
			||||||
 | 
					            debug.noquote() << connectionStatus;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return exitCode;
 | 
					    return exitCode;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user