From 26db620465a33eeac124cd1a74d79d7f2cb467d0 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 11 Jul 2023 16:58:49 +0200 Subject: [PATCH] use of worker/worker-thread so we can work without using buttons (as the cannot be triggered by an automatic update process) --- worker.cpp | 75 +++++++++++++++++++++++++++++++++++++++--------------- worker.h | 40 ++++++++++++++++++++++++----- 2 files changed, 89 insertions(+), 26 deletions(-) diff --git a/worker.cpp b/worker.cpp index 73c0c16..c9954c2 100644 --- a/worker.cpp +++ b/worker.cpp @@ -11,16 +11,20 @@ #include "message_handler.h" #include "plugins/interfaces.h" +#include "ismas/ismas_client.h" +#include "apism/apism_client.h" - -Worker::Worker(QString update_ctrl_file, QString workingDir) - : m_update_ctrl_file(update_ctrl_file) - , m_workingDir(workingDir) - , m_workerThread("workerThread") { - +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) { this->moveToThread(&m_workerThread); + //m_apismClient.moveToThread(&m_workerThread); + m_workerThread.start(); - QThread::usleep(100000); int cnt = 0; while (!m_workerThread.isRunning()) { @@ -31,10 +35,21 @@ Worker::Worker(QString update_ctrl_file, QString workingDir) QThread::sleep(1); } - connect(this, SIGNAL(workNow()), this, SLOT(work()), Qt::QueuedConnection); - connect(&m_timer, SIGNAL(timeout()), this, SLOT(update())); + 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); m_timer.setSingleShot(true); m_timer.start(1000); + } Worker::~Worker() { @@ -48,19 +63,39 @@ Worker::~Worker() { } } } + if (m_update) { + delete m_update; + } } -void Worker::update() { - qCritical() << __func__ << ":" << __LINE__; - emit workNow(); +void Worker::onExecuteOpkgCommands() { + qCritical() << "ON EXECUTE OPKG COMMANDS"; } -void Worker::work() { - qCritical() << __func__ << ":" << __LINE__; - //Update m_update(m_update_ctrl_file, m_workingDir); - QThread::sleep(3); - //if (m_update.doUpdate()) { - //} - m_workerThread.quit(); - QApplication::quit(); +// 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(); } diff --git a/worker.h b/worker.h index ced641e..6070972 100644 --- a/worker.h +++ b/worker.h @@ -4,27 +4,55 @@ #include #include #include +#include +#include #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 { Q_OBJECT - QString m_update_ctrl_file; - QString m_workingDir; WorkerThread m_workerThread; QTimer m_timer; + Update *m_update; + ApismClient m_apismClient; + GitClient m_gc; + 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(); void quit() { return m_workerThread.quit(); } signals: - void workNow(); + void executeOpkgCommands(); public slots: - void work(); - void update(); + void onIsmasResponseReceived(QJsonObject ismasResponse); + void onExecuteOpkgCommands(); + +private slots: + void runUpdate(); }; #endif // WORKER_H_INCLUDED