From 9cc912b0a30e8b03b08ca9e315d804e6fa72ac31 Mon Sep 17 00:00:00 2001 From: unai_71 Date: Tue, 10 Mar 2026 18:50:32 +0000 Subject: [PATCH] feat: add app entry point and CMake target for Qt GUI app --- CMakeLists.txt | 9 ++++++++ src/app/main.cxx | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/app/main.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c77dc1..bc87918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,15 @@ add_library(core target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(core PUBLIC Qt5::Core) +# Main Application +add_executable(app + src/app/main.cxx + src/app/MainWindow.cxx + include/MainWindow.hpp +) +target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_link_libraries(app PRIVATE core Qt5::Widgets) + #tests enable_testing() add_subdirectory(tests) diff --git a/src/app/main.cxx b/src/app/main.cxx new file mode 100644 index 0000000..b533a86 --- /dev/null +++ b/src/app/main.cxx @@ -0,0 +1,58 @@ +// main.cxx +// SPDX-License-Identifier: GPL-3.0-or-later +// Author: Unai Blazquez + +#include +#include +#include +#include + +#include "Consumer.hpp" +#include "MainWindow.hpp" +#include "Producer.hpp" +#include "UnixIpcBridge.hpp" + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + const std::string socket_path = "/tmp/azkoyen.sock"; + const std::string sysfs_path = "./fake_sysfs_input"; + + // 1. Consumer — listens on the socket, emits Qt signal on receive + ConsumerThread consumer(socket_path); + + // 2. GUI — minimal window that displays received values + MainWindow window; + window.show(); + + // Connect consumer signal → window slot (auto-queued across threads, + // so the GUI never blocks even if the producer is stuck in cool-down) + QObject::connect(&consumer, &ConsumerThread::valueReceived, &window, + &MainWindow::onValueReceived); + + consumer.start(); + + // 3. Bridge — sends ints over the UNIX domain socket + UnixIpcBridge bridge(socket_path); + + // 4. Producer — reads sysfs, generates random int, sends via bridge. + // Logs to a file instead of console (console is for the consumer). + std::ofstream log_file("producer.log", std::ios::app); + + Producer producer( + sysfs_path, [&bridge](int value) { bridge.send(value); }, + []() { return std::rand() % 1000; }, + [&log_file](const std::string& msg) { log_file << msg << std::endl; }); + + producer.start(); + + // 5. Run the Qt event loop (GUI stays responsive, signals are delivered) + int result = app.exec(); + + // 6. Graceful shutdown + producer.stop(); + consumer.stop(); + + return result; +}