2017-12-17 05:09:51 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QDebug>
|
2017-12-17 17:15:42 -05:00
|
|
|
#include <unistd.h>
|
2017-12-17 05:09:51 -05:00
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2017-12-17 17:15:42 -05:00
|
|
|
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteInstance, Message)
|
|
|
|
|
2017-12-17 05:09:51 -05:00
|
|
|
MainCore *MainCore::m_instance = 0;
|
|
|
|
|
2017-12-17 06:08:18 -05:00
|
|
|
MainCore::MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QObject *parent) :
|
|
|
|
QObject(parent),
|
2017-12-17 05:09:51 -05:00
|
|
|
m_settings(),
|
|
|
|
m_masterTabIndex(-1),
|
|
|
|
m_dspEngine(DSPEngine::instance()),
|
|
|
|
m_lastEngineState((DSPDeviceSourceEngine::State)-1),
|
2017-12-17 18:00:21 -05:00
|
|
|
m_logger(logger)
|
2017-12-17 05:09:51 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2017-12-18 07:56:10 -05:00
|
|
|
loadSettings();
|
|
|
|
|
2017-12-17 05:09:51 -05:00
|
|
|
m_apiAdapter = new WebAPIAdapterSrv(*this);
|
2017-12-17 18:00:21 -05:00
|
|
|
m_requestMapper = new WebAPIRequestMapper(this);
|
2017-12-17 05:09:51 -05:00
|
|
|
m_requestMapper->setAdapter(m_apiAdapter);
|
|
|
|
m_apiServer = new WebAPIServer(parser.getServerAddress(), parser.getServerPort(), m_requestMapper);
|
|
|
|
m_apiServer->start();
|
|
|
|
|
|
|
|
qDebug() << "MainCore::MainCore: end";
|
|
|
|
}
|
|
|
|
|
|
|
|
MainCore::~MainCore()
|
|
|
|
{
|
2017-12-18 07:56:10 -05:00
|
|
|
m_apiServer->stop();
|
|
|
|
m_settings.save();
|
2017-12-17 05:09:51 -05:00
|
|
|
delete m_apiServer;
|
|
|
|
delete m_requestMapper;
|
|
|
|
delete m_apiAdapter;
|
|
|
|
|
|
|
|
delete m_pluginManager;
|
|
|
|
|
|
|
|
qDebug() << "MainCore::~MainCore: end";
|
|
|
|
delete m_logger;
|
|
|
|
}
|
2017-12-17 06:08:18 -05:00
|
|
|
|
2017-12-17 17:15:42 -05:00
|
|
|
bool MainCore::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
if (MsgDeleteInstance::match(cmd))
|
|
|
|
{
|
2017-12-17 18:00:21 -05:00
|
|
|
emit finished();
|
2017-12-17 17:15:42 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainCore::handleMessages()
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
|
|
|
{
|
|
|
|
qDebug("MainCore::handleMessages: message: %s", message->getIdentifier());
|
|
|
|
handleMessage(*message);
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:56:10 -05:00
|
|
|
void MainCore::loadSettings()
|
|
|
|
{
|
|
|
|
qDebug() << "MainCore::loadSettings";
|
|
|
|
|
|
|
|
m_settings.load();
|
|
|
|
m_settings.sortPresets();
|
|
|
|
setLoggingOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainCore::setLoggingOptions()
|
|
|
|
{
|
|
|
|
m_logger->setConsoleMinMessageLevel(m_settings.getConsoleMinLogLevel());
|
|
|
|
|
|
|
|
if (m_settings.getUseLogFile())
|
|
|
|
{
|
|
|
|
qtwebapp::FileLoggerSettings fileLoggerSettings; // default values
|
|
|
|
|
|
|
|
if (m_logger->hasFileLogger()) {
|
|
|
|
fileLoggerSettings = m_logger->getFileLoggerSettings(); // values from file logger if it exists
|
|
|
|
}
|
|
|
|
|
|
|
|
fileLoggerSettings.fileName = m_settings.getLogFileName(); // put new values
|
|
|
|
m_logger->createOrSetFileLogger(fileLoggerSettings, 2000); // create file logger if it does not exist and apply settings in any case
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_logger->hasFileLogger()) {
|
|
|
|
m_logger->setFileMinMessageLevel(m_settings.getFileMinLogLevel());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_logger->setUseFileLogger(m_settings.getUseLogFile());
|
|
|
|
}
|
|
|
|
|