checkin for saving current state
This commit is contained in:
@@ -65,11 +65,13 @@ contains( CONFIG, DesktopLinux ) {
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
ismas_client.cpp \
|
||||
message_handler.cpp
|
||||
message_handler.cpp \
|
||||
../common/src/utils_internal.cpp
|
||||
|
||||
HEADERS += \
|
||||
ismas_client.h \
|
||||
message_handler.h
|
||||
message_handler.h \
|
||||
../common/include/utils_internal.h
|
||||
|
||||
##########################################################################################
|
||||
# for running program on target through QtCreator
|
||||
|
116
Check/main.cpp
116
Check/main.cpp
@@ -19,6 +19,7 @@
|
||||
#include <optional>
|
||||
|
||||
#include "message_handler.h"
|
||||
#include "utils_internal.h"
|
||||
#include "ismas_client.h"
|
||||
|
||||
|
||||
@@ -40,6 +41,7 @@ int main(int argc, char **argv) {
|
||||
setDebugLevel(LOG_NOTICE);
|
||||
}
|
||||
|
||||
int exitCode = 0;
|
||||
QCommandLineParser parser;
|
||||
QCommandLineOption ismasConnectOption("ismas-connected");
|
||||
QCommandLineOption updateRequestedOption("update-requested");
|
||||
@@ -49,8 +51,9 @@ int main(int argc, char **argv) {
|
||||
parser.addOption(verboseOption);
|
||||
parser.process(a);
|
||||
|
||||
QString connectionStatus{"not connected"};
|
||||
QString updateRequestStatus{"not requested"};
|
||||
QString connectionStatus{internal::ISMAS_NOT_CONNECTED};
|
||||
QString updateRequestStatus{internal::UPDATE_NOT_REQUESTED};
|
||||
QDebug debug = qCritical();
|
||||
|
||||
if (std::optional<QString> result
|
||||
= IsmasClient::sendRequestReceiveResponse(
|
||||
@@ -64,20 +67,20 @@ int main(int argc, char **argv) {
|
||||
if (it != o.constEnd()) {
|
||||
// value for "Broker"
|
||||
QString const &v = it->toString();
|
||||
if (v.contains("connected", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "connected";
|
||||
if (v.contains(internal::ISMAS_CONNECTED, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_CONNECTED;
|
||||
} else
|
||||
if (v.contains("not connected", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "not connected";
|
||||
if (v.contains(internal::ISMAS_NOT_CONNECTED, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
} else
|
||||
if (v.contains("disconnected", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "not connected";
|
||||
if (v.contains(internal::ISMAS_DISCONNECTED, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
} else
|
||||
if (v.contains("connecting", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "not connected";
|
||||
if (v.contains(internal::ISMAS_CONNECTION_IN_PROGRESS, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
} else
|
||||
if (v.contains("disconnecting", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "not connected";
|
||||
if (v.contains(internal::ISMAS_DISCONNECTING, Qt::CaseInsensitive)) {
|
||||
connectionStatus = internal::ISMAS_NOT_CONNECTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -85,65 +88,68 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (connectionStatus != internal::ISMAS_CONNECTED) {
|
||||
if (internal::customerRepoExists() == false) {
|
||||
debug.noquote() << internal::NO_CUSTOMER_REPOSITORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (parser.isSet(updateRequestedOption)) {
|
||||
if (connectionStatus == "connected") {
|
||||
if (std::optional<QString> result
|
||||
= IsmasClient::sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DIRECT_PORT,
|
||||
"#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
|
||||
if (internal::customerRepoExists() == false) {
|
||||
// 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::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 &k : d.object().keys()) { // request ack
|
||||
if (!k.contains("FileUpload", Qt::CaseInsensitive)) continue;
|
||||
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("TRG");
|
||||
if (it == o.constEnd()) break;
|
||||
QJsonObject::const_iterator it = o.find("Aknoledge");
|
||||
if (it == o.constEnd()) continue;
|
||||
|
||||
QString const &v = it->toString();
|
||||
if (v == "WAIT") {
|
||||
updateRequestStatus = "requested";
|
||||
} else
|
||||
if (v.isEmpty()) {
|
||||
QFile f("/mnt/system_data/cust_nr");
|
||||
if (!f.exists()) break;
|
||||
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) break;
|
||||
if (v != "OK") break;
|
||||
|
||||
QTextStream in(&f);
|
||||
in.setCodec("UTF-8");
|
||||
if(!in.atEnd()) {
|
||||
unsigned custNr = in.readLine().toInt();
|
||||
if (custNr > 0) {
|
||||
QString custRepo = QString("/opt/app/tools/atbupdate/customer_%1").arg(custNr);
|
||||
if (!QDir(custRepo).exists()) {
|
||||
updateRequestStatus = "not necessary";
|
||||
}
|
||||
}
|
||||
for (QString const &m : d.object().keys()) { // request ack
|
||||
if (!m.contains("FileUpload", Qt::CaseInsensitive)) continue;
|
||||
QJsonObject o = d.object()[m].toObject();
|
||||
|
||||
QJsonObject::const_iterator it = o.find("TRG");
|
||||
if (it == o.constEnd()) break;
|
||||
|
||||
QString const &v = it->toString();
|
||||
if (v == "WAIT") {
|
||||
updateRequestStatus = internal::UPDATE_REQUESTED;
|
||||
} else {
|
||||
updateRequestStatus = internal::UPDATE_NOT_NECESSARY;
|
||||
}
|
||||
break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
qCritical() << updateRequestStatus;
|
||||
}
|
||||
|
||||
debug.noquote() << updateRequestStatus;
|
||||
} else
|
||||
if (parser.isSet(ismasConnectOption)) {
|
||||
qCritical() << connectionStatus;
|
||||
debug.noquote() << connectionStatus;
|
||||
}
|
||||
|
||||
return 0;
|
||||
qCritical() << __func__ << ":" << __LINE__ << exitCode;
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
Reference in New Issue
Block a user