use of worker/worker-thread so we can work without using buttons (as the cannot be triggered by an automatic update process)

This commit is contained in:
Gerhard Hoffmann 2023-07-11 16:58:49 +02:00
parent bd213b8f8c
commit 26db620465
2 changed files with 89 additions and 26 deletions

View File

@ -11,16 +11,20 @@
#include "message_handler.h" #include "message_handler.h"
#include "plugins/interfaces.h" #include "plugins/interfaces.h"
#include "ismas/ismas_client.h"
#include "apism/apism_client.h"
Worker::Worker(hwinf *hw, QString update_ctrl_file, QString workingDir,
Worker::Worker(QString update_ctrl_file, QString workingDir) bool maintenanceMode, bool testMode, bool executeScriptOnly,
: m_update_ctrl_file(update_ctrl_file) bool dryRun, QObject *parent, char const *serialInterface,
, m_workingDir(workingDir) char const *baudrate)
, m_workerThread("workerThread") { : m_workerThread("workerThread")
, m_apismClient(0, 0, 0, this)
, m_gc("/opt/app/tools/atbupdate/customer_999", "zg1/zone1", this) {
this->moveToThread(&m_workerThread); this->moveToThread(&m_workerThread);
//m_apismClient.moveToThread(&m_workerThread);
m_workerThread.start(); m_workerThread.start();
QThread::usleep(100000);
int cnt = 0; int cnt = 0;
while (!m_workerThread.isRunning()) { while (!m_workerThread.isRunning()) {
@ -31,10 +35,21 @@ Worker::Worker(QString update_ctrl_file, QString workingDir)
QThread::sleep(1); QThread::sleep(1);
} }
connect(this, SIGNAL(workNow()), this, SLOT(work()), Qt::QueuedConnection); m_update = new Update(hw, update_ctrl_file, workingDir,
connect(&m_timer, SIGNAL(timeout()), this, SLOT(update())); 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);
m_timer.setSingleShot(true); m_timer.setSingleShot(true);
m_timer.start(1000); m_timer.start(1000);
} }
Worker::~Worker() { Worker::~Worker() {
@ -48,19 +63,39 @@ Worker::~Worker() {
} }
} }
} }
if (m_update) {
delete m_update;
}
} }
void Worker::update() { void Worker::onExecuteOpkgCommands() {
qCritical() << __func__ << ":" << __LINE__; qCritical() << "ON EXECUTE OPKG COMMANDS";
emit workNow();
} }
void Worker::work() { // sollte ParameterResponse heissen
qCritical() << __func__ << ":" << __LINE__; void Worker::onIsmasResponseReceived(QJsonObject ismasResponse) {
//Update m_update(m_update_ctrl_file, m_workingDir);
QThread::sleep(3); QJsonValue v = ismasResponse.value("TRG");
//if (m_update.doUpdate()) { if (v.type() == QJsonValue::String) {
//} QString s = v.toString();
m_workerThread.quit(); if (s == "WAIT") {
QApplication::quit(); // 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();
} }

View File

@ -4,27 +4,55 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QTimer> #include <QTimer>
#include <QFile>
#include <QJsonObject>
#include "worker_thread.h" #include "worker_thread.h"
#include "update.h"
#include "git/git_client.h"
#include "ismas/ismas_client.h"
#include "apism/apism_client.h"
#ifdef PTU5
#define SERIAL_PORT "ttymxc2"
#else
#define SERIAL_PORT "ttyUSB0"
#endif
class hwinf;
class Worker : public QObject { class Worker : public QObject {
Q_OBJECT Q_OBJECT
QString m_update_ctrl_file;
QString m_workingDir;
WorkerThread m_workerThread; WorkerThread m_workerThread;
QTimer m_timer; QTimer m_timer;
Update *m_update;
ApismClient m_apismClient;
GitClient m_gc;
public: public:
explicit Worker(QString update_ctrl_file, QString workingDir); explicit Worker(hwinf *hw,
QString update_ctrl_file,
QString workingDir = ".",
bool maintenanceMode = false,
bool testMode = false,
bool executeScriptOnly = false,
bool dryRun = false,
QObject *parent = nullptr,
char const *serialInterface = SERIAL_PORT,
char const *baudrate = "115200");
~Worker(); ~Worker();
void quit() { return m_workerThread.quit(); } void quit() { return m_workerThread.quit(); }
signals: signals:
void workNow(); void executeOpkgCommands();
public slots: public slots:
void work(); void onIsmasResponseReceived(QJsonObject ismasResponse);
void update(); void onExecuteOpkgCommands();
private slots:
void runUpdate();
}; };
#endif // WORKER_H_INCLUDED #endif // WORKER_H_INCLUDED