Compare commits
12 Commits
afbce3b4ea
...
82751eb1d4
Author | SHA1 | Date | |
---|---|---|---|
82751eb1d4 | |||
17a4a69df2 | |||
a03261d04a | |||
7832ef5d8c | |||
9c213d0a97 | |||
18378afdc5 | |||
6dd8a8c6b3 | |||
adfb358e12 | |||
ff418b11a1 | |||
38e79f0354 | |||
103b3f3f9c | |||
ff6a6e0e45 |
@ -15,7 +15,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
|||||||
# In order to do so, uncomment the following line.
|
# In order to do so, uncomment the following line.
|
||||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
VERSION=1.3.2
|
VERSION=1.3.4
|
||||||
|
|
||||||
INCLUDEPATH += plugins
|
INCLUDEPATH += plugins
|
||||||
|
|
||||||
|
2
main.cpp
2
main.cpp
@ -97,7 +97,7 @@ int main(int argc, char *argv[]) {
|
|||||||
QCommandLineOption pluginNameOption(QStringList() << "plugin-name" << "plugin-name",
|
QCommandLineOption pluginNameOption(QStringList() << "plugin-name" << "plugin-name",
|
||||||
QCoreApplication::translate("main", "Name of dc-plugin."),
|
QCoreApplication::translate("main", "Name of dc-plugin."),
|
||||||
QCoreApplication::translate("main", "directory"));
|
QCoreApplication::translate("main", "directory"));
|
||||||
QString const pluginNameDefault = "libCAmaster.so";
|
QString const pluginNameDefault = "libCAslave.so";
|
||||||
pluginNameOption.setDefaultValue(pluginNameDefault);
|
pluginNameOption.setDefaultValue(pluginNameDefault);
|
||||||
parser.addOption(pluginNameOption);
|
parser.addOption(pluginNameOption);
|
||||||
|
|
||||||
|
@ -131,9 +131,9 @@ MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *paren
|
|||||||
lst << QString("APISM version : %1").arg(m_worker->apismVersion()).leftJustified(m_width-3);
|
lst << QString("APISM version : %1").arg(m_worker->apismVersion()).leftJustified(m_width-3);
|
||||||
lst << QString("").leftJustified(m_width-3, '=');
|
lst << QString("").leftJustified(m_width-3, '=');
|
||||||
|
|
||||||
|
|
||||||
ui->updateStatus->setText(lst.join('\n'));
|
ui->updateStatus->setText(lst.join('\n'));
|
||||||
ui->updateStatus->setEnabled(true);
|
ui->updateStatus->setEnabled(true);
|
||||||
|
// ui->updateStatus->installEventFilter(this);
|
||||||
|
|
||||||
m_startTimer = new QTimer(this);
|
m_startTimer = new QTimer(this);
|
||||||
connect(m_startTimer, SIGNAL(timeout()), m_worker, SLOT(update()));
|
connect(m_startTimer, SIGNAL(timeout()), m_worker, SLOT(update()));
|
||||||
@ -308,9 +308,18 @@ void MainWindow::onEnableExit() {
|
|||||||
ui->exit->setEnabled(true);
|
ui->exit->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//bool MainWindow::eventFilter(QObject *obj, QEvent *ev) {
|
||||||
|
// if (obj == ui->updateStatus) {
|
||||||
|
// qCritical() << "REc. event for text edit" << ev->type();
|
||||||
|
// }
|
||||||
|
// return QMainWindow::eventFilter(obj, ev);
|
||||||
|
//}
|
||||||
|
|
||||||
void MainWindow::onRestartExitTimer() {
|
void MainWindow::onRestartExitTimer() {
|
||||||
m_exitTimer->stop();
|
m_exitTimer->stop();
|
||||||
m_exitTimer->start(60 * 1000);
|
m_exitTimer->start(60 * 1000);
|
||||||
|
|
||||||
|
// ui->updateStatus->blockSignals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onQuit() {
|
void MainWindow::onQuit() {
|
||||||
@ -320,7 +329,8 @@ void MainWindow::onQuit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::scrollDownTextEdit() {
|
void MainWindow::scrollDownTextEdit() {
|
||||||
qCritical() << "ON REPLACE LAST CALLED AT" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
|
Utils::printInfoMsg(QString("SCROLL-DOWN-TEXT_EDIT CALLED AT ")
|
||||||
|
+ QDateTime::currentDateTime().toString(Qt::ISODateWithMs));
|
||||||
|
|
||||||
ui->updateStatus->setEnabled(true);
|
ui->updateStatus->setEnabled(true);
|
||||||
|
|
||||||
@ -331,30 +341,37 @@ void MainWindow::scrollDownTextEdit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onAppendText(QString text, QString suffix) {
|
void MainWindow::onAppendText(QString text, QString suffix) {
|
||||||
qCritical() << "ON APPEND CALLED AT" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
|
Utils::printInfoMsg(QString("ON APPEND CALLED AT ")
|
||||||
|
+ QDateTime::currentDateTime().toString(Qt::ISODateWithMs));
|
||||||
|
|
||||||
QString editText = ui->updateStatus->toPlainText();
|
QString editText = ui->updateStatus->toPlainText();
|
||||||
if (!suffix.isNull() && suffix.size() > 0) {
|
if (!suffix.isNull() && suffix.size() > 0) {
|
||||||
//qInfo() << "TEXT" << text << "SUFFIX" << suffix;
|
//qInfo() << "TEXT" << text << "SUFFIX" << suffix;
|
||||||
if (suffix == Worker::UPDATE_STEP_SUCCESS || suffix == Worker::UPDATE_STEP_FAIL) {
|
if (suffix == Worker::UPDATE_STEP_SUCCESS || suffix == Worker::UPDATE_STEP_FAIL) {
|
||||||
editText += QString("\n").leftJustified(m_width-3, '=');
|
ui->updateStatus->insertPlainText(QString("\n").leftJustified(m_width-3, '=') + " ");
|
||||||
editText += " ";
|
// editText += QString("\n").leftJustified(m_width-3, '=');
|
||||||
|
// editText += " ";
|
||||||
}
|
}
|
||||||
QString const &add = (QString("\n") + text).leftJustified(m_width - (2 + suffix.size())) + suffix;
|
QString const &add = (QString("\n") + text).leftJustified(m_width - (2 + suffix.size())) + suffix;
|
||||||
editText += add;
|
ui->updateStatus->insertPlainText(add);
|
||||||
|
// editText += add;
|
||||||
} else {
|
} else {
|
||||||
QString const &add = text.leftJustified(m_width-9);
|
QString const &add = text.leftJustified(m_width-9);
|
||||||
editText += add;
|
ui->updateStatus->insertPlainText(add);
|
||||||
|
//editText += add;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::printLineEditInfo(editText.split('\n', QString::SplitBehavior::SkipEmptyParts));
|
// debug
|
||||||
ui->updateStatus->setText(editText.trimmed());
|
// QString editText = ui->updateStatus->toPlainText();
|
||||||
|
// Utils::printLineEditInfo(editText.split('\n', QString::SplitBehavior::SkipEmptyParts));
|
||||||
|
// ui->updateStatus->setText(editText.trimmed());
|
||||||
|
|
||||||
scrollDownTextEdit();
|
scrollDownTextEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) {
|
void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) {
|
||||||
qCritical() << "ON REPLACE LAST CALLED AT" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
|
Utils::printInfoMsg(QString("ON REPLACE LAST (LIST) CALLED AT ")
|
||||||
|
+ QDateTime::currentDateTime().toString(Qt::ISODateWithMs));
|
||||||
|
|
||||||
int const s = newTextLines.size();
|
int const s = newTextLines.size();
|
||||||
if (s > 0) {
|
if (s > 0) {
|
||||||
@ -388,7 +405,8 @@ void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onReplaceLast(QString text, QString suffix) {
|
void MainWindow::onReplaceLast(QString text, QString suffix) {
|
||||||
qCritical() << "ON REPLACE LAST CALLED AT" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
|
Utils::printInfoMsg(QString("ON REPLACE LAST (TEXT) CALLED AT ")
|
||||||
|
+ QDateTime::currentDateTime().toString(Qt::ISODateWithMs));
|
||||||
|
|
||||||
QString editText = ui->updateStatus->toPlainText();
|
QString editText = ui->updateStatus->toPlainText();
|
||||||
QStringList lines = editText.split('\n', QString::SplitBehavior::SkipEmptyParts);
|
QStringList lines = editText.split('\n', QString::SplitBehavior::SkipEmptyParts);
|
||||||
|
@ -21,6 +21,7 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void customEvent(QEvent *event) override;
|
void customEvent(QEvent *event) override;
|
||||||
|
// bool eventFilter(QObject *obj, QEvent *ev) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *parent = nullptr);
|
MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *parent = nullptr);
|
||||||
|
34
update.cpp
34
update.cpp
@ -14,9 +14,9 @@
|
|||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
//#include <iostream>
|
#if defined (Q_OS_UNIX) || defined (Q_OS_LINUX)
|
||||||
//#include <fstream>
|
#include "unistd.h"
|
||||||
//#include <ctime>
|
#endif
|
||||||
|
|
||||||
#include "plugins/interfaces.h"
|
#include "plugins/interfaces.h"
|
||||||
|
|
||||||
@ -40,6 +40,8 @@ static const QMap<QString, int> baudrateMap = {
|
|||||||
{"57600" , 4}, {"115200" , 5}
|
{"57600" , 4}, {"115200" , 5}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QPluginLoader Update::pluginLoader;
|
||||||
|
|
||||||
hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
||||||
hwinf *hw = nullptr;
|
hwinf *hw = nullptr;
|
||||||
if (plugInDir.exists()) {
|
if (plugInDir.exists()) {
|
||||||
@ -48,7 +50,8 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
|||||||
QFileInfo info(pluginLibName);
|
QFileInfo info(pluginLibName);
|
||||||
if (info.exists()) {
|
if (info.exists()) {
|
||||||
pluginLibName = plugInDir.absoluteFilePath(pluginLibName);
|
pluginLibName = plugInDir.absoluteFilePath(pluginLibName);
|
||||||
static QPluginLoader pluginLoader(pluginLibName);
|
pluginLoader.setFileName(pluginLibName);
|
||||||
|
// static QPluginLoader pluginLoader(pluginLibName);
|
||||||
if (!pluginLoader.load()) {
|
if (!pluginLoader.load()) {
|
||||||
qCritical() << "in directory" << plugInDir.absolutePath();
|
qCritical() << "in directory" << plugInDir.absolutePath();
|
||||||
qCritical() << "cannot load plugin" << pluginLoader.fileName();
|
qCritical() << "cannot load plugin" << pluginLoader.fileName();
|
||||||
@ -80,6 +83,21 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
|||||||
return hw;
|
return hw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Update::unloadDCPlugin() {
|
||||||
|
if (pluginLoader.unload()) {
|
||||||
|
qCritical() << "unloaded plugin" << pluginLoader.fileName();
|
||||||
|
// Note: will re-instantiate the library !
|
||||||
|
// QObject *rootObject = pluginLoader.instance();
|
||||||
|
// if (rootObject) {
|
||||||
|
// qCritical() << "reloaded plugin: root object again available";
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// qCritical()unloaded plugin: root object gone";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Update::Update(hwinf *hw,
|
Update::Update(hwinf *hw,
|
||||||
Worker *worker,
|
Worker *worker,
|
||||||
QString customerRepository,
|
QString customerRepository,
|
||||||
@ -724,6 +742,9 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
|||||||
|
|
||||||
QString const &parentName = Utils::getParentName();
|
QString const &parentName = Utils::getParentName();
|
||||||
|
|
||||||
|
Utils::printInfoMsg(
|
||||||
|
QString("PARENT OF ATB-UPDATE-TOOL (ppid=%1) ").arg(getppid()) + parentName);
|
||||||
|
|
||||||
if (parentName == "ATBQT" || parentName == "systemd") {
|
if (parentName == "ATBQT" || parentName == "systemd") {
|
||||||
// the tool was not called during 'service' ot during an automatic
|
// the tool was not called during 'service' ot during an automatic
|
||||||
// update procedure. and it was called explicitly with libCAmaster.so
|
// update procedure. and it was called explicitly with libCAmaster.so
|
||||||
@ -732,6 +753,8 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
|||||||
+ " IS MASTER, BUT ATB-UPDATE-TOOL CALLED WITH libCAmaster.so");
|
+ " IS MASTER, BUT ATB-UPDATE-TOOL CALLED WITH libCAmaster.so");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Utils::printInfoMsg(
|
||||||
|
QString("ATB-UPDATE-TOOL STARTED AS SLAVE OF ") + parentName);
|
||||||
} else
|
} else
|
||||||
if (Utils::isATBQTRunning()) { // manual testing
|
if (Utils::isATBQTRunning()) { // manual testing
|
||||||
if (m_pluginName.contains("master", Qt::CaseInsensitive)) {
|
if (m_pluginName.contains("master", Qt::CaseInsensitive)) {
|
||||||
@ -739,12 +762,15 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
|||||||
"ATBQT IS MASTER, BUT ATB-UPDATE-TOOL CALLED WITH libCAmaster.so");
|
"ATBQT IS MASTER, BUT ATB-UPDATE-TOOL CALLED WITH libCAmaster.so");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Utils::printInfoMsg(
|
||||||
|
"ATB-UPDATE-TOOL STARTED AS SLAVE-SIBLING OF ATBQT-MASTER");
|
||||||
} else {
|
} else {
|
||||||
if (m_pluginName.contains("slave", Qt::CaseInsensitive)) {
|
if (m_pluginName.contains("slave", Qt::CaseInsensitive)) {
|
||||||
Utils::printCriticalErrorMsg(
|
Utils::printCriticalErrorMsg(
|
||||||
"ATB-UPDATE-TOOL CALLED WITH libCAslave.so ALTHOUGH MASTER");
|
"ATB-UPDATE-TOOL CALLED WITH libCAslave.so ALTHOUGH MASTER");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Utils::printInfoMsg("ATB-UPDATE-TOOL STARTED AS MASTER");
|
||||||
|
|
||||||
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate),
|
if ((serialOpened = openSerial(baudrateMap.value(m_baudrate),
|
||||||
m_baudrate,
|
m_baudrate,
|
||||||
|
4
update.h
4
update.h
@ -7,6 +7,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QPluginLoader>
|
||||||
|
|
||||||
#include "plugins/interfaces.h"
|
#include "plugins/interfaces.h"
|
||||||
|
|
||||||
@ -32,11 +33,14 @@ class Update : public QObject {
|
|||||||
bool m_maintenanceMode;
|
bool m_maintenanceMode;
|
||||||
bool m_dryRun;
|
bool m_dryRun;
|
||||||
|
|
||||||
|
static QPluginLoader pluginLoader;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
|
enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
|
||||||
enum class FileTypeJson {CONFIG=1, DEVICE=2, CASH=3, SERIAL=4, TIME=5, PRINTER=6};
|
enum class FileTypeJson {CONFIG=1, DEVICE=2, CASH=3, SERIAL=4, TIME=5, PRINTER=6};
|
||||||
|
|
||||||
static hwinf *loadDCPlugin(QDir const &plugInDir, QString const &fn);
|
static hwinf *loadDCPlugin(QDir const &plugInDir, QString const &fn);
|
||||||
|
static bool unloadDCPlugin();
|
||||||
static QStringList split(QString line, QChar sep = ',');
|
static QStringList split(QString line, QChar sep = ',');
|
||||||
|
|
||||||
|
|
||||||
|
51
utils.cpp
51
utils.cpp
@ -2,13 +2,19 @@
|
|||||||
#include "message_handler.h"
|
#include "message_handler.h"
|
||||||
#include "git/git_client.h"
|
#include "git/git_client.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if defined (Q_OS_UNIX) || defined (Q_OS_LINUX)
|
||||||
#include "unistd.h"
|
#include "unistd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
int Utils::read1stLineOfFile(QString fileName) {
|
int Utils::read1stLineOfFile(QString fileName) {
|
||||||
QFile f(fileName);
|
QFile f(fileName);
|
||||||
@ -177,18 +183,15 @@ bool Utils::sameFilesInDirs(QDir const &dir1, QDir const &dir2,
|
|||||||
|
|
||||||
QString Utils::getParentName() { // get name of parent process
|
QString Utils::getParentName() { // get name of parent process
|
||||||
QString ppid = QString("/proc/%1/status").arg(getppid());
|
QString ppid = QString("/proc/%1/status").arg(getppid());
|
||||||
QFile f(ppid);
|
std::ifstream f(ppid.toStdString().c_str());
|
||||||
if (f.exists()) {
|
if (f.is_open()) {
|
||||||
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
std::string next;
|
||||||
QTextStream in(&f);
|
while (std::getline(f, next)) {
|
||||||
in.setCodec("UTF-8");
|
QString line = QString(next.c_str()).simplified();
|
||||||
while(!in.atEnd()) {
|
if (line.startsWith("Name")) {
|
||||||
// Name: ATBQT
|
int const idx = line.indexOf(QChar(':'));
|
||||||
QStringList line = in.readLine().split(':');
|
if (idx != -1) {
|
||||||
if (line.size() == 2) {
|
return line.mid(idx+1).trimmed();
|
||||||
if (line[0].trimmed() == "Name") {
|
|
||||||
return line[1].trimmed();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,17 +206,19 @@ bool Utils::isATBQTRunning() {
|
|||||||
QDirIterator::Subdirectories);
|
QDirIterator::Subdirectories);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
QString const &nextStatusFile = it.next();
|
QString const &nextStatusFile = it.next();
|
||||||
QFile f(nextStatusFile);
|
static const QRegularExpression re("^/proc/[0-9]{1,}/status");
|
||||||
if (f.exists()) {
|
QRegularExpressionMatch match = re.match(nextStatusFile);
|
||||||
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (match.hasMatch()) {
|
||||||
QTextStream in(&f);
|
std::ifstream f(nextStatusFile.toStdString().c_str());
|
||||||
in.setCodec("UTF-8");
|
if (f.is_open()) {
|
||||||
while(!in.atEnd()) {
|
std::string next;
|
||||||
// Name: ATBQT
|
while (std::getline(f, next)) {
|
||||||
QStringList line = in.readLine().split(':');
|
QString line = QString(next.c_str()).simplified();
|
||||||
if (line.size() == 2) {
|
if (line.startsWith("Name")) {
|
||||||
if (line[0].trimmed() == "Name") {
|
int const idx = line.indexOf(QChar(':'));
|
||||||
if (line[1].trimmed() == "ATBQT") {
|
if (idx != -1) {
|
||||||
|
QString const binary = line.mid(idx+1).trimmed();
|
||||||
|
if (binary == "ATBQT") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user