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