ATBUpdateTool/worker.cpp

102 lines
2.8 KiB
C++
Raw Normal View History

2023-06-16 16:47:13 +02:00
#include "worker.h"
#include "update.h"
#include <QCoreApplication>
#include <QApplication>
#include <QDebug>
#include <QTimer>
#include <QFileInfo>
#include <QDir>
#include <QThread>
#include "message_handler.h"
#include "plugins/interfaces.h"
#include "ismas/ismas_client.h"
#include "apism/apism_client.h"
2023-06-16 16:47:13 +02:00
Worker::Worker(hwinf *hw, QString update_ctrl_file, QString workingDir,
bool maintenanceMode, bool testMode, bool executeScriptOnly,
bool dryRun, QObject *parent, char const *serialInterface,
char const *baudrate)
: m_workerThread("workerThread")
, m_apismClient(0, 0, 0, this)
, m_gc("/opt/app/tools/atbupdate/customer_999", "zg1/zone1", this) {
2023-06-16 16:47:13 +02:00
this->moveToThread(&m_workerThread);
//m_apismClient.moveToThread(&m_workerThread);
2023-06-16 16:47:13 +02:00
m_workerThread.start();
int cnt = 0;
while (!m_workerThread.isRunning()) {
if (++cnt > 5) {
qCritical() << "starting worker thread FAILED";
return;
}
QThread::sleep(1);
}
m_update = new Update(hw, update_ctrl_file, workingDir,
maintenanceMode, testMode, executeScriptOnly, dryRun,
parent, serialInterface, baudrate);
connect(&m_apismClient, SIGNAL(ismasResponseAvailable(QJsonObject)), this,
SLOT(onIsmasResponseReceived(QJsonObject)));
connect(this, SIGNAL(executeOpkgCommands()), this,
SLOT(onExecuteOpkgCommands()), Qt::QueuedConnection);
//connect(this, SIGNAL(workNow()), this, SLOT(work()), Qt::QueuedConnection);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(runUpdate()), Qt::QueuedConnection);
2023-06-16 16:47:13 +02:00
m_timer.setSingleShot(true);
m_timer.start(1000);
2023-06-16 16:47:13 +02:00
}
Worker::~Worker() {
int cnt = 0;
m_workerThread.quit();
while (!m_workerThread.isFinished()) {
if (!m_workerThread.wait(1000)) {
if (++cnt > 5) {
qCritical() << "stopping worker thread FAILED";
return;
}
}
}
if (m_update) {
delete m_update;
}
2023-06-16 16:47:13 +02:00
}
void Worker::onExecuteOpkgCommands() {
qCritical() << "ON EXECUTE OPKG COMMANDS";
2023-06-16 16:47:13 +02:00
}
// sollte ParameterResponse heissen
void Worker::onIsmasResponseReceived(QJsonObject ismasResponse) {
QJsonValue v = ismasResponse.value("TRG");
if (v.type() == QJsonValue::String) {
QString s = v.toString();
if (s == "WAIT") {
// updates available
// git anwerfen
qCritical() << "GIT ANWERFEN";
emit m_gc.ismasUpdatesAvailable();
}
}
//m_workerThread.quit();
//QApplication::quit();
}
void Worker::runUpdate() {
QThread::sleep(2);
IsmasClient is;
QString data = is.setUpdatesAvailable();
m_apismClient.sendUpdateInfoToIsmas(data);
m_apismClient.requestAvailableIsmasUpdates();
2023-06-16 16:47:13 +02:00
}