diff --git a/sdrbase/CMakeLists.txt b/sdrbase/CMakeLists.txt
index 252b74352..a24a9ea45 100644
--- a/sdrbase/CMakeLists.txt
+++ b/sdrbase/CMakeLists.txt
@@ -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)
diff --git a/sdrbase/sdrbase.pro b/sdrbase/sdrbase.pro
index 87734b143..674194d16 100644
--- a/sdrbase/sdrbase.pro
+++ b/sdrbase/sdrbase.pro
@@ -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
diff --git a/sdrbase/webapi/webapiadapterinterface.cpp b/sdrbase/webapi/webapiadapterinterface.cpp
new file mode 100644
index 000000000..3a6204001
--- /dev/null
+++ b/sdrbase/webapi/webapiadapterinterface.cpp
@@ -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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#include "webapiadapterinterface.h"
+
+QString WebAPIAdapterInterface::instanceSummaryURL = "/sdrangel";
+
diff --git a/sdrbase/webapi/webapiadapterinterface.h b/sdrbase/webapi/webapiadapterinterface.h
index 37d71d76c..8a7126b60 100644
--- a/sdrbase/webapi/webapiadapterinterface.h
+++ b/sdrbase/webapi/webapiadapterinterface.h
@@ -19,9 +19,13 @@
#ifndef SDRBASE_WEBAPI_WEBAPIADAPTERINTERFACE_H_
#define SDRBASE_WEBAPI_WEBAPIADAPTERINTERFACE_H_
-#include "SWGInstanceSummaryResponse.h"
-#include "SWGErrorResponse.h"
-#include "SWGErrorResponse.h"
+#include
+
+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;
};
diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp
index 4950670e0..0e5f3c316 100644
--- a/sdrbase/webapi/webapirequestmapper.cpp
+++ b/sdrbase/webapi/webapirequestmapper.cpp
@@ -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
{
diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt
index 68aa53a3c..1e7f6c63c 100644
--- a/sdrgui/CMakeLists.txt
+++ b/sdrgui/CMakeLists.txt
@@ -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
diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp
index 307127abf..c9f73ff25 100644
--- a/sdrgui/mainwindow.cpp
+++ b/sdrgui/mainwindow.cpp
@@ -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;
diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h
index fde50beff..3ef892cc4 100644
--- a/sdrgui/mainwindow.h
+++ b/sdrgui/mainwindow.h
@@ -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);
diff --git a/sdrgui/sdrgui.pro b/sdrgui/sdrgui.pro
index d642d3e6b..c5807a13d 100644
--- a/sdrgui/sdrgui.pro
+++ b/sdrgui/sdrgui.pro
@@ -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\
diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp
new file mode 100644
index 000000000..195cabade
--- /dev/null
+++ b/sdrgui/webapi/webapiadaptergui.cpp
@@ -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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#include
+
+#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;
+}
+
+
diff --git a/sdrgui/webapi/webapiadaptergui.h b/sdrgui/webapi/webapiadaptergui.h
new file mode 100644
index 000000000..6b782d6a0
--- /dev/null
+++ b/sdrgui/webapi/webapiadaptergui.h
@@ -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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#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_ */