Remove direct member m_hw, a pointer to the device-controller-plugin.

The worker shall not load the plugin, otherwise it would block itself inside
an QT slot.
This commit is contained in:
Gerhard Hoffmann 2023-09-06 09:04:43 +02:00
parent cef05b7511
commit c065b57f0c
2 changed files with 53 additions and 16 deletions

View File

@ -31,28 +31,31 @@ QString const Worker::UPDATE_STEP_DONE(" [done]");
QString const Worker::UPDATE_STEP_FAIL(" [FAIL]"); QString const Worker::UPDATE_STEP_FAIL(" [FAIL]");
QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]"); QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]");
Worker::Worker(hwinf *hw, Worker::Worker(int customerNr,
int customerNr,
int machineNr, int machineNr,
int zoneNr, int zoneNr,
QString branchName, QString branchName,
QString pluginName,
QString workingDirectory, QString workingDirectory,
bool dryRun, bool dryRun,
QObject *parent, QObject *parent,
char const *serialInterface, char const *serialInterface,
char const *baudrate) char const *baudrate)
: m_hw(hw) : m_workerThread("workerThread")
, m_workerThread("workerThread")
, m_customerNr(customerNr) , m_customerNr(customerNr)
, m_customerNrStr(QString("customer_") + QString::number(m_customerNr).rightJustified(3, '0')) , m_customerNrStr(QString("customer_") + QString::number(m_customerNr).rightJustified(3, '0'))
, m_machineNr(machineNr) , m_machineNr(machineNr)
, m_zoneNr(zoneNr) , m_zoneNr(zoneNr)
, m_pluginName(pluginName)
, m_workingDirectory(workingDirectory) , m_workingDirectory(workingDirectory)
, m_branchName(branchName) , m_branchName(branchName)
, m_customerRepositoryPath(QString("https://git.mimbach49.de/GerhardHoffmann/%1.git").arg(m_customerNrStr)) , m_customerRepositoryPath(QString("https://git.mimbach49.de/GerhardHoffmann/%1.git").arg(m_customerNrStr))
, m_customerRepository(QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerNrStr)) , m_customerRepository(QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerNrStr))
, m_update(new Update(m_hw, this, m_customerRepository, m_customerNrStr, m_branchName, , m_dryRun(dryRun)
m_workingDirectory, dryRun, parent, serialInterface, baudrate)) , m_parent(parent)
, m_serialInterface(serialInterface)
, m_baudrate(baudrate)
, m_update(nullptr)
, m_gc(m_customerNrStr, m_customerRepository, m_workingDirectory, m_branchName, this) , m_gc(m_customerNrStr, m_customerRepository, m_workingDirectory, m_branchName, this)
, m_osVersion(getOsVersion()) , m_osVersion(getOsVersion())
, m_atbqtVersion(getATBQTVersion()) , m_atbqtVersion(getATBQTVersion())
@ -70,7 +73,7 @@ Worker::Worker(hwinf *hw,
, m_updateProcessRunning(true) , m_updateProcessRunning(true)
, m_returnCode(0) , m_returnCode(0)
, m_progressValue(0) , m_progressValue(0)
, m_withoutIsmasDirectPort(false) /* useful for testing */ { , m_withoutIsmasDirectPort(true) /* useful for testing */ {
QDir::setCurrent(m_workingDirectory); QDir::setCurrent(m_workingDirectory);
@ -95,6 +98,7 @@ Worker::Worker(hwinf *hw,
qInfo() << "MACHINE_NR ................." << m_machineNr; qInfo() << "MACHINE_NR ................." << m_machineNr;
qInfo() << "ZONE_NR ...................." << m_zoneNr; qInfo() << "ZONE_NR ...................." << m_zoneNr;
qInfo() << "BRANCH_NAME ................" << m_branchName; qInfo() << "BRANCH_NAME ................" << m_branchName;
qInfo() << "PLUGIN_NAME ................" << m_pluginName;
qInfo() << "WORKING_DIRECTORY .........." << m_workingDirectory; qInfo() << "WORKING_DIRECTORY .........." << m_workingDirectory;
qInfo() << "APISM VERSION .............." << m_apismVersion; qInfo() << "APISM VERSION .............." << m_apismVersion;
@ -149,10 +153,14 @@ void Worker::update() {
} }
void Worker::privateUpdate() { void Worker::privateUpdate() {
if (!m_mainWindow) {
Utils::printCriticalErrorMsg("m_mainWindow NOT SET");
return;
}
m_updateProcessRunning = true; m_updateProcessRunning = true;
bool sentIsmasLastVersionNotification = false; bool sentIsmasLastVersionNotification = false;
emit disableExit(); emit disableExit();
m_returnCode = -1; m_returnCode = -1;
@ -845,7 +853,7 @@ bool Worker::updateFiles(quint8 percent) {
if (fName.contains("print", Qt::CaseInsensitive)) { if (fName.contains("print", Qt::CaseInsensitive)) {
filesToDownload << fName; // download printer-config-files filesToDownload << fName; // download printer-config-files
} else { } else {
static const QRegularExpression version("^.*dc2c[.][0-9][0-9][.][0-9][0-9][.]bin.*$"); static const QRegularExpression version("^.*dc2c[.][0-9]{0,1}[0-9][.][0-9][0-9][.]bin.*$");
if (fName.contains(version)) { if (fName.contains(version)) {
filesToDownload << fName; // download device controller filesToDownload << fName; // download device controller
} }
@ -858,7 +866,21 @@ bool Worker::updateFiles(quint8 percent) {
if (filesToDownload.size() > 0) { if (filesToDownload.size() > 0) {
Utils::printInfoMsg(QString("FILES_TO_DOWNLOAD_TO_PSA_HW ") + filesToDownload.join(',')); Utils::printInfoMsg(QString("FILES_TO_DOWNLOAD_TO_PSA_HW ") + filesToDownload.join(','));
m_update = new Update(m_mainWindow->getPlugin(),
this,
m_customerRepository,
m_customerNrStr,
m_branchName,
m_pluginName,
m_workingDirectory,
m_dryRun,
m_parent,
m_serialInterface.toStdString().c_str(),
m_baudrate.toStdString().c_str());
ret = m_update->doUpdate(m_displayIndex, filesToDownload); ret = m_update->doUpdate(m_displayIndex, filesToDownload);
} else { } else {
Utils::printCriticalErrorMsg("NO FILES_TO_DOWNLOAD_TO_PSA_HW"); Utils::printCriticalErrorMsg("NO FILES_TO_DOWNLOAD_TO_PSA_HW");
} }
@ -1017,14 +1039,15 @@ QString Worker::getPluginVersion(QString const &pluginFileName) const {
QStringList Worker::getDCVersion() const { QStringList Worker::getDCVersion() const {
QStringList lst = (QStringList() << "N/A" << "N/A"); QStringList lst = (QStringList() << "N/A" << "N/A");
if (m_hw) { hwinf *hwi = m_mainWindow->getPlugin();
m_hw->dc_autoRequest(true); // turn auto-request setting on if (hwi) {
hwi->dc_autoRequest(true); // turn auto-request setting on
QByteArray const cmp(8, char(0)); QByteArray const cmp(8, char(0));
QByteArray hw(""), sw(""); QByteArray hw(""), sw("");
for (int i=0; i<5; ++i) { for (int i=0; i<5; ++i) {
hw = m_hw->dc_getHWversion().toUtf8(); hw = hwi->dc_getHWversion().toUtf8();
sw = m_hw->dc_getSWversion().toUtf8(); sw = hwi->dc_getSWversion().toUtf8();
if (!hw.startsWith(cmp)) { if (!hw.startsWith(cmp)) {
lst.clear(); lst.clear();
qInfo() << hw << sw; qInfo() << hw << sw;
@ -1157,6 +1180,14 @@ PSAInstalled Worker::getPSAInstalled() {
return psaInstalled; return psaInstalled;
} }
hwinf *Worker::getPlugin() {
return m_mainWindow ? m_mainWindow->getPlugin() : nullptr;
}
hwinf const *Worker::getPlugin() const {
return m_mainWindow ? m_mainWindow->getPlugin() : nullptr;
}
/************************************************************************************************ /************************************************************************************************
* operators * operators
*/ */

View File

@ -74,16 +74,20 @@ class hwinf;
class Worker : public QObject { class Worker : public QObject {
Q_OBJECT Q_OBJECT
hwinf *m_hw;
WorkerThread m_workerThread; WorkerThread m_workerThread;
int const m_customerNr; int const m_customerNr;
QString const m_customerNrStr; QString const m_customerNrStr;
int const m_machineNr; int const m_machineNr;
int const m_zoneNr; int const m_zoneNr;
QString const m_pluginName;
QString const m_workingDirectory; QString const m_workingDirectory;
QString const m_branchName; QString const m_branchName;
QString const m_customerRepositoryPath; QString const m_customerRepositoryPath;
QString const m_customerRepository; QString const m_customerRepository;
bool const m_dryRun;
QObject *m_parent;
QString const m_serialInterface;
QString const m_baudrate;
Update *m_update; Update *m_update;
IsmasClient m_ismasClient; IsmasClient m_ismasClient;
GitClient m_gc; GitClient m_gc;
@ -130,11 +134,11 @@ public:
static const QString UPDATE_STEP_FAIL; static const QString UPDATE_STEP_FAIL;
static const QString UPDATE_STEP_SUCCESS; static const QString UPDATE_STEP_SUCCESS;
explicit Worker(hwinf *hw, explicit Worker(int customerNr, // 281
int customerNr, // 281
int machineNr, int machineNr,
int zoneNr, int zoneNr,
QString branchName, QString branchName,
QString pluginName,
QString workingDir = ".", QString workingDir = ".",
bool dryRun = false, bool dryRun = false,
QObject *parent = nullptr, QObject *parent = nullptr,
@ -143,6 +147,8 @@ public:
~Worker(); ~Worker();
void setMainWindow(MainWindow *mainWindow) { m_mainWindow = mainWindow; } void setMainWindow(MainWindow *mainWindow) { m_mainWindow = mainWindow; }
hwinf *getPlugin();
hwinf const *getPlugin() const;
void setProgress(int progress); void setProgress(int progress);
void startProgressLoop(); void startProgressLoop();
void stopProgressLoop(); void stopProgressLoop();