From d82886f3a15b0b86fb6e0f1914ebc4865a2a1b46 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Tue, 22 Apr 2025 09:20:27 +0200 Subject: [PATCH] server implemented but not tested --- server/simulator_base.hpp | 6 ++++++ server/simulators.cpp | 22 ++++++++++++++++++++++ server/simulators/can_debugger.cpp | 2 ++ server/simulators/test_sim.cpp | 2 ++ 4 files changed, 32 insertions(+) diff --git a/server/simulator_base.hpp b/server/simulator_base.hpp index 10cb382..d221cba 100644 --- a/server/simulator_base.hpp +++ b/server/simulator_base.hpp @@ -8,6 +8,12 @@ #include #define PUSH_UI_ITEM(item) push_ui_item(&item) +#define EXPORT_SIM(sim) \ + extern "C" Q_DECL_EXPORT Simulator_base *get_ui(Communication *com, QObject *parent) \ + { \ + return new sim(com, parent); \ + } + struct Communication { CAN_Wrapper *c_if1 = nullptr; diff --git a/server/simulators.cpp b/server/simulators.cpp index 8da1c17..768aacd 100644 --- a/server/simulators.cpp +++ b/server/simulators.cpp @@ -1,6 +1,10 @@ #include "simulators.hpp" +#include +#include #include +typedef Simulator_base *(*Get_Sim)(Communication *, QObject *); + Simulators::Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject *parent) : QObject(parent), m_server_thread(new QThread), m_server(new Websocket(port, nullptr)), m_can_wrapper(new CAN_Wrapper(new CAN_Interface(this), this)), m_serial(new QSerialPort(this)) @@ -28,6 +32,24 @@ Simulators::Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject m_com.c_if1 = m_can_wrapper; m_com.s_if1 = m_serial; + QLibrary lib; + QDirIterator it(QCoreApplication::applicationDirPath(), QStringList() << "*.so" << "*.dll", QDir::Files, + QDirIterator::Subdirectories); + while (it.hasNext()) + { + lib.setFileName(it.next()); + lib.load(); + auto loaded_ui = Get_Sim(lib.resolve("get_sim")); + if (loaded_ui == nullptr) + { + SPDLOG_INFO("{} NOT FOUND", lib.fileName().toStdString()); + continue; + } + auto widget = loaded_ui(&m_com, this); + m_simulators.insert(std::make_pair(widget->name(), widget)); + lib.unload(); + } + // Insert Debug sims here // INSERT_SIMULATOR(TEST_SIM); diff --git a/server/simulators/can_debugger.cpp b/server/simulators/can_debugger.cpp index 2fcfcac..30f20a2 100644 --- a/server/simulators/can_debugger.cpp +++ b/server/simulators/can_debugger.cpp @@ -1,5 +1,7 @@ #include "can_debugger.hpp" +EXPORT_SIM(Can_Debugger); + Can_Debugger::Can_Debugger(Communication *com, QObject *parent) : Simulator_base("Can Debugger", com, std::chrono::milliseconds(100), parent), m_wrapper(com->c_if1), m_can_ui(Color::Black, Color::White) diff --git a/server/simulators/test_sim.cpp b/server/simulators/test_sim.cpp index 96548f1..f6c0f85 100644 --- a/server/simulators/test_sim.cpp +++ b/server/simulators/test_sim.cpp @@ -1,5 +1,7 @@ #include "test_sim.hpp" +EXPORT_SIM(Test_Sim); + Test_Sim::Test_Sim(Communication *com, QObject *parent) : Simulator_base("Test Sim", com, std::chrono::milliseconds(1000), parent), m_button("Off", Color::White, Color::Red),