mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-31 13:00:26 -04:00 
			
		
		
		
	Created web API adapter for he main window
This commit is contained in:
		
							parent
							
								
									9fe66f960c
								
							
						
					
					
						commit
						93d36b20a4
					
				| @ -65,6 +65,7 @@ set(sdrbase_SOURCES | |||||||
|     plugin/pluginapi.cpp |     plugin/pluginapi.cpp | ||||||
|     plugin/pluginmanager.cpp |     plugin/pluginmanager.cpp | ||||||
|      |      | ||||||
|  |     webapi/webapiadapterinterface.cpp | ||||||
|     webapi/webapirequestmapper.cpp |     webapi/webapirequestmapper.cpp | ||||||
|     webapi/webapiserver.cpp |     webapi/webapiserver.cpp | ||||||
|      |      | ||||||
| @ -240,6 +241,7 @@ include_directories( | |||||||
| target_link_libraries(sdrbase | target_link_libraries(sdrbase | ||||||
|     ${QT_LIBRARIES} |     ${QT_LIBRARIES} | ||||||
|     httpserver |     httpserver | ||||||
|  |     swagger | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| if(FFTW3F_FOUND) | if(FFTW3F_FOUND) | ||||||
|  | |||||||
| @ -105,6 +105,7 @@ SOURCES += audio/audiodeviceinfo.cpp\ | |||||||
|         plugin/plugininterface.cpp\ |         plugin/plugininterface.cpp\ | ||||||
|         plugin/pluginapi.cpp\         |         plugin/pluginapi.cpp\         | ||||||
|         plugin/pluginmanager.cpp\ |         plugin/pluginmanager.cpp\ | ||||||
|  |         webapi/webapiadapterinterface.cpp\ | ||||||
|         webapi/webapirequestmapper.cpp\ |         webapi/webapirequestmapper.cpp\ | ||||||
|         webapi/webapiserver.cpp\ |         webapi/webapiserver.cpp\ | ||||||
|         mainparser.cpp |         mainparser.cpp | ||||||
|  | |||||||
							
								
								
									
										22
									
								
								sdrbase/webapi/webapiadapterinterface.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								sdrbase/webapi/webapiadapterinterface.cpp
									
									
									
									
									
										Normal 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"; | ||||||
|  | 
 | ||||||
| @ -19,9 +19,13 @@ | |||||||
| #ifndef SDRBASE_WEBAPI_WEBAPIADAPTERINTERFACE_H_ | #ifndef SDRBASE_WEBAPI_WEBAPIADAPTERINTERFACE_H_ | ||||||
| #define SDRBASE_WEBAPI_WEBAPIADAPTERINTERFACE_H_ | #define SDRBASE_WEBAPI_WEBAPIADAPTERINTERFACE_H_ | ||||||
| 
 | 
 | ||||||
| #include "SWGInstanceSummaryResponse.h" | #include <QString> | ||||||
| #include "SWGErrorResponse.h" | 
 | ||||||
| #include "SWGErrorResponse.h" | namespace Swagger | ||||||
|  | { | ||||||
|  |     class SWGInstanceSummaryResponse; | ||||||
|  |     class SWGErrorResponse; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| class WebAPIAdapterInterface | class WebAPIAdapterInterface | ||||||
| { | { | ||||||
| @ -36,6 +40,8 @@ public: | |||||||
|             Swagger::SWGInstanceSummaryResponse& response __attribute__((unused)), |             Swagger::SWGInstanceSummaryResponse& response __attribute__((unused)), | ||||||
|             Swagger::SWGErrorResponse& error __attribute__((unused))) |             Swagger::SWGErrorResponse& error __attribute__((unused))) | ||||||
|     { return 501; } |     { return 501; } | ||||||
|  | 
 | ||||||
|  |     static QString instanceSummaryURL; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,25 +17,39 @@ | |||||||
| ///////////////////////////////////////////////////////////////////////////////////
 | ///////////////////////////////////////////////////////////////////////////////////
 | ||||||
| 
 | 
 | ||||||
| #include "webapirequestmapper.h" | #include "webapirequestmapper.h" | ||||||
|  | #include "SWGInstanceSummaryResponse.h" | ||||||
|  | #include "SWGErrorResponse.h" | ||||||
| 
 | 
 | ||||||
| WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) : | WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) : | ||||||
|     HttpRequestHandler(parent), |     HttpRequestHandler(parent), | ||||||
|     m_adapter(0) |     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
 |     if (m_adapter == 0) // format service unavailable if adapter is null
 | ||||||
|     { |     { | ||||||
|  |         response.write("Service not available"); | ||||||
|         response.setStatus(500,"Service not available"); |         response.setStatus(500,"Service not available"); | ||||||
|     } |     } | ||||||
|     else // normal processing
 |     else // normal processing
 | ||||||
|     { |     { | ||||||
|         QByteArray path=request.getPath(); |         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 |         else | ||||||
|         { |         { | ||||||
|  | |||||||
| @ -47,6 +47,8 @@ set(sdrgui_SOURCES | |||||||
|     dsp/spectrumscopengcombovis.cpp |     dsp/spectrumscopengcombovis.cpp | ||||||
|      |      | ||||||
|     device/deviceuiset.cpp |     device/deviceuiset.cpp | ||||||
|  |      | ||||||
|  |     webapi/webapiadaptergui.cpp | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| set(sdrgui_HEADERS | set(sdrgui_HEADERS | ||||||
| @ -96,6 +98,8 @@ set(sdrgui_HEADERS | |||||||
|     dsp/spectrumscopengcombovis.h |     dsp/spectrumscopengcombovis.h | ||||||
|      |      | ||||||
|     device/deviceuiset.h |     device/deviceuiset.h | ||||||
|  |      | ||||||
|  |     webapi/webapiadaptergui.h | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| set(sdrgui_SOURCES | set(sdrgui_SOURCES | ||||||
|  | |||||||
| @ -54,6 +54,7 @@ | |||||||
| #include "loggerwithfile.h" | #include "loggerwithfile.h" | ||||||
| #include "webapi/webapirequestmapper.h" | #include "webapi/webapirequestmapper.h" | ||||||
| #include "webapi/webapiserver.h" | #include "webapi/webapiserver.h" | ||||||
|  | #include "webapi/webapiadaptergui.h" | ||||||
| 
 | 
 | ||||||
| #include "mainwindow.h" | #include "mainwindow.h" | ||||||
| #include "ui_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())); | 	connect(ui->tabInputsView, SIGNAL(currentChanged(int)), this, SLOT(tabInputViewIndexChanged())); | ||||||
| 
 | 
 | ||||||
|  | 	m_apiAdapter = new WebAPIAdapterGUI(*this); | ||||||
| 	m_requestMapper = new WebAPIRequestMapper(qApp); | 	m_requestMapper = new WebAPIRequestMapper(qApp); | ||||||
|  | 	m_requestMapper->setAdapter(m_apiAdapter); | ||||||
| 	m_apiServer = new WebAPIServer(parser.getServerAddress(), parser.getServerPort(), m_requestMapper); | 	m_apiServer = new WebAPIServer(parser.getServerAddress(), parser.getServerPort(), m_requestMapper); | ||||||
| 	m_apiServer->start(); | 	m_apiServer->start(); | ||||||
| 
 | 
 | ||||||
| @ -209,6 +212,7 @@ MainWindow::~MainWindow() | |||||||
|     m_apiServer->stop(); |     m_apiServer->stop(); | ||||||
|     delete m_apiServer; |     delete m_apiServer; | ||||||
|     delete m_requestMapper; |     delete m_requestMapper; | ||||||
|  |     delete m_apiAdapter; | ||||||
| 
 | 
 | ||||||
|     delete m_pluginManager; |     delete m_pluginManager; | ||||||
| 	delete m_dateTimeWidget; | 	delete m_dateTimeWidget; | ||||||
|  | |||||||
| @ -52,6 +52,7 @@ class PluginInterface; | |||||||
| class QWidget; | class QWidget; | ||||||
| class WebAPIRequestMapper; | class WebAPIRequestMapper; | ||||||
| class WebAPIServer; | class WebAPIServer; | ||||||
|  | class WebAPIAdapterGUI; | ||||||
| 
 | 
 | ||||||
| namespace qtwebapp { | namespace qtwebapp { | ||||||
|     class LoggerWithFile; |     class LoggerWithFile; | ||||||
| @ -79,6 +80,8 @@ public: | |||||||
| 	const QTimer& getMasterTimer() const { return m_masterTimer; } | 	const QTimer& getMasterTimer() const { return m_masterTimer; } | ||||||
| 	const MainSettings& getMainSettings() const { return m_settings; } | 	const MainSettings& getMainSettings() const { return m_settings; } | ||||||
| 
 | 
 | ||||||
|  | 	friend class WebAPIAdapterGUI; | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
| 	enum { | 	enum { | ||||||
| 		PGroup, | 		PGroup, | ||||||
| @ -121,6 +124,7 @@ private: | |||||||
| 
 | 
 | ||||||
| 	WebAPIRequestMapper *m_requestMapper; | 	WebAPIRequestMapper *m_requestMapper; | ||||||
| 	WebAPIServer *m_apiServer; | 	WebAPIServer *m_apiServer; | ||||||
|  | 	WebAPIAdapterGUI *m_apiAdapter; | ||||||
| 
 | 
 | ||||||
| 	void loadSettings(); | 	void loadSettings(); | ||||||
| 	void loadPresetSettings(const Preset* preset, int tabIndex); | 	void loadPresetSettings(const Preset* preset, int tabIndex); | ||||||
|  | |||||||
| @ -76,7 +76,8 @@ SOURCES += mainwindow.cpp\ | |||||||
|         gui/transverterbutton.cpp\ |         gui/transverterbutton.cpp\ | ||||||
|         gui/transverterdialog.cpp\ |         gui/transverterdialog.cpp\ | ||||||
|         gui/valuedial.cpp\ |         gui/valuedial.cpp\ | ||||||
|         gui/valuedialz.cpp |         gui/valuedialz.cpp\ | ||||||
|  |         webapi/webapiadapergui.cpp | ||||||
| 
 | 
 | ||||||
| HEADERS  += mainwindow.h\ | HEADERS  += mainwindow.h\ | ||||||
|         device/devicesourceapi.h\ |         device/devicesourceapi.h\ | ||||||
| @ -121,7 +122,8 @@ HEADERS  += mainwindow.h\ | |||||||
|         gui/transverterbutton.h\ |         gui/transverterbutton.h\ | ||||||
|         gui/transverterdialog.h\ |         gui/transverterdialog.h\ | ||||||
|         gui/valuedial.h\ |         gui/valuedial.h\ | ||||||
|         gui/valuedialz.h |         gui/valuedialz.h\ | ||||||
|  |         webapi/webapiadapergui.h | ||||||
| 
 | 
 | ||||||
| FORMS    += mainwindow.ui\ | FORMS    += mainwindow.ui\ | ||||||
|         gui/scopewindow.ui\ |         gui/scopewindow.ui\ | ||||||
|  | |||||||
							
								
								
									
										47
									
								
								sdrgui/webapi/webapiadaptergui.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								sdrgui/webapi/webapiadaptergui.cpp
									
									
									
									
									
										Normal 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; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
							
								
								
									
										40
									
								
								sdrgui/webapi/webapiadaptergui.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								sdrgui/webapi/webapiadaptergui.h
									
									
									
									
									
										Normal 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_ */ | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user