From 22f174a2a48d53267d619b566156821803657afe Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 17 Dec 2017 11:09:51 +0100 Subject: [PATCH] Server: basic sdrsrv library --- CMakeLists.txt | 1 + sdrsrv/CMakeLists.txt | 48 ++++++++++++++++++++ sdrsrv/maincore.cpp | 71 ++++++++++++++++++++++++++++++ sdrsrv/maincore.h | 39 ++++++++++++++++ sdrsrv/webapi/webapiadaptersrv.cpp | 38 ++++++++++++++++ sdrsrv/webapi/webapiadaptersrv.h | 38 ++++++++++++++++ 6 files changed, 235 insertions(+) create mode 100644 sdrsrv/CMakeLists.txt create mode 100644 sdrsrv/maincore.cpp create mode 100644 sdrsrv/webapi/webapiadaptersrv.cpp create mode 100644 sdrsrv/webapi/webapiadaptersrv.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c7c4ae1e1..228a641af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fmax-errors=10 -ffast-mat # base libraries add_subdirectory(sdrbase) add_subdirectory(sdrgui) +add_subdirectory(sdrsrv) add_subdirectory(httpserver) add_subdirectory(logging) add_subdirectory(swagger) diff --git a/sdrsrv/CMakeLists.txt b/sdrsrv/CMakeLists.txt new file mode 100644 index 000000000..39aee2666 --- /dev/null +++ b/sdrsrv/CMakeLists.txt @@ -0,0 +1,48 @@ +project (sdrsrv) + +set(sdrsrv_SOURCES + maincore.cpp + webapi/webapiadaptersrv.cpp +) + +set(sdrsrv_HEADERS + maincore.h + webapi/webapiadaptersrv.h +) + +set(sdrsrv_SOURCES + ${sdrsrv_SOURCES} + ${sdrsrv_HEADERS} +) + +add_definitions(${QT_DEFINITIONS}) +add_definitions(-DQT_SHARED) + +add_library(sdrsrv SHARED + ${sdrsrv_SOURCES} + ${sdrsrv_HEADERS_MOC} +) + +include_directories( + . + ${CMAKE_SOURCE_DIR}/sdrbase + ${CMAKE_SOURCE_DIR}/logging + ${CMAKE_SOURCE_DIR}/httpserver + ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client + ${CMAKE_CURRENT_BINARY_DIR} + ${OPENGL_INCLUDE_DIR} +) + +target_link_libraries(sdrsrv + ${QT_LIBRARIES} + sdrbase + logging +) + +set_target_properties(sdrsrv PROPERTIES DEFINE_SYMBOL "sdrangel_EXPORTS") +target_compile_features(sdrsrv PRIVATE cxx_generalized_initializers) # cmake >= 3.1.0 + +qt5_use_modules(sdrsrv Core Multimedia) + +install(TARGETS sdrsrv DESTINATION lib) + diff --git a/sdrsrv/maincore.cpp b/sdrsrv/maincore.cpp new file mode 100644 index 000000000..16d7b3c9f --- /dev/null +++ b/sdrsrv/maincore.cpp @@ -0,0 +1,71 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 "dsp/dspengine.h" +#include "dsp/dspdevicesourceengine.h" +#include "plugin/pluginmanager.h" +#include "loggerwithfile.h" +#include "webapi/webapirequestmapper.h" +#include "webapi/webapiserver.h" +#include "webapi/webapiadaptersrv.h" + +#include "maincore.h" + +MainCore *MainCore::m_instance = 0; + +MainCore::MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser) : + m_settings(), + m_masterTabIndex(-1), + m_dspEngine(DSPEngine::instance()), + m_lastEngineState((DSPDeviceSourceEngine::State)-1), + m_logger(logger) +{ + qDebug() << "MainCore::MainCore: start"; + + m_instance = this; + m_settings.setAudioDeviceInfo(&m_audioDeviceInfo); + + m_pluginManager = new PluginManager(this); + m_pluginManager->loadPlugins(QString("pluginssrv")); + + connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleMessages()), Qt::QueuedConnection); + m_masterTimer.start(50); + + m_apiAdapter = new WebAPIAdapterSrv(*this); + m_requestMapper = new WebAPIRequestMapper(QCoreApplication::instance()); + m_requestMapper->setAdapter(m_apiAdapter); + m_apiServer = new WebAPIServer(parser.getServerAddress(), parser.getServerPort(), m_requestMapper); + m_apiServer->start(); + + qDebug() << "MainCore::MainCore: end"; +} + +MainCore::~MainCore() +{ + m_apiServer->stop(); + delete m_apiServer; + delete m_requestMapper; + delete m_apiAdapter; + + delete m_pluginManager; + + qDebug() << "MainCore::~MainCore: end"; + delete m_logger; +} diff --git a/sdrsrv/maincore.h b/sdrsrv/maincore.h index f1522a5f0..ff8fa8412 100644 --- a/sdrsrv/maincore.h +++ b/sdrsrv/maincore.h @@ -20,7 +20,13 @@ #define SDRSRV_MAINCORE_H_ #include +#include + +#include "settings/mainsettings.h" +#include "util/message.h" +#include "util/messagequeue.h" #include "util/export.h" +#include "mainparser.h" class AudioDeviceInfo; class DSPEngine; @@ -37,8 +43,41 @@ class WebAPIRequestMapper; class WebAPIServer; class WebAPIAdapterSrv; // TODO: create this class +namespace qtwebapp { + class LoggerWithFile; +} + class SDRANGEL_API MainCore : public QObject { Q_OBJECT + +public: + explicit MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser); + ~MainCore(); + static MainCore *getInstance() { return m_instance; } // Main Core is de facto a singleton so this just returns its reference + + MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; } + + const QTimer& getMasterTimer() const { return m_masterTimer; } + const MainSettings& getMainSettings() const { return m_settings; } + + friend class WebAPIAdapterSrv; + +private: + static MainCore *m_instance; + MessageQueue m_inputMessageQueue; + QTimer m_masterTimer; + MainSettings m_settings; + int m_masterTabIndex; + DSPEngine* m_dspEngine; + PluginManager* m_pluginManager; + int m_lastEngineState; + AudioDeviceInfo m_audioDeviceInfo; + + qtwebapp::LoggerWithFile *m_logger; + + WebAPIRequestMapper *m_requestMapper; + WebAPIServer *m_apiServer; + WebAPIAdapterSrv *m_apiAdapter; }; diff --git a/sdrsrv/webapi/webapiadaptersrv.cpp b/sdrsrv/webapi/webapiadaptersrv.cpp new file mode 100644 index 000000000..e259f8ddf --- /dev/null +++ b/sdrsrv/webapi/webapiadaptersrv.cpp @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 + +#include + +#include "maincore.h" + +#include "webapiadaptersrv.h" + +WebAPIAdapterSrv::WebAPIAdapterSrv(MainCore& mainCore) : + m_mainCore(mainCore) +{ +} + +WebAPIAdapterSrv::~WebAPIAdapterSrv() +{ +} + + + diff --git a/sdrsrv/webapi/webapiadaptersrv.h b/sdrsrv/webapi/webapiadaptersrv.h new file mode 100644 index 000000000..42260d7a2 --- /dev/null +++ b/sdrsrv/webapi/webapiadaptersrv.h @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRSRV_WEBAPI_WEBAPIADAPTERSRV_H_ +#define SDRSRV_WEBAPI_WEBAPIADAPTERSRV_H_ + +#include + +#include "webapi/webapiadapterinterface.h" + +class MainCore; + +class WebAPIAdapterSrv: public WebAPIAdapterInterface +{ +public: + WebAPIAdapterSrv(MainCore& mainCore); + virtual ~WebAPIAdapterSrv(); + +private: + MainCore& m_mainCore; +}; + +#endif /* SDRSRV_WEBAPI_WEBAPIADAPTERSRV_H_ */