ATBUpdateTool/worker.h
Gerhard Hoffmann f5198efab3 Added worker/worker-thread-pair.
Worker uses event-loop of worker-thread.
Worker itself is used as work-horse for the update-process.
2023-07-14 13:32:00 +02:00

101 lines
2.6 KiB
C++

#ifndef WORKER_H_INCLUDED
#define WORKER_H_INCLUDED
#include <QObject>
#include <QString>
#include <QStringList>
#include <QTimer>
#include <QFile>
#include <QJsonObject>
#include <QHash>
#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
WorkerThread m_workerThread;
QTimer m_startUpdateProcess;
Update *m_update;
ApismClient m_apismClient;
GitClient m_gc;
QString const m_customerId;
QString const m_workingDirectory;
QString const m_branchName;
QString const m_customerRepository;
bool m_maintenanceMode;
int m_ismasUpdateRequests;
QTimer m_waitForNewUpdates;
IsmasClient m_ismasClient;
int m_machineNr; // setzen
int m_customerNr;
enum { ISMAS_UPDATE_REQUESTS = 6 };
enum class UPDATE_STATUS : quint8 {
STARTED,
STOPPED,
ERROR_BACKEND
} m_updateStatus;
public:
explicit Worker(hwinf *hw,
QString update_ctrl_file,
QString repositoryPath,
QString customerId,
QString branchName,
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 executeOpkgCommands(QStringList);
void executeOpkgCommand(QString);
void handleChangedFiles(QStringList);
void summarizeUpload(QStringList);
void summarizeRepositoryStatus();
void sendCmdSendVersionToIsmas();
void finishUpdateProcess(bool changes);
void terminateUpdateProcess();
public slots:
void onIsmasResponseReceived(QJsonObject ismasResponse);
void onExecuteOpkgCommands(QStringList opkgCommands);
void onExecuteOpkgCommand(QString opkgCommand);
private slots:
void askIsmasForNewData();
void onSendCmdSendVersionToIsmas();
void onSummarizeRepositoryStatus();
void onFinishUpdateProcess(bool changes);
void onTerminateUpdateProcess();
void onSummarizeUpload(QStringList);
void onHandleChangedFiles(QStringList);
};
//Q_DECLARE_METATYPE((QHash<QString, QString>))
//Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(QHash)
#endif // WORKER_H_INCLUDED