added better thread management

cross compilation features.
This commit is contained in:
Lukas Heiligenbrunner 2020-05-10 18:10:44 +02:00
parent ab772aac55
commit 0eea7095e0
4 changed files with 47 additions and 53 deletions

View File

@ -19,8 +19,8 @@ SET(LIB_METHOD STATIC) #SHARED / STATIC
option(BUILD_DOC "Build documentation" ON) # additional dependency for Doxygen option(BUILD_DOC "Build documentation" ON) # additional dependency for Doxygen
option(PACKAGING "Allow Packaging to <exe>, <deb> or <rpm>" ON) # additional dependencies for RPMbuild,dpkg or NSIS option(PACKAGING "Allow Packaging to <exe>, <deb> or <rpm>" ON) # additional dependencies for RPMbuild,dpkg or NSIS
option(TESTS "Build Tests" ON) # additional dependencies for GTEST - to build tests option(TESTS "Build Tests" ON) # additional dependencies for GTEST - to build tests
option(GUI "Build GUI elements" OFF) # additional dependencies to QT libraries needed option(GUI "Build GUI elements" ON) # additional dependencies to QT libraries needed
set(WinBuild false) set(WinBuild true)
# helper variables # helper variables
SET(CMAKE_CXX_STANDARD 17) SET(CMAKE_CXX_STANDARD 17)
@ -99,6 +99,10 @@ if (${WinBuild})
message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}") message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}")
include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc) include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc)
if (${GUI})
set(CMAKE_PREFIX_PATH "/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib/cmake")
endif ()
else () else ()
find_package(CURL REQUIRED) find_package(CURL REQUIRED)
if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES) if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES)
@ -130,6 +134,15 @@ else ()
include_directories(${LIBCONFIG_INCLUDE_DIRS}) include_directories(${LIBCONFIG_INCLUDE_DIRS})
endif () endif ()
if (${GUI})
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
find_package(Qt5Sql REQUIRED)
endif ()
message("") message("")
#read sample config #read sample config
@ -175,12 +188,6 @@ add_executable(iprefresher src/main.cpp)
target_link_libraries(iprefresher dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES}) target_link_libraries(iprefresher dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES})
if (${GUI}) if (${GUI})
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
find_package(Qt5Sql REQUIRED)
set(QT5_LIBRARIES Qt5::Widgets Qt5::PrintSupport Qt5::Sql) set(QT5_LIBRARIES Qt5::Widgets Qt5::PrintSupport Qt5::Sql)
set(UI_SOURCES set(UI_SOURCES

View File

@ -1,22 +1,24 @@
#include <inc/api/IPAPI.h>
#include <inc/IPRefresher.h>
#include "MainWindow.h" #include "MainWindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "inc/Config.h" #include "api/IPAPI.h"
#include "inc/Logger.h" #include "IPRefresher.h"
#include "Config.h"
#include "Logger.h"
#include <thread>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this); ui->setupUi(this);
// needs to be defined out of scope -- would be termintated after this constructor. // needs to be defined out of scope -- would be termintated after this constructor.
// myThread = std::thread([this](){ new std::thread([this]() {
// IPAPI ipapi; IPAPI ipapi;
// std::string ip = ipapi.getGlobalIp(); std::string ip = ipapi.getGlobalIp();
// Logger::message("Current global IP: " + ip); Logger::message("Current global IP: " + ip);
// std::string msg = "Your current global IP: "+ip; std::string msg = "Your current global IP: " + ip;
// ui->labelCurrentIP->setText(msg.c_str()); this->ui->labelCurrentIP->setText(msg.c_str());
// }); });
if (Config::validateConfig()) if (Config::validateConfig())
@ -28,7 +30,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(ui->buttonRefreshIP, SIGNAL(clicked()), this, SLOT(refreshIPBtn())); connect(ui->buttonRefreshIP, SIGNAL(clicked()), this, SLOT(refreshIPBtn()));
connect(this, SIGNAL(appendLogField(QString)), ui->textLog, SLOT(appendPlainText(QString))); connect(this, SIGNAL(appendLogField(QString)), ui->textLog, SLOT(appendPlainText(QString)));
// connect(this, SIGNAL(setProgressBarValue(int)), ui->progressmanual, SLOT(setValue(int)));
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
@ -54,7 +55,7 @@ void MainWindow::refreshIPBtn() {
Logger::message("start refreshing Dynu IP."); Logger::message("start refreshing Dynu IP.");
appendLogField(""); appendLogField("");
appendLogField("start refreshing Dynu IP."); appendLogField("start refreshing Dynu IP.");
new std::thread([this](){ new std::thread([this]() {
IPRefresher ipr; IPRefresher ipr;
if (Config::readConfig()) { if (Config::readConfig()) {
ipr.checkIPAdress(false); ipr.checkIPAdress(false);
@ -63,21 +64,6 @@ new std::thread([this](){
} }
Logger::message("Finished refreshing Dynu IP."); Logger::message("Finished refreshing Dynu IP.");
appendLogField("Finished refreshing Dynu IP."); this->appendLogField("Finished refreshing Dynu IP.");
delete this; });
});
// myThread = std::thread([this](){
// IPRefresher ipr;
// if (Config::readConfig()) {
// ipr.checkIPAdress(false);
// } else {
// std::cout << "incorrect credentials!" << std::endl;
// }
//
// Logger::message("Finished refreshing Dynu IP.");
// appendLogField("Finished refreshing Dynu IP.");
// ui->textLog->appendPlainText("Finished refreshing Dynu IP.");
// });
} }

View File

@ -4,29 +4,29 @@
#pragma once #pragma once
#include <thread>
#include <QtWidgets/QMainWindow> #include <QtWidgets/QMainWindow>
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
} }
class MainWindow : public QMainWindow{ class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QWidget *parent = nullptr); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
std::thread myThread;
private slots: private slots:
// void startdownloadBtn();
void checkConfigBtn(); void checkConfigBtn();
void refreshIPBtn();
void refreshIPBtn();
signals: signals:
void appendLogField(QString); void appendLogField(QString);
// void setInfoLabelText(QString);
// void setProgressBarValue(int);
}; };

View File

@ -8,6 +8,7 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
std::cout << "gui here!" << std::endl; std::cout << "gui here!" << std::endl;
QCoreApplication::addLibraryPath(".");
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;