re-implement to use dc-plugin as shsred onject

This commit is contained in:
Gerhard Hoffmann 2023-06-16 16:48:58 +02:00
parent c4c503080e
commit dc90705f24

View File

@ -5,8 +5,7 @@
#include <QFileInfo> #include <QFileInfo>
#include "message_handler.h" #include "message_handler.h"
#include "interfaces.h" #include "plugins/interfaces.h"
#include "DCPlugin/include/hwapi.h"
#include <unistd.h> #include <unistd.h>
#include <thread> #include <thread>
@ -17,6 +16,10 @@
#include <QDir> #include <QDir>
#include "update.h" #include "update.h"
#include "worker_thread.h"
#include "worker.h"
#include <thread>
#ifdef PTU5 #ifdef PTU5
#define SERIAL_PORT "ttymxc2" #define SERIAL_PORT "ttymxc2"
@ -24,20 +27,13 @@
#define SERIAL_PORT "ttyUSB0" #define SERIAL_PORT "ttyUSB0"
#endif #endif
class Work : public QRunnable { static void doWork(QString update_ctrl_file, QString workingDir) {
QString m_update_ctrl_file; std::this_thread::sleep_for(std::chrono::milliseconds(2000));
QString m_workingDir; //Update update(update_ctrl_file, workingDir);
public: //update.doUpdate();
explicit Work(QString update_ctrl_file, QString workingDir) std::this_thread::sleep_for(std::chrono::milliseconds(2000));
: m_update_ctrl_file(update_ctrl_file) QCoreApplication::quit();
, m_workingDir(workingDir) { }
}
void run() {
Update m_update(m_update_ctrl_file, m_workingDir);
// if (m_update.doUpdate()) {
// }
}
};
// argv[1]: file to send to dc // argv[1]: file to send to dc
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -54,15 +50,29 @@ int main(int argc, char *argv[]) {
qputenv("XDG_RUNTIME_DIR", "/run/user/0"); qputenv("XDG_RUNTIME_DIR", "/run/user/0");
} }
QString rtPath = QCoreApplication::applicationDirPath();
QString plugInDir(rtPath +(rtPath.endsWith("/") ? "" : "/") + "plugins");
if (!QDir(plugInDir).exists()) {
qCritical() << plugInDir
<< "does not exists, but has to contain dc-library";
exit(-1);
}
qInfo() << "pwd" << "=" << rtPath;
qInfo() << "plugInDir" << "=" << plugInDir;
hwinf *hw = Update::loadDCPlugin(QDir(plugInDir), "libCAmaster.so");
QString const update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv"; QString const update_ctrl_file = "/opt/app/tools/atbupdate/update_log.csv";
QString const workingDir = (argc == 2) ? argv[1] : "."; QString const workingDir = (argc == 2) ? argv[1] : ".";
Update update(hw, update_ctrl_file, workingDir);
Work work(update_ctrl_file, workingDir);
work.setAutoDelete(false);
QThreadPool *threadPool = QThreadPool::globalInstance();
threadPool->start(&work);
if (!threadPool->waitForDone()) {
return -1;
}
return 0; return 0;
std::thread t(doWork, update_ctrl_file, workingDir);
int ret = a.exec();
t.join();
return ret;
} }