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:
75
worker.cpp
75
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user