From 361648a2b5d10f64aadc318aa1ed46fc131d6856 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 17 Dec 2017 12:08:18 +0100 Subject: [PATCH] Server: added a basic server application --- CMakeLists.txt | 28 +++++++++++++++++++++++ appsrv/main.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ sdrsrv/maincore.cpp | 11 ++++++++- sdrsrv/maincore.h | 8 ++++++- 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 appsrv/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 228a641af..ccb1e60a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,6 +205,9 @@ include_directories( ${OPENGL_INCLUDE_DIR} ) +############################################################################## +# main GUI application + set(sdrangel_SOURCES app/main.cpp ) @@ -236,6 +239,30 @@ endif(WIN32) qt5_use_modules(sdrangel Widgets Multimedia) +############################################################################## +# main server application + +set(sdrangelsrv_SOURCES + appsrv/main.cpp +) + +add_executable(sdrangelsrv + ${sdrangelsrv_SOURCES} +) + +target_include_directories(sdrangelsrv + PUBLIC ${CMAKE_SOURCE_DIR}/sdrsrv +) + +target_link_libraries(sdrangelsrv + sdrbase + sdrsrv + logging + ${QT_LIBRARIES} +) + +qt5_use_modules(sdrangelsrv Multimedia) + ############################################################################## if (BUILD_DEBIAN) @@ -265,6 +292,7 @@ endif(LIBUSB_FOUND AND UNIX) #install targets install(TARGETS sdrangel DESTINATION bin) +install(TARGETS sdrangelsrv DESTINATION bin) #install(TARGETS sdrbase DESTINATION lib) #install files and directories diff --git a/appsrv/main.cpp b/appsrv/main.cpp new file mode 100644 index 000000000..b93653781 --- /dev/null +++ b/appsrv/main.cpp @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB. // +// // +// Swagger server adapter interface // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "loggerwithfile.h" +#include "maincore.h" + + +static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *logger) +{ + QCoreApplication a(argc, argv); + + QCoreApplication::setOrganizationName("f4exb"); + QCoreApplication::setApplicationName("SDRangelSrv"); + QCoreApplication::setApplicationVersion("3.9.0"); + + MainParser parser; + parser.parse(a); + MainCore m(logger, parser, &a); + + // This will cause the application to exit when the main core is finished + QObject::connect(&m, SIGNAL(finished()), &a, SLOT(quit())); + + // This will run the main core from the application event loop. + QTimer::singleShot(0, &m, SLOT(run())); + + return a.exec(); +} + +int main(int argc, char* argv[]) +{ + qtwebapp::LoggerWithFile *logger = new qtwebapp::LoggerWithFile(qApp); + logger->installMsgHandler(); + int res = runQtApplication(argc, argv, logger); + qWarning("SDRangel quit."); + return res; +} + + diff --git a/sdrsrv/maincore.cpp b/sdrsrv/maincore.cpp index 16d7b3c9f..33c1ff610 100644 --- a/sdrsrv/maincore.cpp +++ b/sdrsrv/maincore.cpp @@ -30,7 +30,8 @@ MainCore *MainCore::m_instance = 0; -MainCore::MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser) : +MainCore::MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QObject *parent) : + QObject(parent), m_settings(), m_masterTabIndex(-1), m_dspEngine(DSPEngine::instance()), @@ -69,3 +70,11 @@ MainCore::~MainCore() qDebug() << "MainCore::~MainCore: end"; delete m_logger; } + +void MainCore::run() +{ + qDebug() << "MainCore::run: start"; + // TODO: the main loop is here + qDebug() << "MainCore::run: end"; + emit finished(); +} diff --git a/sdrsrv/maincore.h b/sdrsrv/maincore.h index ff8fa8412..12ed4ddd6 100644 --- a/sdrsrv/maincore.h +++ b/sdrsrv/maincore.h @@ -51,7 +51,7 @@ class SDRANGEL_API MainCore : public QObject { Q_OBJECT public: - explicit MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser); + explicit MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QObject *parent = 0); ~MainCore(); static MainCore *getInstance() { return m_instance; } // Main Core is de facto a singleton so this just returns its reference @@ -62,6 +62,12 @@ public: friend class WebAPIAdapterSrv; +public slots: + void run(); + +signals: + void finished(); + private: static MainCore *m_instance; MessageQueue m_inputMessageQueue;