1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00

Created web API adapter for he main window

This commit is contained in:
f4exb 2017-11-18 19:34:47 +01:00
parent 9fe66f960c
commit 93d36b20a4
11 changed files with 153 additions and 7 deletions

View File

@ -65,6 +65,7 @@ set(sdrbase_SOURCES
plugin/pluginapi.cpp
plugin/pluginmanager.cpp
webapi/webapiadapterinterface.cpp
webapi/webapirequestmapper.cpp
webapi/webapiserver.cpp
@ -240,6 +241,7 @@ include_directories(
target_link_libraries(sdrbase
${QT_LIBRARIES}
httpserver
swagger
)
if(FFTW3F_FOUND)

View File

@ -105,6 +105,7 @@ SOURCES += audio/audiodeviceinfo.cpp\
plugin/plugininterface.cpp\
plugin/pluginapi.cpp\
plugin/pluginmanager.cpp\
webapi/webapiadapterinterface.cpp\
webapi/webapirequestmapper.cpp\
webapi/webapiserver.cpp\
mainparser.cpp

View File

@ -0,0 +1,22 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "webapiadapterinterface.h"
QString WebAPIAdapterInterface::instanceSummaryURL = "/sdrangel";

View File

@ -19,9 +19,13 @@
#ifndef SDRBASE_WEBAPI_WEBAPIADAPTERINTERFACE_H_
#define SDRBASE_WEBAPI_WEBAPIADAPTERINTERFACE_H_
#include "SWGInstanceSummaryResponse.h"
#include "SWGErrorResponse.h"
#include "SWGErrorResponse.h"
#include <QString>
namespace Swagger
{
class SWGInstanceSummaryResponse;
class SWGErrorResponse;
}
class WebAPIAdapterInterface
{
@ -36,6 +40,8 @@ public:
Swagger::SWGInstanceSummaryResponse& response __attribute__((unused)),
Swagger::SWGErrorResponse& error __attribute__((unused)))
{ return 501; }
static QString instanceSummaryURL;
};

View File

@ -17,25 +17,39 @@
///////////////////////////////////////////////////////////////////////////////////
#include "webapirequestmapper.h"
#include "SWGInstanceSummaryResponse.h"
#include "SWGErrorResponse.h"
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
HttpRequestHandler(parent),
m_adapter(0)
{ }
void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response __attribute__((unused)))
void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
if (m_adapter == 0) // format service unavailable if adapter is null
{
response.write("Service not available");
response.setStatus(500,"Service not available");
}
else // normal processing
{
QByteArray path=request.getPath();
if (path == "/sdrangel")
if (path == WebAPIAdapterInterface::instanceSummaryURL)
{
Swagger::SWGInstanceSummaryResponse normalResponse;
Swagger::SWGErrorResponse errorResponse;
int status = m_adapter->instanceSummary(normalResponse, errorResponse);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
response.setStatus(status);
}
else
{

View File

@ -47,6 +47,8 @@ set(sdrgui_SOURCES
dsp/spectrumscopengcombovis.cpp
device/deviceuiset.cpp
webapi/webapiadaptergui.cpp
)
set(sdrgui_HEADERS
@ -96,6 +98,8 @@ set(sdrgui_HEADERS
dsp/spectrumscopengcombovis.h
device/deviceuiset.h
webapi/webapiadaptergui.h
)
set(sdrgui_SOURCES

View File

@ -54,6 +54,7 @@
#include "loggerwithfile.h"
#include "webapi/webapirequestmapper.h"
#include "webapi/webapiserver.h"
#include "webapi/webapiadaptergui.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
@ -197,7 +198,9 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse
connect(ui->tabInputsView, SIGNAL(currentChanged(int)), this, SLOT(tabInputViewIndexChanged()));
m_apiAdapter = new WebAPIAdapterGUI(*this);
m_requestMapper = new WebAPIRequestMapper(qApp);
m_requestMapper->setAdapter(m_apiAdapter);
m_apiServer = new WebAPIServer(parser.getServerAddress(), parser.getServerPort(), m_requestMapper);
m_apiServer->start();
@ -209,6 +212,7 @@ MainWindow::~MainWindow()
m_apiServer->stop();
delete m_apiServer;
delete m_requestMapper;
delete m_apiAdapter;
delete m_pluginManager;
delete m_dateTimeWidget;

View File

@ -52,6 +52,7 @@ class PluginInterface;
class QWidget;
class WebAPIRequestMapper;
class WebAPIServer;
class WebAPIAdapterGUI;
namespace qtwebapp {
class LoggerWithFile;
@ -79,6 +80,8 @@ public:
const QTimer& getMasterTimer() const { return m_masterTimer; }
const MainSettings& getMainSettings() const { return m_settings; }
friend class WebAPIAdapterGUI;
private:
enum {
PGroup,
@ -121,6 +124,7 @@ private:
WebAPIRequestMapper *m_requestMapper;
WebAPIServer *m_apiServer;
WebAPIAdapterGUI *m_apiAdapter;
void loadSettings();
void loadPresetSettings(const Preset* preset, int tabIndex);

View File

@ -76,7 +76,8 @@ SOURCES += mainwindow.cpp\
gui/transverterbutton.cpp\
gui/transverterdialog.cpp\
gui/valuedial.cpp\
gui/valuedialz.cpp
gui/valuedialz.cpp\
webapi/webapiadapergui.cpp
HEADERS += mainwindow.h\
device/devicesourceapi.h\
@ -121,7 +122,8 @@ HEADERS += mainwindow.h\
gui/transverterbutton.h\
gui/transverterdialog.h\
gui/valuedial.h\
gui/valuedialz.h
gui/valuedialz.h\
webapi/webapiadapergui.h
FORMS += mainwindow.ui\
gui/scopewindow.ui\

View File

@ -0,0 +1,47 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 <QApplication>
#include "mainwindow.h"
#include "webapiadaptergui.h"
#include "SWGInstanceSummaryResponse.h"
#include "SWGErrorResponse.h"
WebAPIAdapterGUI::WebAPIAdapterGUI(MainWindow& mainWindow) :
m_mainWindow(mainWindow)
{
}
WebAPIAdapterGUI::~WebAPIAdapterGUI()
{
}
int WebAPIAdapterGUI::instanceSummary(
Swagger::SWGInstanceSummaryResponse& response,
Swagger::SWGErrorResponse& error __attribute__((unused)))
{
*response.getVersion() = qApp->applicationVersion();
Swagger::SWGDeviceSetList *deviceSetList = response.getDevicesetlist();
deviceSetList->setDevicesetcount(0);
return 200;
}

View File

@ -0,0 +1,40 @@
///////////////////////////////////////////////////////////////////////////////////
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRGUI_WEBAPI_WEBAPIADAPTERGUI_H_
#define SDRGUI_WEBAPI_WEBAPIADAPTERGUI_H_
#include "webapi/webapiadapterinterface.h"
class MainWindow;
class WebAPIAdapterGUI: public WebAPIAdapterInterface
{
public:
WebAPIAdapterGUI(MainWindow& mainWindow);
virtual ~WebAPIAdapterGUI();
virtual int instanceSummary(
Swagger::SWGInstanceSummaryResponse& response,
Swagger::SWGErrorResponse& error);
private:
MainWindow& m_mainWindow;
};
#endif /* SDRGUI_WEBAPI_WEBAPIADAPTERGUI_H_ */