From e65387aa6003246fabf9d1acd389880a1484bb61 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 7 Nov 2023 09:04:05 +0100 Subject: [PATCH] Turned worker-object into a thread --- worker.h | 67 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/worker.h b/worker.h index 8ba1788..6574b95 100644 --- a/worker.h +++ b/worker.h @@ -10,11 +10,11 @@ #include #include #include +#include #include #include -#include "worker_thread.h" #include "update.h" #include "git/git_client.h" #include "ismas/ismas_client.h" @@ -64,7 +64,6 @@ #define _FILES_TO_UPDATE (37) #define _CHECK_FOR_REPOSITORY_CHANGES_FAILURE (38) #define _FILES_TO_DOWNLOAD (39) -#define _APPLY_REPOSITORY_CHANGES (40) #define _EXEC_OPKG_COMMANDS (41) #define _EXEC_OPKG_COMMAND_1 (42) #define _EXEC_OPKG_COMMAND_2 (43) @@ -78,14 +77,15 @@ #define _EXEC_OPKG_COMMAND_LAST (51) #define _EXEC_OPKG_COMMAND_FAILURE (52) #define _EXEC_OPKG_COMMAND_SUCCESS (53) -#define _DOWNLOAD_CONFIG_FILE (54) -#define _DOWNLOAD_CONFIG_FILE_SUCCESS (63) -#define _DOWNLOAD_CONFIG_FILE_FAILURE (64) +#define _DOWNLOAD_FILES_TO_PSA_HARDWARE (54) +#define _DOWNLOAD_CONFIG_FILE (55) +#define _DOWNLOAD_CONFIG_FILE_SUCCESS (56) +#define _DOWNLOAD_CONFIG_FILE_FAILURE (57) #define _DOWNLOAD_DEVICE_CONTROLLER (65) #define _DOWNLOAD_DEVICE_CONTROLLER_SUCCESS (86) #define _DOWNLOAD_DEVICE_CONTROLLER_FAILURE (87) -#define _APPLY_REPOSITORY_CHANGES_FAILURE (88) -#define _APPLY_REPOSITORY_CHANGES_SUCCESS (89) +#define _DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE (88) +#define _DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS (89) #define _SYNC_CUSTOMER_REPOSITORY (90) #define _SYNC_CUSTOMER_REPOSITORY_FAILURE (91) #define _SYNC_CUSTOMER_REPOSITORY_SUCCESS (92) @@ -110,19 +110,20 @@ class MainWindow; class hwinf; -class Worker : public QObject { +class Worker : public QThread{ Q_OBJECT - WorkerThread m_workerThread; int const m_customerNr; QString const m_customerNrStr; int const m_machineNr; int const m_zoneNr; + QString const m_pluginDir; QString const m_pluginName; QString const m_workingDirectory; QString const m_branchName; QString const m_customerRepositoryPath; QString const m_customerRepository; + bool const m_noUpdatePsaHardware; bool const m_dryRun; QObject *m_parent; QString const m_serialInterface; @@ -240,7 +241,7 @@ public: CHECK_FOR_REPOSITORY_CHANGES_SUCCESS = _CHECK_FOR_REPOSITORY_CHANGES_SUCCESS, CHECK_FOR_REPOSITORY_CHANGES_FAILURE = _CHECK_FOR_REPOSITORY_CHANGES_FAILURE, FILES_TO_UPDATE = _FILES_TO_UPDATE, - APPLY_REPOSITORY_CHANGES = _APPLY_REPOSITORY_CHANGES, + DOWNLOAD_FILES_TO_PSA_HARDWARE = _DOWNLOAD_FILES_TO_PSA_HARDWARE, FILES_TO_DOWNLOAD = _FILES_TO_DOWNLOAD, EXEC_OPKG_COMMANDS = _EXEC_OPKG_COMMANDS, EXEC_OPKG_COMMAND_1 = _EXEC_OPKG_COMMAND_1, @@ -261,8 +262,8 @@ public: DOWNLOAD_DEVICE_CONTROLLER = _DOWNLOAD_DEVICE_CONTROLLER, DOWNLOAD_DEVICE_CONTROLLER_SUCCESS = _DOWNLOAD_DEVICE_CONTROLLER_SUCCESS, DOWNLOAD_DEVICE_CONTROLLER_FAILURE = _DOWNLOAD_DEVICE_CONTROLLER_FAILURE, - APPLY_REPOSITORY_CHANGES_SUCCESS = _APPLY_REPOSITORY_CHANGES_SUCCESS, - APPLY_REPOSITORY_CHANGES_FAILURE = _APPLY_REPOSITORY_CHANGES_FAILURE, + DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS = _DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS, + DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE = _DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE, SYNC_CUSTOMER_REPOSITORY = _SYNC_CUSTOMER_REPOSITORY, SYNC_CUSTOMER_REPOSITORY_SUCCESS = _SYNC_CUSTOMER_REPOSITORY_SUCCESS, SYNC_CUSTOMER_REPOSITORY_FAILURE = _SYNC_CUSTOMER_REPOSITORY_FAILURE, @@ -285,6 +286,10 @@ private: UPDATE_STEP m_currentStep; static Worker *instance; QStringList m_opkgCommands; + Update *m_update = nullptr; + +protected: + virtual void run(); public: QDebug CONSOLE(QStringList const &lst = QStringList()) { @@ -321,8 +326,10 @@ public: int machineNr, int zoneNr, QString branchName, + QString pluginDir, QString pluginName, QString workingDir = ".", + bool noUpdatePsaHardware = false, bool dryRun = false, QObject *parent = nullptr, char const *serialInterface = SERIAL_PORT, @@ -330,8 +337,6 @@ public: ~Worker(); void setMainWindow(MainWindow *mainWindow) { m_mainWindow = mainWindow; } - hwinf *getPlugin(); - hwinf const *getPlugin() const; void setProgress(int progress); void displayProgressInMainWindow(int progress); void startProgressLoop(); @@ -352,6 +357,9 @@ public: MainWindow *mainWindow() { return m_mainWindow; } MainWindow const *mainWindow() const { return m_mainWindow; } + Update *update() { return m_update; } + Update const *update() const { return m_update; } + signals: void appendText(QString, QString suffix = ""); void replaceLast(QString, QString); @@ -365,14 +373,11 @@ signals: void enableExit(); void disableExit(); -public slots: - void update(); - private slots: bool updateTriggerSet(); bool customerEnvironment(); bool filesToUpdate(); - bool updateFiles(); + bool downloadFilesToPSAHardware(); bool syncCustomerRepositoryAndFS(); // bool sendIsmasLastVersionNotification(int progress); bool saveLogFile(); @@ -380,6 +385,8 @@ private slots: private: PSAInstalled getPSAInstalled(); void privateUpdate(); + bool computeFilesToDownload(); + bool execOpkgCommands(); static const QMap smap; @@ -510,7 +517,7 @@ private: break; case UPDATE_STEP::FILES_TO_UPDATE: break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES: { + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE: { lst << instance->m_debugMsg; Utils::printUpdateStatusMsg(debug, lst); } break; @@ -563,9 +570,9 @@ private: lst << instance->m_debugMsg; Utils::printUpdateStatusMsg(debug, lst); break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES_SUCCESS: + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS: break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES_FAILURE: + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE: break; case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY: break; @@ -774,8 +781,8 @@ private: case UPDATE_STEP::FILES_TO_UPDATE: ismasClient.setProgressInPercent(_FILES_TO_UPDATE); break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES: - ismasClient.setProgressInPercent(_APPLY_REPOSITORY_CHANGES); + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE: + ismasClient.setProgressInPercent(_DOWNLOAD_FILES_TO_PSA_HARDWARE); break; case UPDATE_STEP::FILES_TO_DOWNLOAD: ismasClient.setProgressInPercent(_FILES_TO_DOWNLOAD); @@ -922,11 +929,11 @@ private: case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE: ismasClient.setProgressInPercent(_DOWNLOAD_DEVICE_CONTROLLER_FAILURE); break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES_SUCCESS: - ismasClient.setProgressInPercent(_APPLY_REPOSITORY_CHANGES_SUCCESS); + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS: + ismasClient.setProgressInPercent(_DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS); break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES_FAILURE: - ismasClient.setProgressInPercent(_APPLY_REPOSITORY_CHANGES_FAILURE); + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE: + ismasClient.setProgressInPercent(_DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE); break; case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY: ismasClient.setProgressInPercent(_SYNC_CUSTOMER_REPOSITORY); @@ -1110,7 +1117,7 @@ private: emit worker->appendText(QString("\n ") + worker->m_filesToUpdate.at(0)); } } break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES: + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE: break; case UPDATE_STEP::FILES_TO_DOWNLOAD: break; @@ -1160,9 +1167,9 @@ private: break; case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE: break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES_SUCCESS: + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS: break; - case UPDATE_STEP::APPLY_REPOSITORY_CHANGES_FAILURE: + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE: break; case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY: emit worker->appendText("\nSync customer environment with filesystem ...");