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_SUCCESS(" [SUCCESS]");
Worker::Worker(hwinf *hw,
int customerNr,
Worker::Worker(int customerNr,
int machineNr,
int zoneNr,
QString branchName,
QString pluginName,
QString workingDirectory,
bool dryRun,
QObject *parent,
char const *serialInterface,
char const *baudrate)
: m_hw(hw)
, m_workerThread("workerThread")
: m_workerThread("workerThread")
, m_customerNr(customerNr)
, m_customerNrStr(QString("customer_") + QString::number(m_customerNr).rightJustified(3, '0'))
, m_machineNr(machineNr)
, m_zoneNr(zoneNr)
, m_pluginName(pluginName)
, m_workingDirectory(workingDirectory)
, m_branchName(branchName)
, m_customerRepositoryPath(QString("https://git.mimbach49.de/GerhardHoffmann/%1.git").arg(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_workingDirectory, dryRun, parent, serialInterface, baudrate))
, m_dryRun(dryRun)
, m_parent(parent)
, m_serialInterface(serialInterface)
, m_baudrate(baudrate)
, m_update(nullptr)
, m_gc(m_customerNrStr, m_customerRepository, m_workingDirectory, m_branchName, this)
, m_osVersion(getOsVersion())
, m_atbqtVersion(getATBQTVersion())
@ -70,7 +73,7 @@ Worker::Worker(hwinf *hw,
, m_updateProcessRunning(true)
, m_returnCode(0)
, m_progressValue(0)
, m_withoutIsmasDirectPort(false) /* useful for testing */ {
, m_withoutIsmasDirectPort(true) /* useful for testing */ {
QDir::setCurrent(m_workingDirectory);
@ -95,6 +98,7 @@ Worker::Worker(hwinf *hw,
qInfo() << "MACHINE_NR ................." << m_machineNr;
qInfo() << "ZONE_NR ...................." << m_zoneNr;
qInfo() << "BRANCH_NAME ................" << m_branchName;
qInfo() << "PLUGIN_NAME ................" << m_pluginName;
qInfo() << "WORKING_DIRECTORY .........." << m_workingDirectory;
qInfo() << "APISM VERSION .............." << m_apismVersion;
@ -149,10 +153,14 @@ void Worker::update() {
}
void Worker::privateUpdate() {
if (!m_mainWindow) {
Utils::printCriticalErrorMsg("m_mainWindow NOT SET");
return;
}
m_updateProcessRunning = true;
bool sentIsmasLastVersionNotification = false;
emit disableExit();
m_returnCode = -1;
@ -845,7 +853,7 @@ bool Worker::updateFiles(quint8 percent) {
if (fName.contains("print", Qt::CaseInsensitive)) {
filesToDownload << fName; // download printer-config-files
} 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)) {
filesToDownload << fName; // download device controller
}
@ -858,7 +866,21 @@ bool Worker::updateFiles(quint8 percent) {
if (filesToDownload.size() > 0) {
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);
} else {
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 lst = (QStringList() << "N/A" << "N/A");
if (m_hw) {
m_hw->dc_autoRequest(true); // turn auto-request setting on
hwinf *hwi = m_mainWindow->getPlugin();
if (hwi) {
hwi->dc_autoRequest(true); // turn auto-request setting on
QByteArray const cmp(8, char(0));
QByteArray hw(""), sw("");
for (int i=0; i<5; ++i) {
hw = m_hw->dc_getHWversion().toUtf8();
sw = m_hw->dc_getSWversion().toUtf8();
hw = hwi->dc_getHWversion().toUtf8();
sw = hwi->dc_getSWversion().toUtf8();
if (!hw.startsWith(cmp)) {
lst.clear();
qInfo() << hw << sw;
@ -1157,6 +1180,14 @@ PSAInstalled Worker::getPSAInstalled() {
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
*/

View File

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