Web API: have /sdrangel/deviceset/{deviceSetIndex}/device/settings URL in its own right

This commit is contained in:
f4exb 2017-12-06 22:08:34 +01:00
parent fc4627f82e
commit f9794c7701
16 changed files with 1989 additions and 2169 deletions

View File

@ -1,5 +1,7 @@
project(filesource)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(filesource_SOURCES
filesourcegui.cpp
filesourceinput.cpp

File diff suppressed because it is too large Load Diff

View File

@ -30,3 +30,4 @@ QString WebAPIAdapterInterface::instanceDeviceSetsURL = "/sdrangel/devicesets";
std::regex WebAPIAdapterInterface::devicesetURLRe("^/sdrangel/deviceset/([0-9]{1,2})$");
std::regex WebAPIAdapterInterface::devicesetDeviceURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device$");
std::regex WebAPIAdapterInterface::devicesetDeviceSettingsURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device/settings$");

View File

@ -217,7 +217,7 @@ public:
{ return 501; }
/**
* Handler of /sdrangel/devicesets (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* Handler of /sdrangel/deviceset/{devicesetIndex} (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented)
*/
virtual int devicesetGet(
@ -237,10 +237,10 @@ public:
{ return 501; }
/**
* Handler of /sdrangel/deviceset/{devicesetIndex}/device (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* Handler of /sdrangel/deviceset/{devicesetIndex}/device/settings (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented)
*/
virtual int devicesetDeviceGet(
virtual int devicesetDeviceSettingsGet(
int deviceSetIndex __attribute__((unused)),
SWGSDRangel::SWGDeviceSettings& response __attribute__((unused)),
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
@ -257,6 +257,7 @@ public:
static QString instanceDeviceSetsURL;
static std::regex devicesetURLRe;
static std::regex devicesetDeviceURLRe;
static std::regex devicesetDeviceSettingsURLRe;
};

View File

@ -90,6 +90,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
devicesetService(std::string(desc_match[1]), request, response);
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceURLRe)) {
devicesetDeviceService(std::string(desc_match[1]), request, response);
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceSettingsURLRe)) {
devicesetDeviceSettingsService(std::string(desc_match[1]), request, response);
}
else
{
@ -601,15 +603,40 @@ void WebAPIRequestMapper::devicesetDeviceService(const std::string& indexStr, qt
}
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
catch (const boost::bad_lexical_cast &e)
{
errorResponse.init();
*errorResponse.getMessage() = "Wrong integer conversion on device set index";
response.setStatus(400,"Invalid data");
response.write(errorResponse.asJson().toUtf8());
}
}
void WebAPIRequestMapper::devicesetDeviceSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
SWGSDRangel::SWGErrorResponse errorResponse;
try
{
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
if (request.getMethod() == "PUT")
{
}
else if (request.getMethod() == "PATCH")
{
}
else if (request.getMethod() == "GET")
{
SWGSDRangel::SWGDeviceSettings normalResponse;
normalResponse.cleanup();
normalResponse.setFileSourceSettings(0);
normalResponse.setRtlSdrSettings(0);
normalResponse.setLimeSdrInputSettings(0);
normalResponse.setLimeSdrOutputSettings(0);
int status = m_adapter->devicesetDeviceGet(deviceSetIndex, normalResponse, errorResponse);
resetDeviceSettings(normalResponse);
int status = m_adapter->devicesetDeviceSettingsGet(deviceSetIndex, normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
@ -682,4 +709,12 @@ bool WebAPIRequestMapper::validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifi
return (presetIdentifier.getGroupName() && presetIdentifier.getName() && presetIdentifier.getType());
}
void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings)
{
deviceSettings.cleanup();
deviceSettings.setFileSourceSettings(0);
deviceSettings.setRtlSdrSettings(0);
deviceSettings.setLimeSdrInputSettings(0);
deviceSettings.setLimeSdrOutputSettings(0);
}

View File

@ -57,11 +57,14 @@ private:
void devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void devicesetDeviceSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer);
bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
bool parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response);
void resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings);
};
#endif /* SDRBASE_WEBAPI_WEBAPIREQUESTMAPPER_H_ */

View File

@ -694,7 +694,7 @@ int WebAPIAdapterGUI::devicesetDevicePut(
}
}
int WebAPIAdapterGUI::devicesetDeviceGet(
int WebAPIAdapterGUI::devicesetDeviceSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error)

View File

@ -120,7 +120,7 @@ public:
SWGSDRangel::SWGDeviceListItem& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceGet(
virtual int devicesetDeviceSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error);

View File

@ -530,9 +530,11 @@ paths:
$ref: "#/definitions/ErrorResponse"
"501":
description: Function not implemented
/sdrangel/deviceset/{deviceSetIndex}/device/settings:
x-swagger-router-controller: deviceset
get:
description: Get device settings
operationId: devicesetDeviceGet
operationId: devicesetDeviceSettingsGet
tags:
- DeviceSet
parameters:
@ -569,8 +571,6 @@ definitions:
$ref: "#/definitions/LoggingInfo"
devicesetlist:
$ref: "#/definitions/DeviceSetList"
user:
$ref: "http://localhost:8081/User.yaml#/User"
InstanceDevicesResponse:
description: "Summarized information about logical devices from hardware devices attached to this SDRangel instance"
required:

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ SWGDeviceSetApi::SWGDeviceSetApi(QString host, QString basePath) {
void
SWGDeviceSetApi::devicesetDeviceGet(qint32 device_set_index) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/sdrangel/deviceset/{deviceSetIndex}/device");
fullPath.append(this->host).append(this->basePath).append("/sdrangel/deviceset/{deviceSetIndex}/device/settings");
QString device_set_indexPathParam("{"); device_set_indexPathParam.append("deviceSetIndex").append("}");
fullPath.replace(device_set_indexPathParam, stringValue(device_set_index));

View File

@ -40,7 +40,6 @@ SWGInstanceSummaryResponse::init() {
version = new QString("");
logging = new SWGLoggingInfo();
devicesetlist = new SWGDeviceSetList();
user = new SWGUser();
}
void
@ -57,10 +56,6 @@ SWGInstanceSummaryResponse::cleanup() {
if(devicesetlist != nullptr) {
delete devicesetlist;
}
if(user != nullptr) {
delete user;
}
}
SWGInstanceSummaryResponse*
@ -77,7 +72,6 @@ SWGInstanceSummaryResponse::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&version, pJson["version"], "QString", "QString");
::SWGSDRangel::setValue(&logging, pJson["logging"], "SWGLoggingInfo", "SWGLoggingInfo");
::SWGSDRangel::setValue(&devicesetlist, pJson["devicesetlist"], "SWGDeviceSetList", "SWGDeviceSetList");
::SWGSDRangel::setValue(&user, pJson["user"], "SWGUser", "SWGUser");
}
QString
@ -100,8 +94,6 @@ SWGInstanceSummaryResponse::asJsonObject() {
toJsonValue(QString("devicesetlist"), devicesetlist, obj, QString("SWGDeviceSetList"));
toJsonValue(QString("user"), user, obj, QString("SWGUser"));
return obj;
}
@ -132,15 +124,6 @@ SWGInstanceSummaryResponse::setDevicesetlist(SWGDeviceSetList* devicesetlist) {
this->devicesetlist = devicesetlist;
}
SWGUser*
SWGInstanceSummaryResponse::getUser() {
return user;
}
void
SWGInstanceSummaryResponse::setUser(SWGUser* user) {
this->user = user;
}
}

View File

@ -24,7 +24,6 @@
#include "SWGDeviceSetList.h"
#include "SWGLoggingInfo.h"
#include "SWGUser.h"
#include <QString>
#include "SWGObject.h"
@ -54,15 +53,11 @@ public:
SWGDeviceSetList* getDevicesetlist();
void setDevicesetlist(SWGDeviceSetList* devicesetlist);
SWGUser* getUser();
void setUser(SWGUser* user);
private:
QString* version;
SWGLoggingInfo* logging;
SWGDeviceSetList* devicesetlist;
SWGUser* user;
};
}

View File

@ -41,7 +41,6 @@
#include "SWGPresets.h"
#include "SWGRtlSdrSettings.h"
#include "SWGSamplingDevice.h"
#include "SWGUser.h"
namespace SWGSDRangel {
@ -127,9 +126,6 @@ namespace SWGSDRangel {
if(QString("SWGSamplingDevice").compare(type) == 0) {
return new SWGSamplingDevice();
}
if(QString("SWGUser").compare(type) == 0) {
return new SWGUser();
}
return nullptr;
}

View File

@ -1,109 +0,0 @@
/**
* SDRangel
* This is the web API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube
*
* OpenAPI spec version: 4.0.0
* Contact: f4exb06@gmail.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
#include "SWGUser.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace SWGSDRangel {
SWGUser::SWGUser(QString* json) {
init();
this->fromJson(*json);
}
SWGUser::SWGUser() {
init();
}
SWGUser::~SWGUser() {
this->cleanup();
}
void
SWGUser::init() {
index = 0;
name = new QString("");
}
void
SWGUser::cleanup() {
if(name != nullptr) {
delete name;
}
}
SWGUser*
SWGUser::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGUser::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&index, pJson["index"], "qint32", "");
::SWGSDRangel::setValue(&name, pJson["name"], "QString", "QString");
}
QString
SWGUser::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject*
SWGUser::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("index", QJsonValue(index));
toJsonValue(QString("name"), name, obj, QString("QString"));
return obj;
}
qint32
SWGUser::getIndex() {
return index;
}
void
SWGUser::setIndex(qint32 index) {
this->index = index;
}
QString*
SWGUser::getName() {
return name;
}
void
SWGUser::setName(QString* name) {
this->name = name;
}
}

View File

@ -1,59 +0,0 @@
/**
* SDRangel
* This is the web API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube
*
* OpenAPI spec version: 4.0.0
* Contact: f4exb06@gmail.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
/*
* SWGUser.h
*
*
*/
#ifndef SWGUser_H_
#define SWGUser_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
namespace SWGSDRangel {
class SWGUser: public SWGObject {
public:
SWGUser();
SWGUser(QString* json);
virtual ~SWGUser();
void init();
void cleanup();
QString asJson ();
QJsonObject* asJsonObject();
void fromJsonObject(QJsonObject &json);
SWGUser* fromJson(QString &jsonString);
qint32 getIndex();
void setIndex(qint32 index);
QString* getName();
void setName(QString* name);
private:
qint32 index;
QString* name;
};
}
#endif /* SWGUser_H_ */